ExpressionValueVisitor
(class from pyomo.core.expr.visitor
)
- class pyomo.core.expr.visitor.ExpressionValueVisitor[source]
Bases:
object
Note
This class is a customization of the PyUtilib
ValueVisitor
class that is tailored to efficiently walk Pyomo expression trees. However, this class is not a subclass of the PyUtilibValueVisitor
class because all key methods are reimplemented.- __init__()
Methods
__init__
()dfs_postorder_stack
(node)Perform a depth-first search in postorder using a stack implementation.
finalize
(ans)This method defines the return value for the search methods in this class.
visit
(node, values)Visit a node in a tree and compute its value using the values of its children.
visiting_potential_leaf
(node)Visit a node and return its value if it is a leaf.
Member Documentation
- dfs_postorder_stack(node)[source]
Perform a depth-first search in postorder using a stack implementation.
Note
This method has the same functionality as the PyUtilib
ValueVisitor.dfs_postorder_stack
method. The difference is that this method is tailored to efficiently walk Pyomo expression trees.- Parameters:
node – The root node of the expression tree that is searched.
- Returns:
The return value is determined by the
finalize()
function, which may be defined by the user.
- finalize(ans)[source]
This method defines the return value for the search methods in this class.
The default implementation returns the value of the initial node (aka the root node), because this visitor pattern computes and returns value for each node to enable the computation of this value.
- Parameters:
ans – The final value computed by the search method.
- Returns:
The final value after the search. Defaults to simply returning
ans
.
- visit(node, values)[source]
Visit a node in a tree and compute its value using the values of its children.
This method should be over-written by a user that is creating a sub-class.
- Parameters:
node – a node in a tree
values – a list of values of this node’s children
- Returns:
The value for this node, which is computed using
values
- visiting_potential_leaf(node)[source]
Visit a node and return its value if it is a leaf.
Note
This method needs to be over-written for a specific visitor application.
- Parameters:
node – a node in a tree
- Returns:
(flag, value)
. Ifflag
is False, then the node is not a leaf andvalue
isNone
. Otherwise,value
is the computed value for this node.- Return type:
A tuple