ams.opt.Objective#

class ams.opt.Objective(name: str | None = None, e_str: str | None = None, e_fn: Callable | None = None, info: str | None = None, unit: str | None = None, sense: str | None = 'min')[source]#

Base class for objective functions.

Exactly one of e_str or e_fn should be provided. e_fn(r) is the Phase 4.1+ form: a callable that takes a RoutineNS and returns the inner CVXPY expression to be minimized/maximized (the cp.Minimize/cp.Maximize wrapping is handled by Objective.evaluate).

Parameters:
namestr, optional

A user-defined name for the objective function.

e_strstr, optional

A mathematical expression (legacy form).

e_fncallable, optional

Callable e_fn(r) -> cp.Expression taking a RoutineNS.

infostr, optional

Additional informational text about the objective function.

sensestr, optional

The sense of the objective function, default to 'min'. min for minimization and max for maximization.

Attributes:
vNoneType

Return the CVXPY objective value.

rtnams.routines.Routine

The owner routine instance.

codestr

The code string for the objective function.

__init__(name: str | None = None, e_str: str | None = None, e_fn: Callable | None = None, info: str | None = None, unit: str | None = None, sense: str | None = 'min')[source]#

Methods

add_term(fn)

Register an extra cost term added to this objective at evaluate time.

evaluate(*args, **kwargs)

get_all_idxes()

Return all the indexes of this item.

get_idx()

parse(*args, **kwargs)

Attributes

class_name

Return the class name

e

Return the calculated numerical value of the underlying expression.

e_fn

Mutex descriptor for e_str / e_fn on opt elements.

e_str

Mutex descriptor for e_str / e_fn on opt elements.

formulation_source

Where the live CVXPY object for this item came from.

n

Return the number of elements.

shape

Return the shape.

size

Return the size.

v

Return the CVXPY objective value.