1 package com.google.ortools;
3 import com.google.ortools.Loader;
4 import com.google.ortools.linearsolver.MPConstraint;
5 import com.google.ortools.linearsolver.MPObjective;
6 import com.google.ortools.linearsolver.MPSolver;
7 import com.google.ortools.linearsolver.MPVariable;
8 import org.junit.jupiter.api.Test;
16 new MPSolver(
"SimpleLpProgram", MPSolver.OptimizationProblemType.GLOP_LINEAR_PROGRAMMING);
17 MPVariable x = solver.makeNumVar(0.0, 1.0,
"x");
18 MPVariable y = solver.makeNumVar(0.0, 2.0,
"y");
19 System.out.println(
"Number of variables = " + solver.numVariables());
20 MPConstraint ct = solver.makeConstraint(0.0, 2.0,
"ct");
21 ct.setCoefficient(x, 1);
22 ct.setCoefficient(y, 1);
23 System.out.println(
"Number of constraints = " + solver.numConstraints());
24 MPObjective objective = solver.objective();
25 objective.setCoefficient(x, 3);
26 objective.setCoefficient(y, 1);
27 objective.setMaximization();
29 System.out.println(
"Solution:");
30 System.out.println(
"Objective value = " + objective.value());
31 System.out.println(
"x = " + x.solutionValue());
32 System.out.println(
"y = " + y.solutionValue());