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;
8 import org.junit.jupiter.api.Test;
9 
11 public class CMakeTest {
12  @Test
13  public void testLP() {
15  MPSolver solver =
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 }
static void loadNativeLibraries()
Definition: Loader.java:80
MPObjective objective()
Returns the mutable objective object.
Definition: MPSolver.java:282
double value()
Returns the objective value of the best solution found so far.
GLOP_LINEAR_PROGRAMMING
Definition: MPSolver.java:602
Load native libraries needed for using ortools-java.
Definition: Loader.java:19
MPVariable makeNumVar(double lb, double ub, String name)
Creates a continuous variable.
Definition: MPSolver.java:193
void setCoefficient(MPVariable var, double coeff)
Sets the coefficient of the variable in the objective.
void setCoefficient(MPVariable var, double coeff)
Sets the coefficient of the variable on the constraint.
void testLP()
Definition: CMakeTest.java:13
double solutionValue()
Returns the value of the variable in the current solution.
Definition: MPVariable.java:65
The class for constraints of a Mathematical Programming (MP) model.
void setMaximization()
Sets the optimization direction to maximize.
MPConstraint makeConstraint(double lb, double ub)
Creates a linear constraint with given bounds.
Definition: MPSolver.java:250
Definition: CMakeTest.java:11
The type of problems (LP or MIP) that will be solved and the underlying solver (GLOP,...
Definition: MPSolver.java:599
A class to express a linear objective.
int numVariables()
Returns the number of variables.
Definition: MPSolver.java:156
The class for variables of a Mathematical Programming (MP) model.
Definition: MPVariable.java:16
int numConstraints()
Returns the number of constraints.
Definition: MPSolver.java:217
MPSolver.ResultStatus solve()
Solves the problem using the default parameter values.
Definition: MPSolver.java:290
This mathematical programming (MP) solver class is the main class though which users build and solve...
Definition: MPSolver.java:17