picos.modeling.problem¶
Implementation of Problem
.
Outline¶
Classes¶
An optimization objective composed of search direction and function. 

PICOS’ representation of an optimization problem. 
Exceptions¶
Solving the problem failed. 
Classes¶
Objective¶

class
picos.modeling.problem.
Objective
(direction=None, function=None)[source]¶ Bases:
object
An optimization objective composed of search direction and function.

__init__
(direction=None, function=None)[source]¶ Construct an optimization objective.
 Parameters
direction (str) –
Case insensitive search direction string. One of
"min"
or"minimize"
,"max"
or"maximize"
,"find"
orNone
(for a feasibility problem).
function (Expression) – The objective function. Must be
None
for a feasibility problem.

FIND
= 'find'¶ Short string denoting a feasibility problem.

MAX
= 'max'¶ Short string denoting a maximization problem.

MIN
= 'min'¶ Short string denoting a minimization problem.

property
direction
¶ Search direction as a short string.

property
feasibility
¶ Whether the objective is “find an assignment”.

property
function
¶ Objective function.

property
normalized
¶ The objective but with feasiblity posed as “minimize 0”.
>>> from picos import Objective >>> obj = Objective(); obj <Objective: find a variable assignment> >>> obj.normalized <Objective: minimize 0>

property
pair
¶ Search direction and objective function as a pair.

property
value
¶ Value of the objective function.

Problem¶

class
picos.modeling.problem.
Problem
(copyOptions=None, useOptions=None, **extra_options)[source]¶ Bases:
object
PICOS’ representation of an optimization problem.
 Example
>>> from picos import Problem, RealVariable >>> X = RealVariable("X", (2,2), lower = 0) >>> P = Problem() >>> P.set_objective("max", X.tr) >>> C1 = P.add_constraint(X.sum <= 10) >>> C2 = P.add_constraint(X[0,0] == 1) >>> print(P)  Linear Program maximize tr(X) over 2×2 real variable X (bounded below) subject to ∑(X) ≤ 10 X[0,0] = 1  >>> # PICOS will select a suitable solver if you don't specify one. >>> solution = P.solve(solver = "cvxopt") >>> solution.claimedStatus 'optimal' >>> solution.searchTime 0.002137422561645508 >>> round(P, 1) 10.0 >>> print(X) [ 1.00e+00 4.89e10] [ 4.89e10 9.00e+00] >>> round(C1.dual, 1) 1.0

__init__
(copyOptions=None, useOptions=None, **extra_options)[source]¶ Create an empty problem and optionally set initial solver options.
 Parameters
copyOptions – An
Options
object to copy instead of using the default options.useOptions – An
Options
object to use (without making a copy) instead of using the default options.extra_options – A sequence of additional solver options to apply on top of the default options or those given by
copyOptions
oruseOptions
.

add_constraint
(constraint, key=None)[source]¶ Add a constraint to the problem.
 Parameters
constraint (
Constraint
) – The constraint to be added.key (str) – Optional name of the constraint.
 Returns
The constraint that was added to the problem.

add_list_of_constraints
(lst, it=None, indices=None, key=None)[source]¶ Add a list of constraints to the problem.
Adds a list of constraints to the problem, enabling the use of Python list comprehensions (see the example below).
 Parameters
lst (list(picos.constraints.Constraint)) – Constraints to add.
it – DEPRECATED
indices – DEPRECATED
key – DEPRECATED
 Returns
A list of all constraints that were added.
 Example
>>> import picos as pic >>> import cvxopt as cvx >>> from pprint import pprint >>> prob=pic.Problem() >>> x=[prob.add_variable('x[{0}]'.format(i),2) for i in range(5)] >>> pprint(x) [<2×1 Real Variable: x[0]>, <2×1 Real Variable: x[1]>, <2×1 Real Variable: x[2]>, <2×1 Real Variable: x[3]>, <2×1 Real Variable: x[4]>] >>> y=prob.add_variable('y',5) >>> IJ=[(1,2),(2,0),(4,2)] >>> w={} >>> for ij in IJ: ... w[ij]=prob.add_variable('w[{},{}]'.format(*ij),3) ... >>> u=pic.new_param('u',cvx.matrix([2,5])) >>> C1=prob.add_list_of_constraints([u.T*x[i] < y[i] for i in range(5)]) >>> C2=prob.add_list_of_constraints([abs(w[i,j])<y[j] for (i,j) in IJ]) >>> C3=prob.add_list_of_constraints([y[t] > y[t+1] for t in range(4)]) >>> print(prob)  Feasibility Problem find an assignment for 2×1 real variable x[i] ∀ i ∈ [0…4] 3×1 real variable w[i,j] ∀ (i,j) ∈ zip([1,2,4],[2,0,2]) 5×1 real variable y subject to uᵀ·x[i] ≤ y[i] ∀ i ∈ [0…4] ‖w[i,j]‖ ≤ y[j] ∀ (i,j) ∈ zip([1,2,4],[2,0,2]) y[i] ≥ y[i+1] ∀ i ∈ [0…3] 

add_variable
(name, size=1, vtype='continuous', lower=None, upper=None)[source]¶ Legacy method to create a PICOS variable.
 Parameters
name (str) – The name of the variable.
size (anything recognized by
load_shape
) – The shape of the variable.vtype (str) –
Domain of the variable. Can be any of
'continuous'
– real valued,'binary'
– either zero or one,'integer'
– integer valued,'symmetric'
– symmetric matrix,'antisym'
or'skewsym'
– skewsymmetric matrix,'complex'
– complex matrix,'hermitian'
– complex hermitian matrix.
lower (anything recognized by
load_data
) – A lower bound on the variable.upper (anything recognized by
load_data
) – An upper bound on the variable.
 Returns
A
BaseVariable
instance. Example
>>> from picos import Problem >>> P = Problem() >>> x = P.add_variable("x", 3) >>> x <3×1 Real Variable: x> >>> # Variable are not stored inside the problem any more: >>> P.variables mappingproxy(OrderedDict()) >>> # They are only part of the problem if they actually appear: >>> P.set_objective("min", abs(x)**2) >>> P.variables mappingproxy(OrderedDict([('x', <3×1 Real Variable: x>)]))
Deprecated since version 2.0: Variables can now be created independent of problems, and do not need to be added to any problem explicitly.

as_dual
()[source]¶ Return the Lagrangian dual problem of the standardized problem.
Deprecated since version 2.0: Use
dual
instead.

check_current_value_feasibility
(tol=1e05, inttol=None)[source]¶ Check if the problem is feasibly valued.
Checks whether all variables that appear in constraints are valued and satisfy both their bounds and the constraints up to the given tolerance.
 Parameters
tol (float) – Largest tolerated absolute violation of a constraint or variable bound. If
None
, then theabs_prim_fsb_tol
solver option is used.inttol – DEPRECATED
 Returns
A tuple
(feasible, violation)
wherefeasible
is a bool stating whether the solution is feasible andviolation
is eitherNone
, iffeasible == True
, or the amount of violation, otherwise.

clone
(copyOptions=True)[source]¶ Create a semideep copy of the problem.
The copy is constrained by the same constraint objects and thereby references the existing variables that appear in these constraints.
The clone can be modified to describe a new problem, but whenever a solution is applied to its variables, some of these variables can be the same that still appear in the original problem. If this is not a problem to you, then cloning can be much faster than copying.
 Parameters
copyOptions (bool) – Whether to make an independent copy of the problem’s options. Disabling this will apply any option changes to the original problem as well but yields a (very small) reduction in cloning time.

continuous_relaxation
(copy_continuous_variables=True)[source]¶ Return a continuous relaxation of the problem.
This is done by replacing integer variables with continuous ones.

get_constraint
(idOrIndOrCon)[source]¶ Return a (list of) constraint(s) of the problem.
 Parameters
idOrIndOrCon (picos.constraints.Constraint or int or tuple or list) –
One of the following:
A constraint object. It will be returned when the constraint is part of the problem, otherwise a KeyError is raised.
The integer ID of the constraint.
The integer offset of the constraint in the list of all constraints that are part of the problem, in the order that they were added.
A list or tuple of length 1. Its only element is the index of a constraint group (of constraints that were added together), where groups are indexed in the order that they were added to the problem. The whole group is returned as a list of constraints. That list has the constraints in the order that they were added.
A list or tuple of length 2. The first element is a constraint group offset as above, the second an offset within that list.
 Returns
A
constraint
or a list thereof. Example
>>> import picos as pic >>> import cvxopt as cvx >>> from pprint import pprint >>> prob=pic.Problem() >>> x=[prob.add_variable('x[{0}]'.format(i),2) for i in range(5)] >>> y=prob.add_variable('y',5) >>> Cx=prob.add_list_of_constraints([(1x[i]) < y[i] for i in range(5)]) >>> Cy=prob.add_constraint(y>0) >>> print(prob)  Linear Feasibility Problem find an assignment for 2×1 real variable x[i] ∀ i ∈ [0…4] 5×1 real variable y subject to ∑(x[i]) ≤ y[i] ∀ i ∈ [0…4] y ≥ 0  >>> # Retrieve the second constraint, indexed from zero: >>> prob.get_constraint(1) <1×1 Affine Constraint: ∑(x[1]) ≤ y[1]> >>> # Retrieve the fourth consraint from the first group: >>> prob.get_constraint((0,3)) <1×1 Affine Constraint: ∑(x[3]) ≤ y[3]> >>> # Retrieve the whole first group of constraints: >>> pprint(prob.get_constraint((0,))) [<1×1 Affine Constraint: ∑(x[0]) ≤ y[0]>, <1×1 Affine Constraint: ∑(x[1]) ≤ y[1]>, <1×1 Affine Constraint: ∑(x[2]) ≤ y[2]>, <1×1 Affine Constraint: ∑(x[3]) ≤ y[3]>, <1×1 Affine Constraint: ∑(x[4]) ≤ y[4]>] >>> # Retrieve the second "group", containing just one constraint: >>> prob.get_constraint((1,)) [<5×1 Affine Constraint: y ≥ 0>]

get_valued_variable
(name)[source]¶ Retrieve values of variables referenced by the problem.
This method works the same
get_variable
but it returns the variable’svalues
instead of the variable objects. Raises
NotValued – If any of the selected variables is not valued.

get_variable
(name)[source]¶ Retrieve variables referenced by the problem.
Retrieves either a single variable with the given name or a group of variables all named
name[param]
with different values forparam
. If the values forparam
are the integers from zero to the size of the group minus one, then the group is returned as alist
ordered byparam
, otherwise it is returned as adict
with the values ofparam
as keys.Note
Since PICOS 2.0, variables are independent of problems and only appear in a problem for as long as they are referenced by the problem’s objective function or constraints.
 Parameters
name (str) – The name of a variable, or the base name of a group of variables.
 Returns
 Example
>>> from picos import Problem, RealVariable >>> from pprint import pprint >>> # Create a number of variables with structured names. >>> vars = [RealVariable("x")] >>> for i in range(4): ... vars.append(RealVariable("y[{}]".format(i))) >>> for key in ["alice", "bob", "carol"]: ... vars.append(RealVariable("z[{}]".format(key))) >>> # Make the variables appear in a problem. >>> P = Problem() >>> P.set_objective("min", sum([var for var in vars])) >>> print(P)  Linear Program minimize x + y[0] + y[1] + y[2] + y[3] + z[alice] + z[bob] + z[carol] over 1×1 real variable x, y[0], y[1], y[2], y[3], z[alice], z[bob], z[carol]  >>> # Retrieve the variables from the problem. >>> P.get_variable("x") <1×1 Real Variable: x> >>> pprint(P.get_variable("y")) [<1×1 Real Variable: y[0]>, <1×1 Real Variable: y[1]>, <1×1 Real Variable: y[2]>, <1×1 Real Variable: y[3]>] >>> pprint(P.get_variable("z")) {'alice': <1×1 Real Variable: z[alice]>, 'bob': <1×1 Real Variable: z[bob]>, 'carol': <1×1 Real Variable: z[carol]>} >>> P.get_variable("z")["alice"] is P.get_variable("z[alice]") True

is_continuous
()[source]¶ Whether all variables are of continuous types.
Deprecated since version 2.0: Use
continuous
instead.

is_pure_integer
()[source]¶ Whether all variables are of integral types.
Deprecated since version 2.0: Use
pure_integer
instead.

maximize
(obj, **extra_options)[source]¶ Look for a maximization solution.
Sets the objective to maximize the given objective function and calls the solver with the given additional options.
 Parameters
obj (
Expression
) – The objective function to maximize.extra_options – A sequence of additional solver options.
 Returns
A dictionary, see
solve
.
Warning
This is equivalent to
set_objective
followed bysolve
and will thus override any existing objective function and direction.Deprecated since version 2.0: Misleading semantics. Maybe
picos.maximize
is what you want.

minimize
(obj, **extra_options)[source]¶ Look for a minimizing solution.
Sets the objective to minimize the given objective function and calls the solver with the given additional options.
 Parameters
obj (
Expression
) – The objective function to minimize.extra_options – A sequence of additional solver options.
 Returns
A dictionary, see
solve
.
Warning
This is equivalent to
set_objective
followed bysolve
and will thus override any existing objective function and direction.Deprecated since version 2.0: Misleading semantics. Maybe
picos.minimize
is what you want.

obj_value
()[source]¶ Objective function value.
 Raises
AttributeError – If the problem is a feasibility problem or if the objective function is not valued. This is legacy behavior. Note that
value
just returnsNone
while functions that do raise an exception to denote an unvalued expression would raiseNotValued
instead.
Deprecated since version 2.0: Use
value
instead.

prepared
(steps=None, **extra_options)[source]¶ Perform a dryrun returning the reformulated (prepared) problem.
This behaves like
solve
in that it takes a number of additional temporary options, finds a solution strategy matching the problem and options, and performs the strategy’s reformulations in turn to obtain modified problems. However, it stops after the given number of steps and never hands the reformulated problem to a solver. Instead of a solution,prepared
then returns the last reformulated problem.Unless this method returns the problem itself, the special attributes
prepared_strategy
andprepared_steps
are added to the returned problem. They then contain the (partially) executed solution strategy and the number of performed reformulations, respectively. Parameters
steps (int) – Number of reformulations to perform.
None
means as many as there are. If this parameter is , then the problem itself is returned. If it is , then only the implicit first reformulationExtraOptions
is executed, which may also output the problem itself, depending onextra_options
.extra_options – Additional solver options to use with this dryrun only.
 Returns
The reformulated problem.
 Raises
NoStrategyFound – If no solution strategy was found.
ValueError – If there are not as many reformulation steps as requested.
 Example
>>> from picos import Problem, RealVariable >>> x = RealVariable("x") >>> P = Problem() >>> P.set_objective("min", x**2) >>> Q = P.prepared(solver = "cvxopt") >>> print(Q.prepared_strategy) # Show prepared reformulation steps. 1. ExtraOptions 2. EpigraphReformulation 3. ConvexQuadraticToConicReformulation 4. CVXOPTSolver >>> Q.prepared_steps # Check how many steps have been performed. 3 >>> print(P)  Quadratic Program minimize x² over 1×1 real variable x  >>> print(Q)  Second Order Cone Program minimize __..._t over 1×1 real variable __..._t, x subject to ‖quadroot(x²)‖² ≤ (aff(x²)  __..._t) ∧ (aff(x²)  __..._t) ≥ 0 

remove_all_constraints
()[source]¶ Remove all constraints from the problem.
Note
This method does not remove bounds set directly on variables.

remove_constraint
(idOrIndOrCon)[source]¶ Delete a constraint from the problem.
 Parameters
idOrIndOrCon – See
get_constraint
. Example
>>> import picos >>> from pprint import pprint >>> P = picos.Problem() >>> x = [P.add_variable('x[{0}]'.format(i), 2) for i in range(4)] >>> y = P.add_variable('y', 4) >>> Cxy = P.add_list_of_constraints( ... [(1  x[i]) <= y[i] for i in range(4)]) >>> Cy = P.add_constraint(y >= 0) >>> Cx0to2 = P.add_list_of_constraints([x[i] <= 2 for i in range(3)]) >>> Cx3 = P.add_constraint(x[3] <= 1) >>> pprint(list(P.constraints.values())) [<1×1 Affine Constraint: ∑(x[0]) ≤ y[0]>, <1×1 Affine Constraint: ∑(x[1]) ≤ y[1]>, <1×1 Affine Constraint: ∑(x[2]) ≤ y[2]>, <1×1 Affine Constraint: ∑(x[3]) ≤ y[3]>, <4×1 Affine Constraint: y ≥ 0>, <2×1 Affine Constraint: x[0] ≤ [2]>, <2×1 Affine Constraint: x[1] ≤ [2]>, <2×1 Affine Constraint: x[2] ≤ [2]>, <2×1 Affine Constraint: x[3] ≤ [1]>] >>> # Delete the 2nd constraint (counted from 0): >>> P.remove_constraint(1) >>> pprint(list(P.constraints.values())) [<1×1 Affine Constraint: ∑(x[0]) ≤ y[0]>, <1×1 Affine Constraint: ∑(x[2]) ≤ y[2]>, <1×1 Affine Constraint: ∑(x[3]) ≤ y[3]>, <4×1 Affine Constraint: y ≥ 0>, <2×1 Affine Constraint: x[0] ≤ [2]>, <2×1 Affine Constraint: x[1] ≤ [2]>, <2×1 Affine Constraint: x[2] ≤ [2]>, <2×1 Affine Constraint: x[3] ≤ [1]>] >>> # Delete the 2nd group of constraints, i.e. the constraint y > 0: >>> P.remove_constraint((1,)) >>> pprint(list(P.constraints.values())) [<1×1 Affine Constraint: ∑(x[0]) ≤ y[0]>, <1×1 Affine Constraint: ∑(x[2]) ≤ y[2]>, <1×1 Affine Constraint: ∑(x[3]) ≤ y[3]>, <2×1 Affine Constraint: x[0] ≤ [2]>, <2×1 Affine Constraint: x[1] ≤ [2]>, <2×1 Affine Constraint: x[2] ≤ [2]>, <2×1 Affine Constraint: x[3] ≤ [1]>] >>> # Delete the 3rd remaining group of constraints, i.e. x[3] < [1]: >>> P.remove_constraint((2,)) >>> pprint(list(P.constraints.values())) [<1×1 Affine Constraint: ∑(x[0]) ≤ y[0]>, <1×1 Affine Constraint: ∑(x[2]) ≤ y[2]>, <1×1 Affine Constraint: ∑(x[3]) ≤ y[3]>, <2×1 Affine Constraint: x[0] ≤ [2]>, <2×1 Affine Constraint: x[1] ≤ [2]>, <2×1 Affine Constraint: x[2] ≤ [2]>] >>> # Delete 2nd constraint of the 2nd remaining group, i.e. x[1] < 2: >>> P.remove_constraint((1,1)) >>> pprint(list(P.constraints.values())) [<1×1 Affine Constraint: ∑(x[0]) ≤ y[0]>, <1×1 Affine Constraint: ∑(x[2]) ≤ y[2]>, <1×1 Affine Constraint: ∑(x[3]) ≤ y[3]>, <2×1 Affine Constraint: x[0] ≤ [2]>, <2×1 Affine Constraint: x[2] ≤ [2]>]

remove_variable
(name)[source]¶ Does nothing.
Deprecated since version 2.0: Whether a problem references a variable is now determined dynamically, so this method has no effect.

reset
(resetOptions=False)[source]¶ Reset the problem instance to its initial empty state.
 Parameters
resetOptions (bool) – Whether also solver options should be reset to their default values.

set_all_options_to_default
()[source]¶ Set all solver options to their default value.
Deprecated since version 2.0: Use
Problem.options
instead.

set_objective
(direction=None, expression=None)[source]¶ Set the optimization direction and objective function of the problem.
 Parameters
direction (str) –
Case insensitive search direction string. One of
"min"
or"minimize"
,"max"
or"maximize"
,"find"
orNone
(for a feasibility problem).
expression (Expression) – The objective function. Must be
None
for a feasibility problem.

set_option
(key, val)[source]¶ Set a single solver option to the given value.
 Parameters
key (str) – String name of the option, see below for a list.
val – New value for the option.
Deprecated since version 2.0: Use
Problem.options
instead.

set_var_value
(name, value)[source]¶ Set the
value
of a variable.For a
Problem
P
, this is the same asP.variables[name] = value
. Parameters
Deprecated since version 2.0: Use
variables
instead.

solve
(**extra_options)[source]¶ Hand the problem to a solver.
You can select the solver manually with the
solver
option. Otherwise a suitable solver will be selected among those that are available on the platform.The default behavior (options
primals=True
,duals=None
) is to raise aSolutionFailure
when the primal solution is not found optimal by the solver, while the dual solution is allowed to be missing or incomplete.When this method succeeds and unless
apply_solution=False
, you can access the solution as follows: Parameters
extra_options –
A sequence of additional solver options to use with this solution search only. In particular, this lets you
select a solver via the
solver
option,obtain nonoptimal primal solutions by setting
primals=None
,require a complete and optimal dual solution with
duals=True
, andskip valuing variables or constraints with
apply_solution=False
.
 Returns ~picos.Solution or list(~picos.Solution)
A solution object or list thereof.
 Raises
In the following cases:
No solution strategy was found.
Multiple solutions were requested but none were returned.
A primal solution was explicitly requested (
primals=True
) but the primal solution is missing/incomplete or not claimed optimal.A dual solution was explicitly requested (
duals=True
) but the dual solution is missing/incomplete or not claimed optimal.
The case number is stored in the
code
attribute of the exception.

update_options
(**options)[source]¶ Set multiple solver options at once.
 Parameters
options – A parameter sequence of options to set.
Deprecated since version 2.0: Use
Problem.options
instead.

verbosity
()[source]¶ Return the problem’s current verbosity level.
Deprecated since version 2.0: Use
Problem.options
instead.

property
constraints
¶ Maps constraint IDs to constraints that are part of the problem.
 Returns
A readonly view to an
OrderedDict
. The order is that in which constraints were added.

property
continuous
¶ Whether all variables are of continuous types.

property
countCons
¶ The same as
len
applied toconstraints
.Deprecated since version 2.0: Still used internally by legacy code; will be removed together with that code.

property
countVar
¶ The same as
len
applied tovariables
.Deprecated since version 2.0: Still used internally by legacy code; will be removed together with that code.

property
dual
¶ The Lagrangian dual problem of the standardized problem.
More precisely, this property invokes the following:
The primal problem is posed as an equivalent conic standard form minimization problem, with variable bounds expressed as additional constraints.
The Lagrangian dual problem of the reposed primal is computed.
The optimization direction and objective function sign of the dual are adjusted such that, given strong duality and primal feasibility, the optimal values of both problems are equal. In particular, if the primal problem is a minimization or a maximization problem, the dual problem returned will be the respective other.
This property is intended for educational purposes. If you want to solve the primal problem via its dual, use the dualize option instead.

property
no
¶ Normalized objective as an
Objective
instance.Either a minimization or a maximization objective, with feasibility posed as “minimize 0”.
The same as the
normalized
attribute of theobjective
.

property
numberConeConstraints
¶ Number of quadratic conic constraints stored.
Deprecated since version 2.0: Still used internally by legacy code; will be removed together with that code.

property
numberLSEConstraints
¶ Number of
LogSumExpConstraint
stored.Deprecated since version 2.0: Still used internally by legacy code; will be removed together with that code.

property
numberOfVars
¶ The sum of the dimensions of all referenced variables.
Deprecated since version 2.0: Still used internally by legacy code; will be removed together with that code.

property
numberQuadConstraints
¶ Number of quadratic constraints stored.
Deprecated since version 2.0: Still used internally by legacy code; will be removed together with that code.

property
numberSDPConstraints
¶ Number of
LMIConstraint
stored.Deprecated since version 2.0: Still used internally by legacy code; will be removed together with that code.

property
pure_integer
¶ Whether all variables are of integral types.

property
status
¶ The solution status string as claimed by
last_solution
.

property
strategy
¶ Solution strategy as a
Strategy
object.A strategy is available once you order the problem to be solved and it will be reused for successive solution attempts (of a modified problem) while it remains valid with respect to the problem’s
footprint
.When a strategy is reused, modifications to the variables, constraints, and objective of a problem are passed step by step through the strategy’s reformulation pipeline while existing reformulation work is not repeated. If the solver also supports these kinds of updates, then modifying and resolving a problem can be much faster than solving the problem from scratch.
 Example
>>> from picos import Problem, RealVariable >>> x = RealVariable("x") >>> P = Problem() >>> P.set_objective("min", x**2) >>> print(P.strategy) None >>> sol = P.solve(solver = "cvxopt") # Creates a solution strategy. >>> print(P.strategy) 1. ExtraOptions 2. EpigraphReformulation 3. ConvexQuadraticToConicReformulation 4. CVXOPTSolver >>> P.add_constraint((x2)**2 <= 1) # Also convex quadratic. <Convex Quadratic Constraint: (x  2)² ≤ 1> >>> P.strategy.valid(solver = "cvxopt") True >>> P.strategy.valid(solver = "glpk") False >>> sol = P.solve(solver = "cvxopt") # Reuses the strategy.
It’s also possible to create a startegy from scratch:
>>> from picos.modeling import Strategy >>> from picos.reforms import (EpigraphReformulation, ... ConvexQuadraticToConicReformulation) >>> from picos.solvers import CVXOPTSolver >>> # Mimic what solve() does when no strategy exists: >>> P.strategy = Strategy(P, CVXOPTSolver, EpigraphReformulation, ... ConvexQuadraticToConicReformulation)

property
type
¶ The problem type as a string, such as “Linear Program”.

property
value
¶ Objective function value.
If all variables that appear in the objective function are valued, in particular after a successful solution search, this is the numeric value of the objective function. If the objective function is not fully valued or if the problem is a feasiblity problem without an objective function, this is
None
.

property
variables
¶ Maps names to variables in use by the problem.
 Returns
A readonly view to an
OrderedDict
. The order is deterministic and depends on the order of operations performed on theProblem
instance as well as on the variables’ names.
Exceptions¶
SolutionFailure¶

exception
picos.modeling.problem.
SolutionFailure
(code, message)[source]¶ Bases:
RuntimeError
Solving the problem failed.

__init__
(code, message)[source]¶ Construct a
SolutionFailure
. Parameters
code (int) – Status code, as defined in
Problem.solve
.message (str) – Text description of the failure.

__new__
()¶ Create and return a new object. See help(type) for accurate signature.
