SimpleExpressionVisitor

(class from pyomo.core.expr.visitor)

class pyomo.core.expr.visitor.SimpleExpressionVisitor[source]

Bases: object

Note

This class is a customization of the PyUtilib SimpleVisitor class that is tailored to efficiently walk Pyomo expression trees. However, this class is not a subclass of the PyUtilib SimpleVisitor class because all key methods are reimplemented.

__init__()

Methods

__init__()

finalize()

Return the "final value" of the search.

visit(node)

Visit a node in an expression tree and perform some operation on it.

xbfs(node)

Breadth-first search of an expression tree, except that leaf nodes are immediately visited.

xbfs_yield_leaves(node)

Breadth-first search of an expression tree, except that leaf nodes are immediately visited.

Member Documentation

finalize()[source]

Return the “final value” of the search.

The default implementation returns None, because the traditional visitor pattern does not return a value.

Returns:

The final value after the search. Default is None.

visit(node)[source]

Visit a node in an expression tree and perform some operation on it.

This method should be over-written by a user that is creating a sub-class.

Parameters:

node – a node in an expression tree

Returns:

nothing

xbfs(node)[source]

Breadth-first search of an expression tree, except that leaf nodes are immediately visited.

Note

This method has the same functionality as the PyUtilib SimpleVisitor.xbfs 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. Defaults to None.

xbfs_yield_leaves(node)[source]

Breadth-first search of an expression tree, except that leaf nodes are immediately visited.

Note

This method has the same functionality as the PyUtilib SimpleVisitor.xbfs_yield_leaves 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. Defaults to None.