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
NumericExpression
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.int16'>, <class 'float'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.int32'>, <class 'complex'>, <class 'numpy.uint64'>, <class 'int'>, <class 'numpy.int64'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'numpy.int8'>, <class 'numpy.float32'>, <class 'numpy.uint16'>}
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 'str'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.int32'>, <class 'NoneType'>, <class 'slice'>, <class 'numpy.float32'>, <class 'numpy.uint16'>, <class 'numpy.int16'>, <class 'numpy.bool_'>, <class 'complex'>, <class 'bytes'>, <class 'numpy.ndarray'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'numpy.int8'>, <class 'bool'>, <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 'str'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.int32'>, <class 'NoneType'>, <class 'slice'>, <class 'numpy.float32'>, <class 'numpy.uint16'>, <class 'numpy.int16'>, <class 'numpy.bool_'>, <class 'complex'>, <class 'pyomo.core.expr.numvalue.NonNumericValue'>, <class 'bytes'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'numpy.int8'>, <class 'bool'>, <class 'float'>, <class 'int'>}
set() -> new empty set object set(iterable) -> new set object
Build an unordered collection of unique elements.
NumericValue and NumericExpression
- 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 non-constant) or variable values will raise an exception.
- Raises:
- __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 non-constant) or variable values will raise an exception.
- Raises:
- __ge__(other)[source]
Greater than or equal operator
This method is called when Python processes statements of the form:
self >= other other <= self
- __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 non-constant) or variable values will raise an exception.
- Raises:
- __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
- __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
- is_relational()[source]
DEPRECATED.
Return True if this numeric value represents a relational expression.
Deprecated since version 6.4.3: is_relational() is deprecated in favor of is_expression_type(ExpressionType.RELATIONAL)
- 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 string representation consists of nested functions. Otherwise, the string representation is an infix algebraic equation. Defaults toFalse
.labeler – An object that generates string labels for non-constant in the expression tree. Defaults to
None
.smap – A SymbolMap instance that stores string labels for non-constant nodes in the expression tree. Defaults to
None
.compute_values (bool) – If
True
, then fixed expressions are evaluated and the string representation of the resulting value is returned.
- Returns:
A string representation for the expression tree.
- class pyomo.core.expr.NumericExpression(args)[source]
Bases:
ExpressionBase
,NumericValue
The base class for Pyomo expressions.
This class is used to define nodes in a numeric expression tree.
- PRECEDENCE = 0
Return the associativity of this operator.
Returns 1 if this operator is left-to-right associative or -1 if it is right-to-left 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 over-written 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
.
- property args
Return the child nodes
- create_potentially_variable_object()[source]
DEPRECATED.
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.
Deprecated since version 6.4.3: The implicit recasting of a “not potentially variable” expression node to a potentially variable one is no longer supported (this violates that immutability promise for Pyomo5 expression trees).
- nargs()[source]
Returns the number of child nodes.
Note
Individual expression nodes may use different internal storage schemes, so it is imperative that developers use this method and not assume the existence of a particular attribute!
- Returns:
int
- Return type:
A nonnegative integer that is the number of child nodes.
Other Public Classes
- class pyomo.core.expr.NegationExpression(args)[source]
Bases:
NumericExpression
Negation expressions:
- x
- PRECEDENCE = 4
Return the associativity of this operator.
Returns 1 if this operator is left-to-right associative or -1 if it is right-to-left 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).
- _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 over-written 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 note that if this class contains auxiliary 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 over-written 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)[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:
- 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.
Note
Individual expression nodes may use different internal storage schemes, so it is imperative that developers use this method and not assume the existence of a particular attribute!
- Returns:
int
- Return type:
A nonnegative integer that is the number of child nodes.
- class pyomo.core.expr.ExternalFunctionExpression(args, fcn=None)[source]
Bases:
NumericExpression
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
- PRECEDENCE = None
Return the associativity of this operator.
Returns 1 if this operator is left-to-right associative or -1 if it is right-to-left 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).
- _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 over-written 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 note that if this class contains auxiliary 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.
- _fcn
- _to_string(values, verbose, smap)[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:
- 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 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.
Note
Individual expression nodes may use different internal storage schemes, so it is imperative that developers use this method and not assume the existence of a particular attribute!
- Returns:
int
- Return type:
A nonnegative integer that is the number of child nodes.
- class pyomo.core.expr.ProductExpression(args)[source]
Bases:
NumericExpression
Product expressions:
x*y
- PRECEDENCE = 4
Return the associativity of this operator.
Returns 1 if this operator is left-to-right associative or -1 if it is right-to-left 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).
- _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 over-written 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 note that if this class contains auxiliary 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 over-written 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 over-written 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
.
- class pyomo.core.expr.DivisionExpression(args)[source]
Bases:
NumericExpression
Division expressions:
x/y
- PRECEDENCE = 4
Return the associativity of this operator.
Returns 1 if this operator is left-to-right associative or -1 if it is right-to-left 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).
- _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 over-written 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 note that if this class contains auxiliary 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 over-written 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
.
- class pyomo.core.expr.InequalityExpression(args, strict)[source]
Bases:
RelationalExpression
Inequality expressions, which define less-than or less-than-or-equal relations:
x < y x <= y
- Parameters:
- PRECEDENCE = 9
Return the associativity of this operator.
Returns 1 if this operator is left-to-right associative or -1 if it is right-to-left 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).
- _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 over-written 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 note that if this class contains auxiliary 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)[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:
- 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 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.
- nargs()[source]
Returns the number of child nodes.
Note
Individual expression nodes may use different internal storage schemes, so it is imperative that developers use this method and not assume the existence of a particular attribute!
- Returns:
int
- Return type:
A nonnegative integer that is the number of child nodes.
- property strict
- class pyomo.core.expr.EqualityExpression(args)[source]
Bases:
RelationalExpression
Equality expression:
x == y
- PRECEDENCE = 9
Return the associativity of this operator.
Returns 1 if this operator is left-to-right associative or -1 if it is right-to-left 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).
- _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 over-written 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 note that if this class contains auxiliary 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)[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:
- Returns:
A string representation for this node.
- nargs()[source]
Returns the number of child nodes.
Note
Individual expression nodes may use different internal storage schemes, so it is imperative that developers use this method and not assume the existence of a particular attribute!
- Returns:
int
- Return type:
A nonnegative integer that is the number of child nodes.
- class pyomo.core.expr.SumExpression(args)[source]
Bases:
NumericExpression
Sum expression:
x + y + ...
This node represents an “n-ary” sum expression over at least 2 arguments.
- Parameters:
args (list) – Children nodes
- PRECEDENCE = 6
Return the associativity of this operator.
Returns 1 if this operator is left-to-right associative or -1 if it is right-to-left 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).
- _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 over-written 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 note that if this class contains auxiliary 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 over-written 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
.
- _nargs
- _to_string(values, verbose, smap)[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:
- Returns:
A string representation for this node.
- add(new_arg)[source]
DEPRECATED.
Deprecated since version 6.6.0: SumExpression.add() is deprecated. Please use regular Python operators (infix ‘+’ or inplace ‘+=’.)
- property args
Return the child nodes
- 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.
Note
Individual expression nodes may use different internal storage schemes, so it is imperative that developers use this method and not assume the existence of a particular attribute!
- Returns:
int
- Return type:
A nonnegative integer that is the number of child nodes.
- class pyomo.core.expr.GetItemExpression(args=())[source]
Bases:
ExpressionBase
Expression to call
__getitem__()
on the base object.- PRECEDENCE = 1
Return the associativity of this operator.
Returns 1 if this operator is left-to-right associative or -1 if it is right-to-left 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).
- _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 over-written 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 note that if this class contains auxiliary 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.
- _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 over-written 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)[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:
- 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.
Note
Individual expression nodes may use different internal storage schemes, so it is imperative that developers use this method and not assume the existence of a particular attribute!
- Returns:
int
- Return type:
A nonnegative integer that is the number of child nodes.
- class pyomo.core.expr.Expr_ifExpression(args)[source]
Bases:
NumericExpression
A numeric ternary (if-then-else) expression:
Expr_if(IF=x, THEN=y, ELSE=z)
Note that this is a mixed expression: IF can be numeric or logical; THEN and ELSE are numeric, and the result is a numeric expression.
- PRECEDENCE = None
Return the associativity of this operator.
Returns 1 if this operator is left-to-right associative or -1 if it is right-to-left 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).
- _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 over-written 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 note that if this class contains auxiliary 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 over-written 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 over-written 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)[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:
- 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.
Note
Individual expression nodes may use different internal storage schemes, so it is imperative that developers use this method and not assume the existence of a particular attribute!
- Returns:
int
- Return type:
A nonnegative integer that is the number of child nodes.
- class pyomo.core.expr.UnaryFunctionExpression(args, name=None, fcn=None)[source]
Bases:
NumericExpression
An expression object for intrinsic (math) 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
- PRECEDENCE = None
Return the associativity of this operator.
Returns 1 if this operator is left-to-right associative or -1 if it is right-to-left 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).
- _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 over-written 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 note that if this class contains auxiliary 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.
- _fcn
- _name
- _to_string(values, verbose, smap)[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:
- 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 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.
Note
Individual expression nodes may use different internal storage schemes, so it is imperative that developers use this method and not assume the existence of a particular attribute!
- Returns:
int
- Return type:
A nonnegative integer that is the number of child nodes.
- class pyomo.core.expr.AbsExpression(arg)[source]
Bases:
UnaryFunctionExpression
An expression object for the
abs()
function.- Parameters:
args (tuple) – Children nodes
- 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 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.