next up previous contents
Next: OSModelInterfaces Up: OSCommonInterfaces Previous: Mapping Rules   Contents


The OSExpressionTree OSnLNode Classes

The OSExpressionTree class provides the in-memory representation of the nonlinear terms. Our design goal is to allow for efficient parsing of OSiL instances, while providing an API that meets the needs of diverse solvers. Conceptually, any nonlinear expression in the objective or constraints is represented by a tree. The expression tree for the nonlinear part of the objective function (1), for example, has the form illustrated in Figure 14. The choice of a data structure to store such a tree -- along with the associated methods of an API -- is a key aspect in the design of the OSInstance class.

Figure 14: Conceptual expression tree for the nonlinear part of the objective (1).
Image expressiontree

A base abstract class OSnLNode is defined and all of an OSiL file's operator and operand elements used in defining a nonlinear expression are extensions of the base element type OSnLNode. There is an element type OSnLNodePlus, for example, that extends OSnLNode; then in an OSiL instance file, there are <plus> elements that are of type OSnLNodePlus. Each OSExpressionTree object contains a pointer to an OSnLNode object that is the root of the corresponding expression tree. To every element that extends the OSnLNode type in an OSiL instance file, there corresponds a class that derives from the OSnLNode class in an OSInstance data structure. Thus we can construct an expression tree of homogenous nodes, and methods that operate on the expression tree to calculate function values, derivatives, postfix notation, and the like do not require switches or complicated logic.

Figure 15: The function calculation method for the ``plus'' node class with polymorphism
\begin{figure}\centering
\small {\obeyspaces\let =\
\fbox{\tt\begin{tabular}{@{...
.../calculateFunction\\ [0pt]
\end{tabular} }} \medskip\vspace{-8pt}\end{figure}

The OSInstance class has a variety of calculate() methods, based on two pure virtual functions in the OSInstance class. The first of these, calculateFunction(), takes an array of double values corresponding to decision variables, and evaluates the expression tree for those values. Every class that extends OSnLNode must implement this method. As an example, the calculateFunction method for the OSnLNodePlus class is shown in Figure 15. Because the OSiL instance file must be validated against its schema, and in the schema each <OSnLNodePlus> element is specified to have exactly two child elements, this calculateFunction method can assume that there are exactly two children of the node that it is operating on. The use of polymorphism and recursion makes adding new operator elements easy; it is simply a matter of adding a new class and implementing the calculateFunction() method for it.

Although in the OSnL schema, there are 200+ nonlinear operators, only the following OSnLNode classes are currently supported in our implementation.


next up previous contents
Next: OSModelInterfaces Up: OSCommonInterfaces Previous: Mapping Rules   Contents
Kipp Martin 2008-01-16