org.optimizationservices.oscommon.representationparser
Class FMLReader

java.lang.Object
  extended by org.optimizationservices.oscommon.representationparser.FMLReader

public class FMLReader
extends java.lang.Object

The FMLReader class creates the SAX2XMLReader parser object. Associated with the FMLReader class are numerous virtual "on" methods that when called by an FMLHandler object create the necessary data structures for the solver. In FMLReader these methods are empty and the solver specific classes that extends from FMLReader are responsible for the actual implementation of these methods. Each "on" method has a corresponding opposite "set" method in the FMLWriter class. There is no specific sequence the user should follow to invoke these on methods.

Since:
OS 1.0
Version:
1.0, 03/14/2004
Author:
Robert Fourer, Jun Ma, Kipp Martin
See Also:
FMLHandler, FMLWriter, XMLReader

Constructor Summary
FMLReader()
          constructor
 
Method Summary
 java.lang.String convertToOSiL()
          Converts an FML instance to an OSiL linear instance.
 boolean getColumnMajor()
           
 int getConstraintCount()
           
 double[] getConstraintLhs()
           
 java.lang.String[] getConstraintNames()
           
 double[] getConstraintRhs()
           
 boolean getMinimization()
           
 int[] getNonzeroIndexes()
           
 double[] getNonzeroValues()
           
 double[] getObjectiveCoefficients()
           
 double getObjectiveConstant()
           
 java.lang.String getSource()
           
 int[] getStartIndexes()
           
 int getVariableCount()
           
 char[] getVariableDomains()
           
 double[] getVariableLbs()
           
 java.lang.String[] getVariableNames()
           
 double[] getVariableUbs()
           
 boolean isValidate()
           
static void main(java.lang.String[] argv)
          main for test purposes.
 boolean onAMatrix(boolean isColumnMajor, double[] nonzeroValues, int[] nonzeroIndexes, int[] endIndexes, int[] numberOfNonzeros)
          Receive notification when an AMatrix is encountered.
 boolean onConstraints(java.lang.String[] constraintNames, double[] constraintLhs, double[] constraintRhs)
          Receive notification when constraints are encountered.
 void onDescription(java.lang.String source, int variableCount, int constraintCount)
          Receive notification when a linearProgramDescription is encountered.
 boolean onDualSolution(java.lang.String[] dualNames, double[] dualValues, int[] dualIndexes)
          Receive notification when dual solutions are encountered.
 boolean onObjective(boolean isMinimization, double objectiveConstant, double[] ObjectiveCoefficients)
          Receive notification when an objective function is encountered.
 boolean onOption(java.lang.String[] optionNames, java.lang.String[] optionValues)
          Receive notification when options are encountered.
 boolean onPrimalSolution(java.lang.String[] primalNames, double[] primalValues, int[] primalIndexes)
          Receive notification when primal solutions are encountered.
 void onSolution(java.lang.String statusId, java.lang.String status, java.lang.String solverMessage, double optimalValue)
          Receive notification when an objective solution is encountered.
 boolean onVariables(java.lang.String[] variableNames, double[] variableLbs, double[] variableUbs, char[] variableDomains)
          Receive notification when variables are encountered.
 boolean readFile(java.lang.String fileName)
          Read the xml file that contains the FML linear program instance.
 boolean readString(java.lang.String fmlString)
          Read the xml string that contains the FML linear program instance.
 void setValidate(boolean xsdValidate)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FMLReader

public FMLReader()
constructor

Method Detail

isValidate

public boolean isValidate()
Returns:
whether the parser should be validating against the schema or not.

setValidate

public void setValidate(boolean xsdValidate)
Parameters:
xsdValidate - holds whether the parser should be validating against the schema or not.

readFile

public boolean readFile(java.lang.String fileName)
Read the xml file that contains the FML linear program instance.

Parameters:
fileName - holds the xml filename that contains the FML linear program instance
Returns:
whether the file is read successfully without any error.

readString

public boolean readString(java.lang.String fmlString)
Read the xml string that contains the FML linear program instance.

Parameters:
fmlString - holds the xml string that contains the FML linear program instance
Returns:
whether the string is read successfully without any error.

onDescription

public void onDescription(java.lang.String source,
                          int variableCount,
                          int constraintCount)
Receive notification when a linearProgramDescription is encountered.

Parameters:
source - holds the source information of the optimization problem.
variableCount - holds the number of columns, i.e. variable number.
constraintCount - holds the number of rows, i.e. constraint number.

onOption

public boolean onOption(java.lang.String[] optionNames,
                        java.lang.String[] optionValues)
Receive notification when options are encountered.

Parameters:
optionNames - holds the names of all the options.
optionValues - holds the values of all the options corresponding to the names.
Returns:
whether user wants to clear the arrays passed in to save memory if the arrays will still be referenced, a false value is to be returned.

onVariables

public boolean onVariables(java.lang.String[] variableNames,
                           double[] variableLbs,
                           double[] variableUbs,
                           char[] variableDomains)
Receive notification when variables are encountered.

Parameters:
variableNames - holds the names of all the columns, i.e. variable names.
variableLbs - holds the values of lower bounds for the variables.
variableUbs - holds the values of upper bounds for the variables.
variableDomains - holds the types of all the variables, (e.g. 'C' for continuous type, 'I' for integer type, and 'B' for binary type).
Returns:
whether user wants to clear the arrays passed in to save memory if the arrays will still be referenced, a false value is to be returned.

onConstraints

public boolean onConstraints(java.lang.String[] constraintNames,
                             double[] constraintLhs,
                             double[] constraintRhs)
Receive notification when constraints are encountered.

The constraint information contains all the information about the linear constraints except for the AMatrix, which is notified in the onAMatrix method.

Parameters:
constraintNames - holds the names of all the rows, i.e. constraint names.
constraintLhs - holds the values of the lower bounds for the constraints.
constraintRhs - holds the values of the upper bounds for the constraints.
Returns:
whether user wants to clear the arrays passed in to save memory if the arrays will still be referenced, a false value is to be returned.
See Also:
onAMatrix(boolean, double[], int[], int[], int[])

onAMatrix

public boolean onAMatrix(boolean isColumnMajor,
                         double[] nonzeroValues,
                         int[] nonzeroIndexes,
                         int[] endIndexes,
                         int[] numberOfNonzeros)
Receive notification when an AMatrix is encountered.

The AMatrix stores all the information in the A part of the linear constraints lhs<=AX<=rhs

Parameters:
isColumnMajor - holds the value of whether the AMatrix holding linear program data is stored by column. If false, the matrix is stored by row.
nonzeroValues - holds the values of the vector element nonz in AMatrix, which contains nonzero elements.
nonzeroIndexes - holds the values of the vector element rowIdx or colIdx in AMatrix. If the matrix is stored by column (row), rowIdx (colIdx) is the vector of row (column) indices.
endIndexes - holds the values of the vector element pntANonz in AMatrix, which points to the end of a column (row) of nonzero elements in AMatrix.
numberOfNonzeros - holds the values of the vector element numNonz in AMatrix. The vector numNonz, if present, stores the number of nonzero elements in the column (row). If numNonz is not present, then nonz stores the columns (rows) in matrix order. If the matrix is stored by column (row), rowIdx (colIdx) is the vector of row (column) indices.
Returns:
whether user wants to clear the arrays passed in to save memory if the arrays will still be referenced, a false value is to be returned.

onObjective

public boolean onObjective(boolean isMinimization,
                           double objectiveConstant,
                           double[] ObjectiveCoefficients)
Receive notification when an objective function is encountered.

Parameters:
isMinimization - holds whether the objective is minimization or not.
objectiveConstant - holds the value of objective function constant.
ObjectiveCoefficients - holds the values of the objective function coefficients.
Returns:
whether user wants to clear the arrays passed in to save memory if the arrays will still be referenced, a false value is to be returned.

onSolution

public void onSolution(java.lang.String statusId,
                       java.lang.String status,
                       java.lang.String solverMessage,
                       double optimalValue)
Receive notification when an objective solution is encountered. It only provides general solution information.

The information does not include primal and dual solutions which are notified in the onPrimalSolution and onDualSolution methods.

Parameters:
statusId - holds the information of optimization solution status id.
status - holds the status message of the optimization solution.
solverMessage - holds the value of solver message.
optimalValue - holds the value of the optimal solution.
See Also:
onPrimalSolution(java.lang.String[], double[], int[]), onDualSolution(java.lang.String[], double[], int[])

onPrimalSolution

public boolean onPrimalSolution(java.lang.String[] primalNames,
                                double[] primalValues,
                                int[] primalIndexes)
Receive notification when primal solutions are encountered.

Parameters:
priamlNames - holds the names of primal variable solutions. It may be empty.
primalValues - holds the values of primal variable solutions corresponding to the primalIndexes.
primalIndexes - holds the indexes of primal variable solutions corresponding to the primalValues.
Returns:
whether user wants to clear the arrays passed in to save memory if the arrays will still be referenced, a false value is to be returned.

onDualSolution

public boolean onDualSolution(java.lang.String[] dualNames,
                              double[] dualValues,
                              int[] dualIndexes)
Receive notification when dual solutions are encountered.

Parameters:
dualNames - holds the names of dual variable solutions. It may be empty.
dualValues - holds the values of dual variable solutions corresponding to the primalIndexes.
dualIndexes - holds the indexes of dual variable solutions corresponding to the primalValues.
Returns:
whether user wants to clear the arrays passed in to save memory if the arrays will still be referenced, a false value is to be returned.

getSource

public java.lang.String getSource()
Returns:
the source information of the optimization problem.

getVariableCount

public int getVariableCount()
Returns:
the number of columns, i.e. variable number.

getConstraintCount

public int getConstraintCount()
Returns:
the number of rows, i.e. constraint number.

getVariableNames

public java.lang.String[] getVariableNames()
Returns:
the names of all the columns, i.e. variable names.

getVariableLbs

public double[] getVariableLbs()
Returns:
the values of lower bounds for the variables.

getVariableUbs

public double[] getVariableUbs()
Returns:
the values of upper bounds for the variables.

getVariableDomains

public char[] getVariableDomains()
Returns:
the types of all the variables, (e.g. 'C' for continuous type, 'I' for integer type, and 'B' for binary type).

getConstraintNames

public java.lang.String[] getConstraintNames()
Returns:
the names of all the rows, i.e. constraint names.

getConstraintLhs

public double[] getConstraintLhs()
Returns:
the values of the lower bounds for the constraints.

getConstraintRhs

public double[] getConstraintRhs()
Returns:
the values of the upper bounds for the constraints.

getColumnMajor

public boolean getColumnMajor()
Returns:
the value of whether the AMatrix holding linear program data is stored by column. If false, the matrix is stored by row.

getNonzeroValues

public double[] getNonzeroValues()
Returns:
the values of the vector element nonz in AMatrix, which contains nonzero elements.

getNonzeroIndexes

public int[] getNonzeroIndexes()
Returns:
the values of the vector element rowIdx or colIdx in AMatrix. If the matrix is stored by column (row), rowIdx (colIdx) is the vector of row (column) indices.

getStartIndexes

public int[] getStartIndexes()
Returns:
the values of the vector element pntANonz in AMatrix, which points to the end of a column (row) of nonzero elements in AMatrix.

getMinimization

public boolean getMinimization()
Returns:
whether the objective is minimization or not.

getObjectiveConstant

public double getObjectiveConstant()
Returns:
the value of objective function constant.

getObjectiveCoefficients

public double[] getObjectiveCoefficients()
Returns:
the values of the objective function coefficients.

convertToOSiL

public java.lang.String convertToOSiL()
Converts an FML instance to an OSiL linear instance.

Returns:
the OSiL linear instance that is converted from the FML instance. A null is returned if there is any error in the conversion.

main

public static void main(java.lang.String[] argv)
main for test purposes.

Parameters:
argv - command line arguments.