BOP - binary project selection
Problem: choose the most valuable set of binary projects without exceeding budget, engineering, or design capacity.
Show code
import { initMPSolver, MPSolver, setWorkerBridgeEnabled } from 'or-tools-wasm/mp-solver';
setWorkerBridgeEnabled(true);
await initMPSolver();
const solver = MPSolver.CreateSolver('BOP');
if (!solver) throw new Error('BOP backend is unavailable');
solver.SetNumThreads(4);
const projects = [
{ name: 'analytics', value: 82, budget: 36, engineering: 28, design: 8 },
{ name: 'mobile', value: 76, budget: 30, engineering: 18, design: 24 },
{ name: 'alerts', value: 58, budget: 18, engineering: 16, design: 6 },
];
const x = Object.fromEntries(projects.map((project) => [project.name, solver.BoolVar(project.name)]));
const budget = solver.Constraint(-solver.infinity(), 105, 'budget');
const engineering = solver.Constraint(-solver.infinity(), 92, 'engineering_team');
const design = solver.Constraint(-solver.infinity(), 48, 'design_team');
const objective = solver.Objective();
for (const project of projects) {
budget.SetCoefficient(x[project.name], project.budget);
engineering.SetCoefficient(x[project.name], project.engineering);
design.SetCoefficient(x[project.name], project.design);
objective.SetCoefficient(x[project.name], project.value);
}
objective.SetMaximization();
const status = await solver.Solve();
if (status !== MPSolver.OPTIMAL) throw new Error(`expected OPTIMAL, got ${status}`);
- Each project is a Boolean decision: pick it or leave it out.
- The objective maximizes total project value.
- Budget, engineering, and design are shared resources with upper bounds.
- The manual draft is interactive; the solver computes the best feasible portfolio from the same editable data.
Solve the BOP model to view the selected projects.
Status / Response: