19 #include "OSParameters.h"
22 #include "CoinFinite.hpp"
27 using std::ostringstream;
47 std::string tmpname, tmpsense;
48 double tmplb, tmpub, tmpconst, tmpweight;
53 outStr <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ;
55 outStr <<
"<osil xmlns=\"os.optimizationservices.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
56 outStr <<
"xsi:schemaLocation=\"os.optimizationservices.org http://www.optimizationservices.org/schemas/";
58 outStr <<
"/OSiL.xsd\" >" ;
60 outStr <<
"<instanceHeader>";
91 outStr <<
"</instanceHeader>" ;
93 outStr <<
"<instanceData>" ;
99 outStr <<
"<variables " ;
100 outStr <<
"numberOfVariables=\"";
111 if (i < m_OSInstance->instanceData->variables->numberOfVariables - 1)
134 outStr <<
" type=\"" ;
152 outStr <<
" mult=\"" << mult <<
"\"";
158 outStr <<
"</variables>" ;
163 outStr <<
"<objectives " ;
164 outStr <<
"numberOfObjectives=\"";
174 if (j < m_OSInstance->instanceData->objectives->numberOfObjectives - 1)
188 for (kk=0; kk < tmpnum; kk++)
195 if ( kk < tmpnum)
break;
202 outStr <<
" maxOrMin=\"" ;
208 outStr <<
" constant=\"" ;
214 outStr <<
" weight=\"" ;
223 outStr <<
" numberOfObjCoef=\"" ;
227 outStr <<
" mult=\"" << mult <<
"\"";
237 outStr <<
" idx=\"" ;
245 outStr <<
"</coef>" ;
255 outStr <<
"</objectives>" ;
261 outStr <<
"<constraints " ;
262 outStr <<
"numberOfConstraints=\"";
272 if (i < m_OSInstance->instanceData->constraints->numberOfConstraints - 1)
295 outStr <<
" constant=\"" ;
312 outStr <<
" mult=\"" << mult <<
"\"";
318 outStr <<
"</constraints>" ;
324 outStr <<
"<linearConstraintCoefficients " ;
325 outStr <<
"numberOfValues=\"";
335 outStr <<
"<start>" ;
348 outStr <<
"<el mult=\"" << mult <<
"\">";
350 outStr <<
"<el mult=\"" << mult <<
"\" incr=\"" << incr <<
"\">";
359 outStr <<
"<base64BinaryData sizeOf=\"" <<
sizeof(
int) <<
"\" >" ;
362 outStr <<
"</base64BinaryData>" ;
366 outStr <<
"</start>" ;
369 outStr <<
"<rowIdx>" ;
380 outStr <<
"<el mult=\"" << mult <<
"\">";
382 outStr <<
"<el mult=\"" << mult <<
"\" incr=\"" << incr <<
"\">";
392 outStr <<
"<base64BinaryData sizeOf=\"" <<
sizeof(
int) <<
"\" >" ;
395 outStr <<
"</base64BinaryData>" ;
398 outStr <<
"</rowIdx>" ;
408 outStr <<
"<start>" ;
421 outStr <<
"<el mult=\"" << mult <<
"\">";
423 outStr <<
"<el mult=\"" << mult <<
"\" incr=\"" << incr <<
"\">";
432 outStr <<
"<base64BinaryData sizeOf=\"" <<
sizeof(
int) <<
"\" >" ;
435 outStr <<
"</base64BinaryData>" ;
439 outStr <<
"</start>" ;
442 outStr <<
"<colIdx>";
453 outStr <<
"<el mult=\"" << mult <<
"\">";
455 outStr <<
"<el mult=\"" << mult <<
"\" incr=\"" << incr <<
"\">";
464 outStr <<
"<base64BinaryData sizeOf=\"" <<
sizeof(
int) <<
"\" >" ;
467 outStr <<
"</base64BinaryData>" ;
470 outStr <<
"</colIdx>" ;
476 outStr <<
"<value>" ;
489 outStr <<
"<el mult=\"" << mult <<
"\">";
498 outStr <<
"<base64BinaryData sizeOf=\"" <<
sizeof(double) <<
"\" >" ;
501 outStr <<
"</base64BinaryData>" ;
505 outStr <<
"</value>" ;
508 outStr <<
"</linearConstraintCoefficients>" ;
513 outStr <<
"<quadraticCoefficients";
514 outStr <<
" numberOfQuadraticTerms=\"";
527 outStr <<
" idxOne=\"";
530 outStr <<
" idxTwo=\"";
535 outStr <<
" coef=\"";
543 outStr <<
"</quadraticCoefficients>";
549 outStr <<
"<nonlinearExpressions";
550 outStr <<
" numberOfNonlinearExpressions=\"";
566 if (tempStr !=
"" && tempStr !=
"general")
568 outStr <<
" shape=\"" << tempStr <<
"\"";
577 outStr <<
"</nonlinearExpressions>";
583 outStr <<
"<matrices";
584 outStr <<
" numberOfMatrices=\"";
595 outStr <<
"</matrices>" << endl;
601 outStr <<
" numberOfCones=\"";
640 outStr <<
"</cones>" << endl;
645 outStr <<
"<matrixProgramming>";
649 outStr <<
"<matrixVariables";
650 outStr <<
" numberOfMatrixVar=\"";
654 outStr <<
"<matrixVar";
655 outStr <<
" numberOfRows=\"";
657 outStr <<
" numberOfColumns=\"";
662 outStr <<
" templateMatrixIdx=\"";
668 outStr <<
" varReferenceMatrixIdx=\"";
674 outStr <<
" lbMatrixIdx=\"";
680 outStr <<
" lbConeIdx=\"";
686 outStr <<
" ubMatrixIdx=\"";
692 outStr <<
" ubConeIdx=\"";
698 outStr <<
" name=\"";
704 outStr <<
" varType=\"";
708 outStr <<
"/>" << endl;
710 outStr <<
"</matrixVariables>" << endl;
715 outStr <<
"<matrixObjectives";
716 outStr <<
" numberOfMatrixObj=\"";
720 outStr <<
"<matrixObj";
721 outStr <<
" numberOfRows=\"";
723 outStr <<
" numberOfColumns=\"";
728 outStr <<
" templateMatrixIdx=\"";
734 outStr <<
" objReferenceMatrixIdx=\"";
740 outStr <<
" orderConeIdx=\"";
746 outStr <<
" constantMatrixIdx=\"";
752 outStr <<
" name=\"";
756 outStr <<
"/>" << endl;
758 outStr <<
"</matrixObjectives>" << endl;
763 outStr <<
"<matrixConstraints";
764 outStr <<
" numberOfMatrixCon=\"";
768 outStr <<
"<matrixCon";
769 outStr <<
" numberOfRows=\"";
771 outStr <<
" numberOfColumns=\"";
776 outStr <<
" templateMatrixIdx=\"";
782 outStr <<
" conReferenceMatrixIdx=\"";
788 outStr <<
" lbMatrixIdx=\"";
794 outStr <<
" lbConeIdx=\"";
800 outStr <<
" ubMatrixIdx=\"";
806 outStr <<
" ubConeIdx=\"";
812 outStr <<
" name=\"";
816 outStr <<
"/>" << endl;
818 outStr <<
"</matrixConstraints>" << endl;
823 outStr <<
"<matrixExpressions";
824 outStr <<
" numberOfExpr=\"";
840 if (tempStr !=
"" && tempStr !=
"general");
842 outStr <<
" shape=\"" << tempStr <<
"\"";
852 outStr <<
"</matrixExpressions>";
856 outStr <<
"</matrixProgramming>" << endl;
860 outStr <<
"</instanceData>";
861 outStr <<
"</osil>" ;
int numberOfExpr
numberOfExpr gives the number of expressions
ENUM_NL_EXPR_SHAPE shape
shape holds the shape of the nonlinear expression (linear/quadratic/convex/general) (see further up i...
MatrixVar ** matrixVar
matrixVar is an array of pointers to the <matrixVar> children
int numberOfMatrixCon
numberOfMatrixCon gives the number of <matrixCon> children
std::string name
name corresponds to the optional attribute that holds the variable name, the default value is empty ...
Constraints * constraints
constraints is a pointer to a Constraints object
std::string name
the name of the objective function
The in-memory representation of a rotated quadratic cone.
int numberOfColumns
numberOfColumns gives the number of columns of this matrix
int numberOfMatrixVar
numberOfMatrixVar gives the number of <matrixVar> children
IntVector * rowIdx
a pointer of row indices if the problem is stored by column
int ubConeIdx
ubConeIdx gives a cone that must contain ubMatrix - matrixCon
NonlinearExpressions * nonlinearExpressions
nonlinearExpressions is a pointer to a NonlinearExpressions object
int orderConeIdx
orderConeIdx gives a cone that expresses preferences during the optimization x is (weakly) preferred ...
bool verifyVarType(char vt)
MatrixExpression ** expr
a pointer to an array of linear and nonlinear expressions that evaluate to matrices ...
int numberOfMatrixObj
numberOfMatrixObj gives the number of <matrixObj> children
IntVector * colIdx
a pointer of column indices if the problem is stored by row
std::string maxOrMin
declare the objective function to be a max or a min
std::string name
an optional name to this matrixObj
ObjCoef ** coef
coef is pointer to an array of ObjCoef object pointers
ENUM_CONE_TYPE coneType
The type of the cone.
MatrixCon ** matrixCon
matrixCon is an array of pointers to the <matrixCon> children
int idxTwo
idxTwo is the index of the second variable in the quadratic term
QuadraticTerm ** qTerm
qTerm is a pointer to an array of QuadraticTerm object pointers
Constraint ** con
con is pointer to an array of Constraint object pointers
bool m_bWriteBase64
m_bWriteBase64 is set to true if we encode the linear constraint coefficients in base64 binary ...
MatrixConstraints * matrixConstraints
a pointer to the matrixConstraints object
static std::string encodeb64(char *bytes, int size)
encode the data in base 64
const OSInstance * m_OSInstance
m_OSInstance is an object in the class OSInstance
int numberOfRows
numberOfRows gives the number of rows of this matrix
char type
type corresponds to the attribute that holds the variable type: C (Continuous), B (binary)...
int numberOfVariables
numberOfVariables is the number of variables in the instance
int lbConeIdx
lbConeIdx gives a cone that must contain matrixCon - lbMatrix
ENUM_NL_EXPR_SHAPE shape
shape holds the shape of the nonlinear expression (linear/quadratic/convex/general) (see further up i...
double lb
lb is the lower bound on the constraint
int numberOfObjectives
numberOfObjectives is the number of objective functions in the instance
OSiLWriter()
Default constructor.
IntVector * start
a pointer to the start of each row or column stored in sparse format
double ub
ub is the upper bound on the constraint
The in-memory representation of an intersection cone.
MatrixObjectives * matrixObjectives
a pointer to the matrixObjectives object
double OSNaN()
returns the value for NaN used in OS
double weight
weight is the weight applied to the given objective function, 1.0 by default
std::string name
an optional name to this matrixVar
#define OS_SCHEMA_VERSION
Nl ** nl
nl is pointer to an array of Nl object pointers
std::string name
an optional name to this MatrixCon
DoubleVector * value
a pointer to the array of nonzero values being stored
int constantMatrixIdx
constantMatrixIdx gives a constant added to the matrixObj
double lb
lb corresponds to the optional attribute that holds the variable lower bound.
double constant
constant is the constant term added to the objective function, 0 by default
int lbMatrixIdx
lbMatrixIdx gives a lower bound for this matrixVar
Variable ** var
Here we define a pointer to an array of var pointers.
int lbConeIdx
lbConeIdx gives a cone that must contain matrixVar - lbMatrix
int numberOfColumns
numberOfColumns gives the number of columns of this matrix
The in-memory representation of a quadratic cone.
MatrixExpressions * matrixExpressions
a pointer to the matrixExpressions object
double value
value is the value of the objective function coefficient corresponding to the variable with index idx...
int idxOne
idxOne is the index of the first variable in the quadratic term
int numberOfValues
numberOfValues is the number of nonzero elements stored in the <linearConstraintCoefficients> element...
MatrixObj ** matrixObj
matrixObj is an array of pointers to the <matrixObj> children
int ubMatrixIdx
ubMatrixIdx gives an upper bound for this matrixCon
int getMult(int *i, int size)
getMult
double ub
ub corresponds to the optional attribute that holds the variable upper bound.
Variables * variables
variables is a pointer to a Variables object
void getMultIncr(int *i, int *mult, int *incr, int size, int defaultIncr)
getMultIncr
MatrixVariables * matrixVariables
a pointer to the matrixVariables object
bool m_bWhiteSpace
m_bWhiteSpace is set to true if we write white space in the file
int templateMatrixIdx
templateMatrixIdx refers to a matrix that describes the locations in this matrixVar that are allowed ...
GeneralFileHeader * instanceHeader
the instanceHeader is implemented as a general file header object to allow sharing of classes between...
MatrixExpressionTree * matrixExpressionTree
matrixExpressionTree contains the root of the MatrixExpressionTree
int numberOfConstraints
numberOfConstraints is the number of constraints in the instance
OSnLNode * m_treeRoot
m_treeRoot holds the root node (of OSnLNode type) of the expression tree.
int varReferenceMatrixIdx
varReferenceMatrixIdx allows some or all of the components of this matrix variable to be copied from ...
int numberOfRows
numberOfRows gives the number of rows of this matrix
InstanceData * instanceData
A pointer to an InstanceData object.
OSnLMNode * m_treeRoot
m_treeRoot holds the root node (of OSnLMNode type) of the expression tree.
std::string returnExprShapeString(ENUM_NL_EXPR_SHAPE shape)
static Bigint * mult(Bigint *a, Bigint *b)
int idx
idx holds the row index of the nonlinear expression
Objective ** obj
coef is pointer to an array of ObjCoef object pointers
virtual std::string getMatrixNodeInXML()
Matrices * matrices
matrices is a pointer to a Matrices object
std::string writeOSiL(const OSInstance *theosinstance)
create an osil string from an OSInstance object
double coef
coef is the coefficient of the quadratic term
int numberOfColumns
numberOfColumns gives the number of columns of this matrix
bool OSIsEqual(double x, double y)
int templateMatrixIdx
templateMatrixIdx refers to a matrix that describes the locations in this matrixObj that are allowed ...
The in-memory representation of a cone of semidefinite matrices.
int ubMatrixIdx
ubMatrixIdx gives an upper bound for this matrixVar
Objectives * objectives
objectives is a pointer to a Objectives object
std::string os_dtoa_format(double x)
ScalarExpressionTree * osExpressionTree
osExpressionTree contains the root of the ScalarExpressionTree
MatrixProgramming * matrixProgramming
matrixProgramming is a pointer to a MatrixProgramming object
Cones * cones
cones is a pointer to a Cones object
~OSiLWriter()
Class destructor.
int numberOfNonlinearExpressions
numberOfNonlinearExpressions is the number of <nl> elements in the <nonlinearExpressions> element...
int numberOfObjCoef
numberOfObjCoef is the number of variables with a nonzero objective function coefficient ...
virtual std::string getNonlinearExpressionInXML()
The following method writes an OSnLNode or OSnLMNode in OSiL format.
int numberOfQuadraticTerms
numberOfQuadraticTerms is the number of quadratic terms in the <quadraticCoefficients> element...
int numberOfMatrices
numberOfMatrices is the number of <nl> elements in the <matrices> element.
int idx
idx holds the row index of the nonlinear expression
Cone ** cone
cone is pointer to an array of Cone object pointers
int conReferenceMatrixIdx
conReferenceMatrixIdx allows some or all of the components of this matrixCon to be copied from constr...
The in-memory representation of an OSiL instance..
int ubConeIdx
ubConeIdx gives a cone that must contain ubMatrix - matrixVar
QuadraticCoefficients * quadraticCoefficients
quadraticCoefficients is a pointer to a QuadraticCoefficients object
int idx
idx is the index of the variable corresponding to the coefficient
OSMatrix ** matrix
matrix is a pointer to an array of OSMatrix object pointers
char varType
an optional variable type (C, B, I, D, J, S).
int idx
idx is the index of the row in which the quadratic term appears
The in-memory representation of a product cone.
LinearConstraintCoefficients * linearConstraintCoefficients
linearConstraintCoefficients is a pointer to a LinearConstraintCoefficients object ...
int numberOfRows
numberOfRows gives the number of rows of this matrix
int numberOfCones
numberOfCones is the number of <nl> elements in the <cones> element.
double constant
constant is a value that is added to the constraint
The NonnegativeCone Class.
int templateMatrixIdx
templateMatrixIdx refers to a matrix that describes the locations in this matrixVar that are allowed ...
int objReferenceMatrixIdx
objReferenceMatrixIdx allows some or all of the components of this matrixObj to be copied from object...
std::string name
name is the name of the constraint
int lbMatrixIdx
lbMatrixIdx gives a lower bound for this matrixCon
The NonpositiveCone Class.
std::string writeStringData(std::string str)
writeStringData