next up previous contents
Next: Set Methods Up: The OSInstance API Previous: The OSInstance API   Contents

Get Methods

The get() methods are used by other classes to access data in an existing OSInstance object or get an expression tree representation of an instance in postfix or prefix format. Assume osinstance is an object in the OSInstance class created as illustrated in Figure 10. Then, for example,

osinstance->getVariableNumber();
will return an integer which is the number of variables in the problem,
osintance->getVariableTypes();
will return a char pointer to the variable types (C for continuous, B for binary, and I for general integer),
getVariableLowerBounds();
will return a double pointer to the lower bound on each variable. There are similar get methods for the constraints. There are numerous get methods for the data in the <linearConstraintCoefficients> element, the <quadraticCoefficients> element, and the <nonlinearExpressions> element.

When an osinstance object is created, it is stored as in expression tree in an OSExpressionTree object. However, some solver APIs (e.g. LINDO) may take the data in a different format such as postfix and prefix. There are methods to return the data in either postfix or prefix format.

First define a vector of pointers to OSnLNode objects.

std::vector<OSnLNode*> postfixVec;
then get the expression tree for the objective function (index = -1) as a postfix vector of nodes.
postfixVec = osinstance->getNonlinearExpressionTreeInPostfix( -1);
If, for example, the osinstance object was the in-memory representation of the instance illustrated in Section 14.2 then the code
for (i = 0 ; i < n; i++){
	cout << postfixVec[i]->snodeName << endl;	
}
will produce
number
variable
minus
number
power
number
variable
variable
number
power
minus
number
power
times
plus
The method, processNonlinearExpressions() in the LindoSolver class in the OSSolverInterfaces library component illustrates using a postfix vector of OSnLNode objects to build a Lindo model instance.


next up previous contents
Next: Set Methods Up: The OSInstance API Previous: The OSInstance API   Contents
Kipp Martin 2008-01-16