org.optimizationservices.oscommon.representationparser
Class FMLWriter

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

public class FMLWriter
extends java.lang.Object

The FMLWriter class is used to output different parts of a linear program (e.g. data and solutions) to a document object model (DOM) that follows FML Schema. Each element declared in the FML 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 FML construction through a group of higher level optimization related public "set" methods (e.g. setConstraints). Each "set" method has a corresponding opposite "on" method in the FMLReader class, which has exactly the same set of arguments. Each method checks within itself the argument consistency against FML Schema. 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. User should, though, make sure values submitted through different "set" methods are consistent. For example if variableCount in setDescription is set to 2, then the variableLbs array in setVariables has to have a length 2.

The FMLWriter class also provides auxiliary facilities to write the xml to different output.

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

Constructor Summary
FMLWriter()
          constructor
 
Method Summary
static void main(java.lang.String[] argv)
          main for test purposes.
 boolean setAMatrix(boolean isColumnMajor, double[] nonzeroValues, int[] nonzeroIndexes, int[] endIndexes, int[] numberOfNonzeros)
          Set the AMatrix related elements.
 boolean setConstraints(java.lang.String[] constraintNames, double[] constraintLhs, double[] constraintRhs)
          Set the constraint related elements.
 boolean setDescription(java.lang.String source, int variableCount, int constraintCount)
          Set the linearProgramDescription related elements.
 boolean setDualSolution(java.lang.String[] dualNames, double[] dualValues, int[] dualIndexes)
          Set the dual solution related elements.
 boolean setObjective(boolean isMinimization, double objectiveConstant, double[] ObjectiveCoefficients)
          Set the objective function related elements.
 boolean setOption(java.lang.String[] optionNames, java.lang.String[] optionValues)
          Set the option related elements.
 boolean setPrimalSolution(java.lang.String[] primalNames, double[] primalValues, int[] primalIndexes)
          Set the primal solution related elements.
 boolean setSolution(java.lang.String statusId, java.lang.String status, java.lang.String solverMessage, double optimalValue)
          Set the objective solution related elements.
 boolean setVariables(java.lang.String[] variableNames, double[] variableLbs, double[] variableUbs, char[] variableDomains)
          Set the variable related elements.
 boolean writeToFile(java.lang.String fileName)
          Write the xml file from the internally constructed DOM tree structure that contains the FML linear program instance (data and/or solution) to a file.
 java.lang.String writeToSring()
          Write the xml file from the internally constructed DOM tree structure that contains the FML linear program instance (data and/or solution) to a string to be returned.
 boolean writeToStandardOutput()
          Write the xml file from the internally constructed DOM tree structure that contains the FML linear program instance (data and/or solution) to the standard output (e.g.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FMLWriter

public FMLWriter()
constructor

Method Detail

writeToFile

public boolean writeToFile(java.lang.String fileName)
Write the xml file from the internally constructed DOM tree structure that contains the FML linear program instance (data and/or solution) to a file.

Parameters:
fileName - holds the xml filename to write out the file to.
Returns:
whether the file is written successfully without any error.

writeToStandardOutput

public boolean writeToStandardOutput()
Write the xml file from the internally constructed DOM tree structure that contains the FML linear program instance (data and/or solution) to the standard output (e.g. screen).

Returns:
whether the output is written successfully without any error.

writeToSring

public java.lang.String writeToSring()
Write the xml file from the internally constructed DOM tree structure that contains the FML linear program instance (data and/or solution) to a string to be returned.

Returns:
a string that contains the FML linear program instance (data and/or solution). If error is encountered in writing the string, null is returned.

setDescription

public boolean setDescription(java.lang.String source,
                              int variableCount,
                              int constraintCount)
Set the linearProgramDescription related elements. If the elements (e.g. the required elements) are already there, it will reset the them. If the elements are not there (e.g. the optional elements), it will add them.

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.
Returns:
whether the linearProgramDescription construction is successful.

setOption

public boolean setOption(java.lang.String[] optionNames,
                         java.lang.String[] optionValues)
Set the option related elements. If the elements (e.g. the required elements) are already there, it will reset the them. If the elements are not there (e.g. the optional elements), it will add them.

Parameters:
optionNames - holds the names of all the options.
optionValues - holds the values of all the options corresponding to the names.
Returns:
whether the option construction is successful.

setVariables

public boolean setVariables(java.lang.String[] variableNames,
                            double[] variableLbs,
                            double[] variableUbs,
                            char[] variableDomains)
Set the variable related elements. If the elements (e.g. the required elements) are already there, it will reset the them. If the elements are not there (e.g. the optional elements), it will add them.

Parameters:
variableNames - holds the names of all the columns, i.e. variable names. 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.
variableDomains - 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.
Returns:
whether variable construction is successful.

setConstraints

public boolean setConstraints(java.lang.String[] constraintNames,
                              double[] constraintLhs,
                              double[] constraintRhs)
Set the constraint related elements. If the elements (e.g. the required elements) are already there, it will reset the them. If the elements are not there (e.g. the optional elements), it will add them.

The constraint information contains all the information about the linear constraints except for the AMatrix, which is to be set in the setAMatrix method.

Parameters:
constraintNames - holds the names of all the rows, i.e. constraint names. It may be empty.
constraintLhs - holds the values of the lower bounds for the constraints. It may be empty.
constraintRhs - holds the values of the upper bounds for the constraints. It may be empty.
Returns:
whether constraint construction is successful.

setAMatrix

public boolean setAMatrix(boolean isColumnMajor,
                          double[] nonzeroValues,
                          int[] nonzeroIndexes,
                          int[] endIndexes,
                          int[] numberOfNonzeros)
Set the AMatrix related elements. If the elements (e.g. the required elements) are already there, it will reset the them. If the elements are not there (e.g. the optional elements), it will add them.

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) indexes.
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) indexes.
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.

setObjective

public boolean setObjective(boolean isMinimization,
                            double objectiveConstant,
                            double[] ObjectiveCoefficients)
Set the objective function related elements. If the elements (e.g. the required elements) are already there, it will reset the them. If the elements are not there (e.g. the optional elements), it will add them.

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. It may be empty.
Returns:
whether objective construction is successful.

setSolution

public boolean setSolution(java.lang.String statusId,
                           java.lang.String status,
                           java.lang.String solverMessage,
                           double optimalValue)
Set the objective solution related elements. If the elements (e.g. the required elements) are already there, it will reset the them. If the elements are not there (e.g. the optional elements), it will add them.

The objective solution does not include primal and dual solutions which are to be set in the setPrimalSolution and setDualSolution 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.
Returns:
whether solution construction is successful.
See Also:
setPrimalSolution(java.lang.String[], double[], int[]), setDualSolution(java.lang.String[], double[], int[])

setPrimalSolution

public boolean setPrimalSolution(java.lang.String[] primalNames,
                                 double[] primalValues,
                                 int[] primalIndexes)
Set the primal solution related elements. If the elements (e.g. the required elements) are already there, it will reset the them. If the elements are not there (e.g. the optional elements), it will add them.

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 primal solution construction is successful.

setDualSolution

public boolean setDualSolution(java.lang.String[] dualNames,
                               double[] dualValues,
                               int[] dualIndexes)
Set the dual solution related elements. If the elements (e.g. the required elements) are already there, it will reset the them. If the elements are not there (e.g. the optional elements), it will add them.

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 dual solution construction is successful.

main

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

Parameters:
argv - command line arguments.