Objective

class optlang.interface.Objective(expression, value=None, direction='max', *args, **kwargs)[source]

Bases: optlang.interface.OptimizationExpression

Objective objects are used to represent the objective function of an optimization problem. An objective consists of a symbolic expression of variables in the problem and a direction. The direction can be either ‘min’ or ‘max’ and specifies whether the problem is a minimization or a maximization problem.

After a problem has been optimized, the optimal objective value can be accessed from the ‘value’ attribute of the model’s objective, i.e. obj_val = model.objective.value.

Attributes

expression: sympy The mathematical expression defining the objective.
name: str, optional The name of the constraint.
direction: ‘max’ or ‘min’ The optimization direction.
value: float, read-only The current objective value.
problem: solver The low-level solver object.

Methods

classmethod clone(objective, model=None, **kwargs)[source]

Make a copy of an objective. The objective being copied can be of the same type or belong to a different solver interface.

direction

The direction of optimization. Either ‘min’ or ‘max’.

classmethod from_json(json_obj, variables=None)[source]

Constructs an Objective from the provided json-object.

set_linear_coefficients(coefficients)[source]

Set linear coefficients in objective.

coefficients : dict
A dictionary of the form {variable1: coefficient1, variable2: coefficient2, ...}
to_json()[source]

Returns a json-compatible object from the objective that can be saved using the json module.

value

The objective value.