AMPLRepn

(class from pyomo.repn.ampl)

class pyomo.repn.ampl.AMPLRepn(const, linear, nonlinear)[source]

Bases: object

The “compiled” representation of an expression in AMPL NL format.

This stores a compiled form of an expression in the AMPL “NL” format. The data structure contains 6 fields:

mult

A constant multiplier applied to this expression. The :py:class`AMPLRepn` returned by the :py:class`AMPLRepnVisitor` should always have mult == 1.

Type:

float

const

The constant portion of this expression

Type:

float

linear

Mapping of id(VarData) to linear coefficient

Type:

Dict[int, float] or None

nonlinear

The general nonlinear portion of the compiled expression as a tuple of two parts:

  • the nl template string: this is the NL string with placeholders (%s) for all the variables that appear in the expression.

  • an iterable if the VarData IDs that correspond to the placeholders in the nl template string

This is None if there is no general nonlinear part of the expression. Note that this can be a list of tuple fragments within AMPLRepnVisitor, but that list is concatenated to a single tuple when exiting the AMPLRepnVisitor.

Type:

Tuple[str, List[int]] or List[Tuple[str, List[int]]] or None

named_exprs

A set of IDs point to named expressions (Expression) objects appearing in this expression.

Type:

Set[int]

nl

This holds the complete compiled representation of this expression (including multiplier, constant, linear terms, and nonlinear fragment) using the same format as the nonlinear attribute. This field (if not None) should be considered authoritative, as there are NL fragments that are not representable by {mult, const, linear, nonlinear} (e.g., string arguments).

Type:

Tuple[str, Iterable[int]]

__init__(const, linear, nonlinear)[source]

Methods

__init__(const, linear, nonlinear)

append(other)

Append a child result from acceptChildResult

compile_nonlinear_fragment()

compile_repn([prefix, args, named_exprs])

duplicate()

to_expr(var_map)

Attributes

nl

mult

const

linear

nonlinear

named_exprs

Member Documentation

append(other)[source]

Append a child result from acceptChildResult

Notes

This method assumes that the operator was “+”. It is implemented so that we can directly use an AMPLRepn() as a data object in the expression walker (thereby avoiding the function call for a custom callback)