Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
Public Member Functions | |
__init__ (self, name, problem_type) | |
IsMip (self) | |
Clear (self) | |
NumVariables (self) | |
variables (self) | |
variable (self, index) | |
LookupVariable (self, var_name) | |
Var (self, lb, ub, integer, name) | |
NumVar (self, lb, ub, name) | |
IntVar (self, lb, ub, name) | |
BoolVar (self, name) | |
NumConstraints (self) | |
constraints (self) | |
constraint (self, index) | |
LookupConstraint (self, constraint_name) | |
Constraint (self, *args) | |
Objective (self) | |
Solve (self, *args) | |
Write (self, file_name) | |
ComputeConstraintActivities (self) | |
VerifySolution (self, tolerance, log_errors) | |
InterruptSolve (self) | |
FillSolutionResponseProto (self, response) | |
ExportModelToProto (self, output_model) | |
SetSolverSpecificParametersAsString (self, parameters) | |
EnableOutput (self) | |
SuppressOutput (self) | |
iterations (self) | |
nodes (self) | |
SolverVersion (self) | |
ComputeExactConditionNumber (self) | |
NextSolution (self) | |
set_time_limit (self, time_limit_milliseconds) | |
wall_time (self) | |
LoadModelFromProto (self, input_model) | |
LoadModelFromProtoKeepNames (self, input_model) | |
LoadModelFromProtoWithUniqueNamesOrDie (self, input_model) | |
LoadSolutionFromProto (self, *args) | |
ExportModelAsLpFormat (self, obfuscated) | |
ExportModelAsMpsFormat (self, fixed_format, obfuscated) | |
SetHint (self, variables, values) | |
SetNumThreads (self, num_theads) | |
Add (self, constraint, name='') | |
Sum (self, expr_array) | |
RowConstraint (self, *args) | |
Minimize (self, expr) | |
Maximize (self, expr) | |
SetTimeLimit (self, x) | |
WallTime (self) | |
Iterations (self) | |
Static Public Member Functions | |
CreateSolver (solver_id) | |
SupportsProblemType (problem_type) | |
SolveWithProto (model_request, response, interrupt=None) | |
infinity () | |
Infinity () | |
Static Public Attributes | |
CLP_LINEAR_PROGRAMMING = _pywraplp.Solver_CLP_LINEAR_PROGRAMMING | |
GLPK_LINEAR_PROGRAMMING = _pywraplp.Solver_GLPK_LINEAR_PROGRAMMING | |
GLOP_LINEAR_PROGRAMMING = _pywraplp.Solver_GLOP_LINEAR_PROGRAMMING | |
PDLP_LINEAR_PROGRAMMING = _pywraplp.Solver_PDLP_LINEAR_PROGRAMMING | |
SCIP_MIXED_INTEGER_PROGRAMMING = _pywraplp.Solver_SCIP_MIXED_INTEGER_PROGRAMMING | |
GLPK_MIXED_INTEGER_PROGRAMMING = _pywraplp.Solver_GLPK_MIXED_INTEGER_PROGRAMMING | |
CBC_MIXED_INTEGER_PROGRAMMING = _pywraplp.Solver_CBC_MIXED_INTEGER_PROGRAMMING | |
BOP_INTEGER_PROGRAMMING = _pywraplp.Solver_BOP_INTEGER_PROGRAMMING | |
SAT_INTEGER_PROGRAMMING = _pywraplp.Solver_SAT_INTEGER_PROGRAMMING | |
GUROBI_LINEAR_PROGRAMMING = _pywraplp.Solver_GUROBI_LINEAR_PROGRAMMING | |
GUROBI_MIXED_INTEGER_PROGRAMMING = _pywraplp.Solver_GUROBI_MIXED_INTEGER_PROGRAMMING | |
CPLEX_LINEAR_PROGRAMMING = _pywraplp.Solver_CPLEX_LINEAR_PROGRAMMING | |
CPLEX_MIXED_INTEGER_PROGRAMMING = _pywraplp.Solver_CPLEX_MIXED_INTEGER_PROGRAMMING | |
XPRESS_LINEAR_PROGRAMMING = _pywraplp.Solver_XPRESS_LINEAR_PROGRAMMING | |
XPRESS_MIXED_INTEGER_PROGRAMMING = _pywraplp.Solver_XPRESS_MIXED_INTEGER_PROGRAMMING | |
OPTIMAL = _pywraplp.Solver_OPTIMAL | |
FEASIBLE = _pywraplp.Solver_FEASIBLE | |
INFEASIBLE = _pywraplp.Solver_INFEASIBLE | |
UNBOUNDED = _pywraplp.Solver_UNBOUNDED | |
ABNORMAL = _pywraplp.Solver_ABNORMAL | |
MODEL_INVALID = _pywraplp.Solver_MODEL_INVALID | |
NOT_SOLVED = _pywraplp.Solver_NOT_SOLVED | |
FREE = _pywraplp.Solver_FREE | |
AT_LOWER_BOUND = _pywraplp.Solver_AT_LOWER_BOUND | |
AT_UPPER_BOUND = _pywraplp.Solver_AT_UPPER_BOUND | |
FIXED_VALUE = _pywraplp.Solver_FIXED_VALUE | |
BASIC = _pywraplp.Solver_BASIC | |
Properties | |
thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") | |
This mathematical programming (MP) solver class is the main class though which users build and solve problems.
Definition at line 73 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.__init__ | ( | self, | |
name, | |||
problem_type ) |
Create a solver with the given name and underlying solver backend.
Definition at line 97 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.Add | ( | self, | |
constraint, | |||
name = '' ) |
Definition at line 498 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.BoolVar | ( | self, | |
name ) |
Creates a boolean variable.
Definition at line 194 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.Clear | ( | self | ) |
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 145 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.ComputeConstraintActivities | ( | self | ) |
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 290 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.ComputeExactConditionNumber | ( | self | ) |
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: - o kappa <= 1e7: virtually no chance of numerical issues - o 1e7 < kappa <= 1e10: small chance of numerical issues - o 1e10 < kappa <= 1e13: medium chance of numerical issues - o kappa > 1e13: high chance of numerical issues The computation of the condition number depends on the quality of the LU decomposition, so it is not very accurate when the matrix is ill conditioned.
Definition at line 410 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.Constraint | ( | self, | |
* | args ) |
*Overload 1:* Creates a linear constraint with given bounds. Bounds can be finite or +/- MPSolver::infinity(). The MPSolver class assumes ownership of the constraint. :rtype: :py:class:`MPConstraint` :return: a pointer to the newly created constraint. | *Overload 2:* Creates a constraint with -infinity and +infinity bounds. | *Overload 3:* Creates a named constraint with given bounds. | *Overload 4:* Creates a named constraint with -infinity and +infinity bounds.
Definition at line 224 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.constraint | ( | self, | |
index ) |
Returns the constraint at the given index.
Definition at line 210 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.constraints | ( | self | ) |
Returns the array of constraints handled by the MPSolver. They are listed in the order in which they were created.
Definition at line 202 of file pywraplp.py.
|
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: - CLP_LINEAR_PROGRAMMING or CLP - CBC_MIXED_INTEGER_PROGRAMMING or CBC - GLOP_LINEAR_PROGRAMMING or GLOP - BOP_INTEGER_PROGRAMMING or BOP - SAT_INTEGER_PROGRAMMING or SAT or CP_SAT - SCIP_MIXED_INTEGER_PROGRAMMING or SCIP - GUROBI_LINEAR_PROGRAMMING or GUROBI_LP - GUROBI_MIXED_INTEGER_PROGRAMMING or GUROBI or GUROBI_MIP - CPLEX_LINEAR_PROGRAMMING or CPLEX_LP - CPLEX_MIXED_INTEGER_PROGRAMMING or CPLEX or CPLEX_MIP - XPRESS_LINEAR_PROGRAMMING or XPRESS_LP - XPRESS_MIXED_INTEGER_PROGRAMMING or XPRESS or XPRESS_MIP - GLPK_LINEAR_PROGRAMMING or GLPK_LP - GLPK_MIXED_INTEGER_PROGRAMMING or GLPK or GLPK_MIP
Definition at line 103 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.EnableOutput | ( | self | ) |
Enables solver logging.
Definition at line 386 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.ExportModelAsLpFormat | ( | self, | |
obfuscated ) |
Definition at line 472 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.ExportModelAsMpsFormat | ( | self, | |
fixed_format, | |||
obfuscated ) |
Definition at line 475 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.ExportModelToProto | ( | self, | |
output_model ) |
Exports model to protocol buffer.
Definition at line 359 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.FillSolutionResponseProto | ( | self, | |
response ) |
Encodes the current solution in a solution response protocol buffer.
Definition at line 333 of file pywraplp.py.
|
static |
Definition at line 540 of file pywraplp.py.
|
static |
Infinity. You can use -MPSolver::infinity() for negative infinity.
Definition at line 378 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.InterruptSolve | ( | self | ) |
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 320 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.IntVar | ( | self, | |
lb, | |||
ub, | |||
name ) |
Creates an integer variable.
Definition at line 190 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.IsMip | ( | self | ) |
Definition at line 142 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.Iterations | ( | self | ) |
Definition at line 549 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.iterations | ( | self | ) |
Returns the number of simplex iterations.
Definition at line 394 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.LoadModelFromProto | ( | self, | |
input_model ) |
Definition at line 460 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.LoadModelFromProtoKeepNames | ( | self, | |
input_model ) |
Definition at line 463 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.LoadModelFromProtoWithUniqueNamesOrDie | ( | self, | |
input_model ) |
Definition at line 466 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.LoadSolutionFromProto | ( | self, | |
* | args ) |
Definition at line 469 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.LookupConstraint | ( | self, | |
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 214 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.LookupVariable | ( | self, | |
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 168 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.Maximize | ( | self, | |
expr ) |
Definition at line 526 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.Minimize | ( | self, | |
expr ) |
Definition at line 514 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.NextSolution | ( | self | ) |
Some solvers (MIP only, not LP) can produce multiple solutions to the problem. Returns true when another solution is available, and updates the MPVariable* objects to make the new solution queryable. Call only after calling solve. The optimality properties of the additional solutions found, and whether or not the solver computes them ahead of time or when NextSolution() is called is solver specific. As of 2020-02-10, only Gurobi and SCIP support NextSolution(), see linear_solver_interfaces_test for an example of how to configure these solvers for multiple solutions. Other solvers return false unconditionally.
Definition at line 437 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.nodes | ( | self | ) |
Returns the number of branch-and-bound nodes evaluated during the solve. Only available for discrete problems.
Definition at line 398 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.NumConstraints | ( | self | ) |
Returns the number of constraints.
Definition at line 198 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.NumVar | ( | self, | |
lb, | |||
ub, | |||
name ) |
Creates a continuous variable.
Definition at line 186 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.NumVariables | ( | self | ) |
Returns the number of variables.
Definition at line 153 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.Objective | ( | self | ) |
Returns the mutable objective object.
Definition at line 253 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.RowConstraint | ( | self, | |
* | args ) |
Definition at line 511 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.set_time_limit | ( | self, | |
time_limit_milliseconds ) |
Definition at line 454 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.SetHint | ( | self, | |
variables, | |||
values ) |
Set 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 478 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.SetNumThreads | ( | self, | |
num_theads ) |
Sets the number of threads to be used by the solver.
Definition at line 494 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.SetSolverSpecificParametersAsString | ( | self, | |
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 363 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.SetTimeLimit | ( | self, | |
x ) |
Definition at line 543 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.Solve | ( | self, | |
* | args ) |
*Overload 1:* Solves the problem using the default parameter values. | *Overload 2:* Solves the problem using the specified parameter values.
Definition at line 271 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.SolverVersion | ( | self | ) |
Returns a string describing the underlying solver and its version.
Definition at line 406 of file pywraplp.py.
|
static |
Solves the model encoded by a MPModelRequest protocol buffer and fills the solution encoded as a MPSolutionResponse. The solve is stopped prematurely if interrupt is non-null at set to true during (or before) solving. Interruption is only supported if SolverTypeSupportsInterruption() returns true for the requested solver. Passing a non-null interruption with any other solver type immediately returns an MPSOLVER_INCOMPATIBLE_OPTIONS error. `interrupt` is non-const because the internal solver may set it to true itself, in some cases. Note(user): This attempts to first use `DirectlySolveProto()` (if implemented). Consequently, this most likely does *not* override any of the default parameters of the underlying solver. This behavior *differs* from `MPSolver::Solve()` which by default sets the feasibility tolerance and the gap limit (as of 2020/02/11, to 1e-7 and 0.0001, respectively).
Definition at line 338 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.Sum | ( | self, | |
expr_array ) |
Definition at line 507 of file pywraplp.py.
|
static |
Whether the given problem type is supported (this will depend on the targets that you linked).
Definition at line 135 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.SuppressOutput | ( | self | ) |
Suppresses solver logging.
Definition at line 390 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.Var | ( | self, | |
lb, | |||
ub, | |||
integer, | |||
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 176 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.variable | ( | self, | |
index ) |
Returns the variable at position index.
Definition at line 164 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.variables | ( | self | ) |
Returns the array of variables handled by the MPSolver. (They are listed in the order in which they were created.)
Definition at line 157 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.VerifySolution | ( | self, | |
tolerance, | |||
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: - This can only be called after Solve() was called. - "tolerance" is interpreted as an absolute error threshold. - For the objective value only, if the absolute error is too large, the tolerance is interpreted as a relative error threshold instead. - If "log_errors" is true, every single violation will be logged. - If "tolerance" is negative, it will be set to infinity(). Most users should just set the --verify_solution flag and not bother using this method directly.
Definition at line 299 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.wall_time | ( | self | ) |
Definition at line 457 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.WallTime | ( | self | ) |
Definition at line 546 of file pywraplp.py.
ortools.linear_solver.pywraplp.Solver.Write | ( | self, | |
file_name ) |
Writes the model using the solver internal write function. Currently only available for Gurobi.
Definition at line 283 of file pywraplp.py.
|
static |
Definition at line 264 of file pywraplp.py.
|
static |
Definition at line 372 of file pywraplp.py.
|
static |
Definition at line 373 of file pywraplp.py.
|
static |
Definition at line 375 of file pywraplp.py.
|
static |
Definition at line 88 of file pywraplp.py.
|
static |
Definition at line 87 of file pywraplp.py.
|
static |
Definition at line 81 of file pywraplp.py.
|
static |
Definition at line 92 of file pywraplp.py.
|
static |
Definition at line 93 of file pywraplp.py.
|
static |
Definition at line 258 of file pywraplp.py.
|
static |
Definition at line 374 of file pywraplp.py.
|
static |
Definition at line 371 of file pywraplp.py.
|
static |
Definition at line 83 of file pywraplp.py.
|
static |
Definition at line 82 of file pywraplp.py.
|
static |
Definition at line 86 of file pywraplp.py.
|
static |
Definition at line 90 of file pywraplp.py.
|
static |
Definition at line 91 of file pywraplp.py.
|
static |
Definition at line 260 of file pywraplp.py.
|
static |
Definition at line 266 of file pywraplp.py.
|
static |
Definition at line 268 of file pywraplp.py.
|
static |
Definition at line 256 of file pywraplp.py.
|
static |
Definition at line 84 of file pywraplp.py.
|
static |
Definition at line 89 of file pywraplp.py.
|
static |
Definition at line 85 of file pywraplp.py.
|
static |
Definition at line 262 of file pywraplp.py.
|
static |
Definition at line 94 of file pywraplp.py.
|
static |
Definition at line 95 of file pywraplp.py.
|
static |
Definition at line 79 of file pywraplp.py.