GLOP - 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('GLOP');
if (!solver) throw new Error('GLOP is unavailable');
solver.SetNumThreads(4);

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();

Direct port of ortools/linear_solver/samples/simple_lp_program.py.

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.
  • GLOP solves the LP and returns the best feasible corner.
Run the solver to view the solution.

Status / Response: