picos.modeling.objective

Implementation of Objective.

Classes

class picos.modeling.objective.Objective(direction=None, function=None)[source]

Bases: Valuable

An optimization objective composed of search direction and function.

Example

>>> from picos import Objective, RealVariable
>>> x = RealVariable("x")
>>> obj = Objective("min", x); obj
<Objective: minimize x>
>>> obj + x**2  # Add a term to the objective function.
<Objective: minimize x + x²>
>>> obj/2 + 2*obj  # Scale and combine two objectives.
<Objective: minimize x/2 + 2·x>
>>> -obj  # Flip the optimization direction.
<Objective: maximize -x>
__add__(other)[source]

Denote the sum of two compatible objectives.

__eq__(other)[source]

Report whether two objectives are the same.

__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" or None (for a feasibility problem).

  • function (Expression) – The objective function. Must be None for a feasibility problem.

__mul__(other)[source]

Denote the product of the objective with an expression.

__neg__()[source]

Return the negated objective with the search direction flipped.

__pos__()[source]

Return the objective as-is.

__rmul__(other)[source]

Denote the product of the objective with an expression.

__sub__(other)[source]

Denote the difference of two compatible objectives.

__truediv__(other)[source]

Denote division of the objective by an expression.

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[source]

The objective but with feasiblity posed as “minimize 0”.

>>> from picos import Objective
>>> obj = Objective(); obj
<Objective: find an assignment>
>>> obj.normalized
<Objective: minimize 0>
property pair

Search direction and objective function as a pair.