19#include "OSParameters.h"
22#include "CoinFinite.hpp"
27using 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>" ;
bool OSIsEqual(double x, double y)
std::string os_dtoa_format(double x)
void getMultIncr(int *i, int *mult, int *incr, int size, int defaultIncr)
getMultIncr
int getMult(int *i, int size)
getMult
double OSNaN()
returns the value for NaN used in OS
std::string writeStringData(std::string str)
writeStringData
static Bigint * mult(Bigint *a, Bigint *b)
static std::string encodeb64(char *bytes, int size)
encode the data in base 64
ENUM_CONE_TYPE coneType
The type of the cone.
Cone ** cone
cone is pointer to an array of Cone object pointers
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
double ub
ub is the upper bound on the constraint
double lb
lb is the lower bound on the constraint
std::string name
name is the name of the constraint
int numberOfConstraints
numberOfConstraints is the number of constraints in the instance
Constraint ** con
con is pointer to an array of Constraint object pointers
virtual std::string getNonlinearExpressionInXML()
The following method writes an OSnLNode or OSnLMNode in OSiL format.
Variables * variables
variables is a pointer to a Variables object
QuadraticCoefficients * quadraticCoefficients
quadraticCoefficients is a pointer to a QuadraticCoefficients object
Constraints * constraints
constraints is a pointer to a Constraints object
Cones * cones
cones is a pointer to a Cones object
NonlinearExpressions * nonlinearExpressions
nonlinearExpressions is a pointer to a NonlinearExpressions object
MatrixProgramming * matrixProgramming
matrixProgramming is a pointer to a MatrixProgramming object
Matrices * matrices
matrices is a pointer to a Matrices object
Objectives * objectives
objectives is a pointer to a Objectives object
LinearConstraintCoefficients * linearConstraintCoefficients
linearConstraintCoefficients is a pointer to a LinearConstraintCoefficients object
The in-memory representation of an intersection cone.
DoubleVector * value
a pointer to the array of nonzero values being stored
int numberOfValues
numberOfValues is the number of nonzero elements stored in the <linearConstraintCoefficients> element
IntVector * start
a pointer to the start of each row or column stored in sparse format
IntVector * rowIdx
a pointer of row indices if the problem is stored by column
IntVector * colIdx
a pointer of column indices if the problem is stored by row
int numberOfMatrices
numberOfMatrices is the number of <nl> elements in the <matrices> element.
OSMatrix ** matrix
matrix is a pointer to an array of OSMatrix object pointers
int numberOfColumns
numberOfColumns gives the number of columns of this matrix
std::string name
an optional name to this MatrixCon
int lbConeIdx
lbConeIdx gives a cone that must contain matrixCon - lbMatrix
int ubConeIdx
ubConeIdx gives a cone that must contain ubMatrix - matrixCon
int lbMatrixIdx
lbMatrixIdx gives a lower bound for this matrixCon
int numberOfRows
numberOfRows gives the number of rows of this matrix
int templateMatrixIdx
templateMatrixIdx refers to a matrix that describes the locations in this matrixVar that are allowed ...
int conReferenceMatrixIdx
conReferenceMatrixIdx allows some or all of the components of this matrixCon to be copied from constr...
int ubMatrixIdx
ubMatrixIdx gives an upper bound for this matrixCon
int numberOfMatrixCon
numberOfMatrixCon gives the number of <matrixCon> children
MatrixCon ** matrixCon
matrixCon is an array of pointers to the <matrixCon> children
int idx
idx holds the row index of the nonlinear expression
MatrixExpressionTree * matrixExpressionTree
matrixExpressionTree contains the root of the MatrixExpressionTree
ENUM_NL_EXPR_SHAPE shape
shape holds the shape of the nonlinear expression (linear/quadratic/convex/general) (see further up i...
OSnLMNode * m_treeRoot
m_treeRoot holds the root node (of OSnLMNode type) of the expression tree.
int numberOfExpr
numberOfExpr gives the number of expressions
MatrixExpression ** expr
a pointer to an array of linear and nonlinear expressions that evaluate to matrices
int numberOfColumns
numberOfColumns gives the number of columns of this matrix
int numberOfRows
numberOfRows gives the number of rows of this matrix
int orderConeIdx
orderConeIdx gives a cone that expresses preferences during the optimization x is (weakly) preferred ...
int constantMatrixIdx
constantMatrixIdx gives a constant added to the matrixObj
int templateMatrixIdx
templateMatrixIdx refers to a matrix that describes the locations in this matrixObj that are allowed ...
std::string name
an optional name to this matrixObj
int objReferenceMatrixIdx
objReferenceMatrixIdx allows some or all of the components of this matrixObj to be copied from object...
int numberOfMatrixObj
numberOfMatrixObj gives the number of <matrixObj> children
MatrixObj ** matrixObj
matrixObj is an array of pointers to the <matrixObj> children
MatrixObjectives * matrixObjectives
a pointer to the matrixObjectives object
MatrixConstraints * matrixConstraints
a pointer to the matrixConstraints object
MatrixExpressions * matrixExpressions
a pointer to the matrixExpressions object
MatrixVariables * matrixVariables
a pointer to the matrixVariables object
int ubConeIdx
ubConeIdx gives a cone that must contain ubMatrix - matrixVar
char varType
an optional variable type (C, B, I, D, J, S).
int lbMatrixIdx
lbMatrixIdx gives a lower bound for this matrixVar
std::string name
an optional name to this matrixVar
int lbConeIdx
lbConeIdx gives a cone that must contain matrixVar - lbMatrix
int numberOfRows
numberOfRows gives the number of rows of this matrix
int varReferenceMatrixIdx
varReferenceMatrixIdx allows some or all of the components of this matrix variable to be copied from ...
int numberOfColumns
numberOfColumns gives the number of columns of this matrix
int ubMatrixIdx
ubMatrixIdx gives an upper bound for this matrixVar
int templateMatrixIdx
templateMatrixIdx refers to a matrix that describes the locations in this matrixVar that are allowed ...
MatrixVar ** matrixVar
matrixVar is an array of pointers to the <matrixVar> children
int numberOfMatrixVar
numberOfMatrixVar gives the number of <matrixVar> children
int idx
idx holds the row index of the nonlinear expression
ScalarExpressionTree * osExpressionTree
osExpressionTree contains the root of the ScalarExpressionTree
ENUM_NL_EXPR_SHAPE shape
shape holds the shape of the nonlinear expression (linear/quadratic/convex/general) (see further up i...
int numberOfNonlinearExpressions
numberOfNonlinearExpressions is the number of <nl> elements in the <nonlinearExpressions> element.
Nl ** nl
nl is pointer to an array of Nl object pointers
The NonnegativeCone Class.
The NonpositiveCone Class.
The in-memory representation of an OSiL instance..
GeneralFileHeader * instanceHeader
the instanceHeader is implemented as a general file header object to allow sharing of classes between...
InstanceData * instanceData
A pointer to an InstanceData object.
virtual std::string getMatrixNodeInXML()
OSiLWriter()
Default constructor.
~OSiLWriter()
Class destructor.
std::string writeOSiL(const OSInstance *theosinstance)
create an osil string from an OSInstance object
const OSInstance * m_OSInstance
m_OSInstance is an object in the class OSInstance
bool m_bWriteBase64
m_bWriteBase64 is set to true if we encode the linear constraint coefficients in base64 binary
bool m_bWhiteSpace
m_bWhiteSpace is set to true if we write white space in the file
double value
value is the value of the objective function coefficient corresponding to the variable with index idx
int idx
idx is the index of the variable corresponding to the coefficient
ObjCoef ** coef
coef is pointer to an array of ObjCoef object pointers
double constant
constant is the constant term added to the objective function, 0 by default
double weight
weight is the weight applied to the given objective function, 1.0 by default
int numberOfObjCoef
numberOfObjCoef is the number of variables with a nonzero objective function coefficient
std::string name
the name of the objective function
std::string maxOrMin
declare the objective function to be a max or a min
int numberOfObjectives
numberOfObjectives is the number of objective functions in the instance
Objective ** obj
coef is pointer to an array of ObjCoef object pointers
The in-memory representation of a product cone.
QuadraticTerm ** qTerm
qTerm is a pointer to an array of QuadraticTerm object pointers
int numberOfQuadraticTerms
numberOfQuadraticTerms is the number of quadratic terms in the <quadraticCoefficients> element.
The in-memory representation of a quadratic cone.
double coef
coef is the coefficient of the quadratic term
int idxOne
idxOne is the index of the first variable in the quadratic term
int idx
idx is the index of the row in which the quadratic term appears
int idxTwo
idxTwo is the index of the second variable in the quadratic term
The in-memory representation of a rotated quadratic cone.
OSnLNode * m_treeRoot
m_treeRoot holds the root node (of OSnLNode type) of the expression tree.
The in-memory representation of a cone of semidefinite matrices.
double ub
ub corresponds to the optional attribute that holds the variable upper bound.
std::string name
name corresponds to the optional attribute that holds the variable name, the default value is empty
double lb
lb corresponds to the optional attribute that holds the variable lower bound.
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
Variable ** var
Here we define a pointer to an array of var pointers.
This file defines the OSInstance class along with its supporting classes.
bool verifyVarType(char vt)
#define OS_SCHEMA_VERSION
std::string returnExprShapeString(ENUM_NL_EXPR_SHAPE shape)
@ ENUM_CONE_TYPE_nonnegative
@ ENUM_CONE_TYPE_quadratic
@ ENUM_CONE_TYPE_nonpositive
@ ENUM_CONE_TYPE_rotatedQuadratic
@ ENUM_CONE_TYPE_intersection
@ ENUM_CONE_TYPE_semidefinite