public class MPSolver
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
MPSolver.BasisStatus
Advanced usage: possible basis status values for a variable and the slack
variable of a linear constraint. |
static class |
MPSolver.OptimizationProblemType
The type of problems (LP or MIP) that will be solved and the underlying
solver (GLOP, GLPK, CLP, CBC or SCIP) that will solve them. |
static class |
MPSolver.ResultStatus
The status of solving the problem.
|
Modifier and Type | Field and Description |
---|---|
protected boolean |
swigCMemOwn |
Modifier | Constructor and Description |
---|---|
protected |
MPSolver(long cPtr,
boolean cMemoryOwn) |
|
MPSolver(java.lang.String name,
MPSolver.OptimizationProblemType problem_type)
Create a solver with the given name and underlying solver backend.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the objective (including the optimization direction), all variables
and constraints. |
double[] |
computeConstraintActivities()
Advanced usage: compute the "activities" of all constraints, which are the
sums of their linear terms. |
double |
computeExactConditionNumber()
Advanced usage: computes the exact condition number of the current scaled
basis: L1norm(B) * L1norm(inverse(B)), where B is the scaled basis. |
MPConstraint |
constraint(int index)
Returns the constraint at the given index.
|
MPConstraint[] |
constraints()
Returns the array of constraints handled by the MPSolver.
|
MPSolutionResponse |
createSolutionResponseProto()
Fills the solution found to a response proto and returns it.
|
static MPSolver |
createSolver(java.lang.String solver_id)
Recommended factory method to create a MPSolver instance, especially in
non C++ languages. |
void |
delete() |
void |
enableOutput()
Enables solver logging.
|
java.lang.String |
exportModelAsLpFormat()
Export the loaded model in LP format.
|
java.lang.String |
exportModelAsLpFormat(boolean obfuscate)
Export the loaded model in LP format.
|
java.lang.String |
exportModelAsMpsFormat(boolean fixed_format,
boolean obfuscate)
Export the loaded model in MPS format.
|
MPModelProto |
exportModelToProto()
Export the loaded model to proto and returns it.
|
protected void |
finalize() |
protected static long |
getCPtr(MPSolver obj) |
static double |
infinity()
Infinity.
|
boolean |
interruptSolve()
Interrupts the Solve() execution to terminate processing if possible.
|
boolean |
isMip() |
long |
iterations()
Returns the number of simplex iterations.
|
java.lang.String |
loadModelFromProto(MPModelProto input_model)
Loads a model and returns the error message, which will be empty iff the
model is valid. |
java.lang.String |
loadModelFromProtoKeepNames(MPModelProto input_model)
Like loadModelFromProto(), but keeps the names and returns an error if
there are duplicate names. |
java.lang.String |
loadModelFromProtoWithUniqueNamesOrDie(MPModelProto input_model) |
boolean |
loadSolutionFromProto(MPSolutionResponse response)
Load a solution encoded in a protocol buffer onto this solver for easy
access via the MPSolver interface. |
MPConstraint |
lookupConstraintOrNull(java.lang.String constraint_name)
Looks up a constraint by name, and returns nullptr if it does not exist.
|
MPVariable |
lookupVariableOrNull(java.lang.String var_name)
Looks up a variable by name, and returns nullptr if it does not exist.
|
MPVariable |
makeBoolVar(java.lang.String name)
Creates a boolean variable.
|
MPVariable[] |
makeBoolVarArray(int count) |
MPVariable[] |
makeBoolVarArray(int count,
java.lang.String var_name) |
MPConstraint |
makeConstraint()
Creates a constraint with -infinity and +infinity bounds.
|
MPConstraint |
makeConstraint(double lb,
double ub)
Creates a linear constraint with given bounds.
|
MPConstraint |
makeConstraint(double lb,
double ub,
java.lang.String name)
Creates a named constraint with given bounds.
|
MPConstraint |
makeConstraint(java.lang.String name)
Creates a named constraint with -infinity and +infinity bounds.
|
MPVariable |
makeIntVar(double lb,
double ub,
java.lang.String name)
Creates an integer variable.
|
MPVariable[] |
makeIntVarArray(int count,
double lb,
double ub) |
MPVariable[] |
makeIntVarArray(int count,
double lb,
double ub,
java.lang.String var_name) |
MPVariable |
makeNumVar(double lb,
double ub,
java.lang.String name)
Creates a continuous variable.
|
MPVariable[] |
makeNumVarArray(int count,
double lb,
double ub) |
MPVariable[] |
makeNumVarArray(int count,
double lb,
double ub,
java.lang.String var_name) |
MPVariable |
makeVar(double lb,
double ub,
boolean integer,
java.lang.String name)
Creates a variable with the given bounds, integrality requirement and
name. |
MPVariable[] |
makeVarArray(int count,
double lb,
double ub,
boolean integer)
Creates and returns an array of variables.
|
MPVariable[] |
makeVarArray(int count,
double lb,
double ub,
boolean integer,
java.lang.String var_name)
Creates and returns an array of named variables.
|
long |
nodes()
Returns the number of branch-and-bound nodes evaluated during the solve.
|
int |
numConstraints()
Returns the number of constraints.
|
int |
numVariables()
Returns the number of variables.
|
MPObjective |
objective()
Returns the mutable objective object.
|
MPSolver.OptimizationProblemType |
problemType()
Returns the optimization problem type set at construction.
|
void |
reset()
Advanced usage: resets extracted model to solve from scratch.
|
void |
setHint(MPVariable[] variables,
double[] values)
Sets a hint for solution.
|
boolean |
setNumThreads(int num_theads)
Sets the number of threads to be used by the solver.
|
boolean |
setSolverSpecificParametersAsString(java.lang.String parameters)
Advanced usage: pass solver specific parameters in text format.
|
void |
setTimeLimit(long time_limit_milliseconds) |
MPSolver.ResultStatus |
solve()
Solves the problem using the default parameter values.
|
MPSolver.ResultStatus |
solve(MPSolverParameters param)
Solves the problem using the specified parameter values.
|
java.lang.String |
solverVersion()
Returns a string describing the underlying solver and its version.
|
static MPSolutionResponse |
solveWithProto(MPModelRequest model_request)
Solves the given model proto and returns a response proto.
|
static boolean |
supportsProblemType(MPSolver.OptimizationProblemType problem_type)
Whether the given problem type is supported (this will depend on the
targets that you linked). |
void |
suppressOutput()
Suppresses solver logging.
|
protected static long |
swigRelease(MPSolver obj) |
MPVariable |
variable(int index)
Returns the variable at position index.
|
MPVariable[] |
variables()
Returns the array of variables handled by the MPSolver.
|
boolean |
verifySolution(double tolerance,
boolean log_errors)
Advanced usage: Verifies the *correctness* of the solution.
|
long |
wallTime() |
void |
write(java.lang.String file_name)
Writes the model using the solver internal write function.
|
boolean |
writeModelToMpsFile(java.lang.String filename,
boolean fixed_format,
boolean obfuscate)
Write the loaded model to file in MPS format.
|
protected MPSolver(long cPtr, boolean cMemoryOwn)
public MPSolver(java.lang.String name, MPSolver.OptimizationProblemType problem_type)
protected static long getCPtr(MPSolver obj)
protected static long swigRelease(MPSolver obj)
protected void finalize()
finalize
in class java.lang.Object
public void delete()
public MPVariable[] makeVarArray(int count, double lb, double ub, boolean integer)
public MPVariable[] makeVarArray(int count, double lb, double ub, boolean integer, java.lang.String var_name)
public MPVariable[] makeNumVarArray(int count, double lb, double ub)
public MPVariable[] makeNumVarArray(int count, double lb, double ub, java.lang.String var_name)
public MPVariable[] makeIntVarArray(int count, double lb, double ub)
public MPVariable[] makeIntVarArray(int count, double lb, double ub, java.lang.String var_name)
public MPVariable[] makeBoolVarArray(int count)
public MPVariable[] makeBoolVarArray(int count, java.lang.String var_name)
public static MPSolver createSolver(java.lang.String solver_id)
public static boolean supportsProblemType(MPSolver.OptimizationProblemType problem_type)
public boolean isMip()
public MPSolver.OptimizationProblemType problemType()
public void clear()
public int numVariables()
public MPVariable[] variables()
public MPVariable variable(int index)
public MPVariable lookupVariableOrNull(java.lang.String var_name)
public MPVariable makeVar(double lb, double ub, boolean integer, java.lang.String name)
public MPVariable makeNumVar(double lb, double ub, java.lang.String name)
public MPVariable makeIntVar(double lb, double ub, java.lang.String name)
public MPVariable makeBoolVar(java.lang.String name)
public int numConstraints()
public MPConstraint[] constraints()
public MPConstraint constraint(int index)
public MPConstraint lookupConstraintOrNull(java.lang.String constraint_name)
public MPConstraint makeConstraint(double lb, double ub)
public MPConstraint makeConstraint()
public MPConstraint makeConstraint(double lb, double ub, java.lang.String name)
public MPConstraint makeConstraint(java.lang.String name)
public MPObjective objective()
public MPSolver.ResultStatus solve()
public MPSolver.ResultStatus solve(MPSolverParameters param)
public void write(java.lang.String file_name)
public double[] computeConstraintActivities()
public boolean verifySolution(double tolerance, boolean log_errors)
public void reset()
public boolean interruptSolve()
public boolean setSolverSpecificParametersAsString(java.lang.String parameters)
public static double infinity()
public void enableOutput()
public void suppressOutput()
public long iterations()
public long nodes()
public java.lang.String solverVersion()
public double computeExactConditionNumber()
public void setTimeLimit(long time_limit_milliseconds)
public long wallTime()
public java.lang.String loadModelFromProto(MPModelProto input_model)
public java.lang.String loadModelFromProtoKeepNames(MPModelProto input_model)
public java.lang.String loadModelFromProtoWithUniqueNamesOrDie(MPModelProto input_model)
public MPModelProto exportModelToProto()
public MPSolutionResponse createSolutionResponseProto()
public boolean loadSolutionFromProto(MPSolutionResponse response)
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...
}
public static MPSolutionResponse solveWithProto(MPModelRequest model_request)
public java.lang.String exportModelAsLpFormat(boolean obfuscate)
public java.lang.String exportModelAsLpFormat()
public java.lang.String exportModelAsMpsFormat(boolean fixed_format, boolean obfuscate)
public boolean writeModelToMpsFile(java.lang.String filename, boolean fixed_format, boolean obfuscate)
public void setHint(MPVariable[] variables, double[] values)
public boolean setNumThreads(int num_theads)
Copyright © 2025. All rights reserved.