Core Classes
The following are the two core classes documented here:
The remaining classes are the public classes for expressions, which
developers may need to know about. The methods for these classes are not
documented because they are described in the
ExpressionBase
class.
Sets with Expression Types
The following sets can be used to develop visitor patterns for Pyomo expressions.

pyomo.core.expr.numvalue.
native_numeric_types
= {<class 'numpy.uint64'>, <class 'numpy.int64'>, <class 'numpy.ndarray'>, <class 'numpy.float64'>, <class 'bool'>, <class 'numpy.float16'>, <class 'float'>, <class 'numpy.uint8'>, <class 'numpy.int8'>, <class 'numpy.float32'>, <class 'numpy.uint16'>, <class 'numpy.int16'>, <class 'int'>, <class 'numpy.uint32'>, <class 'numpy.int32'>} set() > new empty set object set(iterable) > new set object
Build an unordered collection of unique elements.

pyomo.core.expr.numvalue.
native_types
= {<class 'numpy.uint64'>, <class 'numpy.int64'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.int32'>, <class 'slice'>, <class 'bool'>, <class 'numpy.float32'>, <class 'numpy.uint16'>, <class 'numpy.int16'>, <class 'numpy.bool_'>, <class 'NoneType'>, <class 'str'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'numpy.int8'>, <class 'bytes'>, <class 'numpy.ndarray'>, <class 'float'>, <class 'int'>} set() > new empty set object set(iterable) > new set object
Build an unordered collection of unique elements.

pyomo.core.expr.numvalue.
nonpyomo_leaf_types
= {<class 'numpy.uint64'>, <class 'numpy.int64'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'numpy.int8'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.int32'>, <class 'bytes'>, <class 'slice'>, <class 'numpy.ndarray'>, <class 'bool'>, <class 'NoneType'>, <class 'float'>, <class 'numpy.float32'>, <class 'pyomo.core.expr.numvalue.NonNumericValue'>, <class 'numpy.uint16'>, <class 'numpy.int16'>, <class 'numpy.bool_'>, <class 'int'>, <class 'str'>} set() > new empty set object set(iterable) > new set object
Build an unordered collection of unique elements.
NumericValue and ExpressionBase

class
pyomo.core.expr.numvalue.
NumericValue
[source] This is the base class for numeric values used in Pyomo.

__abs__
()[source] Absolute value
This method is called when Python processes the statement:
abs(self)

__add__
(other)[source] Binary addition
This method is called when Python processes the statement:
self + other

__bool__
()[source] Coerce the value to a bool
Numeric values can be coerced to bool only if the value / expression is constant. Fixed (but nonconstant) or variable values will raise an exception.
Raises: PyomoException –

__div__
(other)[source] Binary division
This method is called when Python processes the statement:
self / other

__eq__
(other)[source] Equal to operator
This method is called when Python processes the statement:
self == other

__float__
()[source] Coerce the value to a floating point
Numeric values can be coerced to float only if the value / expression is constant. Fixed (but nonconstant) or variable values will raise an exception.
Raises: TypeError –

__ge__
(other)[source] Greater than or equal operator
This method is called when Python processes statements of the form:
self >= other other <= self

__getstate__
()[source] Prepare a picklable state of this instance for pickling.
Nominally, __getstate__() should execute the following:
state = super(Class, self).__getstate__() for i in Class.__slots__: state[i] = getattr(self,i) return state
However, in this case, the (nominal) parent class is ‘object’, and object does not implement __getstate__. So, we will check to make sure that there is a base __getstate__() to call. You might think that there is nothing to check, but multiple inheritance could mean that another class got stuck between this class and “object” in the MRO.
Further, since there are actually no slots defined here, the real question is to either return an empty dict or the parent’s dict.

__gt__
(other)[source] Greater than operator
This method is called when Python processes statements of the form:
self > other other < self

__hash__
= None

__iadd__
(other)[source] Binary addition
This method is called when Python processes the statement:
self += other

__idiv__
(other)[source] Binary division
This method is called when Python processes the statement:
self /= other

__imul__
(other)[source] Binary multiplication
This method is called when Python processes the statement:
self *= other

__int__
()[source] Coerce the value to an integer
Numeric values can be coerced to int only if the value / expression is constant. Fixed (but nonconstant) or variable values will raise an exception.
Raises: TypeError –

__ipow__
(other)[source] Binary power
This method is called when Python processes the statement:
self **= other

__isub__
(other)[source] Binary subtraction
This method is called when Python processes the statement:
self = other

__itruediv__
(other)[source] Binary division (when __future__.division is in effect)
This method is called when Python processes the statement:
self /= other

__le__
(other)[source] Less than or equal operator
This method is called when Python processes statements of the form:
self <= other other >= self

__lt__
(other)[source] Less than operator
This method is called when Python processes statements of the form:
self < other other > self

__mul__
(other)[source] Binary multiplication
This method is called when Python processes the statement:
self * other

__pos__
()[source] Positive expression
This method is called when Python processes the statement:
+ self

__pow__
(other)[source] Binary power
This method is called when Python processes the statement:
self ** other

__radd__
(other)[source] Binary addition
This method is called when Python processes the statement:
other + self

__rdiv__
(other)[source] Binary division
This method is called when Python processes the statement:
other / self

__rmul__
(other)[source] Binary multiplication
This method is called when Python processes the statement:
other * self
when other is not a
NumericValue
object.

__rpow__
(other)[source] Binary power
This method is called when Python processes the statement:
other ** self

__rsub__
(other)[source] Binary subtraction
This method is called when Python processes the statement:
other  self

__rtruediv__
(other)[source] Binary division (when __future__.division is in effect)
This method is called when Python processes the statement:
other / self

__setstate__
(state)[source] Restore a pickled state into this instance
Our model for setstate is for derived classes to modify the state dictionary as control passes up the inheritance hierarchy (using super() calls). All assignment of state > object attributes is handled at the last class before ‘object’, which may – or may not (thanks to MRO) – be here.

__sub__
(other)[source] Binary subtraction
This method is called when Python processes the statement:
self  other

__truediv__
(other)[source] Binary division (when __future__.division is in effect)
This method is called when Python processes the statement:
self / other

_compute_polynomial_degree
(values)[source] Compute the polynomial degree of this expression given the degree values of its children.
Parameters: values (list) – A list of values that indicate the degree of the children expression. Returns: None

getname
(fully_qualified=False, name_buffer=None)[source] If this is a component, return the component’s name on the owning block; otherwise return the value converted to a string

to_string
(verbose=None, labeler=None, smap=None, compute_values=False)[source] Return a string representation of the expression tree.
Parameters:  verbose (bool) – If
True
, then the the string representation consists of nested functions. Otherwise, the string representation is an algebraic equation. Defaults toFalse
.  labeler – An object that generates string labels for
variables in the expression tree. Defaults to
None
.
Returns: A string representation for the expression tree.
 verbose (bool) – If


class
pyomo.core.expr.current.
ExpressionBase
(args)[source] Bases:
pyomo.core.expr.numvalue.NumericValue
The base class for Pyomo expressions.
This class is used to define nodes in an expression tree.
Parameters: args (list or tuple) – Children of this node. 
__call__
(exception=True)[source] Evaluate the value of the expression tree.
Parameters: exception (bool) – If False
, then an exception raised while evaluating is captured, and the value returned isNone
. Default isTrue
.Returns: The value of the expression or None
.

__str__
()[source] Returns a string description of the expression.
Note
The value of
pyomo.core.expr.expr_common.TO_STRING_VERBOSE
is used to configure the execution of this method. If this value isTrue
, then the string representation is a nested function description of the expression. The default isFalse
, which is an algebraic description of the expression.Returns: A string.

_apply_operation
(result)[source] Compute the values of this node given the values of its children.
This method is called by the
_EvaluationVisitor
class. It must be overwritten by expression classes to customize this logic.Note
This method applies the logical operation of the operator to the arguments. It does not evaluate the arguments in the process, but assumes that they have been previously evaluated. But noted that if this class contains auxilliary data (e.g. like the numeric coefficients in the
LinearExpression
class, then those values must be evaluated as part of this function call. An uninitialized parameter value encountered during the execution of this method is considered an error.Parameters: values (list) – A list of values that indicate the value of the children expressions. Returns: A floating point value for this expression.

_associativity
()[source] Return the associativity of this operator.
Returns 1 if this operator is lefttoright associative or 1 if it is righttoleft associative. Any other return value will be interpreted as “not associative” (implying any arguments that are at this operator’s _precedence() will be enclosed in parens).

_compute_polynomial_degree
(values)[source] Compute the polynomial degree of this expression given the degree values of its children.
This method is called by the
_PolynomialDegreeVisitor
class. It can be overwritten by expression classes to customize this logic.Parameters: values (list) – A list of values that indicate the degree of the children expression. Returns: A nonnegative integer that is the polynomial degree of the expression, or None
. Default isNone
.

_is_fixed
(values)[source] Compute whether this expression is fixed given the fixed values of its children.
This method is called by the
_IsFixedVisitor
class. It can be overwritten by expression classes to customize this logic.Parameters: values (list) – A list of boolean values that indicate whether the children of this expression are fixed Returns: A boolean that is True
if the fixed values of the children are allTrue
.

_to_string
(values, verbose, smap, compute_values)[source] Construct a string representation for this node, using the string representations of its children.
This method is called by the
_ToStringVisitor
class. It must must be defined in subclasses.Parameters:  values (list) – The string representations of the children of this node.
 verbose (bool) – If
True
, then the the string representation consists of nested functions. Otherwise, the string representation is an algebraic equation.  smap – If specified, this
SymbolMap
is used to cache labels for variables.  compute_values (bool) – If
True
, then parameters and fixed variables are evaluated before the expression string is generated.
Returns: A string representation for this node.

arg
(i)[source] Return the ith child node.
Parameters: i (int) – Nonnegative index of the child that is returned. Returns: The ith child node.

property
args
Return the child nodes
 Returns: Either a list or tuple (depending on the node storage
 model) containing only the child nodes of this node

clone
(substitute=None)[source] Return a clone of the expression tree.
Note
This method does not clone the leaves of the tree, which are numeric constants and variables. It only clones the interior nodes, and expression leaf nodes like
_MutableLinearExpression
. However, named expressions are treated like leaves, and they are not cloned.Parameters: substitute (dict) – a dictionary that maps object ids to clone objects generated earlier during the cloning process. Returns: A new expression tree.

create_node_with_local_data
(args, classtype=None)[source] Construct a node using given arguments.
This method provides a consistent interface for constructing a node, which is used in tree visitor scripts. In the simplest case, this simply returns:
self.__class__(args)
But in general this creates an expression object using local data as well as arguments that represent the child nodes.
Parameters: args (list) – A list of child nodes for the new expression object Returns: A new expression object with the same type as the current class.

create_potentially_variable_object
()[source] Create a potentially variable version of this object.
This method returns an object that is a potentially variable version of the current object. In the simplest case, this simply sets the value of __class__:
self.__class__ = self.__class__.__mro__[1]Note that this method is allowed to modify the current object and return it. But in some cases it may create a new potentially variable object.
Returns: An object that is potentially variable.

getname
(*args, **kwds)[source] Return the text name of a function associated with this expression object.
In general, no arguments are passed to this function.
Parameters:  *arg – a variable length list of arguments
 **kwds – keyword arguments
Returns: A string name for the function.

is_constant
()[source] Return True if this expression is an atomic constant
This method contrasts with the is_fixed() method. This method returns True if the expression is an atomic constant, that is it is composed exclusively of constants and immutable parameters. NumericValue objects returning is_constant() == True may be simplified to their numeric value at any point without warning.
Note: This defaults to False, but gets redefined in subclasses.

is_expression_type
()[source] Return
True
if this object is an expression.This method obviously returns
True
for this class, but it is included in other classes within Pyomo that are not expressions, which allows for a check for expressions without evaluating the class type.Returns: A boolean.

is_named_expression_type
()[source] Return
True
if this object is a named expression.This method returns
False
for this class, and it is included in other classes within Pyomo that are not named expressions, which allows for a check for named expressions without evaluating the class type.Returns: A boolean.

is_potentially_variable
()[source] Return
True
if this expression might represent a variable expression.This method returns
True
when (a) the expression tree contains one or more variables, or (b) the expression tree contains a named expression. In both cases, the expression cannot be treated as constant since (a) the variables may not be fixed, or (b) the named expressions may be changed at a later time to include nonfixed variables.Returns: A boolean. Defaults to True
for expressions.

nargs
()[source] Returns the number of child nodes.
By default, Pyomo expressions represent binary operations with two arguments.
Note
This function does not simply compute the length of
_args_
because some expression classes use a subset of the_args_
array. Thus, it is imperative that developers use this method!Returns: A nonnegative integer that is the number of child nodes.

polynomial_degree
()[source] Return the polynomial degree of the expression.
Returns: A nonnegative integer that is the polynomial degree if the expression is polynomial, or None
otherwise.

size
()[source] Return the number of nodes in the expression tree.
Returns: A nonnegative integer that is the number of interior and leaf nodes in the expression tree.

to_string
(verbose=None, labeler=None, smap=None, compute_values=False)[source] Return a string representation of the expression tree.
Parameters:  verbose (bool) – If
True
, then the the string representation consists of nested functions. Otherwise, the string representation is an algebraic equation. Defaults toFalse
.  labeler – An object that generates string labels for
variables in the expression tree. Defaults to
None
.  smap – If specified, this
SymbolMap
is used to cache labels for variables.  compute_values (bool) – If
True
, then parameters and fixed variables are evaluated before the expression string is generated. Default isFalse
.
Returns: A string representation for the expression tree.
 verbose (bool) – If

Other Public Classes

class
pyomo.core.expr.current.
NegationExpression
(args)[source] Bases:
pyomo.core.expr.numeric_expr.ExpressionBase
Negation expressions:
 x

PRECEDENCE
= 4

_apply_operation
(result)[source] Compute the values of this node given the values of its children.
This method is called by the
_EvaluationVisitor
class. It must be overwritten by expression classes to customize this logic.Note
This method applies the logical operation of the operator to the arguments. It does not evaluate the arguments in the process, but assumes that they have been previously evaluated. But noted that if this class contains auxilliary data (e.g. like the numeric coefficients in the
LinearExpression
class, then those values must be evaluated as part of this function call. An uninitialized parameter value encountered during the execution of this method is considered an error.Parameters: values (list) – A list of values that indicate the value of the children expressions. Returns: A floating point value for this expression.

_compute_polynomial_degree
(result)[source] Compute the polynomial degree of this expression given the degree values of its children.
This method is called by the
_PolynomialDegreeVisitor
class. It can be overwritten by expression classes to customize this logic.Parameters: values (list) – A list of values that indicate the degree of the children expression. Returns: A nonnegative integer that is the polynomial degree of the expression, or None
. Default isNone
.

_to_string
(values, verbose, smap, compute_values)[source] Construct a string representation for this node, using the string representations of its children.
This method is called by the
_ToStringVisitor
class. It must must be defined in subclasses.Parameters:  values (list) – The string representations of the children of this node.
 verbose (bool) – If
True
, then the the string representation consists of nested functions. Otherwise, the string representation is an algebraic equation.  smap – If specified, this
SymbolMap
is used to cache labels for variables.  compute_values (bool) – If
True
, then parameters and fixed variables are evaluated before the expression string is generated.
Returns: A string representation for this node.

getname
(*args, **kwds)[source] Return the text name of a function associated with this expression object.
In general, no arguments are passed to this function.
Parameters:  *arg – a variable length list of arguments
 **kwds – keyword arguments
Returns: A string name for the function.

nargs
()[source] Returns the number of child nodes.
By default, Pyomo expressions represent binary operations with two arguments.
Note
This function does not simply compute the length of
_args_
because some expression classes use a subset of the_args_
array. Thus, it is imperative that developers use this method!Returns: A nonnegative integer that is the number of child nodes.


class
pyomo.core.expr.current.
ExternalFunctionExpression
(args, fcn=None)[source] Bases:
pyomo.core.expr.numeric_expr.ExpressionBase
External function expressions
Example:
model = ConcreteModel() model.a = Var() model.f = ExternalFunction(library='foo.so', function='bar') expr = model.f(model.a)
Parameters:  args (tuple) – children of this node
 fcn – a class that defines this external function

_apply_operation
(result)[source] Compute the values of this node given the values of its children.
This method is called by the
_EvaluationVisitor
class. It must be overwritten by expression classes to customize this logic.Note
This method applies the logical operation of the operator to the arguments. It does not evaluate the arguments in the process, but assumes that they have been previously evaluated. But noted that if this class contains auxilliary data (e.g. like the numeric coefficients in the
LinearExpression
class, then those values must be evaluated as part of this function call. An uninitialized parameter value encountered during the execution of this method is considered an error.Parameters: values (list) – A list of values that indicate the value of the children expressions. Returns: A floating point value for this expression.

_compute_polynomial_degree
(result)[source] Compute the polynomial degree of this expression given the degree values of its children.
This method is called by the
_PolynomialDegreeVisitor
class. It can be overwritten by expression classes to customize this logic.Parameters: values (list) – A list of values that indicate the degree of the children expression. Returns: A nonnegative integer that is the polynomial degree of the expression, or None
. Default isNone
.

_fcn

_to_string
(values, verbose, smap, compute_values)[source] Construct a string representation for this node, using the string representations of its children.
This method is called by the
_ToStringVisitor
class. It must must be defined in subclasses.Parameters:  values (list) – The string representations of the children of this node.
 verbose (bool) – If
True
, then the the string representation consists of nested functions. Otherwise, the string representation is an algebraic equation.  smap – If specified, this
SymbolMap
is used to cache labels for variables.  compute_values (bool) – If
True
, then parameters and fixed variables are evaluated before the expression string is generated.
Returns: A string representation for this node.

create_node_with_local_data
(args, classtype=None)[source] Construct a node using given arguments.
This method provides a consistent interface for constructing a node, which is used in tree visitor scripts. In the simplest case, this simply returns:
self.__class__(args)
But in general this creates an expression object using local data as well as arguments that represent the child nodes.
Parameters: args (list) – A list of child nodes for the new expression object Returns: A new expression object with the same type as the current class.

getname
(*args, **kwds)[source] Return the text name of a function associated with this expression object.
In general, no arguments are passed to this function.
Parameters:  *arg – a variable length list of arguments
 **kwds – keyword arguments
Returns: A string name for the function.

nargs
()[source] Returns the number of child nodes.
By default, Pyomo expressions represent binary operations with two arguments.
Note
This function does not simply compute the length of
_args_
because some expression classes use a subset of the_args_
array. Thus, it is imperative that developers use this method!Returns: A nonnegative integer that is the number of child nodes.

class
pyomo.core.expr.current.
ProductExpression
(args)[source] Bases:
pyomo.core.expr.numeric_expr.ExpressionBase
Product expressions:
x*y

PRECEDENCE
= 4

_apply_operation
(result)[source] Compute the values of this node given the values of its children.
This method is called by the
_EvaluationVisitor
class. It must be overwritten by expression classes to customize this logic.Note
This method applies the logical operation of the operator to the arguments. It does not evaluate the arguments in the process, but assumes that they have been previously evaluated. But noted that if this class contains auxilliary data (e.g. like the numeric coefficients in the
LinearExpression
class, then those values must be evaluated as part of this function call. An uninitialized parameter value encountered during the execution of this method is considered an error.Parameters: values (list) – A list of values that indicate the value of the children expressions. Returns: A floating point value for this expression.

_compute_polynomial_degree
(result)[source] Compute the polynomial degree of this expression given the degree values of its children.
This method is called by the
_PolynomialDegreeVisitor
class. It can be overwritten by expression classes to customize this logic.Parameters: values (list) – A list of values that indicate the degree of the children expression. Returns: A nonnegative integer that is the polynomial degree of the expression, or None
. Default isNone
.

_is_fixed
(args)[source] Compute whether this expression is fixed given the fixed values of its children.
This method is called by the
_IsFixedVisitor
class. It can be overwritten by expression classes to customize this logic.Parameters: values (list) – A list of boolean values that indicate whether the children of this expression are fixed Returns: A boolean that is True
if the fixed values of the children are allTrue
.

_to_string
(values, verbose, smap, compute_values)[source] Construct a string representation for this node, using the string representations of its children.
This method is called by the
_ToStringVisitor
class. It must must be defined in subclasses.Parameters:  values (list) – The string representations of the children of this node.
 verbose (bool) – If
True
, then the the string representation consists of nested functions. Otherwise, the string representation is an algebraic equation.  smap – If specified, this
SymbolMap
is used to cache labels for variables.  compute_values (bool) – If
True
, then parameters and fixed variables are evaluated before the expression string is generated.
Returns: A string representation for this node.


class
pyomo.core.expr.current.
DivisionExpression
(args)[source] Bases:
pyomo.core.expr.numeric_expr.ExpressionBase
Division expressions:
x/y

PRECEDENCE
= 4

_apply_operation
(result)[source] Compute the values of this node given the values of its children.
This method is called by the
_EvaluationVisitor
class. It must be overwritten by expression classes to customize this logic.Note
This method applies the logical operation of the operator to the arguments. It does not evaluate the arguments in the process, but assumes that they have been previously evaluated. But noted that if this class contains auxilliary data (e.g. like the numeric coefficients in the
LinearExpression
class, then those values must be evaluated as part of this function call. An uninitialized parameter value encountered during the execution of this method is considered an error.Parameters: values (list) – A list of values that indicate the value of the children expressions. Returns: A floating point value for this expression.

_compute_polynomial_degree
(result)[source] Compute the polynomial degree of this expression given the degree values of its children.
This method is called by the
_PolynomialDegreeVisitor
class. It can be overwritten by expression classes to customize this logic.Parameters: values (list) – A list of values that indicate the degree of the children expression. Returns: A nonnegative integer that is the polynomial degree of the expression, or None
. Default isNone
.

_to_string
(values, verbose, smap, compute_values)[source] Construct a string representation for this node, using the string representations of its children.
This method is called by the
_ToStringVisitor
class. It must must be defined in subclasses.Parameters:  values (list) – The string representations of the children of this node.
 verbose (bool) – If
True
, then the the string representation consists of nested functions. Otherwise, the string representation is an algebraic equation.  smap – If specified, this
SymbolMap
is used to cache labels for variables.  compute_values (bool) – If
True
, then parameters and fixed variables are evaluated before the expression string is generated.
Returns: A string representation for this node.

getname
(*args, **kwds)[source] Return the text name of a function associated with this expression object.
In general, no arguments are passed to this function.
Parameters:  *arg – a variable length list of arguments
 **kwds – keyword arguments
Returns: A string name for the function.

nargs
()[source] Returns the number of child nodes.
By default, Pyomo expressions represent binary operations with two arguments.
Note
This function does not simply compute the length of
_args_
because some expression classes use a subset of the_args_
array. Thus, it is imperative that developers use this method!Returns: A nonnegative integer that is the number of child nodes.


class
pyomo.core.expr.current.
InequalityExpression
(args, strict)[source] Bases:
pyomo.core.expr.numeric_expr._LinearOperatorExpression
Inequality expressions, which define lessthan or lessthanorequal relations:
x < y x <= y
Parameters: 
PRECEDENCE
= 9

_apply_operation
(result)[source] Compute the values of this node given the values of its children.
This method is called by the
_EvaluationVisitor
class. It must be overwritten by expression classes to customize this logic.Note
This method applies the logical operation of the operator to the arguments. It does not evaluate the arguments in the process, but assumes that they have been previously evaluated. But noted that if this class contains auxilliary data (e.g. like the numeric coefficients in the
LinearExpression
class, then those values must be evaluated as part of this function call. An uninitialized parameter value encountered during the execution of this method is considered an error.Parameters: values (list) – A list of values that indicate the value of the children expressions. Returns: A floating point value for this expression.

_strict

_to_string
(values, verbose, smap, compute_values)[source] Construct a string representation for this node, using the string representations of its children.
This method is called by the
_ToStringVisitor
class. It must must be defined in subclasses.Parameters:  values (list) – The string representations of the children of this node.
 verbose (bool) – If
True
, then the the string representation consists of nested functions. Otherwise, the string representation is an algebraic equation.  smap – If specified, this
SymbolMap
is used to cache labels for variables.  compute_values (bool) – If
True
, then parameters and fixed variables are evaluated before the expression string is generated.
Returns: A string representation for this node.

create_node_with_local_data
(args)[source] Construct a node using given arguments.
This method provides a consistent interface for constructing a node, which is used in tree visitor scripts. In the simplest case, this simply returns:
self.__class__(args)
But in general this creates an expression object using local data as well as arguments that represent the child nodes.
Parameters: args (list) – A list of child nodes for the new expression object Returns: A new expression object with the same type as the current class.

is_constant
()[source] Return True if this expression is an atomic constant
This method contrasts with the is_fixed() method. This method returns True if the expression is an atomic constant, that is it is composed exclusively of constants and immutable parameters. NumericValue objects returning is_constant() == True may be simplified to their numeric value at any point without warning.
Note: This defaults to False, but gets redefined in subclasses.

is_potentially_variable
()[source] Return
True
if this expression might represent a variable expression.This method returns
True
when (a) the expression tree contains one or more variables, or (b) the expression tree contains a named expression. In both cases, the expression cannot be treated as constant since (a) the variables may not be fixed, or (b) the named expressions may be changed at a later time to include nonfixed variables.Returns: A boolean. Defaults to True
for expressions.

nargs
()[source] Returns the number of child nodes.
By default, Pyomo expressions represent binary operations with two arguments.
Note
This function does not simply compute the length of
_args_
because some expression classes use a subset of the_args_
array. Thus, it is imperative that developers use this method!Returns: A nonnegative integer that is the number of child nodes.

property
strict


class
pyomo.core.expr.current.
EqualityExpression
(args)[source] Bases:
pyomo.core.expr.numeric_expr._LinearOperatorExpression
Equality expression:
x == y

PRECEDENCE
= 9

_apply_operation
(result)[source] Compute the values of this node given the values of its children.
This method is called by the
_EvaluationVisitor
class. It must be overwritten by expression classes to customize this logic.Note
This method applies the logical operation of the operator to the arguments. It does not evaluate the arguments in the process, but assumes that they have been previously evaluated. But noted that if this class contains auxilliary data (e.g. like the numeric coefficients in the
LinearExpression
class, then those values must be evaluated as part of this function call. An uninitialized parameter value encountered during the execution of this method is considered an error.Parameters: values (list) – A list of values that indicate the value of the children expressions. Returns: A floating point value for this expression.

_to_string
(values, verbose, smap, compute_values)[source] Construct a string representation for this node, using the string representations of its children.
This method is called by the
_ToStringVisitor
class. It must must be defined in subclasses.Parameters:  values (list) – The string representations of the children of this node.
 verbose (bool) – If
True
, then the the string representation consists of nested functions. Otherwise, the string representation is an algebraic equation.  smap – If specified, this
SymbolMap
is used to cache labels for variables.  compute_values (bool) – If
True
, then parameters and fixed variables are evaluated before the expression string is generated.
Returns: A string representation for this node.

is_constant
()[source] Return True if this expression is an atomic constant
This method contrasts with the is_fixed() method. This method returns True if the expression is an atomic constant, that is it is composed exclusively of constants and immutable parameters. NumericValue objects returning is_constant() == True may be simplified to their numeric value at any point without warning.
Note: This defaults to False, but gets redefined in subclasses.

is_potentially_variable
()[source] Return
True
if this expression might represent a variable expression.This method returns
True
when (a) the expression tree contains one or more variables, or (b) the expression tree contains a named expression. In both cases, the expression cannot be treated as constant since (a) the variables may not be fixed, or (b) the named expressions may be changed at a later time to include nonfixed variables.Returns: A boolean. Defaults to True
for expressions.

nargs
()[source] Returns the number of child nodes.
By default, Pyomo expressions represent binary operations with two arguments.
Note
This function does not simply compute the length of
_args_
because some expression classes use a subset of the_args_
array. Thus, it is imperative that developers use this method!Returns: A nonnegative integer that is the number of child nodes.


class
pyomo.core.expr.current.
SumExpression
(args)[source] Bases:
pyomo.core.expr.numeric_expr.SumExpressionBase
Sum expression:
x + y
Parameters: args (list) – Children nodes 
PRECEDENCE
= 6

_apply_operation
(result)[source] Compute the values of this node given the values of its children.
This method is called by the
_EvaluationVisitor
class. It must be overwritten by expression classes to customize this logic.Note
This method applies the logical operation of the operator to the arguments. It does not evaluate the arguments in the process, but assumes that they have been previously evaluated. But noted that if this class contains auxilliary data (e.g. like the numeric coefficients in the
LinearExpression
class, then those values must be evaluated as part of this function call. An uninitialized parameter value encountered during the execution of this method is considered an error.Parameters: values (list) – A list of values that indicate the value of the children expressions. Returns: A floating point value for this expression.

_nargs

_to_string
(values, verbose, smap, compute_values)[source] Construct a string representation for this node, using the string representations of its children.
This method is called by the
_ToStringVisitor
class. It must must be defined in subclasses.Parameters:  values (list) – The string representations of the children of this node.
 verbose (bool) – If
True
, then the the string representation consists of nested functions. Otherwise, the string representation is an algebraic equation.  smap – If specified, this
SymbolMap
is used to cache labels for variables.  compute_values (bool) – If
True
, then parameters and fixed variables are evaluated before the expression string is generated.
Returns: A string representation for this node.

create_node_with_local_data
(args, classtype=None)[source] Construct a node using given arguments.
This method provides a consistent interface for constructing a node, which is used in tree visitor scripts. In the simplest case, this simply returns:
self.__class__(args)
But in general this creates an expression object using local data as well as arguments that represent the child nodes.
Parameters: args (list) – A list of child nodes for the new expression object Returns: A new expression object with the same type as the current class.

is_constant
()[source] Return True if this expression is an atomic constant
This method contrasts with the is_fixed() method. This method returns True if the expression is an atomic constant, that is it is composed exclusively of constants and immutable parameters. NumericValue objects returning is_constant() == True may be simplified to their numeric value at any point without warning.
Note: This defaults to False, but gets redefined in subclasses.

is_potentially_variable
()[source] Return
True
if this expression might represent a variable expression.This method returns
True
when (a) the expression tree contains one or more variables, or (b) the expression tree contains a named expression. In both cases, the expression cannot be treated as constant since (a) the variables may not be fixed, or (b) the named expressions may be changed at a later time to include nonfixed variables.Returns: A boolean. Defaults to True
for expressions.

nargs
()[source] Returns the number of child nodes.
By default, Pyomo expressions represent binary operations with two arguments.
Note
This function does not simply compute the length of
_args_
because some expression classes use a subset of the_args_
array. Thus, it is imperative that developers use this method!Returns: A nonnegative integer that is the number of child nodes.


class
pyomo.core.expr.current.
GetItemExpression
(args)[source] Bases:
pyomo.core.expr.numeric_expr.ExpressionBase
Expression to call
__getitem__()
on the base object.
PRECEDENCE
= 1

_apply_operation
(result)[source] Compute the values of this node given the values of its children.
This method is called by the
_EvaluationVisitor
class. It must be overwritten by expression classes to customize this logic.Note
This method applies the logical operation of the operator to the arguments. It does not evaluate the arguments in the process, but assumes that they have been previously evaluated. But noted that if this class contains auxilliary data (e.g. like the numeric coefficients in the
LinearExpression
class, then those values must be evaluated as part of this function call. An uninitialized parameter value encountered during the execution of this method is considered an error.Parameters: values (list) – A list of values that indicate the value of the children expressions. Returns: A floating point value for this expression.

_args_

_compute_polynomial_degree
(result)[source] Compute the polynomial degree of this expression given the degree values of its children.
This method is called by the
_PolynomialDegreeVisitor
class. It can be overwritten by expression classes to customize this logic.Parameters: values (list) – A list of values that indicate the degree of the children expression. Returns: A nonnegative integer that is the polynomial degree of the expression, or None
. Default isNone
.

_is_fixed
(values)[source] Compute whether this expression is fixed given the fixed values of its children.
This method is called by the
_IsFixedVisitor
class. It can be overwritten by expression classes to customize this logic.Parameters: values (list) – A list of boolean values that indicate whether the children of this expression are fixed Returns: A boolean that is True
if the fixed values of the children are allTrue
.

_to_string
(values, verbose, smap, compute_values)[source] Construct a string representation for this node, using the string representations of its children.
This method is called by the
_ToStringVisitor
class. It must must be defined in subclasses.Parameters:  values (list) – The string representations of the children of this node.
 verbose (bool) – If
True
, then the the string representation consists of nested functions. Otherwise, the string representation is an algebraic equation.  smap – If specified, this
SymbolMap
is used to cache labels for variables.  compute_values (bool) – If
True
, then parameters and fixed variables are evaluated before the expression string is generated.
Returns: A string representation for this node.

getname
(*args, **kwds)[source] Return the text name of a function associated with this expression object.
In general, no arguments are passed to this function.
Parameters:  *arg – a variable length list of arguments
 **kwds – keyword arguments
Returns: A string name for the function.

is_potentially_variable
()[source] Return
True
if this expression might represent a variable expression.This method returns
True
when (a) the expression tree contains one or more variables, or (b) the expression tree contains a named expression. In both cases, the expression cannot be treated as constant since (a) the variables may not be fixed, or (b) the named expressions may be changed at a later time to include nonfixed variables.Returns: A boolean. Defaults to True
for expressions.

nargs
()[source] Returns the number of child nodes.
By default, Pyomo expressions represent binary operations with two arguments.
Note
This function does not simply compute the length of
_args_
because some expression classes use a subset of the_args_
array. Thus, it is imperative that developers use this method!Returns: A nonnegative integer that is the number of child nodes.


class
pyomo.core.expr.current.
Expr_ifExpression
(IF_=None, THEN_=None, ELSE_=None)[source] Bases:
pyomo.core.expr.numeric_expr.ExpressionBase
A logical ifthenelse expression:
Expr_if(IF_=x, THEN_=y, ELSE_=z)
Parameters:  IF (expression) – A relational expression
 THEN (expression) – An expression that is used if
IF_
is true.  ELSE (expression) – An expression that is used if
IF_
is false.

_apply_operation
(result)[source] Compute the values of this node given the values of its children.
This method is called by the
_EvaluationVisitor
class. It must be overwritten by expression classes to customize this logic.Note
This method applies the logical operation of the operator to the arguments. It does not evaluate the arguments in the process, but assumes that they have been previously evaluated. But noted that if this class contains auxilliary data (e.g. like the numeric coefficients in the
LinearExpression
class, then those values must be evaluated as part of this function call. An uninitialized parameter value encountered during the execution of this method is considered an error.Parameters: values (list) – A list of values that indicate the value of the children expressions. Returns: A floating point value for this expression.

_compute_polynomial_degree
(result)[source] Compute the polynomial degree of this expression given the degree values of its children.
This method is called by the
_PolynomialDegreeVisitor
class. It can be overwritten by expression classes to customize this logic.Parameters: values (list) – A list of values that indicate the degree of the children expression. Returns: A nonnegative integer that is the polynomial degree of the expression, or None
. Default isNone
.

_else

_if

_is_fixed
(args)[source] Compute whether this expression is fixed given the fixed values of its children.
This method is called by the
_IsFixedVisitor
class. It can be overwritten by expression classes to customize this logic.Parameters: values (list) – A list of boolean values that indicate whether the children of this expression are fixed Returns: A boolean that is True
if the fixed values of the children are allTrue
.

_then

_to_string
(values, verbose, smap, compute_values)[source] Construct a string representation for this node, using the string representations of its children.
This method is called by the
_ToStringVisitor
class. It must must be defined in subclasses.Parameters:  values (list) – The string representations of the children of this node.
 verbose (bool) – If
True
, then the the string representation consists of nested functions. Otherwise, the string representation is an algebraic equation.  smap – If specified, this
SymbolMap
is used to cache labels for variables.  compute_values (bool) – If
True
, then parameters and fixed variables are evaluated before the expression string is generated.
Returns: A string representation for this node.

getname
(*args, **kwds)[source] Return the text name of a function associated with this expression object.
In general, no arguments are passed to this function.
Parameters:  *arg – a variable length list of arguments
 **kwds – keyword arguments
Returns: A string name for the function.

is_constant
()[source] Return True if this expression is an atomic constant
This method contrasts with the is_fixed() method. This method returns True if the expression is an atomic constant, that is it is composed exclusively of constants and immutable parameters. NumericValue objects returning is_constant() == True may be simplified to their numeric value at any point without warning.
Note: This defaults to False, but gets redefined in subclasses.

is_potentially_variable
()[source] Return
True
if this expression might represent a variable expression.This method returns
True
when (a) the expression tree contains one or more variables, or (b) the expression tree contains a named expression. In both cases, the expression cannot be treated as constant since (a) the variables may not be fixed, or (b) the named expressions may be changed at a later time to include nonfixed variables.Returns: A boolean. Defaults to True
for expressions.

nargs
()[source] Returns the number of child nodes.
By default, Pyomo expressions represent binary operations with two arguments.
Note
This function does not simply compute the length of
_args_
because some expression classes use a subset of the_args_
array. Thus, it is imperative that developers use this method!Returns: A nonnegative integer that is the number of child nodes.

class
pyomo.core.expr.current.
UnaryFunctionExpression
(args, name=None, fcn=None)[source] Bases:
pyomo.core.expr.numeric_expr.ExpressionBase
An expression object used to define intrinsic functions (e.g. sin, cos, tan).
Parameters:  args (tuple) – Children nodes
 name (string) – The function name
 fcn – The function that is used to evaluate this expression

_apply_operation
(result)[source] Compute the values of this node given the values of its children.
This method is called by the
_EvaluationVisitor
class. It must be overwritten by expression classes to customize this logic.Note
This method applies the logical operation of the operator to the arguments. It does not evaluate the arguments in the process, but assumes that they have been previously evaluated. But noted that if this class contains auxilliary data (e.g. like the numeric coefficients in the
LinearExpression
class, then those values must be evaluated as part of this function call. An uninitialized parameter value encountered during the execution of this method is considered an error.Parameters: values (list) – A list of values that indicate the value of the children expressions. Returns: A floating point value for this expression.

_compute_polynomial_degree
(result)[source] Compute the polynomial degree of this expression given the degree values of its children.
This method is called by the
_PolynomialDegreeVisitor
class. It can be overwritten by expression classes to customize this logic.Parameters: values (list) – A list of values that indicate the degree of the children expression. Returns: A nonnegative integer that is the polynomial degree of the expression, or None
. Default isNone
.

_fcn

_name

_to_string
(values, verbose, smap, compute_values)[source] Construct a string representation for this node, using the string representations of its children.
This method is called by the
_ToStringVisitor
class. It must must be defined in subclasses.Parameters:  values (list) – The string representations of the children of this node.
 verbose (bool) – If
True
, then the the string representation consists of nested functions. Otherwise, the string representation is an algebraic equation.  smap – If specified, this
SymbolMap
is used to cache labels for variables.  compute_values (bool) – If
True
, then parameters and fixed variables are evaluated before the expression string is generated.
Returns: A string representation for this node.

create_node_with_local_data
(args, classtype=None)[source] Construct a node using given arguments.
This method provides a consistent interface for constructing a node, which is used in tree visitor scripts. In the simplest case, this simply returns:
self.__class__(args)
But in general this creates an expression object using local data as well as arguments that represent the child nodes.
Parameters: args (list) – A list of child nodes for the new expression object Returns: A new expression object with the same type as the current class.

getname
(*args, **kwds)[source] Return the text name of a function associated with this expression object.
In general, no arguments are passed to this function.
Parameters:  *arg – a variable length list of arguments
 **kwds – keyword arguments
Returns: A string name for the function.

nargs
()[source] Returns the number of child nodes.
By default, Pyomo expressions represent binary operations with two arguments.
Note
This function does not simply compute the length of
_args_
because some expression classes use a subset of the_args_
array. Thus, it is imperative that developers use this method!Returns: A nonnegative integer that is the number of child nodes.

class
pyomo.core.expr.current.
AbsExpression
(arg)[source] Bases:
pyomo.core.expr.numeric_expr.UnaryFunctionExpression
An expression object for the
abs()
function.Parameters: args (tuple) – Children nodes