CLP - simple linear program
Problem: choose values for two continuous variables that maximize profit while staying inside two linear resource limits.
Show code
import { initMPSolver, MPSolver, setWorkerBridgeEnabled } from 'or-tools-wasm/mp-solver';
setWorkerBridgeEnabled(true);
await initMPSolver();
const solver = MPSolver.CreateSolver('CLP');
if (!solver) throw new Error('CLP is unavailable');
solver.SetNumThreads(4);
// Same model as simple_lp_program.py, solved with CLP.
const x = solver.NumVar(0, solver.infinity(), 'x');
const y = solver.NumVar(0, solver.infinity(), 'y');
const c0 = solver.Constraint(-solver.infinity(), 17.5);
c0.SetCoefficient(x, 1);
c0.SetCoefficient(y, 7);
const c1 = solver.Constraint(-solver.infinity(), 3.5);
c1.SetCoefficient(x, 1);
const objective = solver.Objective();
objective.SetCoefficient(x, 1);
objective.SetCoefficient(y, 10);
objective.SetMaximization();
await solver.Solve();
The simple_lp_program.py model solved with the COIN-OR CLP backend.
Model
- The decision variables are continuous values for
xandy. - 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: