Java Reference

Java Reference

CMakeTest.java
Go to the documentation of this file.
1 package com.google.ortools;
2 
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;
9 
11 public class CMakeTest {
12  @Test
13  public void testLP() {
15  MPSolver solver =
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();
28  solver.solve();
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());
33  }
34 }
Load native libraries needed for using ortools-java.
Definition: Loader.java:33
static void loadNativeLibraries()
Definition: Loader.java:102