Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
ortools.math_opt.python.result.SolveResult Class Reference

Detailed Description

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.

Definition at line 374 of file result.py.

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.BasisStatusconstraint_status (self, None linear_constraints=...)
solution.BasisStatus constraint_status (self, linear_constraints_mod.LinearConstraint linear_constraints)
List[solution.BasisStatusconstraint_status (self, Iterable[linear_constraints_mod.LinearConstraint] linear_constraints)
 constraint_status (self, linear_constraints=None)
Dict[variables_mod.Variable, solution.BasisStatusvariable_status (self, None variables=...)
solution.BasisStatus variable_status (self, variables_mod.Variable variables)
List[solution.BasisStatusvariable_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

Member Function Documentation

◆ best_objective_bound()

float ortools.math_opt.python.result.SolveResult.best_objective_bound ( self)
Returns a bound on the best possible objective value.

best_objective_bound() is always equal to dual_bound(), so they can be
used interchangeably.

Definition at line 494 of file result.py.

◆ bounded()

bool ortools.math_opt.python.result.SolveResult.bounded ( self)
Returns true only if the problem has been shown to be feasible and bounded.

Definition at line 549 of file result.py.

◆ constraint_status() [1/4]

List[solution.BasisStatus] ortools.math_opt.python.result.SolveResult.constraint_status ( self,
Iterable[linear_constraints_mod.LinearConstraint] linear_constraints )

Definition at line 873 of file result.py.

◆ constraint_status() [2/4]

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).

Definition at line 878 of file result.py.

◆ constraint_status() [3/4]

solution.BasisStatus ortools.math_opt.python.result.SolveResult.constraint_status ( self,
linear_constraints_mod.LinearConstraint linear_constraints )

Definition at line 868 of file result.py.

◆ constraint_status() [4/4]

Dict[linear_constraints_mod.LinearConstraint, solution.BasisStatus] ortools.math_opt.python.result.SolveResult.constraint_status ( self,
None linear_constraints = ... )

Definition at line 863 of file result.py.

◆ dual_bound()

float ortools.math_opt.python.result.SolveResult.dual_bound ( self)
Returns a dual bound on the optimal objective value as described in ObjectiveBounds.

Will return a valid (possibly infinite) bound even if no dual feasible
solutions are available.

Definition at line 443 of file result.py.

◆ dual_values() [1/4]

List[float] ortools.math_opt.python.result.SolveResult.dual_values ( self,
Iterable[linear_constraints_mod.LinearConstraint] linear_constraints )

Definition at line 642 of file result.py.

◆ dual_values() [2/4]

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).

Definition at line 647 of file result.py.

◆ dual_values() [3/4]

float ortools.math_opt.python.result.SolveResult.dual_values ( self,
linear_constraints_mod.LinearConstraint linear_constraints )

Definition at line 637 of file result.py.

◆ dual_values() [4/4]

Dict[linear_constraints_mod.LinearConstraint, float] ortools.math_opt.python.result.SolveResult.dual_values ( self,
None linear_constraints = ... )

Definition at line 632 of file result.py.

◆ has_basis()

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.

Definition at line 848 of file result.py.

◆ has_dual_feasible_solution()

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.

Definition at line 613 of file result.py.

◆ has_dual_ray()

bool ortools.math_opt.python.result.SolveResult.has_dual_ray ( self)
Indicates if at least one dual ray is available.

This is NOT guaranteed to be true when termination.reason is
TerminationReason.Infeasible.

Returns:
  True if at least one dual ray is available.

Definition at line 739 of file result.py.

◆ has_primal_feasible_solution()

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.

Definition at line 451 of file result.py.

◆ has_ray()

bool ortools.math_opt.python.result.SolveResult.has_ray ( self)
Indicates if at least one primal ray is available.

This is NOT guaranteed to be true when termination.reason is
TerminationReason.kUnbounded or TerminationReason.kInfeasibleOrUnbounded.

Returns:
  True if at least one primal ray is available.

Definition at line 557 of file result.py.

◆ objective_value()

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.

Definition at line 471 of file result.py.

◆ primal_bound()

float ortools.math_opt.python.result.SolveResult.primal_bound ( self)
Returns a primal bound on the optimal objective value as described in ObjectiveBounds.

Will return a valid (possibly infinite) bound even if no primal feasible
solutions are available.

Definition at line 435 of file result.py.

◆ ray_dual_values() [1/4]

List[float] ortools.math_opt.python.result.SolveResult.ray_dual_values ( self,
Iterable[linear_constraints_mod.LinearConstraint] linear_constraints )

Definition at line 761 of file result.py.

◆ ray_dual_values() [2/4]

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).

Definition at line 766 of file result.py.

◆ ray_dual_values() [3/4]

float ortools.math_opt.python.result.SolveResult.ray_dual_values ( self,
linear_constraints_mod.LinearConstraint linear_constraints )

Definition at line 756 of file result.py.

◆ ray_dual_values() [4/4]

Dict[linear_constraints_mod.LinearConstraint, float] ortools.math_opt.python.result.SolveResult.ray_dual_values ( self,
None linear_constraints = ... )

Definition at line 751 of file result.py.

◆ ray_reduced_costs() [1/4]

List[float] ortools.math_opt.python.result.SolveResult.ray_reduced_costs ( self,
Iterable[variables_mod.Variable] variables )

Definition at line 811 of file result.py.

◆ ray_reduced_costs() [2/4]

Dict[variables_mod.Variable, float] ortools.math_opt.python.result.SolveResult.ray_reduced_costs ( self,
None variables = ... )

Definition at line 803 of file result.py.

◆ ray_reduced_costs() [3/4]

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).

Definition at line 815 of file result.py.

◆ ray_reduced_costs() [4/4]

float ortools.math_opt.python.result.SolveResult.ray_reduced_costs ( self,
variables_mod.Variable variables )

Definition at line 808 of file result.py.

◆ ray_variable_values() [1/4]

List[float] ortools.math_opt.python.result.SolveResult.ray_variable_values ( self,
Iterable[variables_mod.Variable] variables )

Definition at line 577 of file result.py.

◆ ray_variable_values() [2/4]

Dict[variables_mod.Variable, float] ortools.math_opt.python.result.SolveResult.ray_variable_values ( self,
None variables = ... )

Definition at line 569 of file result.py.

◆ ray_variable_values() [3/4]

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).

Definition at line 581 of file result.py.

◆ ray_variable_values() [4/4]

float ortools.math_opt.python.result.SolveResult.ray_variable_values ( self,
variables_mod.Variable variables )

Definition at line 574 of file result.py.

◆ reduced_costs() [1/4]

List[float] ortools.math_opt.python.result.SolveResult.reduced_costs ( self,
Iterable[variables_mod.Variable] variables )

Definition at line 697 of file result.py.

◆ reduced_costs() [2/4]

Dict[variables_mod.Variable, float] ortools.math_opt.python.result.SolveResult.reduced_costs ( self,
None variables = ... )

Definition at line 689 of file result.py.

◆ reduced_costs() [3/4]

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).

Definition at line 701 of file result.py.

◆ reduced_costs() [4/4]

float ortools.math_opt.python.result.SolveResult.reduced_costs ( self,
variables_mod.Variable variables )

Definition at line 694 of file result.py.

◆ solve_time()

datetime.timedelta ortools.math_opt.python.result.SolveResult.solve_time ( self)
Shortcut for SolveResult.solve_stats.solve_time.

Definition at line 431 of file result.py.

◆ to_proto()

result_pb2.SolveResultProto ortools.math_opt.python.result.SolveResult.to_proto ( self)
Returns an equivalent protocol buffer for a SolveResult.

Definition at line 969 of file result.py.

◆ variable_status() [1/4]

List[solution.BasisStatus] ortools.math_opt.python.result.SolveResult.variable_status ( self,
Iterable[variables_mod.Variable] variables )

Definition at line 929 of file result.py.

◆ variable_status() [2/4]

Dict[variables_mod.Variable, solution.BasisStatus] ortools.math_opt.python.result.SolveResult.variable_status ( self,
None variables = ... )

Definition at line 919 of file result.py.

◆ variable_status() [3/4]

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).

Definition at line 933 of file result.py.

◆ variable_status() [4/4]

solution.BasisStatus ortools.math_opt.python.result.SolveResult.variable_status ( self,
variables_mod.Variable variables )

Definition at line 924 of file result.py.

◆ variable_values() [1/4]

List[float] ortools.math_opt.python.result.SolveResult.variable_values ( self,
Iterable[variables_mod.Variable] variables )

Definition at line 511 of file result.py.

◆ variable_values() [2/4]

Dict[variables_mod.Variable, float] ortools.math_opt.python.result.SolveResult.variable_values ( self,
None variables = ... )

Definition at line 503 of file result.py.

◆ variable_values() [3/4]

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).

Definition at line 515 of file result.py.

◆ variable_values() [4/4]

float ortools.math_opt.python.result.SolveResult.variable_values ( self,
variables_mod.Variable variables )

Definition at line 508 of file result.py.

Member Data Documentation

◆ dual_rays

ortools.math_opt.python.result.SolveResult.dual_rays = dataclasses.field(default_factory=list)
static

Definition at line 425 of file result.py.

◆ gscip_specific_output

ortools.math_opt.python.result.SolveResult.gscip_specific_output = None
static

Definition at line 427 of file result.py.

◆ osqp_specific_output

ortools.math_opt.python.result.SolveResult.osqp_specific_output = None
static

Definition at line 428 of file result.py.

◆ pdlp_specific_output

ortools.math_opt.python.result.SolveResult.pdlp_specific_output = None
static

Definition at line 429 of file result.py.

◆ primal_rays

ortools.math_opt.python.result.SolveResult.primal_rays = dataclasses.field(default_factory=list)
static

Definition at line 424 of file result.py.

◆ solutions

List ortools.math_opt.python.result.SolveResult.solutions = dataclasses.field(default_factory=list)
static

Definition at line 423 of file result.py.

◆ solve_stats

SolveStats ortools.math_opt.python.result.SolveResult.solve_stats = dataclasses.field(default_factory=SolveStats)
static

Definition at line 422 of file result.py.

◆ termination

Termination ortools.math_opt.python.result.SolveResult.termination = dataclasses.field(default_factory=Termination)
static

Definition at line 421 of file result.py.


The documentation for this class was generated from the following file:
  • build/python/ortools/math_opt/python/result.py