|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.optimizationservices.oscommon.representationparser.OSgLWriter
org.optimizationservices.oscommon.representationparser.OSiLWriter
public class OSiLWriter
The OSiLWriter
class is used to construct an optimization instance that follows
the Optimization Services instance Language format. Each element declared in the OSiL Schema has
a corresponding protected element creation method (e.g. createEl for creation of element el).
User do not have direct access to any of these protected methods. They get to manipulate the output of OSiL
construction through a group of higher level optimization related public "set" methods (e.g. setConstraints).
The "set" methods are the opposite "get" method in the corresponding OSiLReader
class. Each method checks within itself the argument consistency against OSiL Schema at the syntax level.
There is no specific sequence the user should follow to invoke these set methods. User can call the
same set methods several times. If the parameters are different, old values will be replaced by new ones.
Users should, though, make sure values submitted through different "set" methods are consistent, i.e. logically correct.
For example if variableCount in setDescription
is set to 2, then the variableLbs array in
setVariables
has to have a length 2.
The OSiLWriter class also provides auxiliary facilities to write the xml to different output.
The OSiLWriter class does not support writing mathML related elements.
OSiLReader
Field Summary |
---|
Fields inherited from class org.optimizationservices.oscommon.representationparser.OSgLWriter |
---|
m_document |
Constructor Summary | |
---|---|
OSiLWriter()
constructor |
Method Summary | |
---|---|
boolean |
addConstraint(java.lang.String constraintName,
double constraintLhs,
double constraintRhs,
double constraintConstant)
Add a constraint (or <con> element) to the existing constraints. |
boolean |
addNlNode(OSExpressionTree expressionTree,
int rowIdx)
Add an nl node. |
boolean |
addNlNode(java.util.Vector tokenizedExpression,
java.lang.String type,
int rowIdx,
int start,
int end)
Add an nl node. |
boolean |
addObjective(java.lang.String objectiveName,
boolean isMin,
double objectiveConstant,
double objectiveWeight,
double[] coefValues,
int[] coefIndexes)
add an objective function related elements. |
boolean |
addSimulation(java.lang.String name,
java.lang.String uri,
OSsLWriter osslWriter)
Add a simulation node. |
boolean |
addUserFunction(java.lang.String name,
int numArg,
OSExpressionTree expressionTree)
Add a userFunction node. |
boolean |
addUserFunction(java.lang.String name,
int numArg,
java.util.Vector tokenizedExpression,
java.lang.String type,
int start,
int end)
Add a userFunction node. |
boolean |
addVariable(java.lang.String variableName,
double variableLb,
double variableUb,
char variableType,
double initialValue,
java.lang.String initialStringValue)
add a variable (or var element). |
static void |
main(java.lang.String[] argv)
main for test purposes. |
boolean |
setConstraints(int numberConstraints,
java.lang.String[] constraintNames,
double[] constraintLbs,
double[] constraintUbs,
double[] constraintConstants)
Set the constraint related elements. |
boolean |
setInstanceHeader(java.lang.String name,
java.lang.String source,
java.lang.String description)
Set the InstanceHeader related elements. |
boolean |
setLinearConstraintCoefficients(int numberOfValues,
boolean isColumnMajor,
double[] nonzeroValues,
int[] nonzeroValuesMultiplicity,
double[] nonzeroValuesIncrement,
int[] nonzeroIndexes,
int[] nonzeroIndexesMultiplicity,
int[] nonzeroIndexesIncrement,
int[] startIndexes,
int[] startIndexesMultiplicity,
int[] startIndexesIncrement)
Set the compressed sparse coefficient matrix related elements with support for multiplicity and increment. |
boolean |
setLinearConstraintCoefficients(int numberOfValues,
boolean isColumnMajor,
double[] nonzeroValues,
int[] nonzeroValuesMultiplicity,
double[] nonzeroValuesIncrement,
int nonzeroValuesBegin,
int nonzeroValuesEnd,
int[] nonzeroIndexes,
int[] nonzeroIndexesMultiplicity,
int[] nonzeroIndexesIncrement,
int nonzeroIndexesBegin,
int nonzeroIndexesEnd,
int[] startIndexes,
int[] startIndexesMultiplicity,
int[] startIndexesIncrement,
int startIndexesBegin,
int startIndexesEnd)
Set the compressed sparse coefficient matrix related elements with support for multiplicity and increment. |
boolean |
setLinearConstraintCoefficients(int numberOfValues,
boolean isColumnMajor,
double[] nonzeroValues,
int[] nonzeroIndexes,
int[] startIndexes)
Set the sparse coefficient matrix related elements. |
boolean |
setLinearConstraintCoefficients(int numberOfValues,
boolean isColumnMajor,
double[] nonzeroValues,
int nonzeroValuesBegin,
int nonzeroValuesEnd,
int[] nonzeroIndexes,
int nonzeroIndexesBegin,
int nonzeroIndexesEnd,
int[] startIndexes,
int startIndexesBegin,
int startIndexesEnd)
Set the sparse coefficient matrix related elements. |
boolean |
setOSInstance(OSInstance osInstance)
set the OSInstance, a standard optimization problem/data api. |
boolean |
setQuadraticTerms(int numberOfQuadraticTerms,
int[] rowIndexes,
int[] varOneIndexes,
int[] varTwoIndexes,
double[] coefficients,
int begin,
int end)
Set the quadratic coefficient terms related elements. |
boolean |
setVariables(int numberVariables,
java.lang.String[] variableNames,
double[] variableLbs,
double[] variableUbs,
char[] variableTypes,
double[] initialValues,
java.lang.String[] initialStringValues)
Set the variable related elements. |
boolean |
setXMLData(org.w3c.dom.Element xmlDataElement)
Set the xmldData related elements. |
boolean |
setXMLData(java.lang.String xmlDataString)
Set the xmldData related elements. |
Methods inherited from class org.optimizationservices.oscommon.representationparser.OSgLWriter |
---|
getDocument, setDocument, writeToFile, writeToSring, writeToStandardOutput |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public OSiLWriter()
Method Detail |
---|
public boolean setOSInstance(OSInstance osInstance) throws java.lang.Exception
java.lang.Exception
- if there are errors setting the OSInstnace.public boolean setInstanceHeader(java.lang.String name, java.lang.String source, java.lang.String description)
name
- holds the name of the optimization problem.source
- holds the source information of the optimization problem.description
- holds the description information of the optimization problem.
public boolean setVariables(int numberVariables, java.lang.String[] variableNames, double[] variableLbs, double[] variableUbs, char[] variableTypes, double[] initialValues, java.lang.String[] initialStringValues)
numberVariables
- holds the number of variables.variableNames
- holds the names of all the variables. It may be empty.variableLbs
- holds the values of lower bounds for the variables. It may be empty.variableUbs
- holds the values of upper bounds for the variables. It may be empty.variableTypes
- holds the types of all the variables, (e.g. 'C' for continuous
type, 'I' for integer type, and 'B' for binary type). It may be empty.initialValues
- holds the initial double values of the variables. It may be empty.initialStringValues
- holds the initial string values of the variables. It may be empty.
public boolean addVariable(java.lang.String variableName, double variableLb, double variableUb, char variableType, double initialValue, java.lang.String initialStringValue)
variableName
- holds the name of a variable. It may be null.variableLb
- holds the value of the lower bound for the variable.variableUb
- holds the value of the upper bound for the variables.variableType
- holds the type of the variable, (e.g. 'C' for continuous
type, 'I' for integer type, and 'B' for binary type).initialValue
- holds the initial value of the variables. It may be NaN, i.e. Double.NaN.initialStringValue
- holds the initial string value of the variables. It may be null.
public boolean addObjective(java.lang.String objectiveName, boolean isMin, double objectiveConstant, double objectiveWeight, double[] coefValues, int[] coefIndexes)
objectiveName
- holds the name of the objective. It may be empty.isMin
- holds whether the objective is minimization or not.objectiveConstant
- holds the objective constant. It may be zero.coefValues
- holds the nonzero coefficient values of the objective function.coefIndexes
- holds the nonzero coefficient variable indexes of the objective function.
public boolean setConstraints(int numberConstraints, java.lang.String[] constraintNames, double[] constraintLbs, double[] constraintUbs, double[] constraintConstants)
The constraint information contains all the information about the constraints
except for the coefMatrix (AMatrix), which is to be set in the setCoefMatrix
method.
numberConstraints
- holds the number of constraints.constraintNames
- holds the names of all the constraints. It may be empty.constraintLbs
- holds the values of the lower bounds for the constraints. It may be empty.constraintUbs
- holds the values of the upper bounds for the constraints. It may be empty.constraintConstants
- holds the values of the constants for the constraints. It may be empty.
public boolean addConstraint(java.lang.String constraintName, double constraintLhs, double constraintRhs, double constraintConstant)
constraintName
- holds the name of a constraint. It may be null.constraintLhs
- holds the value of the lower bounds for the constraint.constraintRhs
- holds the values of the upper bounds for the constraint.constraintConstant
- holds the values of the constant for the constraint.
public boolean setLinearConstraintCoefficients(int numberOfValues, boolean isColumnMajor, double[] nonzeroValues, int[] nonzeroIndexes, int[] startIndexes)
The coefMatrix (AMatrix) stores all the information in the A part of Ax ~ b, i.e. the linear part of all constraints
numberOfValues
- holds the number of specified values in the linear coefficient matrix.isColumnMajor
- holds the value of whether the coefMatrix (AMatrix) holding linear constraint data is stored
by column. If false, the matrix is stored by row.nonzeroValues
- holds the values of the vector element value in coefMatrix (AMatrix), which contains nonzero elements.nonzeroIndexes
- holds the values of the vector element rowIdx or colIdx in coefMatrix (AMatrix). If the matrix is
stored by column (row), rowIdx (colIdx) is the vector of row (column) indexes.startIndexes
- holds the values of the vector element start in coefMatrix (AMatrix), which points to the start of a
column (row) of nonzero elements in coefMatrix (AMatrix).
public boolean setLinearConstraintCoefficients(int numberOfValues, boolean isColumnMajor, double[] nonzeroValues, int nonzeroValuesBegin, int nonzeroValuesEnd, int[] nonzeroIndexes, int nonzeroIndexesBegin, int nonzeroIndexesEnd, int[] startIndexes, int startIndexesBegin, int startIndexesEnd)
The coefMatrix (AMatrix) stores all the information in the A part of Ax ~ b, i.e. the linear part of all constraints
numberOfValues
- holds the number of specified values in the linear coefficient matrix.isColumnMajor
- holds the value of whether the coefMatrix (AMatrix) holding linear constraint data is stored
by column. If false, the matrix is stored by row.nonzeroValues
- holds the values of the vector element value in coefMatrix (AMatrix), which contains nonzero elements.nonzeroValuesBegin
- holds the begin index of the nonzeroValues arraynonzeroValuesEnd
- holds the end index of the nonzeroValues arraynonzeroIndexes
- holds the values of the vector element rowIdx or colIdx in coefMatrix (AMatrix). If the matrix is
stored by column (row), rowIdx (colIdx) is the vector of row (column) indexes.nonzeroIndexesBegin
- holds the begin index of the nonzeroIndexes arraynonzeroIndexesEnd
- holds the end index of the nonzeroIndexes arraystartIndexes
- holds the values of the vector element start in coefMatrix (AMatrix), which points to the start of a
column (row) of nonzero elements in coefMatrix (AMatrix).startIndexesBegin
- holds the begin index of the startIndexes arraystartIndexesEnd
- holds the end index of the startIndexes array
public boolean setLinearConstraintCoefficients(int numberOfValues, boolean isColumnMajor, double[] nonzeroValues, int[] nonzeroValuesMultiplicity, double[] nonzeroValuesIncrement, int[] nonzeroIndexes, int[] nonzeroIndexesMultiplicity, int[] nonzeroIndexesIncrement, int[] startIndexes, int[] startIndexesMultiplicity, int[] startIndexesIncrement)
The coefMatrix (AMatrix) stores all the information in the A part of Ax ~ b, i.e. the linear part of all constraints
numberOfValues
- holds the number of specified values in the linear coefficient matrix.isColumnMajor
- holds the value of whether the coefMatrix (AMatrix) holding linear constraint data is stored
by column. If false, the matrix is stored by row.nonzeroValues
- holds the values of the vector element value in coefMatrix (AMatrix), which contains nonzero elements.nonzeroValuesMultiplicity
- holds the multiplicity (repetition) of each nonzero value in the nonzeroValues array. If null, all multiplicities are 1.nonzeroValuesIncrement
- holds the increment value of each repetition of the nonzeroValues for "multiplicity" times. If null, all increments are 0.nonzeroIndexes
- holds the values of the vector element rowIdx or colIdx in coefMatrix (AMatrix). If the matrix is
stored by column (row), rowIdx (colIdx) is the vector of row (column) indexes.nonzeroIndexesMultiplicity
- holds the multiplicity (repetition) of each nonzero index in the nonzeroIndexes array. If null, all multiplicities are 1.nonzeroIndexesIncrement
- holds the increment value of each repetition of the nonzeroIndexes for "multiplicity" times. If null, all increments are 0.startIndexes
- holds the values of the vector element start in coefMatrix (AMatrix), which points to the start of a
column (row) of nonzero elements in coefMatrix (AMatrix).startIndexesMultiplicity
- holds the multiplicity (repetition) of each start index in the startIndexes array. If null, all multiplicities are 1.startIndexesIncrement
- holds the increment value of each repetition of the startIndexes for "multiplicity" times. If null, all increments are 0.
public boolean setLinearConstraintCoefficients(int numberOfValues, boolean isColumnMajor, double[] nonzeroValues, int[] nonzeroValuesMultiplicity, double[] nonzeroValuesIncrement, int nonzeroValuesBegin, int nonzeroValuesEnd, int[] nonzeroIndexes, int[] nonzeroIndexesMultiplicity, int[] nonzeroIndexesIncrement, int nonzeroIndexesBegin, int nonzeroIndexesEnd, int[] startIndexes, int[] startIndexesMultiplicity, int[] startIndexesIncrement, int startIndexesBegin, int startIndexesEnd)
The coefMatrix (AMatrix) stores all the information in the A part of Ax ~ b, i.e. the linear part of all constraints
numberOfValues
- holds the number of specified values in the linear coefficient matrix.isColumnMajor
- holds the value of whether the coefMatrix (AMatrix) holding linear constraint data is stored
by column. If false, the matrix is stored by row.nonzeroValues
- holds the values of the vector element value in coefMatrix (AMatrix), which contains nonzero elements.nonzeroValuesMultiplicity
- holds the multiplicity (repetition) of each nonzero value in the nonzeroValues array. If null, all multiplicities are 1.nonzeroValuesIncrement
- holds the increment value of each repetition of the nonzeroValues for "multiplicity" times. If null, all increments are 0.nonzeroValuesBegin
- holds the begin index of the nonzeroValues arraynonzeroValuesEnd
- holds the end index of the nonzeroValues arraynonzeroIndexes
- holds the values of the vector element rowIdx or colIdx in coefMatrix (AMatrix). If the matrix is
stored by column (row), rowIdx (colIdx) is the vector of row (column) indexes.nonzeroIndexesMultiplicity
- holds the multiplicity (repetition) of each nonzero index in the nonzeroIndexes array. If null, all multiplicities are 1.nonzeroIndexesIncrement
- holds the increment value of each repetition of the nonzeroIndexes for "multiplicity" times. If null, all increments are 0.nonzeroIndexesBegin
- holds the begin index of the nonzeroIndexes arraynonzeroIndexesEnd
- holds the end index of the nonzeroIndexes arraystartIndexes
- holds the values of the vector element start in coefMatrix (AMatrix), which points to the start of a
column (row) of nonzero elements in coefMatrix (AMatrix).startIndexesMultiplicity
- holds the multiplicity (repetition) of each start index in the startIndexes array. If null, all multiplicities are 1.startIndexesIncrement
- holds the increment value of each repetition of the startIndexes for "multiplicity" times. If null, all increments are 0.startIndexesBegin
- holds the begin index of the startIndexes arraystartIndexesEnd
- holds the end index of the startIndexes array
public boolean setQuadraticTerms(int numberOfQuadraticTerms, int[] rowIndexes, int[] varOneIndexes, int[] varTwoIndexes, double[] coefficients, int begin, int end)
numberOfQuadraticTerms
- holds the number of quadratic terms.rowIndexes
- holds an integer array of row indexes of all the quadratic terms.
A negative integer corresponds to an objective row, e.g. -1 for 1st objective and -2 for 2nd.varOneIndexes
- holds an integer array of the first varialbe indexes of all the quadratic terms.varTwoIndexes
- holds an integer array of the second varialbe indexes of all the quadratic terms.coefficients
- holds a double array all the quadratic term coefficients. If null all coefficient values are 1.begin
- holds the begin index of all the arrays to copy from (usually = 0).end
- holds the end index of all the arrays to copy till (usually = array length -1).
public boolean addNlNode(java.util.Vector tokenizedExpression, java.lang.String type, int rowIdx, 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
are 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
- whether the expression is in postfix, prefix or infixrowIdx
- holds the row number the nl node corresponds to. If rowIdx is negative, it corresponds to an objective.start
- holds the index of the tokenizedExpression to start processing.end
- holds the index of the tokenizedExpression to finish processing.
public boolean addNlNode(OSExpressionTree expressionTree, int rowIdx)
expressionTree
- holds the os expression of the nl node.rowIdx
- holds the row number the nl node corresponds to. If rowIdx is negative, it corresponds to an objective.
public boolean addSimulation(java.lang.String name, java.lang.String uri, OSsLWriter osslWriter)
name
- holds the name of the simulationuri
- holds the uri address of the simulationosslWriter
- holds the the root element of ossl.
public boolean addUserFunction(java.lang.String name, int numArg, java.util.Vector tokenizedExpression, java.lang.String type, int start, int end)
name
- holds the name of the userFunctionnumArg
- holds the number of arguments of the user functiontokenizedExpression
- 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
are 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
- 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.
public boolean addUserFunction(java.lang.String name, int numArg, OSExpressionTree expressionTree)
name
- holds the name of the userFunctionnumArg
- holds the number of arguments of the user functionexpressionTree
- holds the os expression of the nl node.
public boolean setXMLData(org.w3c.dom.Element xmlDataElement)
xmlDataElement
- holds the xmlData element. xmlDataElement can either have a root
of <xmlData> or not. The method will add the root if the root is not there.
public boolean setXMLData(java.lang.String xmlDataString)
xmlDataString
- holds the xmlData element. xmlDataElement can either have a root
of <xmlData> or not. The method will add the root if the root is not there.
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 |