![]() |
Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
|
The result of solving an optimization problem defined by a Model.
We attempt to return as much solution information (primal_solutions,
primal_rays, dual_solutions, dual_rays) as each underlying solver will provide
given its return status. Differences in the underlying solvers result in a
weak contract on what fields will be populated for a given termination
reason. This is discussed in detail in termination_reasons.md, and the most
important points are summarized below:
* When the termination reason is optimal, there will be at least one primal
solution provided that will be feasible up to the underlying solver's
tolerances.
* Dual solutions are only given for convex optimization problems (e.g.
linear programs, not integer programs).
* A basis is only given for linear programs when solved by the simplex
method (e.g., not with PDLP).
* Solvers have widely varying support for returning primal and dual rays.
E.g. a termination_reason of unbounded does not ensure that a feasible
solution or a primal ray is returned, check termination_reasons.md for
solver specific guarantees if this is needed. Further, many solvers will
provide the ray but not the feasible solution when returning an unbounded
status.
* When the termination reason is that a limit was reached or that the result
is imprecise, a solution may or may not be present. Further, for some
solvers (generally, convex optimization solvers, not MIP solvers), the
primal or dual solution may not be feasible.
Solver specific output is also returned for some solvers (and only information
for the solver used will be populated).
Attributes:
termination: The reason the solver stopped.
solve_stats: Statistics on the solve process, e.g. running time, iterations.
solutions: Lexicographically by primal feasibility status, dual feasibility
status, (basic dual feasibility for simplex solvers), primal objective
value and dual objective value.
primal_rays: Directions of unbounded primal improvement, or equivalently,
dual infeasibility certificates. Typically provided for terminal reasons
UNBOUNDED and DUAL_INFEASIBLE.
dual_rays: Directions of unbounded dual improvement, or equivalently, primal
infeasibility certificates. Typically provided for termination reason
INFEASIBLE.
gscip_specific_output: statistics returned by the gSCIP solver, if used.
osqp_specific_output: statistics returned by the OSQP solver, if used.
pdlp_specific_output: statistics returned by the PDLP solver, if used.
Public Member Functions | |
| datetime.timedelta | solve_time (self) |
| float | primal_bound (self) |
| float | dual_bound (self) |
| bool | has_primal_feasible_solution (self) |
| float | objective_value (self) |
| float | best_objective_bound (self) |
| Dict[variables_mod.Variable, float] | variable_values (self, None variables=...) |
| float | variable_values (self, variables_mod.Variable variables) |
| List[float] | variable_values (self, Iterable[variables_mod.Variable] variables) |
| variable_values (self, variables=None) | |
| bool | bounded (self) |
| bool | has_ray (self) |
| Dict[variables_mod.Variable, float] | ray_variable_values (self, None variables=...) |
| float | ray_variable_values (self, variables_mod.Variable variables) |
| List[float] | ray_variable_values (self, Iterable[variables_mod.Variable] variables) |
| ray_variable_values (self, variables=None) | |
| bool | has_dual_feasible_solution (self) |
| Dict[linear_constraints_mod.LinearConstraint, float] | dual_values (self, None linear_constraints=...) |
| float | dual_values (self, linear_constraints_mod.LinearConstraint linear_constraints) |
| List[float] | dual_values (self, Iterable[linear_constraints_mod.LinearConstraint] linear_constraints) |
| dual_values (self, linear_constraints=None) | |
| Dict[variables_mod.Variable, float] | reduced_costs (self, None variables=...) |
| float | reduced_costs (self, variables_mod.Variable variables) |
| List[float] | reduced_costs (self, Iterable[variables_mod.Variable] variables) |
| reduced_costs (self, variables=None) | |
| bool | has_dual_ray (self) |
| Dict[linear_constraints_mod.LinearConstraint, float] | ray_dual_values (self, None linear_constraints=...) |
| float | ray_dual_values (self, linear_constraints_mod.LinearConstraint linear_constraints) |
| List[float] | ray_dual_values (self, Iterable[linear_constraints_mod.LinearConstraint] linear_constraints) |
| ray_dual_values (self, linear_constraints=None) | |
| Dict[variables_mod.Variable, float] | ray_reduced_costs (self, None variables=...) |
| float | ray_reduced_costs (self, variables_mod.Variable variables) |
| List[float] | ray_reduced_costs (self, Iterable[variables_mod.Variable] variables) |
| ray_reduced_costs (self, variables=None) | |
| bool | has_basis (self) |
| Dict[linear_constraints_mod.LinearConstraint, solution.BasisStatus] | constraint_status (self, None linear_constraints=...) |
| solution.BasisStatus | constraint_status (self, linear_constraints_mod.LinearConstraint linear_constraints) |
| List[solution.BasisStatus] | constraint_status (self, Iterable[linear_constraints_mod.LinearConstraint] linear_constraints) |
| constraint_status (self, linear_constraints=None) | |
| Dict[variables_mod.Variable, solution.BasisStatus] | variable_status (self, None variables=...) |
| solution.BasisStatus | variable_status (self, variables_mod.Variable variables) |
| List[solution.BasisStatus] | variable_status (self, Iterable[variables_mod.Variable] variables) |
| variable_status (self, variables=None) | |
| result_pb2.SolveResultProto | to_proto (self) |
Static Public Attributes | |
| Termination | termination = dataclasses.field(default_factory=Termination) |
| SolveStats | solve_stats = dataclasses.field(default_factory=SolveStats) |
| List | solutions = dataclasses.field(default_factory=list) |
| List | primal_rays = dataclasses.field(default_factory=list) |
| List | dual_rays = dataclasses.field(default_factory=list) |
| Optional | gscip_specific_output = None |
| Optional | osqp_specific_output = None |
| Optional | pdlp_specific_output = None |
| float ortools.math_opt.python.result.SolveResult.best_objective_bound | ( | self | ) |
| bool ortools.math_opt.python.result.SolveResult.bounded | ( | self | ) |
| List[solution.BasisStatus] ortools.math_opt.python.result.SolveResult.constraint_status | ( | self, | |
| Iterable[linear_constraints_mod.LinearConstraint] | linear_constraints ) |
| ortools.math_opt.python.result.SolveResult.constraint_status | ( | self, | |
| linear_constraints = None ) |
The constraint basis status associated to the best solution.
If there is at least one primal feasible solution, this corresponds to the
basis associated to the best primal feasible solution. An error will
be raised if the best solution does not have an associated basis.
Args:
linear_constraints: an optional LinearConstraint or iterator of
LinearConstraint indicating what constraint statuses to return. If not
provided, returns a dictionary with the constraint statuses for all
linear constraints.
Returns:
The constraint basis status associated to the best solution.
Raises:
ValueError: The best solution does not have an associated basis.
TypeError: Argument is not None, a LinearConstraint or an iterable of
LinearConstraint.
KeyError: LinearConstraint values requested for an invalid
linear constraint (e.g. is not a LinearConstraint or is a linear
constraint for another model).
| solution.BasisStatus ortools.math_opt.python.result.SolveResult.constraint_status | ( | self, | |
| linear_constraints_mod.LinearConstraint | linear_constraints ) |
| Dict[linear_constraints_mod.LinearConstraint, solution.BasisStatus] ortools.math_opt.python.result.SolveResult.constraint_status | ( | self, | |
| None | linear_constraints = ... ) |
| float ortools.math_opt.python.result.SolveResult.dual_bound | ( | self | ) |
| List[float] ortools.math_opt.python.result.SolveResult.dual_values | ( | self, | |
| Iterable[linear_constraints_mod.LinearConstraint] | linear_constraints ) |
| ortools.math_opt.python.result.SolveResult.dual_values | ( | self, | |
| linear_constraints = None ) |
The dual values associated to the best solution.
If there is at least one primal feasible solution, this corresponds to the
dual values associated to the best primal feasible solution. An error will
be raised if the best solution does not have an associated dual feasible
solution.
Args:
linear_constraints: an optional LinearConstraint or iterator of
LinearConstraint indicating what dual values to return. If not provided,
dual_values() returns a dictionary with the dual values for all linear
constraints.
Returns:
The dual values associated to the best solution.
Raises:
ValueError: The best solution does not have an associated dual feasible
solution.
TypeError: Argument is not None, a LinearConstraint or an iterable of
LinearConstraint.
KeyError: LinearConstraint values requested for an invalid
linear constraint (e.g. is not a LinearConstraint or is a linear
constraint for another model).
| float ortools.math_opt.python.result.SolveResult.dual_values | ( | self, | |
| linear_constraints_mod.LinearConstraint | linear_constraints ) |
| Dict[linear_constraints_mod.LinearConstraint, float] ortools.math_opt.python.result.SolveResult.dual_values | ( | self, | |
| None | linear_constraints = ... ) |
| bool ortools.math_opt.python.result.SolveResult.has_basis | ( | self | ) |
Indicates if the best solution has an associated basis. This is NOT guaranteed to be true when termination.reason is TerminationReason.Optimal. It also may be true even when the best solution does not have an associated primal feasible solution. Returns: True if the best solution has an associated basis.
| bool ortools.math_opt.python.result.SolveResult.has_dual_feasible_solution | ( | self | ) |
Indicates if the best solution has an associated dual feasible solution. This is NOT guaranteed to be true when termination.reason is TerminationReason.Optimal. It also may be true even when the best solution does not have an associated primal feasible solution. Returns: True if the best solution has an associated dual feasible solution.
| bool ortools.math_opt.python.result.SolveResult.has_dual_ray | ( | self | ) |
| bool ortools.math_opt.python.result.SolveResult.has_primal_feasible_solution | ( | self | ) |
Indicates if at least one primal feasible solution is available. When termination.reason is TerminationReason.OPTIMAL or TerminationReason.FEASIBLE, this is guaranteed to be true and need not be checked. Returns: True if there is at least one primal feasible solution is available, False, otherwise.
| bool ortools.math_opt.python.result.SolveResult.has_ray | ( | self | ) |
| float ortools.math_opt.python.result.SolveResult.objective_value | ( | self | ) |
Returns the objective value of the best primal feasible solution. An error will be raised if there are no primal feasible solutions. primal_bound() above is guaranteed to be at least as good (larger or equal for max problems and smaller or equal for min problems) as objective_value() and will never raise an error, so it may be preferable in some cases. Note that primal_bound() could be better than objective_value() even for optimal terminations, but on such optimal termination, both should satisfy the optimality tolerances. Returns: The objective value of the best primal feasible solution. Raises: ValueError: There are no primal feasible solutions.
| float ortools.math_opt.python.result.SolveResult.primal_bound | ( | self | ) |
| List[float] ortools.math_opt.python.result.SolveResult.ray_dual_values | ( | self, | |
| Iterable[linear_constraints_mod.LinearConstraint] | linear_constraints ) |
| ortools.math_opt.python.result.SolveResult.ray_dual_values | ( | self, | |
| linear_constraints = None ) |
The dual values from the first dual ray.
An error will be raised if there are no dual rays.
Args:
linear_constraints: an optional LinearConstraint or iterator of
LinearConstraint indicating what dual values to return. If not provided,
ray_dual_values() returns a dictionary with the dual values for all
linear constraints.
Returns:
The dual values from the first dual ray.
Raises:
ValueError: There are no dual rays.
TypeError: Argument is not None, a LinearConstraint or an iterable of
LinearConstraint.
KeyError: LinearConstraint values requested for an invalid
linear constraint (e.g. is not a LinearConstraint or is a linear
constraint for another model).
| float ortools.math_opt.python.result.SolveResult.ray_dual_values | ( | self, | |
| linear_constraints_mod.LinearConstraint | linear_constraints ) |
| Dict[linear_constraints_mod.LinearConstraint, float] ortools.math_opt.python.result.SolveResult.ray_dual_values | ( | self, | |
| None | linear_constraints = ... ) |
| List[float] ortools.math_opt.python.result.SolveResult.ray_reduced_costs | ( | self, | |
| Iterable[variables_mod.Variable] | variables ) |
| Dict[variables_mod.Variable, float] ortools.math_opt.python.result.SolveResult.ray_reduced_costs | ( | self, | |
| None | variables = ... ) |
| ortools.math_opt.python.result.SolveResult.ray_reduced_costs | ( | self, | |
| variables = None ) |
The reduced costs from the first dual ray.
An error will be raised if there are no dual rays.
Args:
variables: an optional Variable or iterator of Variables indicating what
reduced costs to return. If not provided, ray_reduced_costs() returns a
dictionary with the reduced costs for all variables.
Returns:
The reduced costs from the first dual ray.
Raises:
ValueError: There are no dual rays.
TypeError: Argument is not None, a Variable or an iterable of Variables.
KeyError: Variable values requested for an invalid variable (e.g. is not a
Variable or is a variable for another model).
| float ortools.math_opt.python.result.SolveResult.ray_reduced_costs | ( | self, | |
| variables_mod.Variable | variables ) |
| List[float] ortools.math_opt.python.result.SolveResult.ray_variable_values | ( | self, | |
| Iterable[variables_mod.Variable] | variables ) |
| Dict[variables_mod.Variable, float] ortools.math_opt.python.result.SolveResult.ray_variable_values | ( | self, | |
| None | variables = ... ) |
| ortools.math_opt.python.result.SolveResult.ray_variable_values | ( | self, | |
| variables = None ) |
The variable values from the first primal ray.
An error will be raised if there are no primal rays.
Args:
variables: an optional Variable or iterator of Variables indicating what
variable values to return. If not provided, variable_values() returns a
dictionary with the variable values for all variables.
Returns:
The variable values from the first primal ray.
Raises:
ValueError: There are no primal rays.
TypeError: Argument is not None, a Variable or an iterable of Variables.
KeyError: Variable values requested for an invalid variable (e.g. is not a
Variable or is a variable for another model).
| float ortools.math_opt.python.result.SolveResult.ray_variable_values | ( | self, | |
| variables_mod.Variable | variables ) |
| List[float] ortools.math_opt.python.result.SolveResult.reduced_costs | ( | self, | |
| Iterable[variables_mod.Variable] | variables ) |
| Dict[variables_mod.Variable, float] ortools.math_opt.python.result.SolveResult.reduced_costs | ( | self, | |
| None | variables = ... ) |
| ortools.math_opt.python.result.SolveResult.reduced_costs | ( | self, | |
| variables = None ) |
The reduced costs associated to the best solution.
If there is at least one primal feasible solution, this corresponds to the
reduced costs associated to the best primal feasible solution. An error will
be raised if the best solution does not have an associated dual feasible
solution.
Args:
variables: an optional Variable or iterator of Variables indicating what
reduced costs to return. If not provided, reduced_costs() returns a
dictionary with the reduced costs for all variables.
Returns:
The reduced costs associated to the best solution.
Raises:
ValueError: The best solution does not have an associated dual feasible
solution.
TypeError: Argument is not None, a Variable or an iterable of Variables.
KeyError: Variable values requested for an invalid variable (e.g. is not a
Variable or is a variable for another model).
| float ortools.math_opt.python.result.SolveResult.reduced_costs | ( | self, | |
| variables_mod.Variable | variables ) |
| datetime.timedelta ortools.math_opt.python.result.SolveResult.solve_time | ( | self | ) |
| result_pb2.SolveResultProto ortools.math_opt.python.result.SolveResult.to_proto | ( | self | ) |
| List[solution.BasisStatus] ortools.math_opt.python.result.SolveResult.variable_status | ( | self, | |
| Iterable[variables_mod.Variable] | variables ) |
| Dict[variables_mod.Variable, solution.BasisStatus] ortools.math_opt.python.result.SolveResult.variable_status | ( | self, | |
| None | variables = ... ) |
| ortools.math_opt.python.result.SolveResult.variable_status | ( | self, | |
| variables = None ) |
The variable basis status associated to the best solution.
If there is at least one primal feasible solution, this corresponds to the
basis associated to the best primal feasible solution. An error will
be raised if the best solution does not have an associated basis.
Args:
variables: an optional Variable or iterator of Variables indicating what
reduced costs to return. If not provided, variable_status() returns a
dictionary with the reduced costs for all variables.
Returns:
The variable basis status associated to the best solution.
Raises:
ValueError: The best solution does not have an associated basis.
TypeError: Argument is not None, a Variable or an iterable of Variables.
KeyError: Variable values requested for an invalid variable (e.g. is not a
Variable or is a variable for another model).
| solution.BasisStatus ortools.math_opt.python.result.SolveResult.variable_status | ( | self, | |
| variables_mod.Variable | variables ) |
| List[float] ortools.math_opt.python.result.SolveResult.variable_values | ( | self, | |
| Iterable[variables_mod.Variable] | variables ) |
| Dict[variables_mod.Variable, float] ortools.math_opt.python.result.SolveResult.variable_values | ( | self, | |
| None | variables = ... ) |
| ortools.math_opt.python.result.SolveResult.variable_values | ( | self, | |
| variables = None ) |
The variable values from the best primal feasible solution.
An error will be raised if there are no primal feasible solutions.
Args:
variables: an optional Variable or iterator of Variables indicating what
variable values to return. If not provided, variable_values returns a
dictionary with all the variable values for all variables.
Returns:
The variable values from the best primal feasible solution.
Raises:
ValueError: There are no primal feasible solutions.
TypeError: Argument is not None, a Variable or an iterable of Variables.
KeyError: Variable values requested for an invalid variable (e.g. is not a
Variable or is a variable for another model).
| float ortools.math_opt.python.result.SolveResult.variable_values | ( | self, | |
| variables_mod.Variable | variables ) |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |