Files
ortools-clone/ortools/java/CMakeTest.java

35 lines
1.3 KiB
Java
Raw Normal View History

2020-05-14 18:01:23 +02:00
package com.google.ortools;
import com.google.ortools.Loader;
import com.google.ortools.linearsolver.MPConstraint;
import com.google.ortools.linearsolver.MPObjective;
import com.google.ortools.linearsolver.MPSolver;
import com.google.ortools.linearsolver.MPVariable;
2020-09-14 23:49:23 +02:00
import org.junit.jupiter.api.Test;
2020-05-14 18:01:23 +02:00
2020-09-14 23:49:23 +02:00
/** @author Mizux */
public class CMakeTest {
2020-09-14 23:49:23 +02:00
@Test
public void testLP() {
Loader.loadNativeLibraries();
2020-05-14 18:01:23 +02:00
MPSolver solver =
new MPSolver("SimpleLpProgram", MPSolver.OptimizationProblemType.GLOP_LINEAR_PROGRAMMING);
MPVariable x = solver.makeNumVar(0.0, 1.0, "x");
MPVariable y = solver.makeNumVar(0.0, 2.0, "y");
System.out.println("Number of variables = " + solver.numVariables());
MPConstraint ct = solver.makeConstraint(0.0, 2.0, "ct");
ct.setCoefficient(x, 1);
ct.setCoefficient(y, 1);
System.out.println("Number of constraints = " + solver.numConstraints());
MPObjective objective = solver.objective();
objective.setCoefficient(x, 3);
objective.setCoefficient(y, 1);
objective.setMaximization();
solver.solve();
System.out.println("Solution:");
System.out.println("Objective value = " + objective.value());
System.out.println("x = " + x.solutionValue());
System.out.println("y = " + y.solutionValue());
}
}