Loading solver…
CBC - integer programming backend
Problem: choose integer values for two variables that maximize the objective while satisfying linear limits.
Show code
import { MPSolver } from 'or-tools-wasm/mp-solver';
const solver = MPSolver.createSolver('CBC');
if (!solver) throw new Error('CBC backend is unavailable');
solver.setNumThreads(4);
const x = solver.addIntVariable(0, solver.infinity(), 'x');
const y = solver.addIntVariable(0, solver.infinity(), 'y');
const c0 = solver.addConstraint(-solver.infinity(), 17.5);
c0.setCoefficient(x, 1);
c0.setCoefficient(y, 7);
const c1 = solver.addConstraint(-solver.infinity(), 3.5);
c1.setCoefficient(x, 1);
const objective = solver.objective();
objective.setCoefficient(x, 1);
objective.setCoefficient(y, 10);
objective.setMaximization();
const status = await solver.solve({ executor: 'worker' });
console.log(status, objective.value(), x.solutionValue(), y.solutionValue());
Direct port of simple_mip_program.py through the MPSolver CBC integer backend.
Model
- The decision variables are integer values for
xandy. - The linear constraints define which integer points are feasible.
- The objective maximizes a linear score over those feasible points.
- CBC searches the integer feasible set and returns the best assignment.
Run the solver to view the solution.
Status / Response: