Skip to main content

reoptimize

Function reoptimize 

Source
pub fn reoptimize(
    previous: &Solution,
    problem: &Problem,
    options: &Options,
) -> Result<Solution, Error>
Expand description

Re-optimizes a solved problem after appending constraints to it, with the dual simplex.

problem must be previous.problem plus zero or more <= / >= constraints at the end, and previous must be optimal. The trace starts from the previous final tableau (without artificial columns) with the new rows added, each expressed in the current basis with its own slack basic (Step::ConstraintAdded), and continues with dual simplex pivots until the tableau is feasible again or a row proves the extended problem infeasible.

use simplex_trace::{reoptimize, solve, Method, Options, Problem, Relation, Status, ratio};

// TOYCO (Taha): max 3x1 + 2x2 + 5x3, optimal at z = 1350.
let toyco = Problem::maximize([3, 2, 5])
    .subject_to([1, 2, 1], Relation::Le, 430)
    .subject_to([3, 0, 2], Relation::Le, 460)
    .subject_to([1, 4, 0], Relation::Le, 420);
let first = solve(&toyco, Method::Simplex, &Options::default()).unwrap();

// A new constraint the current optimum violates: one dual pivot fixes it.
let extended = toyco.subject_to([3, 3, 1], Relation::Le, 500);
let second = reoptimize(&first, &extended, &Options::default()).unwrap();
assert_eq!(
    second.status,
    Status::Optimal { objective: ratio(1330, 1), values: vec![ratio(0, 1), ratio(90, 1), ratio(230, 1)] }
);
assert_eq!(second.trace.pivot_count(), 1);