Implementation of Objective.


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

Bases: Valuable

An optimization objective composed of search direction and function.


>>> 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>

Denote the sum of two compatible objectives.


Report whether two objectives are the same.

__init__(direction=None, function=None)[source]

Construct an optimization objective.

  • 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.


Denote the product of the objective with an expression.


Return the negated objective with the search direction flipped.


Return the objective as-is.


Denote the product of the objective with an expression.


Denote the difference of two compatible objectives.


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.