picos.modeling.quicksolve

Functions to quickly solve a problem.

Functions

picos.modeling.quicksolve.find_assignment(subject_to=[], **options)[source]

Find a feasible variable assignment.

Internally, this creates a Problem, adds constraints and performs a solution search.

Parameters
  • subject_to (list(Constraint)) – A collection of constraints to obey.

  • options – A keyword argument sequence of solver options to use. See Options.

Returns

Nothing. Check the concerned variables’ values.

Raises

SolutionFailure – See solve.

Example

>>> from picos import find_assignment, RealVariable
>>> x = RealVariable("x")
>>> values = find_assignment([x**2 + 1 <= x], solver="cvxopt")
... 
Traceback (most recent call last):
    ...
picos.modeling.problem.SolutionFailure: Code 3: ...
>>> x.value
>>> find_assignment([x**2 + 0.25 <= x], solver="cvxopt")
>>> round(x.value, 5)
0.5
picos.modeling.quicksolve.maximize(function, subject_to=[], **options)[source]

Maximize a scalar expression subject to constraints.

Internally, this creates a Problem, sets an objective, adds constraints, performs a solution search and returns an optimum value found.

Parameters
  • function (Expression) – The objective function to maximize.

  • subject_to (list(Constraint)) – A collection of constraints to obey.

  • options – A keyword argument sequence of solver options to use. See Options.

Returns

The optimum value, as computed from an applied solution.

Raises

SolutionFailure – See solve.

Example

>>> from picos import maximize, RealVariable
>>> x = RealVariable("x")
>>> p = maximize(-x**2, [(x - 2)**2 <= x - 2], solver="cvxopt")
>>> round(p, 5)
-4.0
>>> round(x, 5)
2.0
picos.modeling.quicksolve.minimize(function, subject_to=[], **options)[source]

Minimize a scalar expression subject to constraints.

Internally, this creates a Problem, sets an objective, adds constraints, performs a solution search and returns an optimum value found.

Parameters
  • function (Expression) – The objective function to minimize.

  • subject_to (list(Constraint)) – A collection of constraints to obey.

  • options – A keyword argument sequence of solver options to use. See Options.

Returns

The optimum value, as computed from an applied solution.

Raises

SolutionFailure – See solve.

Example

>>> from picos import minimize, RealVariable
>>> x = RealVariable("x")
>>> p = minimize(x**2, [(x - 2)**2 <= x - 2], solver="cvxopt")
>>> round(p, 5)
4.0
>>> round(x, 5)
2.0