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 }
The class for variables of a Mathematical Programming (MP) model.
Definition: MPVariable.java:16
MPConstraint makeConstraint(double lb, double ub)
Creates a linear constraint with given bounds.
Definition: MPSolver.java:273
double solutionValue()
Returns the value of the variable in the current solution.
Definition: MPVariable.java:65
double value()
Returns the objective value of the best solution found so far.
The class for constraints of a Mathematical Programming (MP) model.
MPSolver.ResultStatus solve()
Solves the problem using the default parameter values.
Definition: MPSolver.java:313
int numConstraints()
Returns the number of constraints.
Definition: MPSolver.java:232
void setCoefficient(MPVariable var, double coeff)
Sets the coefficient of the variable in the objective.
This mathematical programming (MP) solver class is the main class though which users build and solve...
Definition: MPSolver.java:17
The type of problems (LP or MIP) that will be solved and the underlying solver (GLOP,...
Definition: MPSolver.java:620
static void loadNativeLibraries()
Definition: Loader.java:103
void setMaximization()
Sets the optimization direction to maximize.
void setCoefficient(MPVariable var, double coeff)
Sets the coefficient of the variable on the constraint.
A class to express a linear objective.
int numVariables()
Returns the number of variables.
Definition: MPSolver.java:163
MPObjective objective()
Returns the mutable objective object.
Definition: MPSolver.java:305
Load native libraries needed for using ortools-java.
Definition: Loader.java:33
MPVariable makeNumVar(double lb, double ub, String name)
Creates a continuous variable.
Definition: MPSolver.java:208