|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.optimizationservices.oscommon.nonlinear.OSExpressionTree
public class OSExpressionTree
The OSExpressionTree
class represents an expression tree for a
nonlinear function (linear ones being special cases) and provide convenience
methods to process the contained nonlinear function. In essence it contains
the root node (of OSnLNode type) of an expression and hides all the internal
nodes. It is the only public class that interfaces with any component (e.g. a
solver) that needs to manipulate the nonlinear functions in an instance. For
example, it is mainly used in the osilReader class to parse a nonlinear
optimization instance.
org.optimizationservices.oscommon.nonlinear.OSnLNode;
,
org.optimizationservices.oscommon.parser.OSiLReader;
Constructor Summary | |
---|---|
OSExpressionTree()
Constructor. |
|
OSExpressionTree(org.w3c.dom.Element expressionTreeRoot,
org.w3c.dom.Element documentRoot)
Constructor |
|
OSExpressionTree(java.util.Vector tokenizedExpression,
java.lang.String type,
int start,
int end)
Constructor |
Method Summary | |
---|---|
double |
calculateDerivative(double[] x,
int index,
boolean functionEvaluated)
Calculate the function derivative value given the current variable values w.r.t one variable. |
it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap |
calculateDerivatives(double[] x,
boolean functionEvaluated)
Calculate the function partial derivatives given the current variable values w.r.t all variables. |
double |
calculateFunction(double[] x)
Calculate the function value of the expression tree. |
double |
calculateFunction(double[] x,
boolean functionEvaluated)
Calculate the expression tree function value given the current variable values. |
java.lang.String |
calculateFunction(java.lang.String[] x,
boolean functionEvaluated)
Calculate the expression tree function value given the current variable values. |
it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap |
calculateHessian(double[] x,
boolean derivativeEvaluated)
Calculate the function Hessian given the current variable values w.r.t all variables. |
OSExpressionTree |
clone()
clone an expression tree to a new copy. |
void |
concatenate(OSExpressionTree eTree)
|
static java.lang.String |
getDelimiter()
|
double |
getDerivative(int index)
Get the expression tree function derivative value given the current variable values values w.r.t one variable. |
it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap |
getDerivatives()
Get the expression tree function derivatives given the current variable values w.r.t all variables. |
org.w3c.dom.Element |
getDomTreeRoot(org.w3c.dom.Document document)
|
java.lang.String |
getDomTreeString(org.w3c.dom.Document document)
|
it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap |
getHessian()
Calculate the function Hessian given the current variable values w.r.t all variables. |
java.util.HashSet |
getIdentifiers()
|
java.util.Vector<java.lang.String> |
getInfix()
|
java.util.HashSet |
getLogicAndRelationalSymbols()
|
java.util.HashSet |
getNetworkArcs()
|
java.util.HashSet |
getNetworkNodes()
|
static java.lang.String |
getNlNodeInfo()
|
int |
getNumberOfComplementsOperator()
|
int |
getNumberOfProbabilityFunctions()
|
int |
getNumberOfProbOperator()
|
int |
getNumberOfStatisticFunctions()
|
int |
getNumberOfTrigonometricFunctions()
|
java.util.HashSet |
getNumberValues()
|
java.util.Vector<java.lang.String> |
getPostfix()
|
java.util.Vector<java.lang.String> |
getPrefix()
|
java.util.HashSet |
getQuadraticTerms()
|
OSnLNode |
getRootNode()
Get the root node of the expression tree. |
java.util.HashSet |
getSimulationNames()
|
int |
getSize()
|
java.util.HashSet |
getUserFunctionNames()
|
it.unimi.dsi.fastutil.ints.IntOpenHashSet |
getVariableIndices()
|
java.util.HashSet |
getXPath()
|
it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap |
linearize()
Linearize the current node so that it doesn't contain linear terms. |
static void |
main(java.lang.String[] argv)
main for test purposes. |
boolean |
quadratize()
Quadratize the current expression tree, or make all the quadratic terms written in the form of a quadratic node with its children being the quadratic terms. |
boolean |
reLabelVariableIndices(int[] newVariableIndices)
relabel variable indices, e.g. |
OSnLNode |
setExpressionTree(org.w3c.dom.Element expressionTreeRoot)
Set the expression tree with an XML element from an OSiL instance that represents a root node of the expression tree. |
OSnLNode |
setExpressionTreeFromInfix(java.util.Vector tokenizedExpression,
int start,
int end)
Set the expression tree with from a tokenized string vector in infix format. |
OSnLNode |
setExpressionTreeFromPostfix(java.util.Vector tokenizedExpression,
int start,
int end)
Set the expression tree with from a tokenized string vector in postfix format. |
OSnLNode |
setExpressionTreeFromPrefix(java.util.Vector tokenizedExpression,
int start,
int end)
Set the expression tree with from a tokenized string vector in prefix format. |
void |
setGlobalDefinition(org.w3c.dom.Element documentRoot)
Set global definitions such as defined userFunctions, simulations, xmlData etc that are used by all the expression trees. |
void |
setRootNode(OSnLNode treeRoot)
Set the root node of the expression tree. |
int |
simplify()
Simplify the current expression tree. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public OSExpressionTree()
public OSExpressionTree(org.w3c.dom.Element expressionTreeRoot, org.w3c.dom.Element documentRoot)
expressionTreeRoot
- holds the XML element from an OSiL instance that represents a
root node of the expression tree.documentRoot
- holds the XML element from an OSiL instance that represents a
root node of the whole OSiL document. This root element of the
document is necessary because some of the node in the
expression tree can point to infomation outside of the
expression tree, which cannot be accessed through
expressionTreeRoot, but can be accessed through documentRoot.public OSExpressionTree(java.util.Vector tokenizedExpression, java.lang.String type, int start, int end)
tokenizedExpression
- holds the expression tokenized in a string vector in either postfix, prefix, or infix.
The operator name in each token has to be exactly the same as the name specified in the OSnL Schema.
The operator name in the token may be followed (without space) by a sequence of ":atrributeValue" and end with
[i] to indicate the number of arguments the operator can take if the operator's type is indefinite.
The attributes specified have to follow the sequence in the OSnL schema.
If one attribute is specified, all attributes have to be specified together. If an attribute
is missing, an empty string has to be in place. Two alternative exception can be allowed for variable
and number. A number can just a a numeric value and the variable can take the form Xi where i is the
integer index of capital letter X.type
- holds whether the expression is in postfix, prefix or infixstart
- holds the index of the tokenizedExpression to start processing.end
- holds the index of the tokenizedExpression to finish processing.Method Detail |
---|
public OSnLNode getRootNode()
public void setRootNode(OSnLNode treeRoot)
treeRoot
- holds the root node (of OSnLNode type) of the expression tree.public OSExpressionTree clone()
clone
in class java.lang.Object
public void setGlobalDefinition(org.w3c.dom.Element documentRoot)
documentRoot
- holds the XML element from an OSiL instance that represents a
root node of the whole OSiL document. This root element of the
document is necessary because some of the node in the
expression tree can point to infomation outside of the
expression tree, which cannot be accessed through
expressionTreeRoot, but can be accessed through documentRoot.public OSnLNode setExpressionTree(org.w3c.dom.Element expressionTreeRoot)
expressionTreeRoot
- holds the XML element from an OSiL instance that represents a
root node of the expression tree.public OSnLNode setExpressionTreeFromPostfix(java.util.Vector tokenizedExpression, int start, int end)
tokenizedExpression
- holds the expression tokenized in a string vector in postfix.
The operator name in the token may be followed (without space) by a sequence of ":atrributeValue" and end with
[i] to indicate the number of arguments the operator can take if the operator's type is indefinite.
The attributes specified have to follow the sequence in the OSnL schema.
If one attribute is specified, all attributes have to be specified together. If an attribute
is missing, an empty string has to be in place. Two alternative exception can be allowed for variable
and number. A number can just a a numeric value and the variable can take the form Xi where i is the
integer index of capital letter X.start
- holds the index of the tokenizedExpression to start processing.end
- holds the index of the tokenizedExpression to finish processing.public OSnLNode setExpressionTreeFromPrefix(java.util.Vector tokenizedExpression, int start, int end)
tokenizedExpression
- holds the expression tokenized in a string vector in prefix.
The operator name in the token may be followed (without space) by a sequence of ":atrributeValue" and end with
[i] to indicate the number of arguments the operator can take if the operator's type is indefinite.
The attributes specified have to follow the sequence in the OSnL schema.
If one attribute is specified, all attributes have to be specified together. If an attribute
is missing, an empty string has to be in place. Two alternative exception can be allowed for variable
and number. A number can just a a numeric value and the variable can take the form Xi where i is the
integer index of capital letter X.start
- holds the index of the tokenizedExpression to start processing.end
- holds the index of the tokenizedExpression to finish processing.public OSnLNode setExpressionTreeFromInfix(java.util.Vector tokenizedExpression, int start, int end)
tokenizedExpression
- holds the expression tokenized in a string vector in infix.
The operator name in the token may be followed (without space) by a sequence of ":atrributeValue" and end with
[i] to indicate the number of arguments the operator can take if the operator's type is indefinite.
The attributes specified have to follow the sequence in the OSnL schema.
If one attribute is specified, all attributes have to be specified together. If an attribute
is missing, an empty string has to be in place. Two alternative exception can be allowed for variable
and number. A number can just a a numeric value and the variable can take the form Xi where i is the
integer index of capital letter X.start
- holds the index of the tokenizedExpression to start processing.end
- holds the index of the tokenizedExpression to finish processing.public void concatenate(OSExpressionTree eTree)
eTree
- holds the expression tree to be concatenated (i.e. linked with
an add operator) to the current expression.public static java.lang.String getDelimiter()
public static java.lang.String getNlNodeInfo()
public double calculateFunction(double[] x)
x
- holds the values of the variables in a double array.
public double calculateFunction(double[] x, boolean functionEvaluated)
x
- holds the values of the variables in a double array.functionEvaluated
- holds whether the function has been evaluated.
public java.lang.String calculateFunction(java.lang.String[] x, boolean functionEvaluated)
x
- holds the values of the variables in a string array.functionEvaluated
- holds whether the function has been evaluated.
public double calculateDerivative(double[] x, int index, boolean functionEvaluated)
x
- holds the values of the variables in a double array.index
- holds the variable index on which to take the derivative.functionEvaluated
- holds whether the function has been evaluated.
public double getDerivative(int index)
index
- holds the variable index on which to get the derivative.
public it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap calculateDerivatives(double[] x, boolean functionEvaluated)
x
- holds the values of the variables in a double array.functionEvaluated
- holds whether the function has been evaluated.
public it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap getDerivatives()
public it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap calculateHessian(double[] x, boolean derivativeEvaluated)
x
- holds the values of the variables in a double array.derivativeEvaluated
- holds whether the function derivatives have been evaluated.
public it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap getHessian()
public java.util.Vector<java.lang.String> getPostfix()
public java.util.Vector<java.lang.String> getPrefix()
public java.util.Vector<java.lang.String> getInfix()
public org.w3c.dom.Element getDomTreeRoot(org.w3c.dom.Document document)
document
- holds the W3C DOM type document to create XML elements and attributes.
It is the parent of the root element, e.g. the <OSiL> element in OSiL. It is used
to create all the nodes in the DOM tree.
public java.lang.String getDomTreeString(org.w3c.dom.Document document)
document
- holds the W3C DOM type document to create XML elements and attributes.
It is the parent of the root element, e.g. the <OSiL> element in OSiL. It is used
to create all the nodes in the DOM tree.
public boolean reLabelVariableIndices(int[] newVariableIndices)
newVariableIndices
- holds the new varialbe indices. For the example above it would be [2, 0, 1].
public int simplify()
public it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap linearize()
Linearize the current node so that it doesn't contain linear terms. The expression tree of the node will become smaller if there are linear terms. If the node is fully linear, the node becomes null. If the node is not linear at all, it will remain the same and the returned hash map has a size zero.
public boolean quadratize()
Quadratize the current expression tree, or make all the quadratic terms written in the form of a quadratic node with its children being the quadratic terms.
public it.unimi.dsi.fastutil.ints.IntOpenHashSet getVariableIndices()
public int getSize()
public int getNumberOfTrigonometricFunctions()
public int getNumberOfStatisticFunctions()
public int getNumberOfProbabilityFunctions()
public java.util.HashSet getNumberValues()
public java.util.HashSet getIdentifiers()
public java.util.HashSet getLogicAndRelationalSymbols()
public java.util.HashSet getQuadraticTerms()
public java.util.HashSet getSimulationNames()
public java.util.HashSet getUserFunctionNames()
public java.util.HashSet getXPath()
public java.util.HashSet getNetworkNodes()
public java.util.HashSet getNetworkArcs()
public int getNumberOfComplementsOperator()
public int getNumberOfProbOperator()
public static void main(java.lang.String[] argv)
argv
- command line arguments.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |