Skip to content

objective

Objective(expr)

Bases: Expression

Examples:

>>> from pyoframe import Variable, Model, sum
>>> m = Model("max")
>>> m.a = Variable()
>>> m.b = Variable({"dim1": [1, 2, 3]})
>>> m.objective = m.a + sum("dim1", m.b)
>>> m.objective
<Objective size=1 dimensions={} terms=4>
objective: a + b[1] + b[2] + b[3]
Source code in pyoframe/objective.py
def __init__(self, expr: SupportsMath) -> None:
    expr = expr.to_expr()
    super().__init__(expr.data)
    self._model = expr._model
    assert (
        self.dimensions is None
    ), "Objective cannot have dimensions as it must be a single expression"
    self._value: Optional[float] = None