picos.modeling.solution

Optimization problem solution representation.

Classes

class picos.modeling.solution.Solution(primals, duals=None, problem=None, solver='user', primalStatus=SS_UNKNOWN, dualStatus=SS_UNKNOWN, problemStatus=PS_UNKNOWN, searchTime=0.0, info=None, vectorizedPrimals=False, reportedValue=None)[source]

Bases: object

Assignment of primal and dual values to variables and constraints.

Instances are usually returned by a solver (and thus bound to a problem instance), but may be manually created by the user:

>>> import picos
>>> x = picos.RealVariable("x")
>>> s = picos.Solution({x: 1}); s
<detached primal solution from user>
>>> s.apply()
>>> x.value
1.0

If the solution was created by a solver (or attached to a problem via attach_to), more information is available:

>>> P = picos.Problem()
>>> P.minimize = x
>>> P += x >= 2
>>> s = P.solve(solver = "cvxopt", duals = False); s
<feasible primal solution (claimed optimal) from cvxopt>
>>> "{:.2f} ms".format(1000.0 * s.searchTime) 
'0.83 ms'
>>> P += x >= 3; s
<infeasible primal solution (was feasible and claimed optimal) from cvxopt>
__init__(primals, duals=None, problem=None, solver='user', primalStatus=SS_UNKNOWN, dualStatus=SS_UNKNOWN, problemStatus=PS_UNKNOWN, searchTime=0.0, info=None, vectorizedPrimals=False, reportedValue=None)[source]

Create a solution to an optimization problem.

Parameters
  • primals (dict(picos.expressions.BaseVariable, object)) – A mapping of variables to their primal solution value.

  • duals (dict(picos.constraints.Constraint, object)) – A mapping of constraints to their dual solution value.

  • problem (picos.Problem) – The problem that was solved to create the solution. If None, then the solution is “detached”.

  • solver (str) – The name of the solver that was used to create the solution.

  • primalStatus (str) – The primal solution status as reported by the solver.

  • dualStatus (str) – The dual solution status as reported by the solver.

  • problemStatus (str) – The state of the problem as reported by the solver.

  • searchTime (float) – Seconds that the solution process took.

  • info (dict) – Additional solution (meta)data.

  • vectorizedPrimals (bool) – Whether primal solution values are given with respect to the variable’s special vectorization format as used by PICOS internally.

  • reportedValue (float) – Objective value of the solution as reported by the solver.

apply(primals=True, duals=True, clearOnNone=True, toProblem=None, snapshotStatus=False)[source]

Apply the solution to the involved variables and constraints.

Parameters
  • primals (bool) – Whether to apply the primal solution.

  • duals (bool) – Whether to apply the dual solution.

  • clearOnNone (bool) – Whether to clear the value of a variable or constraint if the solution has it set to None. This could happen in case of an error or shortcoming of the solver or PICOS.

  • toProblem (picos.Problem) – If set to a copy of the problem that was used to produce the solution, will apply the solution to that copy’s variables and constraints instead.

  • snapshotStatus (bool) – Whether to update the lastStatus attribute with the new (verified) solution status. PICOS enables this whenever it applies a solution returned by a solver.

attach_to(problem, snapshotStatus=False)[source]

Attach (or move) the solution to a problem.

Only variables and constraints that exist on the problem (same name or ID, respectively) are kept.

Parameters

snapshotStatus (bool) – Whether to set the lastStatus attribute of the copy to match the new problem.

claimedStatus

The primal and dual solution status as claimed by the solver.

dualStatus

The dual solution status as claimed by the solver.

duals

The dual solution values returned by the solver.

info

Additional information provided by the solver.

lastStatus

The solution status as verified by PICOS when the solution was applied to the problem.

primalStatus

The primal solution status as claimed by the solver.

primals

The primal solution values returned by the solver.

problem

The problem that was solved to produce the solution.

problemStatus

The problem status as claimed by the solver.

reportedValue

The objective value of the solution as reported by the solver.

property reported_value

The objective value as reported by the solver, or None.

searchTime

Time in seconds that the solution search took.

solver

The solver that produced the solution.

property status

The current solution status as verified by PICOS.

Warning

Accessing this attribute is expensive for large problems as a copy of the problem needs to be created and valued. If you have just applied the solution to a problem, query the solution’s lastStatus attribute instead.

property value

The objective value of the solution as computed by PICOS.

Warning

Accessing this attribute is expensive for large problems as a copy of the problem needs to be created and valued. If you have just applied the solution to a problem, query that problem instead.

vectorizedPrimals

Whether primal values refer to variables’ special vectorizations.

Objects

picos.modeling.solution.PS_FEASIBLE

The problem is primal (and dual) feasible and bounded.

Default value
'feasible'
picos.modeling.solution.PS_ILLPOSED

The problem was found to be in a state that is not amenable to solution.

Default value
'illposed'
picos.modeling.solution.PS_INFEASIBLE

The problem is primal infeasible (and dual unbounded or infeasible).

Default value
'infeasible'
picos.modeling.solution.PS_INF_OR_UNB

The problem is primal infeasible or unbounded.

Being unbounded is usually infered from being dual infeasible.

Default value
'infeasible or unbounded'
picos.modeling.solution.PS_UNBOUNDED

The problem is primal unbounded (and dual infeasible).

Default value
'unbounded'
picos.modeling.solution.PS_UNKNOWN

The solver did not make a clear claim about the problem status.

Default value
'unknown'
picos.modeling.solution.PS_UNSTABLE

The problem was found numerically unstable or otherwise hard to handle.

Default value
'unstable'
picos.modeling.solution.SS_EMPTY

The solver claims not to have produced a solution.

Default value
'empty'
picos.modeling.solution.SS_FAILURE

The search was termined due to a solver failure.

Default value
'failure'
picos.modeling.solution.SS_FEASIBLE

The solution is feasible.

Default value
'feasible'
picos.modeling.solution.SS_INFEASIBLE

No feasible solution exists.

In the case of a primal solution, the problem is infeasible. In the case of a dual solution, the problem is unbounded.

Default value
'infeasible'
picos.modeling.solution.SS_OPTIMAL

The solution is optimal.

Default value
'optimal'
picos.modeling.solution.SS_PREMATURE

The search was prematurely terminated due to some limit.

Default value
'premature'
picos.modeling.solution.SS_UNKNOWN

The solver did not make a clear claim about the solution status.

Default value
'unknown'
picos.modeling.solution.VS_DETACHED

The solution is not attached to a problem (it was given by the user).

Default value
'detached'
picos.modeling.solution.VS_DETACHED_EMPTY

The solution is both detached and empty.

Default value
'detached empty'
picos.modeling.solution.VS_EMPTY

The solution is empty; there are neither primals nor duals.

Default value
'empty'
picos.modeling.solution.VS_FEASIBLE

The solution is primal feasible; there is no dual solution.

Default value
'feasible'
picos.modeling.solution.VS_INCOMPLETE

The primal (dual) solution does not concern all variables (constraints).

Default value
'incomplete'
picos.modeling.solution.VS_INFEASIBLE

The solution is primal infeasible; there is no dual solution.

Default value
'infeasible'
picos.modeling.solution.VS_OUTDATED

The solution does not fit the problem formulation any more.

Variables or constraints were removed from the problem.

Default value
'outdated'
picos.modeling.solution.VS_PRIMAL_FEASIBLE

The solution is primal feasible; a dual solution was not verified.

Default value
'primal feasible'
picos.modeling.solution.VS_PRIMAL_INFEASIBLE

The solution is primal infeasible; a dual solution was not verified.

Default value
'primal infeasible'
picos.modeling.solution.VS_UNKNOWN

PICOS failed to verify the solution.

Default value
'unverified'