Loading solver…

MPSolver — two choices

Problem: solve one small linear model through MPSolver while switching between available LP and integer backends.

MPSolver routes one tiny linear model through selectable backends. GLOP, CLP, and GLPK_LP solve it as a continuous LP; SAT, GLPK, SCIP, CBC, BOP, and Knapsack solve the same model with integral variables.

Model

  • Choose values for x and y without exceeding the shared capacity.
  • The objective rewards x twice as much as y.
  • Compare the answers from different solvers in the result table.
Advanced settings

Warm starts and callbacks

Solver settings

Solution

Run the solver to view the solution.
Solve log
Show code
const model = new MpModel('retained answers');
const retainedX = model.addNumVariable(0, 1, 'x');
model.objective().setCoefficient(retainedX, 2);
model.objective().setMaximization();
const session = model.incremental({
  solverType: MPSolver.GLOP_LINEAR_PROGRAMMING, executor: 'worker',
});
try {
  const first = await session.solve();
  retainedX.setUpperBound(0);
  const second = await session.solve();
  console.log(first.value(retainedX), second.value(retainedX)); // 1, 0
  console.log(second.solverVersion, second.iterations);
} finally {
  await session.close();
}