picos.modeling.solution¶
Optimization problem solution representation.
Classes¶
Solution¶

class
picos.modeling.solution.
Solution
(primals, duals=None, problem=None, solver='user', primalStatus='unknown', dualStatus='unknown', problemStatus='unknown', searchTime=0.0, info=None, vectorizedPrimals=False)[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 >>> P = picos.Problem() >>> x = P.add_variable("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:>>> C1 = P.add_constraint(x >= 2) >>> s = P.minimize(x, solver = "cvxopt", duals = False); s <feasible primal solution (claimed optimal) from cvxopt> >>> "{:.2f} ms".format(1000.0 * s.searchTime) '0.83 ms' >>> C2 = P.add_constraint(x >= 3); s <infeasible primal solution (was feasible and claimed optimal) from cvxopt>

__init__
(primals, duals=None, problem=None, solver='user', primalStatus='unknown', dualStatus='unknown', problemStatus='unknown', searchTime=0.0, info=None, vectorizedPrimals=False)[source]¶ Create a solution to an optimization problem.
 Parameters
object) primals (dict(picos.expressions.BaseVariable,) – A mapping of variables to their primal solution value.
object) duals (dict(picos.constraints.Constraint,) – 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.

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
= None¶ The primal and dual solution status as claimed by the solver.

dualStatus
= None¶ The dual solution status as claimed by the solver.

duals
= None¶ The dual solution values returned by the solver.

info
= None¶ Additional information provided by the solver.

lastStatus
= None¶ The solution status as verified by PICOS when the solution was applied to the problem.

primalStatus
= None¶ The primal solution status as claimed by the solver.

primals
= None¶ The primal solution values returned by the solver.

problem
= None¶ The problem that was solved to produce the solution.

problemStatus
= None¶ The problem status as claimed by the solver.

searchTime
= None¶ Time in seconds that the solution search took.

solver
= None¶ 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.
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
= None¶ Whether primal values refer to variables’ special vectorizations.

Data¶

picos.modeling.solution.
PS_FEASIBLE
¶ The problem is primal (and dual) feasible and bounded.

picos.modeling.solution.
PS_ILLPOSED
¶ The problem was found to be in a state that is not amenable to solution.

picos.modeling.solution.
PS_INFEASIBLE
¶ The problem is primal infeasible (and dual unbounded or infeasible).

picos.modeling.solution.
PS_INF_OR_UNB
¶ The problem is primal infeasible or unbounded.
Being unbounded is usually infered from being dual infeasible.

picos.modeling.solution.
PS_UNBOUNDED
¶ The problem is primal unbounded (and dual infeasible).

picos.modeling.solution.
PS_UNKNOWN
¶ The solver did not make a clear claim about the problem status.

picos.modeling.solution.
PS_UNSTABLE
¶ The problem was found numerically unstable or otherwise hard to handle.

picos.modeling.solution.
SS_EMPTY
¶ The solver claims not to have produced a solution.

picos.modeling.solution.
SS_FAILURE
¶ The search was termined due to a solver failure.

picos.modeling.solution.
SS_FEASIBLE
¶ The solution is 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.

picos.modeling.solution.
SS_OPTIMAL
¶ The solution is optimal.

picos.modeling.solution.
SS_PREMATURE
¶ The search was prematurely terminated due to some limit.

picos.modeling.solution.
SS_UNKNOWN
¶ The solver did not make a clear claim about the solution status.

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

picos.modeling.solution.
VS_DETACHED_EMPTY
¶ The solution is both detached and empty.

picos.modeling.solution.
VS_EMPTY
¶ The solution is empty; there are neither primals nor duals.

picos.modeling.solution.
VS_FEASIBLE
¶ The solution is primal feasible; there is no dual solution.

picos.modeling.solution.
VS_INCOMPLETE
¶ The primal (dual) solution does not concern all variables (constraints).

picos.modeling.solution.
VS_INFEASIBLE
¶ The solution is primal infeasible; there is no dual solution.

picos.modeling.solution.
VS_OUTDATED
¶ The solution does not fit the problem formulation any more.
Variables or constraints were removed from the problem.

picos.modeling.solution.
VS_PRIMAL_FEASIBLE
¶ The solution is primal feasible; a dual solution was not verified.

picos.modeling.solution.
VS_PRIMAL_INFEASIBLE
¶ The solution is primal infeasible; a dual solution was not verified.

picos.modeling.solution.
VS_UNKNOWN
¶ PICOS failed to verify the solution.