Loading solver…
GLOP - simple linear program
Problem: choose values for two continuous variables that maximize profit while staying inside two linear resource limits.
Show code
import { MpModel, MPSolver } from 'or-tools-wasm/mp-solver';
const model = new MpModel('simple_lp');
const x = model.addNumVariable(0, Infinity, 'x');
const y = model.addNumVariable(0, Infinity, 'y');
const c0 = model.addConstraint(-Infinity, 17.5);
c0.setCoefficient(x, 1);
c0.setCoefficient(y, 7);
const c1 = model.addConstraint(-Infinity, 3.5);
c1.setCoefficient(x, 1);
const objective = model.objective();
objective.setCoefficient(x, 1);
objective.setCoefficient(y, 10);
objective.setMaximization();
const result = await MPSolver.solve(model, {
solverType: MPSolver.GLOP_LINEAR_PROGRAMMING,
executor: 'worker', threads: 4,
});
console.log(result.value(x), result.objectiveValue);
Direct port of ortools/linear_solver/samples/simple_lp_program.py.
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.
- GLOP solves the LP and returns the best feasible corner.
Run the solver to view the solution.
Status / Response: