CBC - integer programming backend

Problem: choose integer values for two variables that maximize the objective while satisfying linear limits.

Show code
import { initMPSolver, MPSolver, setWorkerBridgeEnabled } from 'or-tools-wasm/mp-solver';

setWorkerBridgeEnabled(true);
await initMPSolver();
const solver = MPSolver.CreateSolver('CBC');
if (!solver) throw new Error('CBC backend is unavailable');
solver.SetNumThreads(4);

const x = solver.IntVar(0, solver.infinity(), 'x');
const y = solver.IntVar(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();

const status = await solver.Solve();
console.log(status, objective.Value(), x.solution_value(), y.solution_value());

Direct port of simple_mip_program.py through the MPSolver CBC integer backend.

Model

  • The decision variables are integer values for x and y.
  • 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: