Loading solver…

CLP - simple linear program

Problem: choose values for two continuous variables that maximize profit while staying inside two linear resource limits.

Show code
import { MpModel, MPSolver } from 'or-tools-wasm/mp-solver';
const model = new MpModel('simple_lp');

// Same model as simple_lp_program.py, solved with CLP.
const x = model.addNumVariable(0, Infinity, 'x');
const y = model.addNumVariable(0, Infinity, 'y');
const c0 = model.addConstraint(-Infinity, 17.5);
c0.setCoefficient(x, 1);
c0.setCoefficient(y, 7);
const c1 = model.addConstraint(-Infinity, 3.5);
c1.setCoefficient(x, 1);
const objective = model.objective();
objective.setCoefficient(x, 1);
objective.setCoefficient(y, 10);
objective.setMaximization();

const result = await MPSolver.solve(model, {
  solverType: MPSolver.CLP_LINEAR_PROGRAMMING,
  executor: 'worker', threads: 4,
});
console.log(result.value(x), result.objectiveValue);

The simple_lp_program.py model solved with the COIN-OR CLP backend.

Model

  • The decision variables are continuous values for x and y.
  • The constraints limit the feasible region to a small polygon.
  • The objective maximizes a linear profit expression.
  • CLP solves the LP and returns the best feasible corner.
Run the solver to view the solution.

Status / Response: