Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
Classes | |
enum | BasisStatus |
enum | OptimizationProblemType |
enum | ResultStatus |
Static Public Member Functions | |
static MPSolver | createSolver (String solver_id) |
static boolean | supportsProblemType (MPSolver.OptimizationProblemType problem_type) |
static double | infinity () |
static com.google.ortools.linearsolver.MPSolutionResponse | solveWithProto (com.google.ortools.linearsolver.MPModelRequest model_request) |
Protected Member Functions | |
MPSolver (long cPtr, boolean cMemoryOwn) | |
void | finalize () |
Static Protected Member Functions | |
static long | getCPtr (MPSolver obj) |
static long | swigRelease (MPSolver obj) |
Protected Attributes | |
transient boolean | swigCMemOwn |
This mathematical programming (MP) solver class is the main class
though which users build and solve problems.
Definition at line 17 of file MPSolver.java.
|
protected |
Definition at line 21 of file MPSolver.java.
com.google.ortools.linearsolver.MPSolver.MPSolver | ( | String | name, |
MPSolver.OptimizationProblemType | problem_type ) |
Create a solver with the given name and underlying solver backend.
Definition at line 107 of file MPSolver.java.
void com.google.ortools.linearsolver.MPSolver.clear | ( | ) |
Clears the objective (including the optimization direction), all variables
and constraints. All the other properties of the MPSolver (like the time
limit) are kept untouched.
Definition at line 168 of file MPSolver.java.
double[] com.google.ortools.linearsolver.MPSolver.computeConstraintActivities | ( | ) |
Advanced usage: compute the "activities" of all constraints, which are the
sums of their linear terms. The activities are returned in the same order
as constraints(), which is the order in which constraints were added; but
you can also use MPConstraint.index() to get a constraint's index.
Definition at line 350 of file MPSolver.java.
double com.google.ortools.linearsolver.MPSolver.computeExactConditionNumber | ( | ) |
Advanced usage: computes the exact condition number of the current scaled
basis: L1norm(B) * L1norm(inverse(B)), where B is the scaled basis.
This method requires that a basis exists: it should be called after Solve.
It is only available for continuous problems. It is implemented for GLPK
but not CLP because CLP does not provide the API for doing it.
The condition number measures how well the constraint matrix is conditioned
and can be used to predict whether numerical issues will arise during the
solve: the model is declared infeasible whereas it is feasible (or
vice-versa), the solution obtained is not optimal or violates some
constraints, the resolution is slow because of repeated singularities.
The rule of thumb to interpret the condition number kappa is:
Definition at line 482 of file MPSolver.java.
MPConstraint com.google.ortools.linearsolver.MPSolver.constraint | ( | int | index | ) |
Returns the constraint at the given index.
Definition at line 260 of file MPSolver.java.
MPConstraint[] com.google.ortools.linearsolver.MPSolver.constraints | ( | ) |
Returns the array of constraints handled by the MPSolver.
They are listed in the order in which they were created.
Definition at line 253 of file MPSolver.java.
com.google.ortools.linearsolver.MPSolutionResponse com.google.ortools.linearsolver.MPSolver.createSolutionResponseProto | ( | ) |
Fills the solution found to a response proto and returns it.
Definition at line 533 of file MPSolver.java.
|
static |
Recommended factory method to create a MPSolver instance, especially in
non C++ languages.
It returns a newly created solver instance if successful, or a nullptr
otherwise. This can occur if the relevant interface is not linked in, or if
a needed license is not accessible for commercial solvers.
Ownership of the solver is passed on to the caller of this method.
It will accept both string names of the OptimizationProblemType enum, as
well as a short version (i.e. "SCIP_MIXED_INTEGER_PROGRAMMING" or "SCIP").
solver_id is case insensitive, and the following names are supported:
Definition at line 139 of file MPSolver.java.
synchronized void com.google.ortools.linearsolver.MPSolver.delete | ( | ) |
Definition at line 47 of file MPSolver.java.
void com.google.ortools.linearsolver.MPSolver.enableOutput | ( | ) |
Enables solver logging.
Definition at line 424 of file MPSolver.java.
String com.google.ortools.linearsolver.MPSolver.exportModelAsLpFormat | ( | ) |
Export the loaded model in LP format.
Definition at line 607 of file MPSolver.java.
String com.google.ortools.linearsolver.MPSolver.exportModelAsLpFormat | ( | MPModelExportOptions | options | ) |
Export the loaded model in LP format.
Definition at line 600 of file MPSolver.java.
String com.google.ortools.linearsolver.MPSolver.exportModelAsMpsFormat | ( | ) |
Export the loaded model in MPS format.
Definition at line 621 of file MPSolver.java.
String com.google.ortools.linearsolver.MPSolver.exportModelAsMpsFormat | ( | MPModelExportOptions | options | ) |
Export the loaded model in MPS format.
Definition at line 614 of file MPSolver.java.
com.google.ortools.linearsolver.MPModelProto com.google.ortools.linearsolver.MPSolver.exportModelToProto | ( | ) |
Export the loaded model to proto and returns it.
Definition at line 517 of file MPSolver.java.
|
protected |
Definition at line 43 of file MPSolver.java.
|
staticprotected |
Definition at line 26 of file MPSolver.java.
|
static |
Infinity.
You can use -MPSolver.infinity() for negative infinity.
Definition at line 417 of file MPSolver.java.
boolean com.google.ortools.linearsolver.MPSolver.interruptSolve | ( | ) |
Interrupts the Solve() execution to terminate processing if possible.
If the underlying interface supports interruption; it does that and returns
true regardless of whether there's an ongoing Solve() or not. The Solve()
call may still linger for a while depending on the conditions. If
interruption is not supported; returns false and does nothing.
MPSolver::SolverTypeSupportsInterruption can be used to check if
interruption is supported for a given solver type.
Definition at line 398 of file MPSolver.java.
boolean com.google.ortools.linearsolver.MPSolver.isMip | ( | ) |
Definition at line 152 of file MPSolver.java.
long com.google.ortools.linearsolver.MPSolver.iterations | ( | ) |
Returns the number of simplex iterations.
Definition at line 438 of file MPSolver.java.
String com.google.ortools.linearsolver.MPSolver.loadModelFromProto | ( | com.google.ortools.linearsolver.MPModelProto | input_model | ) |
Loads a model and returns the error message, which will be empty iff the
model is valid. Clears all names (see also loadModelFromProtoKeepNames()).
Definition at line 498 of file MPSolver.java.
String com.google.ortools.linearsolver.MPSolver.loadModelFromProtoKeepNames | ( | com.google.ortools.linearsolver.MPModelProto | input_model | ) |
Like loadModelFromProto(), but keeps the names and returns an error if
there are duplicate names.
Definition at line 506 of file MPSolver.java.
String com.google.ortools.linearsolver.MPSolver.loadModelFromProtoWithUniqueNamesOrDie | ( | com.google.ortools.linearsolver.MPModelProto | input_model | ) |
Definition at line 510 of file MPSolver.java.
boolean com.google.ortools.linearsolver.MPSolver.loadSolutionFromProto | ( | com.google.ortools.linearsolver.MPSolutionResponse | response | ) |
Load a solution encoded in a protocol buffer onto this solver for easy
access via the MPSolver interface.
IMPORTANT: This may only be used in conjunction with ExportModel(),
following this example:
MPSolver my_solver;
... add variables and constraints ...
MPModelProto model_proto;
my_solver.ExportModelToProto(&model_proto);
MPSolutionResponse solver_response;
MPSolver::SolveWithProto(model_proto, &solver_response);
if (solver_response.result_status() == MPSolutionResponse::OPTIMAL) {
CHECK_OK(my_solver.LoadSolutionFromProto(solver_response));
... inspect the solution using the usual API: solution_value(), etc...
}
The response must be in OPTIMAL or FEASIBLE status.
Returns a false if a problem arised (typically, if it wasn't used
like it should be):
Definition at line 577 of file MPSolver.java.
MPConstraint com.google.ortools.linearsolver.MPSolver.lookupConstraintOrNull | ( | String | constraint_name | ) |
Looks up a constraint by name, and returns nullptr if it does not exist.
The first call has a O(n) complexity, as the constraint name index is
lazily created upon first use. Will crash if constraint names are not
unique.
Definition at line 272 of file MPSolver.java.
MPVariable com.google.ortools.linearsolver.MPSolver.lookupVariableOrNull | ( | String | var_name | ) |
Looks up a variable by name, and returns nullptr if it does not exist. The
first call has a O(n) complexity, as the variable name index is lazily
created upon first use. Will crash if variable names are not unique.
Definition at line 200 of file MPSolver.java.
MPVariable com.google.ortools.linearsolver.MPSolver.makeBoolVar | ( | String | name | ) |
Creates a boolean variable.
Definition at line 236 of file MPSolver.java.
MPVariable[] com.google.ortools.linearsolver.MPSolver.makeBoolVarArray | ( | int | count | ) |
Definition at line 96 of file MPSolver.java.
MPVariable[] com.google.ortools.linearsolver.MPSolver.makeBoolVarArray | ( | int | count, |
String | var_name ) |
Definition at line 100 of file MPSolver.java.
MPConstraint com.google.ortools.linearsolver.MPSolver.makeConstraint | ( | ) |
Creates a constraint with -infinity and +infinity bounds.
Definition at line 293 of file MPSolver.java.
MPConstraint com.google.ortools.linearsolver.MPSolver.makeConstraint | ( | double | lb, |
double | ub ) |
Creates a linear constraint with given bounds.
Bounds can be finite or +/- MPSolver.infinity(). The MPSolver class
assumes ownership of the constraint.
Definition at line 285 of file MPSolver.java.
MPConstraint com.google.ortools.linearsolver.MPSolver.makeConstraint | ( | double | lb, |
double | ub, | ||
String | name ) |
Creates a named constraint with given bounds.
Definition at line 301 of file MPSolver.java.
MPConstraint com.google.ortools.linearsolver.MPSolver.makeConstraint | ( | String | name | ) |
Creates a named constraint with -infinity and +infinity bounds.
Definition at line 309 of file MPSolver.java.
MPVariable com.google.ortools.linearsolver.MPSolver.makeIntVar | ( | double | lb, |
double | ub, | ||
String | name ) |
Creates an integer variable.
Definition at line 228 of file MPSolver.java.
MPVariable[] com.google.ortools.linearsolver.MPSolver.makeIntVarArray | ( | int | count, |
double | lb, | ||
double | ub ) |
Definition at line 88 of file MPSolver.java.
MPVariable[] com.google.ortools.linearsolver.MPSolver.makeIntVarArray | ( | int | count, |
double | lb, | ||
double | ub, | ||
String | var_name ) |
Definition at line 92 of file MPSolver.java.
MPVariable com.google.ortools.linearsolver.MPSolver.makeNumVar | ( | double | lb, |
double | ub, | ||
String | name ) |
Creates a continuous variable.
Definition at line 220 of file MPSolver.java.
MPVariable[] com.google.ortools.linearsolver.MPSolver.makeNumVarArray | ( | int | count, |
double | lb, | ||
double | ub ) |
Definition at line 80 of file MPSolver.java.
MPVariable[] com.google.ortools.linearsolver.MPSolver.makeNumVarArray | ( | int | count, |
double | lb, | ||
double | ub, | ||
String | var_name ) |
Definition at line 84 of file MPSolver.java.
MPVariable com.google.ortools.linearsolver.MPSolver.makeVar | ( | double | lb, |
double | ub, | ||
boolean | integer, | ||
String | name ) |
Creates a variable with the given bounds, integrality requirement and
name. Bounds can be finite or +/- MPSolver.infinity(). The MPSolver owns
the variable (i.e. the returned pointer is borrowed). Variable names are
optional. If you give an empty name, name() will auto-generate one for you
upon request.
Definition at line 212 of file MPSolver.java.
MPVariable[] com.google.ortools.linearsolver.MPSolver.makeVarArray | ( | int | count, |
double | lb, | ||
double | ub, | ||
boolean | integer ) |
Creates and returns an array of variables.
Definition at line 60 of file MPSolver.java.
MPVariable[] com.google.ortools.linearsolver.MPSolver.makeVarArray | ( | int | count, |
double | lb, | ||
double | ub, | ||
boolean | integer, | ||
String | var_name ) |
Creates and returns an array of named variables.
Definition at line 71 of file MPSolver.java.
long com.google.ortools.linearsolver.MPSolver.nodes | ( | ) |
Returns the number of branch-and-bound nodes evaluated during the solve.
Only available for discrete problems.
Definition at line 447 of file MPSolver.java.
int com.google.ortools.linearsolver.MPSolver.numConstraints | ( | ) |
Returns the number of constraints.
Definition at line 244 of file MPSolver.java.
int com.google.ortools.linearsolver.MPSolver.numVariables | ( | ) |
Returns the number of variables.
Definition at line 175 of file MPSolver.java.
MPObjective com.google.ortools.linearsolver.MPSolver.objective | ( | ) |
Returns the mutable objective object.
Definition at line 317 of file MPSolver.java.
MPSolver.OptimizationProblemType com.google.ortools.linearsolver.MPSolver.problemType | ( | ) |
Returns the optimization problem type set at construction.
Definition at line 159 of file MPSolver.java.
void com.google.ortools.linearsolver.MPSolver.reset | ( | ) |
Advanced usage: resets extracted model to solve from scratch.
This won't reset the parameters that were set with
SetSolverSpecificParametersAsString() or set_time_limit() or even clear the
linear program. It will just make sure that next Solve() will be as if
everything was reconstructed from scratch.
Definition at line 384 of file MPSolver.java.
void com.google.ortools.linearsolver.MPSolver.setHint | ( | MPVariable[] | variables, |
double[] | values ) |
Sets a hint for solution.
If a feasible or almost-feasible solution to the problem is already known,
it may be helpful to pass it to the solver so that it can be used. A
solver that supports this feature will try to use this information to
create its initial feasible solution.
Note that it may not always be faster to give a hint like this to the
solver. There is also no guarantee that the solver will use this hint or
try to return a solution "close" to this assignment in case of multiple
optimal solutions.
Definition at line 638 of file MPSolver.java.
boolean com.google.ortools.linearsolver.MPSolver.setNumThreads | ( | int | num_theads | ) |
Sets the number of threads to be used by the solver.
Definition at line 645 of file MPSolver.java.
boolean com.google.ortools.linearsolver.MPSolver.setSolverSpecificParametersAsString | ( | String | parameters | ) |
Advanced usage: pass solver specific parameters in text format.
The format is solver-specific and is the same as the corresponding solver
configuration file format. Returns true if the operation was successful.
Definition at line 408 of file MPSolver.java.
void com.google.ortools.linearsolver.MPSolver.setTimeLimit | ( | long | time_limit_milliseconds | ) |
Definition at line 486 of file MPSolver.java.
MPSolver.ResultStatus com.google.ortools.linearsolver.MPSolver.solve | ( | ) |
Solves the problem using the default parameter values.
Definition at line 325 of file MPSolver.java.
MPSolver.ResultStatus com.google.ortools.linearsolver.MPSolver.solve | ( | MPSolverParameters | param | ) |
Solves the problem using the specified parameter values.
Definition at line 332 of file MPSolver.java.
String com.google.ortools.linearsolver.MPSolver.solverVersion | ( | ) |
Returns a string describing the underlying solver and its version.
Definition at line 454 of file MPSolver.java.
|
static |
Solves the given model proto and returns a response proto.
Definition at line 584 of file MPSolver.java.
|
static |
Whether the given problem type is supported (this will depend on the
targets that you linked).
Definition at line 148 of file MPSolver.java.
void com.google.ortools.linearsolver.MPSolver.suppressOutput | ( | ) |
Suppresses solver logging.
Definition at line 431 of file MPSolver.java.
|
staticprotected |
Definition at line 30 of file MPSolver.java.
MPVariable com.google.ortools.linearsolver.MPSolver.variable | ( | int | index | ) |
Returns the variable at position index.
Definition at line 190 of file MPSolver.java.
MPVariable[] com.google.ortools.linearsolver.MPSolver.variables | ( | ) |
Returns the array of variables handled by the MPSolver. (They are listed in
the order in which they were created.)
Definition at line 183 of file MPSolver.java.
boolean com.google.ortools.linearsolver.MPSolver.verifySolution | ( | double | tolerance, |
boolean | log_errors ) |
Advanced usage: Verifies the correctness of the solution.
It verifies that all variables must be within their domains, all
constraints must be satisfied, and the reported objective value must be
accurate.
Usage:
Definition at line 372 of file MPSolver.java.
long com.google.ortools.linearsolver.MPSolver.wallTime | ( | ) |
Definition at line 490 of file MPSolver.java.
void com.google.ortools.linearsolver.MPSolver.write | ( | String | file_name | ) |
Writes the model using the solver internal write function. Currently only
available for Gurobi.
Definition at line 340 of file MPSolver.java.
|
protected |
Definition at line 19 of file MPSolver.java.