OSInstance.cpp
Go to the documentation of this file.
1 /* $Id: OSInstance.cpp 5032 2015-06-15 15:49:04Z Gassmann $ */
17 #include "OSGeneral.h"
18 #include "OSInstance.h"
19 #include "OSMathUtil.h"
20 #include "OSMatrix.h"
21 #include "OSErrorClass.h"
22 #include "OSParameters.h"
23 #include "OSOutput.h"
24 #include "OSgLWriter.h"
25 
26 #include <cstdlib>
27 #include <stack>
28 #include <iostream>
29 #include <sstream>
30 
31 
32 using namespace std;
33 using std::ostringstream;
34 
35 
37  bVariablesModified(false),
38  bObjectivesModified(false),
39  bConstraintsModified(false),
40  bAMatrixModified(false),
41  m_sInstanceName(""),
42  m_sInstanceSource(""),
43  m_sInstanceDescription(""),
44  m_sInstanceCreator(""),
45  m_sInstanceLicence(""),
46  m_bProcessVariables(false),
47  m_iVariableNumber(-1),
48  m_iNumberOfIntegerVariables( 0),
49  m_iNumberOfBinaryVariables( 0),
50  m_iNumberOfSemiContinuousVariables( 0),
51  m_iNumberOfSemiIntegerVariables( 0),
52  m_iNumberOfStringVariables( 0),
53  m_msVariableNames(NULL),
54  m_mcVariableTypes(NULL),
55  m_mdVariableLowerBounds(NULL),
56  m_mdVariableUpperBounds(NULL),
57  //m_mdVariableInitialValues(NULL), -- deprecated
58  //m_msVariableInitialStringValues(NULL), -- deprecated
59  m_bProcessObjectives(false),
60  m_iObjectiveNumber(-1),
61  m_iObjectiveNumberNonlinear( 0),
62  m_msObjectiveNames(NULL),
63  m_msMaxOrMins(NULL),
64  m_miNumberOfObjCoef(NULL),
65  m_mdObjectiveConstants(NULL),
66  m_mdObjectiveWeights(NULL),
67  m_mObjectiveCoefficients(NULL),
68  m_bGetDenseObjectives(false),
69  m_mmdDenseObjectiveCoefficients(NULL),
70  m_bProcessConstraints(false),
71  m_iConstraintNumber(-1),
72  m_iConstraintNumberNonlinear( 0),
73  m_msConstraintNames(NULL),
74  m_mdConstraintLowerBounds(NULL),
75  m_mdConstraintUpperBounds(NULL),
76  m_mdConstraintConstants( NULL),
77  m_mcConstraintTypes(NULL),
78  m_bProcessLinearConstraintCoefficients(false),
79  m_iLinearConstraintCoefficientNumber(-1),
80  m_bColumnMajor(true),
81  m_linearConstraintCoefficientsInColumnMajor(NULL),
82  m_linearConstraintCoefficientsInRowMajor(NULL),
83  m_iNumberOfQuadraticRowIndexes( 0),
84  m_bQuadraticRowIndexesProcessed(false),
85  m_miQuadRowIndexes( NULL),
86  m_bProcessQuadraticTerms(false),
87  m_iQuadraticTermNumber(-1),
88  m_quadraticTerms( NULL),
89  m_bQTermsAdded( false),
90  m_iNumberOfNonlinearExpressionTreeIndexes( 0),
91  m_bNonlinearExpressionTreeIndexesProcessed( false),
92  m_miNonlinearExpressionTreeIndexes( NULL),
93  m_iNumberOfNonlinearExpressionTreeModIndexes( 0),
94  m_bNonlinearExpressionTreeModIndexesProcessed( false),
95  m_miNonlinearExpressionTreeModIndexes( NULL),
96  m_binitForAlgDiff( false),
97  m_iNumberOfNonlinearVariables( 0),
98  m_bProcessNonlinearExpressions( false),
99  m_iNonlinearExpressionNumber( -1),
100  m_miNonlinearExpressionIndexes( NULL),
101  m_bProcessExpressionTrees( false),
102  m_bProcessExpressionTreesMod( false),
103  m_mdConstraintFunctionValues( NULL),
104  m_mdObjectiveFunctionValues( NULL),
105  m_iJacValueSize( 0),
106  m_miJacStart( NULL),
107  m_miJacIndex( NULL),
108  m_mdJacValue( NULL),
109  m_miJacNumConTerms( NULL),
110  m_sparseJacMatrix( NULL),
111  m_iHighestTaylorCoeffOrder(-1),
112  m_LagrangianExpTree(NULL),
113  m_bLagrangianExpTreeCreated( false),
114  m_LagrangianSparseHessian( NULL),
115  m_bLagrangianSparseHessianCreated( false),
116  m_miNonLinearVarsReverseMap( NULL),
117  m_bAllNonlinearVariablesIndex( false),
118  m_bOSADFunIsCreated( false),
119  m_bCppADTapesBuilt( false),
120  m_bCppADMustReTape( false),
121  m_bDuplicateExpressionTreesMap( false),
122  m_bNonLinearStructuresInitialized( false),
123  m_bSparseJacobianCalculated( false),
124  m_iHighestOrderEvaluated( -1),
125  m_mmdObjGradient( NULL),
126  m_bProcessMatrices( false),
127  m_iMatrixNumber (-1),
128  m_miMatrixSymmetry(NULL),
129  m_miMatrixType(NULL),
130  m_miMatrixNumberOfColumns(NULL),
131  m_miMatrixNumberOfRows(NULL),
132  m_msMatrixNames(NULL),
133  m_mMatrix(NULL),
134 
135 // m_mExpandedMatricesInColumnMajor(NULL),
136 // m_mExpandedMatricesInRowMajor(NULL),
137 // m_mMatrixBlocksInColumnMajor(NULL),
138 // m_mMatrixTransformation(NULL),
139 
140  m_iMatrixVarNumber(-1),
141  m_iMatrixObjNumber(-1),
142  m_iMatrixConNumber(-1),
143  m_iMatrixExpressionNumber(-1),
144 
145  m_bProcessTimeDomain( false),
146  m_bProcessTimeStages( false),
147  m_bProcessTimeInterval( false),
148  m_bFiniteTimeStages( false),
149  m_iNumberOfTimeStages(-1),
150  m_sTimeDomainFormat(""),
151  m_msTimeDomainStageNames(NULL),
152  m_miTimeDomainStageVariableNumber(NULL),
153  m_mmiTimeDomainStageVarList(NULL),
154  m_miTimeDomainStageConstraintNumber(NULL),
155  m_mmiTimeDomainStageConList(NULL),
156  m_miTimeDomainStageObjectiveNumber(NULL),
157  m_mmiTimeDomainStageObjList(NULL),
158  bUseExpTreeForFunEval( false)
159 {
160 #ifndef NDEBUG
161  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside OSInstance Constructor");
162 #endif
163  this->instanceHeader = new GeneralFileHeader();
164  this->instanceData = new InstanceData();
165 }
166 
168 {
169  std::ostringstream outStr;
170 
171 #ifndef NDEBUG
172  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "OSInstance Destructor Called");
173 #endif
174  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
175  // delete the temporary arrays
176 
177  if (this->instanceData->variables != NULL &&
178  this->instanceData->variables->numberOfVariables > 0 &&
179  m_bProcessVariables == true)
180  {
181  if (m_msVariableNames != NULL) delete[] m_msVariableNames;
182  m_msVariableNames = NULL;
183  if (m_mcVariableTypes != NULL) delete[] m_mcVariableTypes;
184  m_mcVariableTypes = NULL;
185  if (m_mdVariableLowerBounds != NULL) delete[] m_mdVariableLowerBounds;
187  if (m_mdVariableUpperBounds != NULL) delete[] m_mdVariableUpperBounds;
189  }
190 
191 
192  if(m_bProcessConstraints == true)
193  {
194  if (m_msConstraintNames != NULL) delete[] m_msConstraintNames;
195  m_msConstraintNames = NULL;
196  if (m_mcConstraintTypes != NULL) delete[] m_mcConstraintTypes;
197  m_mcConstraintTypes = NULL;
198  if (m_mdConstraintConstants != NULL) delete[] m_mdConstraintConstants;
204  }
205 
206 
207  int i;
208  //if(instanceData->objectives->numberOfObjectives > 0 && m_mObjectiveCoefficients != NULL){
209  if(instanceData->objectives != NULL && m_bProcessObjectives == true )
210  {
211  for(i = 0; i < instanceData->objectives->numberOfObjectives; i++)
212  {
213 #ifndef NDEBUG
214  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, "Delete m_mObjectiveCoefficients[i]");
215 #endif
216  if (m_mObjectiveCoefficients[i] != NULL) delete m_mObjectiveCoefficients[i];
217  m_mObjectiveCoefficients[i] = NULL;
218  }
219 #ifndef NDEBUG
220  outStr.str("");
221  outStr.clear();
222  outStr << "Delete m_msObjectiveNames" << std::endl;
223  outStr << "Delete m_msMaxOrMins" << std::endl;
224  outStr << "Delete m_miNumberOfObjCoef" << std::endl;
225  outStr << "Delete m_mdObjectiveConstants" << std::endl;
226  outStr << "Delete m_mdObjectiveWeights" << std::endl;
228 #endif
229  if (m_msObjectiveNames != NULL) delete[] m_msObjectiveNames;
230  m_msObjectiveNames = NULL;
231  if (m_msMaxOrMins != NULL) delete[] m_msMaxOrMins;
232  m_msMaxOrMins = NULL;
233  if (m_miNumberOfObjCoef != NULL) delete[] m_miNumberOfObjCoef;
234  m_miNumberOfObjCoef = NULL;
235  if (m_mdObjectiveConstants != NULL) delete[] m_mdObjectiveConstants;
236  m_mdObjectiveConstants = NULL;
237  if (m_mdObjectiveWeights != NULL) delete[] m_mdObjectiveWeights;
238  m_mdObjectiveWeights = NULL;
241  }
242 
243  if(instanceData->objectives != NULL && m_bGetDenseObjectives == true)
244  {
245  for(i = 0; i < instanceData->objectives->numberOfObjectives; i++)
246  {
247  //delete m_mmdDenseObjectiveCoefficients[i];
248 #ifndef NDEBUG
249  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, "delete m_mmdDenseObjectiveCoefficients[i]");
250 #endif
251  if (m_mmdDenseObjectiveCoefficients[i] != NULL)
254  }
255  if (m_mmdDenseObjectiveCoefficients != NULL)
258  }
259 
264 
265  if( (m_binitForAlgDiff == true) )
266  {
269 
270  if (instanceData->objectives != NULL &&
272  m_mmdObjGradient != NULL)
273  {
274 #ifndef NDEBUG
275  outStr.str("");
276  outStr.clear();
277  outStr << "The number of objectives = " << instanceData->objectives->numberOfObjectives << std::endl;
279 #endif
280  for(i = 0; i < instanceData->objectives->numberOfObjectives; i++)
281  {
282 #ifndef NDEBUG
283  outStr.str("");
284  outStr.clear();
285  outStr << "deleting Objective function gradient " << i << std::endl;
287 #endif
288  if (m_mmdObjGradient[i] != NULL) delete[] m_mmdObjGradient[i];
289  m_mmdObjGradient[i] = NULL;
290  }
291  if (m_mmdObjGradient != NULL) delete[] m_mmdObjGradient;
292  m_mmdObjGradient = NULL;
293  }
294  }
295 
296  // garbage collection for the gradient
297 #ifndef NDEBUG
299  "Do garbage collection for the nonlinear API");
300 #endif
302  {
307  }
308  if(m_bSparseJacobianCalculated == true)
309  {
310  if (m_miJacStart != NULL) delete[] m_miJacStart;
311  m_miJacStart = NULL;
312  if (m_miJacIndex != NULL) delete[] m_miJacIndex;
313  m_miJacIndex = NULL;
314  if (m_mdJacValue != NULL) delete[] m_mdJacValue;
315  m_mdJacValue = NULL;
316  if (m_miJacNumConTerms != NULL) delete[] m_miJacNumConTerms;
317  m_miJacNumConTerms = NULL;
318  }
319  if( m_bLagrangianExpTreeCreated == true)
320  {
321  if (m_LagrangianExpTree != NULL) delete m_LagrangianExpTree;
322  m_LagrangianExpTree = NULL;
323  }
325  {
328  }
329  if( m_bSparseJacobianCalculated == true)
330  {
331  if (m_sparseJacMatrix != NULL) delete m_sparseJacMatrix;
332  m_sparseJacMatrix = NULL;
333  }
335  {
336  if( (m_bProcessQuadraticTerms == true) )
337  {
338  if (m_quadraticTerms != NULL) delete m_quadraticTerms;
339  m_quadraticTerms = NULL;
340  }
341  if( (m_bQuadraticRowIndexesProcessed == true) )
342  {
343  if (m_miQuadRowIndexes != NULL) delete[] m_miQuadRowIndexes;
344  m_miQuadRowIndexes = NULL;
345  }
346  }
347  //
348  // delete the new expression trees that got created
349  //if( m_bLagrangianExpTreeCreated == false || m_bLagrangianExpTreeCreated == true){
350  if( (m_bProcessExpressionTrees == true) && (m_bDuplicateExpressionTreesMap == false) )
351  {
352  for(posMapExpTree = m_mapExpressionTrees.begin(); posMapExpTree != m_mapExpressionTrees.end(); ++posMapExpTree)
353  {
354 #ifndef NDEBUG
355  outStr.str("");
356  outStr.clear();
357  outStr << "Deleting an expression tree from the map for row " << posMapExpTree->first << std::endl;
359 #endif
360  delete m_mapExpressionTrees[ posMapExpTree->first ];
361  }
362  }
363  if( m_bDuplicateExpressionTreesMap == true)
364  {
365  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
366  {
367 #ifndef NDEBUG
368  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Deleting an expression tree from m_mapExpressionTreesMod");
369 #endif
370  delete m_mapExpressionTreesMod[ posMapExpTree->first ];
371  }
372  }
373  //}
376  {
377 #ifndef NDEBUG
378  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, "Deleting m_miNonlinearExpressionTreeIndexes");
379 #endif
381 #ifndef NDEBUG
382  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, "Done Deleting m_miNonlinearExpressionTreeIndexes");
383 #endif
385  }
387  {
388 #ifndef NDEBUG
389  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, "Deleting m_miNonlinearExpressionTreeModIndexes");
390 #endif
392 #ifndef NDEBUG
393  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, "Done Deleting m_miNonlinearExpressionTreeModIndexes");
394 #endif
396  }
397  if(m_bOSADFunIsCreated == true)
398  {
399  try
400  {
401 #ifdef COIN_HAS_CPPAD
402  delete Fad;
403  Fad = NULL;
404 #else
405  throw ErrorClass( "Error: An Algorithmic Differentiation Package Not Available");
406 #endif
407  }
408  catch(const ErrorClass& eclass)
409  {
410  throw ErrorClass( eclass.errormsg);
411  }
412  }
413 
414  if (this->instanceData->matrices != NULL &&
415  this->instanceData->matrices->numberOfMatrices > 0 &&
416  m_bProcessMatrices == true)
417  {
418  if (m_miMatrixSymmetry != NULL) delete[] m_miMatrixSymmetry;
419  m_miMatrixSymmetry = NULL;
420  if (m_miMatrixType != NULL) delete[] m_miMatrixType;
421  m_miMatrixType = NULL;
424  if (m_miMatrixNumberOfRows != NULL) delete[] m_miMatrixNumberOfRows;
425  m_miMatrixNumberOfRows = NULL;
426  if (m_msMatrixNames != NULL) delete[] m_msMatrixNames;
427  m_msMatrixNames = NULL;
428 
429  if (m_mMatrix != NULL)
430  {
431  for (int i=0; i < instanceData->matrices->numberOfMatrices; i++)
432  {
433  if (m_mMatrix[i] != NULL)
434  delete m_mMatrix[i];
435  m_mMatrix[i] = NULL;
436  }
437  delete[] m_mMatrix;
438  m_mMatrix = NULL;
439  }
440 
441 #if 0
442  if (m_mExpandedMatricesInColumnMajor != NULL)
443  {
444  for (int i=0; i < instanceData->matrices->numberOfMatrices; i++)
445  {
446  if (m_mExpandedMatricesInColumnMajor[i] != NULL)
447  delete m_mExpandedMatricesInColumnMajor[i];
448  m_mExpandedMatricesInColumnMajor[i] = NULL;
449  }
450  delete[] m_mExpandedMatricesInColumnMajor;
451  m_mExpandedMatricesInColumnMajor = NULL;
452  }
453 
454  if (m_mExpandedMatricesInRowMajor != NULL)
455  {
456  for (int i=0; i < instanceData->matrices->numberOfMatrices; i++)
457  {
458  if (m_mExpandedMatricesInRowMajor[i] != NULL)
459  delete m_mExpandedMatricesInRowMajor[i];
460  m_mExpandedMatricesInRowMajor[i] = NULL;
461  }
462  delete[] m_mExpandedMatricesInRowMajor;
463  m_mExpandedMatricesInRowMajor = NULL;
464  }
465 
466  if (m_mMatrixBlocksInColumnMajor != NULL)
467  {
468  for (int i=0; i < instanceData->matrices->numberOfMatrices; i++)
469  {
470  if (m_mMatrixBlocksInColumnMajor[i] != NULL)
471  delete m_mMatrixBlocksInColumnMajor[i];
472  m_mMatrixBlocksInColumnMajor[i] = NULL;
473  }
474  delete[] m_mMatrixBlocksInColumnMajor;
475  m_mMatrixBlocksInColumnMajor = NULL;
476  }
477  }
478 
479  if (m_mMatrixTransformation != NULL)
480  {
481  for (int i=0; i < instanceData->matrices->numberOfMatrices; i++)
482  {
483  if (m_mMatrixTransformation[i] != NULL)
484  delete m_mMatrixTransformation[i];
485  m_mMatrixTransformation[i] = NULL;
486  }
487  delete[] m_mMatrixTransformation;
488  m_mMatrixTransformation = NULL;
489  }
490  }
491 #endif
492 
493 
494 // if( (instanceData->timeDomain->stages->stage != NULL) && (m_bProcessTimeStages == true) ){
495 // delete m_Stages;
496 // m_Stages = NULL;
497  }
498 
499  if (m_msTimeDomainStageNames != NULL)
500  {
501  delete[] m_msTimeDomainStageNames;
502  m_msTimeDomainStageNames = NULL;
503  }
504 
505  if (m_miTimeDomainStageVariableNumber != NULL)
506  {
507  delete[] m_miTimeDomainStageVariableNumber;
508  m_miTimeDomainStageVariableNumber = NULL;
509  }
510 
511  if (m_mmiTimeDomainStageVarList != NULL)
512  {
513  for (int i = 0; i < m_iNumberOfTimeStages; i ++)
514  delete[] m_mmiTimeDomainStageVarList[i];
515  delete[] m_mmiTimeDomainStageVarList;
516  m_mmiTimeDomainStageVarList = NULL;
517  }
518 
519  if (m_miTimeDomainStageConstraintNumber != NULL)
520  {
521  delete[] m_miTimeDomainStageConstraintNumber;
522  m_miTimeDomainStageConstraintNumber = NULL;
523  }
524 
525  if (m_mmiTimeDomainStageConList != NULL)
526  {
527  for (int i = 0; i < m_iNumberOfTimeStages; i ++)
528  delete[] m_mmiTimeDomainStageConList[i];
529  delete[] m_mmiTimeDomainStageConList;
530  m_mmiTimeDomainStageConList = NULL;
531  }
532 
533  if (m_miTimeDomainStageObjectiveNumber != NULL)
534  {
535  delete[] m_miTimeDomainStageObjectiveNumber;
536  m_miTimeDomainStageObjectiveNumber = NULL;
537  }
538 
539  if (m_mmiTimeDomainStageObjList != NULL)
540  {
541  for (int i = 0; i < m_iNumberOfTimeStages; i ++)
542  delete[] m_mmiTimeDomainStageObjList[i];
543  delete[] m_mmiTimeDomainStageObjList;
544  m_mmiTimeDomainStageObjList = NULL;
545  }
546 
547  // delete the two children of OSInstance
548  //delete instanceHeader object
549  delete instanceHeader;
550  instanceHeader = NULL;
551  //delete instanceData object
552  delete instanceData;
553  instanceData = NULL;
554 }//OSInstance Destructor
555 
556 
558  lb(0.0),
559  ub(OSDBL_MAX),
560  //init(OSNaN()), deprecated
561  type('C'),
562  name("")
563  //initString("") deprecated
564 {
565 #ifndef NDEBUG
566  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Variable Constructor");
567 #endif
568 }
569 
571 {
572 #ifndef NDEBUG
573  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Variable Destructor");
574 #endif
575 }
576 
578 {
579 #ifndef NDEBUG
580  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Variables Constructor");
581 #endif
582  numberOfVariables = 0;
583  var = NULL;
584 }
585 
587 {
588 #ifndef NDEBUG
589  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Variables Destructor");
590 #endif
591  int i;
592  if(numberOfVariables > 0 && var != NULL)
593  {
594  for(i = 0; i < numberOfVariables; i++)
595  {
596 #ifndef NDEBUG
598 #endif
599  delete var[i];
600  var[i] = NULL;
601  }
602  }
603  if (var != NULL)
604  delete[] var;
605  var = NULL;
606 }
607 
609  idx(-1),
610  value(0.0)
611 {
612 #ifndef NDEBUG
613  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ObjCoef Constructor");
614 #endif
615 }
616 
618 {
619 #ifndef NDEBUG
620  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ObjCoef Destructor");
621 #endif
622 }
623 
625  name("") ,
626  maxOrMin("min"),
627  constant(0.0),
628  weight(OSNaN()),
629  numberOfObjCoef(0),
630  coef(NULL)
631 {
632 
633 #ifndef NDEBUG
634  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Objective Constructor");
635 #endif
636 }
637 
639 {
640 #ifndef NDEBUG
641  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Objective Destructor");
642 #endif
643  int i;
644  if(numberOfObjCoef > 0 && coef != NULL)
645  {
646  for(i = 0; i < numberOfObjCoef; i++)
647  {
648  delete coef[i];
649  coef[i] = NULL;
650  }
651  }
652  if (coef != NULL)
653  delete[] coef;
654  coef = NULL;
655 }
656 
658 {
659 #ifndef NDEBUG
660  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Objectives Constructor");
661 #endif
662  numberOfObjectives = 0;
663  obj = NULL;
664 }
665 
667 {
668 #ifndef NDEBUG
669  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Objectives Destructor");
670 #endif
671  int i;
672  if(numberOfObjectives > 0 && obj != NULL)
673  {
674  for(i = 0; i < numberOfObjectives; i++)
675  {
676  delete obj[i];
677  obj[i] = NULL;
678  }
679  }
680  if (obj != NULL)
681  delete[] obj;
682  obj = NULL;
683 }
684 
686  name(""),
687  constant(0.0),
688  lb(-OSDBL_MAX),
689  ub(OSDBL_MAX)
690 
691 {
692 #ifndef NDEBUG
693  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Constraint Constructor");
694 #endif
695 }
696 
698 {
699 #ifndef NDEBUG
700  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Constraint Destructor");
701 #endif
702 }
703 
705  numberOfConstraints(0),
706  con(NULL)
707 {
708 #ifndef NDEBUG
709  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Constraints Constructor");
710 #endif
711 }
712 
714 {
715 #ifndef NDEBUG
716  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Constraints Destructor");
717 #endif
718  int i;
719  if(numberOfConstraints > 0 && con != NULL)
720  {
721  for( i = 0; i < numberOfConstraints; i++)
722  {
723  delete con[i];
724  con[i] = NULL;
725  }
726  }
727  if (con != NULL)
728  delete[] con;
729  con = NULL;
730 }
731 
732 
733 
735  numberOfValues(0) ,
736  iNumberOfStartElements( 0)
737 {
738 #ifndef NDEBUG
739  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the LinearConstraintCoefficients Constructor");
740 #endif
741  start = new IntVector();
742  rowIdx = new IntVector();
743  colIdx = new IntVector();
744  value = new DoubleVector();
745 }
746 
747 
749 {
750 #ifndef NDEBUG
751  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the LinearConstraintCoefficients Destructor");
752 #endif
753  delete start;
754  start = NULL;
755  delete rowIdx;
756  rowIdx = NULL;
757  delete colIdx;
758  colIdx = NULL;
759  delete value;
760  value = NULL;
761 }
762 
764 
765  idx(0),
766  idxOne(-1),
767  idxTwo(-1),
768  coef(0.0)
769 
770 {
771 #ifndef NDEBUG
772  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the QuadraticTerm Constructor");
773 #endif
774 }
775 
776 
778 {
779 #ifndef NDEBUG
780  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the QuadraticTerm Destructor");
781 #endif
782 }
783 
784 
785 
787  numberOfQuadraticTerms(0),
788  qTerm(NULL)
789 {
790 #ifndef NDEBUG
791  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the QuadraticCoefficients Constructor");
792 #endif
793 }//end QuadraticCoefficients()
794 
795 
797 {
798 #ifndef NDEBUG
799  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the QuadraticCoefficients Destructor");
800 #endif
801  int i;
802  if(numberOfQuadraticTerms > 0 && qTerm != NULL)
803  {
804  for( i = 0; i < numberOfQuadraticTerms; i++)
805  {
806  delete qTerm[i];
807  qTerm[i] = NULL;
808  }
809  }
810  if (qTerm != NULL)
811  delete[] qTerm;
812  qTerm = NULL;
813 }//end ~QuadraticCoefficients()
814 
815 
817 {
818 #ifndef NDEBUG
819  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Nl Constructor");
820 #endif
821  idx = 0;
823  osExpressionTree = NULL;
825 }//end Nl
826 
827 
829 {
830 #ifndef NDEBUG
831  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Nl Destructor");
832 #endif
833  // don't delete the expression tree if we created a map of the expression
834  // trees, otherwise we would destroy twice
835  if( m_bDeleteExpressionTree == true)
836  {
837  if (osExpressionTree != NULL) delete osExpressionTree;
838  osExpressionTree = NULL;
839  }
840 }//end ~Nl
841 
842 
843 
845  numberOfNonlinearExpressions(0) ,
846  nl(NULL)
847 {
848 #ifndef NDEBUG
849  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the NonlinearExpressions Constructor");
850 #endif
851 }//end NonlinearExpressions()
852 
854 {
855  std::ostringstream outStr;
856 
857 #ifndef NDEBUG
858  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the NonlinearExpressions Destructor");
859  outStr.str("");
860  outStr.clear();
861  outStr << "NUMBER OF NONLINEAR EXPRESSIONS = " << numberOfNonlinearExpressions << endl;
863 #endif
864  int i;
865  if(numberOfNonlinearExpressions > 0 && nl != NULL)
866  {
867  for( i = 0; i < numberOfNonlinearExpressions; i++)
868  {
869 #ifndef NDEBUG
870  outStr.str("");
871  outStr.clear();
872  outStr << "DESTROYING EXPRESSION " << i << "(row " << nl[ i]->idx << ")" << endl;
874 #endif
875  if(nl != NULL)
876  {
877  if(nl[i] != NULL)
878  {
879  delete nl[i];
880  nl[i] = NULL;
881  }
882  }
883  }
884  }
885  if(nl != NULL)
886  {
887  delete[] nl;
888  }
889  nl = NULL;
890 }//end ~NonlinearExpressions()
891 
892 
894  numberOfMatrices(0) ,
895  matrix(NULL)
896 {
897 #ifndef NDEBUG
898  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Matrices Constructor");
899 #endif
900 }//end Matrices()
901 
903 {
904  std::ostringstream outStr;
905 
906 #ifndef NDEBUG
907  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Matrices Destructor");
908  outStr.str("");
909  outStr.clear();
910  outStr << "NUMBER OF MATRICES = " << numberOfMatrices << endl;
912 #endif
913  int i;
914  if(numberOfMatrices > 0 && matrix != NULL)
915  {
916  for (i = 0; i < numberOfMatrices; i++)
917  {
918 #ifndef NDEBUG
919  outStr.str("");
920  outStr.clear();
921  outStr << "DESTROYING MATRIX " << i << endl;
923 #endif
924  if(matrix[i] != NULL)
925  {
926  delete matrix[i];
927  matrix[i] = NULL;
928  }
929  }
930  }
931  if(matrix != NULL)
932  {
933  delete[] matrix;
934  matrix = NULL;
935  }
936 }//end ~Matrices()
937 
938 
940  numberOfCones(0) ,
941  cone(NULL)
942 {
943 #ifndef NDEBUG
944  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Cones Constructor");
945 #endif
946 }//end Cones()
947 
949 {
950  std::ostringstream outStr;
951 
952 #ifndef NDEBUG
953  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Cones Destructor");
954  outStr.str("");
955  outStr.clear();
956  outStr << "NUMBER OF CONES = " << numberOfCones << endl;
958 #endif
959  int i;
960  if(numberOfCones > 0 && cone != NULL)
961  {
962  for( i = 0; i < numberOfCones; i++)
963  {
964 #ifndef NDEBUG
965  outStr.str("");
966  outStr.clear();
967  outStr << "DESTROYING CONE " << i << endl;
969 #endif
970  if(cone != NULL)
971  {
972  if(cone[i] != NULL)
973  {
974  delete cone[i];
975  cone[i] = NULL;
976  }
977  }
978  }
979  }
980  if(cone != NULL)
981  {
982  delete [] cone;
983  cone = NULL;
984  }
985 }//end ~Cones()
986 
988  numberOfRows(0),
989  numberOfColumns(0),
990  numberOfOtherIndexes(0),
991  otherIndexes(NULL),
992  coneType(ENUM_CONE_TYPE_unknown),
993  idx(-1)
994 {
995 #ifndef NDEBUG
996  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Cone Constructor");
997 #endif
998 }//end Cone()
999 
1001 {
1002 #ifndef NDEBUG
1003  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Cone Destructor");
1004 #endif
1005  if(otherIndexes != NULL)
1006  {
1007  delete[] otherIndexes;
1008  otherIndexes = NULL;
1009  }
1010 }//end ~Cone()
1011 
1012 std::string Cone::getConeName()
1013 {
1014  return "genericCone";
1015 }// end Cone::getConeName()
1016 
1018 {
1019 #ifndef NDEBUG
1020  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the NonnegativeCone Constructor");
1021 #endif
1022 }//end NonnegativeCone()
1023 
1025 {
1026 #ifndef NDEBUG
1027  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the NonnegativeCone Destructor");
1028 #endif
1029 }//end ~NonnegativeCone()
1030 
1032 {
1033  return "nonnegativeCone";
1034 }// end NonnegativeCone::getConeName()
1035 
1037 {
1038 #ifndef NDEBUG
1039  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the NonpositiveCone Constructor");
1040 #endif
1041 }//end NonnegativeCone()
1042 
1044 {
1045 #ifndef NDEBUG
1046  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the NonpositiveCone Destructor");
1047 #endif
1048 }//end ~NonpositiveCone()
1049 
1051 {
1052  return "nonpositiveCone";
1053 }// end NonpositiveCone::getConeName()
1054 
1056  ub(NULL),
1057  lb(NULL)
1058 {
1059 #ifndef NDEBUG
1060  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OrthantCone Constructor");
1061 #endif
1062 }//end OrthantCone()
1063 
1065 {
1066 #ifndef NDEBUG
1067  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OrthantCone Destructor");
1068 #endif
1069  if(ub != NULL)
1070  {
1071  delete[] ub;
1072  ub = NULL;
1073  }
1074  if(lb != NULL)
1075  {
1076  delete[] lb;
1077  lb = NULL;
1078  }
1079 }//end ~OrthantCone()
1080 
1082 {
1083  return "orthantCone";
1084 }// end OrthantCone::getConeName()
1085 
1087  referenceMatrixIdx(0)
1088 {
1089 #ifndef NDEBUG
1090  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the PolyhedralCone Constructor");
1091 #endif
1092 }//end PolyhedralCone()
1093 
1095 {
1096 #ifndef NDEBUG
1097  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the PolyhedralCone Destructor");
1098 #endif
1099 }//end ~PolyhedralCone()
1100 
1102 {
1103  return "polyhedralCone";
1104 }// end PolyhedralCone::getConeName()
1105 
1106 
1108  normScaleFactor(1.0),
1109  distortionMatrixIdx(-1),
1110  axisDirection(0)
1111 {
1112 #ifndef NDEBUG
1113  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the QuadraticCone Constructor");
1114 #endif
1115 }//end QuadraticCone()
1116 
1118 {
1119 #ifndef NDEBUG
1120  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the QuadraticCone Destructor");
1121 #endif
1122 }//end ~QuadraticCone()
1123 
1125 {
1126  return "quadraticCone";
1127 }// end QuadraticCone::getConeName()
1128 
1129 
1131  normScaleFactor(1.0),
1132  distortionMatrixIdx(-1),
1133  firstAxisDirection(0),
1134  secondAxisDirection(1)
1135 {
1136 #ifndef NDEBUG
1137  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the RotatedQuadraticCone Constructor");
1138 #endif
1139 }//end RotatedQuadraticCone()
1140 
1142 {
1143 #ifndef NDEBUG
1144  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the RotatedQuadraticCone Destructor");
1145 #endif
1146 }//end ~RotatedQuadraticCone()
1147 
1149 {
1150  return "rotatedQuadraticCone";
1151 }// end RotatedQuadraticCone::getConeName()
1152 
1153 
1154 
1155 
1157  semidefiniteness("positive"),
1158  isPositiveSemiDefinite(true)
1159 {
1160 #ifndef NDEBUG
1161  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the SemidefiniteCone Constructor");
1162 #endif
1163 }//end SemidefiniteCone()
1164 
1166 {
1167 #ifndef NDEBUG
1168  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the SemidefiniteCone Destructor");
1169 #endif
1170 }//end ~SemidefiniteCone()
1171 
1173 {
1174  return "semidefiniteCone";
1175 }// end SemidefiniteCone::getConeName()
1176 
1178 {
1179 #ifndef NDEBUG
1180  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the CopositiveMatricesCone Constructor");
1181 #endif
1182 }//end CopositiveMatricesCone()
1183 
1185 {
1186 #ifndef NDEBUG
1187  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the CopositiveMatricesCone Destructor");
1188 #endif
1189 }//end ~CopositiveMatricesCone()
1190 
1192 {
1193  return "copositiveMatricesCone";
1194 }// end CopositiveMatricesCone::getConeName()
1195 
1196 
1198 {
1199 #ifndef NDEBUG
1200  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the CompletelyPositiveMatricesCone Constructor");
1201 #endif
1202 }//end CompletelyPositiveMatricesCone()
1203 
1205 {
1206 #ifndef NDEBUG
1207  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the CompletelyPositiveMatricesCone Destructor");
1208 #endif
1209 }//end ~CompletelyPositiveMatricesCone()
1210 
1212 {
1213  return "completelyPositiveMatricesCone";
1214 }// end CompletelyPositiveMatricesCone::getConeName()
1215 
1217  factors(NULL)
1218 {
1219 #ifndef NDEBUG
1220  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ProductCone Constructor");
1221 #endif
1222 }//end ProductCone()
1223 
1225 {
1226 #ifndef NDEBUG
1227  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ProductCone Destructor");
1228 #endif
1229  if (factors != NULL)
1230  delete factors;
1231  factors = NULL;
1232 }//end ~ProductCone()
1233 
1235 {
1236  return "productCone";
1237 }// end ProductCone::getConeName()
1238 
1239 
1241  components(NULL)
1242 {
1243 #ifndef NDEBUG
1244  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the IntersectionCone Constructor");
1245 #endif
1246 }//end IntersectionCone()
1247 
1249 {
1250 #ifndef NDEBUG
1251  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the IntersectionCone Destructor");
1252 #endif
1253  if (components != NULL)
1254  delete components;
1255  components = NULL;
1256 }//end ~IntersectionCone()
1257 
1259 {
1260  return "intersectionCone";
1261 }// end IntersectionCone::getConeName()
1262 
1263 
1265  referenceConeIdx(0)
1266 {
1267 #ifndef NDEBUG
1268  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the DualCone Constructor");
1269 #endif
1270 }//end DualCone()
1271 
1273 {
1274 #ifndef NDEBUG
1275  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the DualCone Destructor");
1276 #endif
1277 }//end ~DualCone()
1278 
1280 {
1281  return "dualCone";
1282 }// end DualCone::getConeName()
1283 
1284 
1286  referenceConeIdx(0)
1287 {
1288 #ifndef NDEBUG
1289  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the PolarCone Constructor");
1290 #endif
1291 }//end PolarCone()
1292 
1294 {
1295 #ifndef NDEBUG
1296  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the PolarCone Destructor");
1297 #endif
1298 }//end ~PolarCone()
1299 
1301 {
1302  return "polarCone";
1303 }// end PolarCone::getConeName()
1304 
1306  matrixVariables(NULL),
1307  matrixObjectives(NULL),
1308  matrixConstraints(NULL),
1309  matrixExpressions(NULL)
1310 {
1311 #ifndef NDEBUG
1312  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixProgramming Constructor");
1313 #endif
1314 }//end MatrixProgramming()
1315 
1317 {
1318 #ifndef NDEBUG
1319  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixProgramming Destructor");
1320 #endif
1321  if (matrixVariables != NULL)
1322  delete matrixVariables;
1323  matrixVariables = NULL;
1324  if (matrixObjectives != NULL)
1325  delete matrixObjectives;
1326  matrixObjectives = NULL;
1327  if (matrixConstraints != NULL)
1328  delete matrixConstraints;
1329  matrixConstraints = NULL;
1330  if (matrixExpressions != NULL)
1331  delete matrixExpressions;
1332  matrixExpressions = NULL;
1333 }//end ~MatrixProgramming()
1334 
1335 
1337  numberOfMatrixVar(0),
1338  matrixVar(NULL)
1339 {
1340 #ifndef NDEBUG
1341  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixVariables Constructor");
1342 #endif
1343 }//end MatrixVariables()
1344 
1346 {
1347  std::ostringstream outStr;
1348 
1349 #ifndef NDEBUG
1350  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixVariables Destructor");
1351  outStr.str("");
1352  outStr.clear();
1353  outStr << "NUMBER OF MATRIXVAR = " << numberOfMatrixVar << endl;
1355 #endif
1356 
1357  if (numberOfMatrixVar > 0 && matrixVar != NULL)
1358  {
1359  for(int i = 0; i < numberOfMatrixVar; i++)
1360  {
1361 #ifndef NDEBUG
1362  outStr.str("");
1363  outStr.clear();
1364  outStr << "DESTROYING MATRIXVAR " << i << endl;
1366 #endif
1367  if(matrixVar != NULL)
1368  {
1369  if(matrixVar[i] != NULL)
1370  {
1371  delete matrixVar[i];
1372  matrixVar[i] = NULL;
1373  }
1374  }
1375  }
1376  }
1377  if(matrixVar != NULL)
1378  {
1379  delete [] matrixVar;
1380  matrixVar = NULL;
1381  }
1382 }//end ~MatrixVariables()
1383 
1385  numberOfMatrixObj(0),
1386  matrixObj(NULL)
1387 {
1388 #ifndef NDEBUG
1389  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixObjectives Constructor");
1390 #endif
1391 }//end MatrixObjectives()
1392 
1394 {
1395  std::ostringstream outStr;
1396 
1397 #ifndef NDEBUG
1398  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixObjectives Destructor");
1399  outStr.str("");
1400  outStr.clear();
1401  outStr << "NUMBER OF MATRIXOBJ = " << numberOfMatrixObj << endl;
1403 #endif
1404 
1405  if (numberOfMatrixObj > 0 && matrixObj != NULL)
1406  {
1407  for(int i = 0; i < numberOfMatrixObj; i++)
1408  {
1409 #ifndef NDEBUG
1410  outStr.str("");
1411  outStr.clear();
1412  outStr << "DESTROYING MATRIXOBJ " << i << endl;
1414 #endif
1415  if(matrixObj != NULL)
1416  {
1417  if(matrixObj[i] != NULL)
1418  {
1419  delete matrixObj[i];
1420  matrixObj[i] = NULL;
1421  }
1422  }
1423  }
1424  }
1425  if(matrixObj != NULL)
1426  {
1427  delete [] matrixObj;
1428  matrixObj = NULL;
1429  }
1430 }//end ~MatrixObjectives()
1431 
1433  numberOfMatrixCon(0),
1434  matrixCon(NULL)
1435 {
1436 #ifndef NDEBUG
1437  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixConstraints Constructor");
1438 #endif
1439 }//end MatrixConstraints()
1440 
1442 {
1443  std::ostringstream outStr;
1444 
1445 #ifndef NDEBUG
1446  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixConstraints Destructor");
1447  outStr.str("");
1448  outStr.clear();
1449  outStr << "NUMBER OF MATRIXCON = " << numberOfMatrixCon << endl;
1451 #endif
1452 
1453  if (numberOfMatrixCon > 0 && matrixCon != NULL)
1454  {
1455  for(int i = 0; i < numberOfMatrixCon; i++)
1456  {
1457 #ifndef NDEBUG
1458  outStr.str("");
1459  outStr.clear();
1460  outStr << "DESTROYING MATRIXCON " << i << endl;
1462 #endif
1463  if(matrixCon != NULL)
1464  {
1465  if(matrixCon[i] != NULL)
1466  {
1467  delete matrixCon[i];
1468  matrixCon[i] = NULL;
1469  }
1470  }
1471  }
1472  }
1473  if(matrixCon != NULL)
1474  {
1475  delete [] matrixCon;
1476  matrixCon = NULL;
1477  }
1478 }//end ~MatrixConstraints()
1479 
1481  numberOfExpr(0),
1482  expr(NULL)
1483 {
1484 #ifndef NDEBUG
1485  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixExpressions Constructor");
1486 #endif
1487 }//end MatrixExpressions()
1488 
1490 {
1491  std::ostringstream outStr;
1492 
1493 #ifndef NDEBUG
1494  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixExpressions Destructor");
1495  outStr.str("");
1496  outStr.clear();
1497  outStr << "NUMBER OF EXPR = " << numberOfExpr << endl;
1499 #endif
1500 
1501  if (numberOfExpr > 0 && expr != NULL)
1502  {
1503  for(int i = 0; i < numberOfExpr; i++)
1504  {
1505 #ifndef NDEBUG
1506  outStr.str("");
1507  outStr.clear();
1508  outStr << "DESTROYING EXPR " << i << "(\"row\" " << expr[i]->idx << ")" << endl;
1510 #endif
1511  if(expr != NULL)
1512  {
1513  if(expr[i] != NULL)
1514  {
1515  delete expr[i];
1516  expr[i] = NULL;
1517  }
1518  }
1519  }
1520  }
1521  if(expr != NULL)
1522  {
1523  delete [] expr;
1524  expr = NULL;
1525  }
1526 }//end ~MatrixExpressions()
1527 
1528 
1530  numberOfRows(0),
1531  numberOfColumns(0),
1532  templateMatrixIdx(-1),
1533  varReferenceMatrixIdx(-1),
1534  lbMatrixIdx(-1),
1535  lbConeIdx(-1),
1536  ubMatrixIdx(-1),
1537  ubConeIdx(-1),
1538  name(""),
1539  varType('C')
1540 {
1541 #ifndef NDEBUG
1542  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixVar Constructor");
1543 #endif
1544 }//end MatrixVar()
1545 
1547 {
1548 #ifndef NDEBUG
1549  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixVar Destructor");
1550 #endif
1551 }//end ~MatrixVar()
1552 
1553 
1555  numberOfRows(0),
1556  numberOfColumns(0),
1557  templateMatrixIdx(-1),
1558  objReferenceMatrixIdx(-1),
1559  orderConeIdx(-1),
1560  constantMatrixIdx(-1),
1561  name("")
1562 {
1563 #ifndef NDEBUG
1564  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixObj Constructor");
1565 #endif
1566 }//end MatrixObj()
1567 
1569 {
1570 #ifndef NDEBUG
1571  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixObj Destructor");
1572 #endif
1573 }//end ~MatrixObj()
1574 
1575 
1577  numberOfRows(0),
1578  numberOfColumns(0),
1579  templateMatrixIdx(-1),
1580  conReferenceMatrixIdx(-1),
1581  lbMatrixIdx(-1),
1582  lbConeIdx(-1),
1583  ubMatrixIdx(-1),
1584  ubConeIdx(-1),
1585  name("")
1586 {
1587 #ifndef NDEBUG
1588  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixCon Constructor");
1589 #endif
1590 }//end MatrixCon()
1591 
1593 {
1594 #ifndef NDEBUG
1595  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixCon Destructor");
1596 #endif
1597 }//end ~MatrixCon()
1598 
1600 {
1601 #ifndef NDEBUG
1602  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixExpression Constructor");
1603 #endif
1604  idx = 0;
1606  matrixExpressionTree = NULL;
1607  m_bDeleteExpressionTree = true;
1608 }
1609 
1611 {
1612 #ifndef NDEBUG
1613  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixExpression Destructor");
1614 #endif
1615  if( m_bDeleteExpressionTree == true)
1616  {
1617  delete matrixExpressionTree;
1618  matrixExpressionTree = NULL;
1619  }
1620 }
1621 
1622 
1624  idx(0)
1625 {
1626 #ifndef NDEBUG
1627  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageVar Constructor");
1628 #endif
1629 } // end TimeDomainStageVar
1630 
1631 
1633 {
1634 #ifndef NDEBUG
1635  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageVar Destructor");
1636 #endif
1637 } // end ~TimeDomainStageVar
1638 
1639 
1641  numberOfVariables(0),
1642  startIdx(-1)
1643 {
1644 #ifndef NDEBUG
1645  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageVariables Constructor");
1646 #endif
1647  var = NULL;
1648 } // end TimeDomainStageVariables
1649 
1651 {
1652 #ifndef NDEBUG
1653  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageVariables Destructor");
1654 #endif
1655  if (numberOfVariables > 0 && var != NULL)
1656  {
1657  for (int i = 0; i < numberOfVariables; i++)
1658  {
1659  delete var[i];
1660  var[i] = NULL;
1661  }
1662  }
1663  if (var != NULL)
1664  delete [] var;
1665  var = NULL;
1666 } // end ~TimeDomainStageVariables
1667 
1669  idx(0)
1670 {
1671 #ifndef NDEBUG
1672  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageCon Constructor");
1673 #endif
1674 } // end TimeDomainStageCon
1675 
1676 
1678 {
1679 #ifndef NDEBUG
1680  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageCon Destructor");
1681 #endif
1682 } // end ~TimeDomainStageCon
1683 
1684 
1686  numberOfConstraints(0),
1687  startIdx(-1)
1688 {
1689 #ifndef NDEBUG
1690  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageConstraints Constructor");
1691 #endif
1692  con = NULL;
1693 } // end TimeDomainStageConstraints
1694 
1696 {
1697 #ifndef NDEBUG
1698  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageConstraints Destructor");
1699 #endif
1700  if (numberOfConstraints > 0 && con != NULL)
1701  {
1702  for (int i = 0; i < numberOfConstraints; i++)
1703  {
1704  delete con[i];
1705  con[i] = NULL;
1706  }
1707  }
1708  if (con != NULL)
1709  delete [] con;
1710  con = NULL;
1711 } // end ~TimeDomainStageConstraints
1712 
1714  idx(0)
1715 {
1716 #ifndef NDEBUG
1717  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageObj Constructor");
1718 #endif
1719 } // end TimeDomainStageObj
1720 
1721 
1723 {
1724 #ifndef NDEBUG
1725  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageObj Destructor");
1726 #endif
1727 } // end ~TimeDomainStageObj
1728 
1729 
1731  numberOfObjectives(0),
1732  startIdx(-1)
1733 {
1734 #ifndef NDEBUG
1735  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageObjectives Constructor");
1736 #endif
1737  obj = NULL;
1738 } // end TimeDomainStageObjectives
1739 
1741 {
1742 #ifndef NDEBUG
1743  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageObjectives Destructor");
1744 #endif
1745  if (numberOfObjectives > 0 && obj != NULL)
1746  {
1747  for (int i = 0; i < numberOfObjectives; i++)
1748  {
1749  delete obj[i];
1750  obj[i] = NULL;
1751  }
1752  }
1753  if (obj != NULL)
1754  delete [] obj;
1755  obj = NULL;
1756 } // end ~TimeDomainStageObjectives
1757 
1759  name("")
1760 {
1761 #ifndef NDEBUG
1762  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStage Constructor");
1763 #endif
1764  variables = NULL;
1765  constraints = NULL;
1766  objectives = NULL;
1767 }//end TimeDomainStage()
1768 
1769 
1771 {
1772 #ifndef NDEBUG
1773  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStage Destructor");
1774 #endif
1775  if (variables != NULL)
1776  {
1777  delete variables;
1778  variables = NULL;
1779  }
1780  if (constraints != NULL)
1781  {
1782  delete constraints;
1783  constraints = NULL;
1784  }
1785  if (objectives != NULL)
1786  {
1787  delete objectives;
1788  objectives = NULL;
1789  }
1790 }//end ~TimeDomainStage()
1791 
1792 
1794  numberOfStages(0),
1795  stage(NULL)
1796 {
1797 #ifndef NDEBUG
1798  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStages Constructor");
1799 #endif
1800 }
1801 
1802 
1804 {
1805 #ifndef NDEBUG
1806  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStages Destructor");
1807 #endif
1808  int i;
1809  if(numberOfStages > 0 && stage != NULL)
1810  {
1811  for( i = 0; i < numberOfStages; i++)
1812  {
1813  delete stage[i];
1814  stage[i] = NULL;
1815  }
1816  }
1817  if (stage != NULL)
1818  delete[] stage;
1819  stage = NULL;
1820 }
1821 
1823  start(0.0),
1824  horizon(0.0)
1825 {
1826 #ifndef NDEBUG
1827  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainInterval Constructor");
1828 #endif
1829 }
1830 
1831 
1833 {
1834 #ifndef NDEBUG
1835  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainInterval Constructor");
1836 #endif
1837 }
1838 
1840 {
1841 #ifndef NDEBUG
1842  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomain Constructor");
1843 #endif
1844  stages = NULL;
1845  interval = NULL;
1846 }
1847 
1849 {
1850 #ifndef NDEBUG
1851  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomain Constructor");
1852 #endif
1853  if (stages != NULL)
1854  {
1855  delete stages;
1856  stages = NULL;
1857  }
1858  if (interval != NULL)
1859  {
1860  delete interval;
1861  interval = NULL;
1862  }
1863 }
1864 
1865 
1867  variables(NULL),
1868  objectives(NULL),
1869  constraints(NULL),
1870  linearConstraintCoefficients(NULL),
1871  quadraticCoefficients(NULL),
1872  nonlinearExpressions(NULL),
1873  matrices(NULL),
1874  cones(NULL),
1875  matrixProgramming(NULL),
1876  timeDomain(NULL)
1877 {
1878 #ifndef NDEBUG
1879  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the InstanceData Constructor");
1880 #endif
1881 // variables = new Variables();
1882 // objectives = new Objectives();
1883 // constraints = new Constraints();
1884 // linearConstraintCoefficients = new LinearConstraintCoefficients();
1885 // quadraticCoefficients = new QuadraticCoefficients();
1886 // nonlinearExpressions = new NonlinearExpressions();
1887 // matrices = new Matrices();
1888 // cones = new Cones();
1889 // matrixProgramming = new MatrixProgramming();
1890 // timeDomain = NULL;
1891 }//end of InstanceData constructor
1892 
1894 {
1895 #ifndef NDEBUG
1896  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the InstanceData Destructor");
1897 #endif
1898  if (variables != NULL)
1899  {
1900  delete variables;
1901  variables = NULL;
1902  }
1903 
1904  if (objectives != NULL)
1905  {
1906  delete objectives;
1907  objectives = NULL;
1908  }
1909 
1910  if (constraints != NULL)
1911  {
1912  delete constraints;
1913  constraints = NULL;
1914  }
1915 
1916  if (linearConstraintCoefficients != NULL)
1917  {
1920  }
1921 
1922  if (quadraticCoefficients != NULL)
1923  {
1924  delete quadraticCoefficients;
1925  quadraticCoefficients = NULL;
1926  }
1927 
1928  if (nonlinearExpressions != NULL)
1929  {
1930  delete nonlinearExpressions;
1931  nonlinearExpressions = NULL;
1932  }
1933 
1934  if (matrices != NULL)
1935  {
1936  delete matrices;
1937  matrices = NULL;
1938  }
1939 
1940  if (cones != NULL)
1941  {
1942  delete cones;
1943  cones = NULL;
1944  }
1945 
1946  if (matrixProgramming != NULL)
1947  {
1948  delete matrixProgramming;
1949  matrixProgramming = NULL;
1950  }
1951 
1952  if (timeDomain != NULL)
1953  {
1954  delete timeDomain;
1955  timeDomain = NULL;
1956  }
1957 }//end of InstanceData destructor
1958 
1959 
1964 {
1965  if (m_sInstanceName.length() <= 0)
1966  {
1967  if (instanceHeader == NULL)
1968  throw ErrorClass("instanceHeader object undefined in method getInstanceName()");
1970  }
1971  return m_sInstanceName;
1972 }//getInstanceName
1973 
1975 {
1976  if (m_sInstanceSource.length() <= 0)
1977  {
1978  if (instanceHeader == NULL)
1979  throw ErrorClass("instanceHeader object undefined in method getInstanceSource()");
1981  }
1982  return m_sInstanceSource;
1983 }//getInstanceSource
1984 
1986 {
1987  if (m_sInstanceDescription.length() <= 0)
1988  {
1989  if (instanceHeader == NULL)
1990  throw ErrorClass("instanceHeader object undefined in method getInstanceDescription()");
1992  }
1993  return m_sInstanceDescription;
1994 }//getInstanceDescription
1995 
1997 {
1998  if (m_sInstanceCreator.length() <= 0)
1999  {
2000  if (instanceHeader == NULL)
2001  throw ErrorClass("instanceHeader object undefined in method getInstanceCreator()");
2003  }
2004  return m_sInstanceCreator;
2005 }//getInstanceCreator
2006 
2008 {
2009  if (m_sInstanceLicence.length() <= 0)
2010  {
2011  if (instanceHeader == NULL)
2012  throw ErrorClass("instanceHeader object undefined in method getInstanceLicence()");
2014  }
2015  return m_sInstanceLicence;
2016 }//getInstanceLicence
2017 
2019 {
2020  if (m_iVariableNumber == -1)
2021  {
2022  if (instanceData == NULL)
2023  throw ErrorClass("data object undefined in method getVariableNumber()");
2024  if (instanceData->variables == NULL)
2025  m_iVariableNumber = 0;
2026  else
2028  }
2029  return m_iVariableNumber;
2030 }//getVariableNumber
2031 
2033 {
2034  if(m_bProcessVariables == true && bVariablesModified == false) return true;
2035  //m_bProcessVariables = true;
2036  int i = 0;
2037  int varType;
2038  int n = getVariableNumber();
2039  try
2040  {
2044  if(n > 0)
2045  {
2046  if(m_bProcessVariables != true )
2047  {
2048  m_mcVariableTypes = new char[n];
2049  m_mdVariableLowerBounds = new double[n];
2050  m_mdVariableUpperBounds = new double[n];
2051  m_msVariableNames = new string[n];
2052  m_bProcessVariables = true;
2053  }
2054 
2055  for(i = 0; i < n; i++)
2056  {
2057  if(instanceData->variables->var[i] == NULL) throw ErrorClass("processVariables(): var element was never defined");
2058  varType = returnVarType(instanceData->variables->var[i]->type);
2059  switch (varType)
2060  {
2061  case 0:
2062  {
2063  throw ErrorClass("unknown variable type");
2064  break;
2065  }
2067  {
2068  break;
2069  }
2070  case ENUM_VARTYPE_binary:
2071  {
2073  break;
2074  }
2075  case ENUM_VARTYPE_integer:
2076  {
2078  break;
2079  }
2080  case ENUM_VARTYPE_string:
2081  {
2082 
2084  break;
2085  }
2087  {
2089  break;
2090  }
2092  {
2094  break;
2095  }
2096  default:
2097  {
2098  throw ErrorClass("variable type not yet implemented");
2099  break;
2100  }
2101  }
2105  if(instanceData->variables->var[i]->name.length() > 0)
2107  else
2108  m_msVariableNames[i] = "";
2109  }
2110  }
2111  return true;
2112  } //end try
2113  catch(const ErrorClass& eclass)
2114  {
2115  throw ErrorClass( eclass.errormsg);
2116  }
2117 }//processVariables
2118 
2120 {
2121  processVariables();
2122  return m_msVariableNames;
2123 }//getVariableNames
2124 
2126 {
2127  processVariables();
2128  return m_mcVariableTypes;
2129 }//getVariableTypes
2130 
2132 {
2133  processVariables();
2135 }//getNumberOfBinaryVariables
2136 
2138 {
2139  processVariables();
2141 }//getNumberOfIntegerVariables
2142 
2144 {
2145  processVariables();
2147 }//getNumberOfSemiContinuousVariables
2148 
2150 {
2151  processVariables();
2153 }//getNumberOfSemiIntegerVariables
2154 
2156 {
2157  processVariables();
2159 }//getNumberOfStringVariables
2160 
2162 {
2163  processVariables();
2164  return m_mdVariableLowerBounds;
2165 }//getVariableLowerBounds
2166 
2168 {
2169  processVariables();
2170  return m_mdVariableUpperBounds;
2171 }//getVariableUpperBounds
2172 
2173 
2175 {
2176  if (m_iObjectiveNumber == -1)
2177  {
2178  if (instanceData == NULL)
2179  throw ErrorClass("data object undefined in method getVariableNumber()");
2180  if (instanceData->objectives == NULL)
2181  m_iObjectiveNumber = 0;
2182  else
2184  }
2185  return m_iObjectiveNumber;
2186 
2187 }//getObjectiveNumber
2188 
2190 {
2191  if(m_bProcessObjectives == true && bObjectivesModified == false) return true;
2192  //m_bProcessObjectives = true;
2193  int i = 0;
2194  int j = 0;
2195  int n = getObjectiveNumber();
2196  if (n == 0 || instanceData->objectives->obj == NULL) return true;
2197  try
2198  {
2199  if (n > 0)
2200  {
2201  if(m_bProcessObjectives != true)
2202  {
2203  m_msMaxOrMins = new string[n];
2204  m_miNumberOfObjCoef = new int[n];
2205  m_mdObjectiveConstants = new double[n];
2206  m_mdObjectiveWeights = new double[n];
2208  m_msObjectiveNames = new string[n];
2209  for(i = 0; i < n; i++)
2210  {
2211  if(instanceData->objectives->obj[i] == NULL) throw ErrorClass("processObjectives(): obj element was never defined");
2213  //m_mObjectiveCoefficients[i]->bDeleteArrays=false;
2214  }
2215  m_bProcessObjectives = true;
2216  }
2217 
2218  for(i = 0; i < n; i++)
2219  {
2220  if(instanceData->objectives->obj[i] == NULL) throw ErrorClass("processObjectives(): obj element was never defined");
2221  if((instanceData->objectives->obj[i]->maxOrMin.compare("max") != 0) && (instanceData->objectives->obj[i]->maxOrMin.compare("min") != 0 )) throw ErrorClass("wrong objective maxOrMin");
2226  if(instanceData->objectives->obj[i]->coef == NULL && m_miNumberOfObjCoef[i] != 0)
2227  {
2228  throw ErrorClass("objective coefficient number inconsistent with objective coefficient array");
2229  }
2230  if(instanceData->objectives->obj[i]->coef != NULL)
2231  {
2232  for(j = 0; j < m_mObjectiveCoefficients[i]->number; j++)
2233  {
2236  }
2237  }
2238  if(instanceData->objectives->obj[i]->name.length() > 0)
2240  else
2241  m_msObjectiveNames[i] = "";
2242  }
2243  }
2244  return true;
2245  } //end try
2246  catch(const ErrorClass& eclass)
2247  {
2248  throw ErrorClass( eclass.errormsg);
2249  }
2250 }//processObjectives
2251 
2253 {
2255  return m_msObjectiveNames;
2256 }//getObjectiveNames
2257 
2259 {
2261  return m_msMaxOrMins;
2262 }//getObjectiveMaxOrMins
2263 
2265 {
2267  return m_miNumberOfObjCoef;
2268 }//getObjectiveCoefficientNumbers
2269 
2271 {
2273  return m_mdObjectiveConstants;
2274 }//getObjectiveConstants
2275 
2277 {
2279  return m_mdObjectiveWeights;
2280 
2281 }//getObjectiveWeights
2282 
2284 {
2286  return m_mObjectiveCoefficients;
2287 }//getObjectiveCoefficients
2288 
2289 
2291 {
2293  int i, j, numobjcoef;
2294  SparseVector *sparsevec;
2295  int m = getObjectiveNumber();
2296  int n = getVariableNumber();
2297  if (m == 0 || instanceData->objectives->obj == NULL) return NULL;
2298  if (m_bGetDenseObjectives != true)
2299  {
2300  m_mmdDenseObjectiveCoefficients = new double*[m];
2301  for(i = 0; i < m; i++)
2302  {
2303  m_mmdDenseObjectiveCoefficients[ i] = new double[n];
2304  }
2305  m_bGetDenseObjectives = true;
2306  }
2307 
2308  for(i = 0; i < m; i++)
2309  {
2310  sparsevec = this->getObjectiveCoefficients()[i];
2311  for(j = 0; j < n; j++)
2312  {
2314  }
2315  sparsevec = this->getObjectiveCoefficients()[i];
2316  numobjcoef = sparsevec->number;
2317  for(j = 0; j < numobjcoef; j++)
2318  {
2319  m_mmdDenseObjectiveCoefficients[i][ sparsevec->indexes[ j]]
2320  += sparsevec->values[ j];
2321  }
2322  }
2324 }//getDenseObjectiveCoefficients
2325 
2326 
2328 {
2329  if (m_iConstraintNumber == -1)
2330  {
2331  if (instanceData == NULL)
2332  throw ErrorClass("data object undefined in method getConstraintNumber()");
2333  if (instanceData->constraints == NULL)
2334  m_iConstraintNumber = 0;
2335  else
2337  }
2338  return m_iConstraintNumber;
2339 }//getConstraintNumber
2340 
2342 {
2343  if(m_bProcessConstraints == true && bConstraintsModified == false) return true;
2344  //m_bProcessConstraints = true;
2345  int i = 0;
2346  ostringstream outStr;
2347  int n = getConstraintNumber();
2348  if (n == 0 || instanceData->constraints->con == NULL) return true;
2349  try
2350  {
2351  if(n > 0)
2352  {
2353  if(m_bProcessConstraints != true)
2354  {
2355  m_mdConstraintLowerBounds = new double[n];
2356  m_mdConstraintUpperBounds = new double[n];
2357  m_mdConstraintConstants = new double[n];
2358  m_mcConstraintTypes = new char[n];
2359  m_msConstraintNames = new string[n];
2360  m_bProcessConstraints = true;
2361  }
2362  for(i = 0; i < n; i++)
2363  {
2364  if(instanceData->constraints->con[i] == NULL) throw ErrorClass("processConstraints(): con element was never defined");
2369  {
2370  outStr << "Constraint " ;
2371  outStr << i;
2372  outStr << " is infeasible";
2373  throw ErrorClass( outStr.str() );
2374  }
2376  {
2377  outStr << "Constraint " ;
2378  outStr << i;
2379  outStr << " is infeasible";
2380  throw ErrorClass( outStr.str());
2381  }
2383  m_mcConstraintTypes[i] = 'U';
2385  m_mcConstraintTypes[i] = 'E';
2386  else if(m_mdConstraintLowerBounds[i] == -OSDBL_MAX)
2387  m_mcConstraintTypes[i] = 'L';
2388  else if(m_mdConstraintUpperBounds[i] == OSDBL_MAX)
2389  m_mcConstraintTypes[i] = 'G';
2390  else m_mcConstraintTypes[i] = 'R';
2391  if(instanceData->constraints->con[i]->name.length() > 0)
2393  else
2394  m_msConstraintNames[i] = "";
2395  }
2396  }
2397  return true;
2398  }
2399  catch(const ErrorClass& eclass)
2400  {
2401  throw ErrorClass( eclass.errormsg);
2402  }
2403 }//processConstraints
2404 
2405 
2407 {
2409  return m_msConstraintNames;
2410 }//getConstraintNames
2411 
2412 
2414 {
2416  return m_mcConstraintTypes;
2417 }//getConstraintTypes
2418 
2420 {
2423 }//getConstraintLowerBounds
2424 
2426 {
2429 }//getConstraintUpperBounds
2430 
2432 {
2434  return m_mdConstraintConstants;
2435 }//getConstraintConstants
2436 
2437 
2439 {
2440  if(this->getVariableNumber() <= 0 || this->getConstraintNumber() <= 0) return 0;
2442  {
2443  if (instanceData == NULL)
2444  throw ErrorClass("data object undefined in method getLinearConstraintCoefficientNumber()");
2447  else
2450  }
2452 }//getLinearConstraintCoefficientNumber
2453 
2455 {
2456  if(m_bProcessLinearConstraintCoefficients == true && bAMatrixModified == false) return true;
2457  //m_bProcessLinearConstraintCoefficients = true;
2458  try
2459  {
2461  if((instanceData->linearConstraintCoefficients == NULL ) || (n == 0) ) return true;
2462  //value array
2463  if((instanceData->linearConstraintCoefficients->value == NULL ) || (n == 0) ) return true;
2464  //index array
2467  throw ErrorClass("ambiguous linear constraint coefficient major");
2468  else if(instanceData->linearConstraintCoefficients->value->el == NULL) return true;
2469  else
2470  {
2472  {
2473  m_bColumnMajor = true;
2475  {
2479  }
2483  }
2484  else
2485  {
2486  m_bColumnMajor = false;
2488  {
2492  }
2496  }
2497  }
2498  if(m_bColumnMajor == true)
2499  {
2503  }
2504  else
2505  {
2509  }
2510  return true;
2511  }
2512  catch(const ErrorClass& eclass)
2513  {
2514  throw ErrorClass( eclass.errormsg);
2515  }
2516 }//processLinearConstraintCoefficients
2517 
2519 {
2521  return m_bColumnMajor;
2522 }//getLinearConstraintCoefficientMajor
2523 
2525 {
2527  if(getVariableNumber() == 0) return NULL;
2529  if(!m_bColumnMajor)
2530  {
2531  if(m_linearConstraintCoefficientsInRowMajor == NULL) return NULL;
2539  getVariableNumber());
2540  }
2542 }//getLinearConstraintCoefficientsInColumnMajor
2543 
2545 {
2548  if(m_bColumnMajor)
2549  {
2550  if(m_linearConstraintCoefficientsInColumnMajor == NULL) return NULL;
2552 
2560  }
2562 }//getLinearConstraintCoefficientsInRowMajor
2563 
2564 
2566 {
2567  if(m_iQuadraticTermNumber == -1)
2568  {
2569  if (instanceData == NULL)
2570  throw ErrorClass("data object undefined in method getNumberOfQuadraticTerms()");
2571  if (instanceData->quadraticCoefficients == NULL)
2573  else
2575  }
2576  return m_iQuadraticTermNumber;
2577 }//getNumberOfQuadraticTerms
2578 
2580 {
2582  m_bProcessQuadraticTerms = true;
2583  int n = getNumberOfQuadraticTerms();
2584  if(instanceData->quadraticCoefficients->qTerm == NULL) return NULL;
2585  try
2586  {
2587  int i = 0;
2589  if(!quadraticCoefs->qTerm && n != 0)
2590  throw ErrorClass("quadratic term number inconsistent with quadratic term array");
2592  if(n > 0)
2593  {
2594  m_quadraticTerms->rowIndexes = new int[n];
2595  m_quadraticTerms->varOneIndexes = new int[n];
2596  m_quadraticTerms->varTwoIndexes = new int[n];
2597  m_quadraticTerms->coefficients = new double[n];
2598  }
2599  for(i = 0; i < n; i++)
2600  {
2601  m_quadraticTerms->rowIndexes[i] = quadraticCoefs->qTerm[i]->idx;
2602  m_quadraticTerms->varOneIndexes[i] = quadraticCoefs->qTerm[i]->idxOne;
2603  m_quadraticTerms->varTwoIndexes[i] = quadraticCoefs->qTerm[i]->idxTwo;
2604  m_quadraticTerms->coefficients[i] = quadraticCoefs->qTerm[i]->coef;
2605  }
2606  return m_quadraticTerms;
2607  }
2608  catch(const ErrorClass& eclass)
2609  {
2610  throw ErrorClass( eclass.errormsg);
2611  }
2612 }//getQuadraticTerms
2613 
2615 {
2618 }//getNumberOfQuadraticRowIndexes
2619 
2621 {
2624  int n = getNumberOfQuadraticTerms();
2625  if(n <= 0) return NULL;
2626  QuadraticTerms *qTerms = NULL;
2627  qTerms = getQuadraticTerms();
2628  std::map<int, int> foundIdx;
2629  std::map<int, int>::iterator pos;
2630  int i;
2631  try
2632  {
2633  for(i = 0; i < n; i++)
2634  {
2635  // add the terms
2636  foundIdx[ qTerms->rowIndexes[ i] ];
2637  }
2638  // now put the term into an array
2639  m_iNumberOfQuadraticRowIndexes = foundIdx.size();
2641  i = 0;
2642  for(pos = foundIdx.begin(); pos != foundIdx.end(); ++pos)
2643  {
2644  m_miQuadRowIndexes[ i++] = pos->first;
2645  }
2646  foundIdx.clear();
2647  return m_miQuadRowIndexes;
2648  }
2649  catch(const ErrorClass& eclass)
2650  {
2651  throw ErrorClass( eclass.errormsg);
2652  }
2653 }//getQuadraticRowIndexes
2654 
2655 
2657 {
2659  {
2660  if (instanceData == NULL)
2661  throw ErrorClass("data object undefined in method getNumberOfNonlinearExpressions()");
2662  if (instanceData->nonlinearExpressions == NULL)
2664  else
2666  }
2668 }//getNumberOfNonlinearExpressions
2669 
2671 {
2672  Nl** root = new Nl*[getNumberOfNonlinearExpressions()];
2673  for (int i=0; i < getNumberOfNonlinearExpressions(); i++)
2674  {
2675  root[i] = instanceData->nonlinearExpressions->nl[i];
2676  }
2677  return root;
2678 }//getNonlinearExpressions
2679 
2680 
2682 {
2685 }//getNumberOfNonlinearExpressionTreeIndexes
2686 
2688 {
2691  std::map<int, ScalarExpressionTree*> expTrees;
2692  expTrees = getAllNonlinearExpressionTrees();
2693 
2694  std::map<int, ScalarExpressionTree*>::iterator pos;
2695  try
2696  {
2697  // now put the term into an array
2700  int i = 0;
2701  for(pos = expTrees.begin(); pos != expTrees.end(); ++pos)
2702  {
2703  m_miNonlinearExpressionTreeIndexes[ i++] = pos->first;
2704  }
2705  expTrees.clear();
2707  }
2708  catch(const ErrorClass& eclass)
2709  {
2710  throw ErrorClass( eclass.errormsg);
2711  }
2712 }//getNonlinearExpressionTreeIndexes
2713 
2715 {
2718 }//getNumberOfNonlinearExpressionTreeModIndexes
2719 
2721 {
2724  std::map<int, ScalarExpressionTree*> expTrees;
2725  expTrees = getAllNonlinearExpressionTreesMod();
2726  std::map<int, ScalarExpressionTree*>::iterator pos;
2727  try
2728  {
2729  // now put the term into an array
2732  int i = 0;
2733  for(pos = expTrees.begin(); pos != expTrees.end(); ++pos)
2734  {
2735  m_miNonlinearExpressionTreeModIndexes[ i++] = pos->first;
2736  }
2737  expTrees.clear();
2739  }
2740  catch(const ErrorClass& eclass)
2741  {
2742  throw ErrorClass( eclass.errormsg);
2743  }
2744 }//getNonlinearExpressionTreeModIndexes
2745 
2747 {
2748  if( m_bProcessExpressionTrees == false )
2751 }//getNumberOfNonlinearConstraints
2752 
2754 {
2755  if( m_bProcessExpressionTrees == false )
2757 
2759 }//getNumberOfNonlinearObjectivess
2760 
2762 {
2763  // check to make sure rowIdx has a nonlinear term and is in the map
2764  if( m_bProcessExpressionTrees == false )
2765  {
2767  }
2768  if( m_mapExpressionTrees.find( rowIdx) != m_mapExpressionTrees.end())
2769  return m_mapExpressionTrees[ rowIdx];
2770  else return NULL ;
2771 }// getNonlinearExpressionTree for a specific index
2772 
2774 {
2775  // check to make sure rowIdx has a nonlinear term and is in the map
2776  if( m_bProcessExpressionTreesMod == false )
2777  {
2779  }
2780  if( m_mapExpressionTreesMod.find( rowIdx) != m_mapExpressionTreesMod.end())
2781  return m_mapExpressionTreesMod[ rowIdx];
2782  else return NULL ;
2783 }// getNonlinearExpressionTreeMod for a specific index
2784 
2785 std::vector<ExprNode*> OSInstance::getNonlinearExpressionTreeInPostfix( int rowIdx)
2786 {
2787  //if( m_binitForAlgDiff == false) this->initForAlgDiff();
2789  std::vector<ExprNode*> postfixVec;
2790  try
2791  {
2792  if( m_mapExpressionTrees.find( rowIdx) != m_mapExpressionTrees.end())
2793  {
2795  postfixVec = expTree->m_treeRoot->getPostfixFromExpressionTree();
2796  }
2797  else
2798  {
2799  throw ErrorClass("Error in getNonlinearExpressionTreeInPostfix, rowIdx not valid");
2800  }
2801  return postfixVec;
2802  }
2803  catch(const ErrorClass& eclass)
2804  {
2805  throw ErrorClass( eclass.errormsg);
2806  }
2807 }//getNonlinearExpressionTreeInPostfix
2808 
2810 {
2811  if( m_binitForAlgDiff == false) this->initForAlgDiff();
2812 
2814  std::string resultString;
2815  resultString = "";
2816  unsigned int i;
2817  unsigned int j;
2818  unsigned int n;
2819  ostringstream outStr;
2820  std::vector<ExprNode*> postfixVec;
2821 
2822  int rowIdx = rowIdx_;
2823  ExprNode *nlnode = NULL;
2824  OSnLNodeNumber *nlnodeNum = NULL;
2825  OSnLNodeVariable *nlnodeVar = NULL;
2826  OSnLNodeSum *nlnodeSum = NULL;
2827  OSnLNodeProduct *nlnodeProduct = NULL;
2828  OSnLNodeMin *nlnodeMin = NULL;
2829  OSnLNodeMax *nlnodeMax = NULL;
2830  std::string tmp1 = "";
2831  std::string tmp2 = "";
2832  std::string tmp3 = "";
2833  std::stack<ExprNode*> opStack;
2834  std::stack<std::string> tmpStack;
2835  std::stack<std::string> sumStack;
2836  std::stack<std::string> productStack;
2837  std::stack<std::string> minStack;
2838  std::stack<std::string> maxStack;
2839 
2840  try
2841  {
2842  if( m_mapExpressionTrees.find( rowIdx) != m_mapExpressionTrees.end())
2843  {
2844  // get the nodes and separate into operators and operands,
2845  // for now only the number and variable nodes are operator nodes
2846 
2847  ScalarExpressionTree* exptree = this->getNonlinearExpressionTree( rowIdx);
2848  if(exptree != NULL)
2849  {
2850  postfixVec = this->getNonlinearExpressionTreeInPostfix( rowIdx);
2851  n = postfixVec.size();
2852  //put vector in reverse order
2853  for (i = 0 ; i < n; i++)
2854  {
2855  nlnode = postfixVec[ n - 1 - i];
2856  opStack.push( nlnode);
2857  }
2858 
2859  n = opStack.size();
2860  for(i = 0; i < n; i++)
2861  {
2862  nlnode = opStack.top();
2863  switch (nlnode->inodeInt)
2864  {
2865  case OS_NUMBER:
2866  nlnodeNum = (OSnLNodeNumber*)nlnode;
2867  tmpStack.push( os_dtoa_format(nlnodeNum->value) );
2868  break;
2869 
2870  case OS_PI:
2871  tmpStack.push( "PI" );
2872  break;
2873 
2874  case OS_E:
2875  tmpStack.push( "E" );
2876  break;
2877 
2878  case OS_VARIABLE:
2879  outStr.str("");
2880  // handle a variable
2881  nlnodeVar = (OSnLNodeVariable*)nlnode;
2882  // see if the coefficient is specified
2883  if( (nlnodeVar->coef > 1.0) || (nlnodeVar->coef < 1.0) )
2884  {
2885  outStr << "(";
2886  outStr << os_dtoa_format(nlnodeVar->coef);
2887  outStr << "*x_";
2888  outStr << nlnodeVar->idx;
2889  outStr << ")";
2890  tmpStack.push(outStr.str() );
2891  }
2892  else
2893  {
2894  outStr << "x_";
2895  outStr << nlnodeVar->idx;
2896  tmpStack.push(outStr.str() );
2897  }
2898  break;
2899 
2900  case OS_PLUS :
2901  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing plus operator");
2902  tmp1 = tmpStack.top();
2903  tmpStack.pop();
2904  tmp2 = tmpStack.top();
2905  tmpStack.pop();
2906  tmpStack.push("(" + tmp2 + " + " + tmp1 + ")");
2907  break;
2908 
2909  case OS_SUM :
2910  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing sum operator");
2911  //std::cout << "INSIDE SUM NODE " << std::endl;
2912  nlnodeSum = (OSnLNodeSum*)nlnode;
2913  outStr.str("");
2914  for(j = 0; j < nlnodeSum->inumberOfChildren; j++)
2915  {
2916  sumStack.push( tmpStack.top() );
2917  tmpStack.pop();
2918  }
2919  outStr << "(";
2920  for(j = 0; j < nlnodeSum->inumberOfChildren; j++)
2921  {
2922  outStr << sumStack.top();
2923  if (j < nlnodeSum->inumberOfChildren - 1) outStr << " + ";
2924  sumStack.pop();
2925  }
2926  outStr << ")";
2927  tmpStack.push( outStr.str() );
2928  //std::cout << outStr.str() << std::endl;
2929  break;
2930 
2931  case OS_MINUS :
2932  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing minus operator");
2933  tmp1 = tmpStack.top();
2934  tmpStack.pop();
2935  tmp2 = tmpStack.top();
2936  tmpStack.pop();
2937  tmpStack.push("(" + tmp2 + " - " + tmp1 + ")");
2938  break;
2939 
2940  case OS_NEGATE :
2941  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- -- Problem writing negate operator");
2942  tmp1 = tmpStack.top();
2943  tmpStack.pop();
2944  tmpStack.push( "-"+ tmp1 );
2945 
2946 
2947  break;
2948 
2949  case OS_TIMES :
2950  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing times operator");
2951  tmp1 = tmpStack.top();
2952  tmpStack.pop();
2953  tmp2 = tmpStack.top();
2954  tmpStack.pop();
2955  tmpStack.push("(" + tmp2 + "*" + tmp1 + ")");
2956  break;
2957 
2958  case OS_DIVIDE :
2959  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing divide operator");
2960  tmp1 = tmpStack.top();
2961  tmpStack.pop();
2962  tmp2 = tmpStack.top();
2963  tmpStack.pop();
2964  tmpStack.push("(" + tmp2 + " / " + tmp1 + ")");
2965  break;
2966 
2967  case OS_POWER :
2968  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing power operator");
2969  tmp1 = tmpStack.top();
2970  tmpStack.pop();
2971  tmp2 = tmpStack.top();
2972  tmpStack.pop();
2973  tmpStack.push("(" + tmp2 + " ^ " + tmp1 + ")");
2974  break;
2975 
2976 
2977  case OS_ABS :
2978  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing abs operator");
2979  tmp1 = tmpStack.top();
2980  tmpStack.pop();
2981  tmpStack.push( "abs( "+ tmp1 + ")");
2982  break;
2983 
2984  case OS_ERF :
2985  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing erf operator");
2986  tmp1 = tmpStack.top();
2987  tmpStack.pop();
2988  tmpStack.push( "erf( "+ tmp1 + ")");
2989  break;
2990 
2991 
2992  case OS_SQUARE :
2993  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing square operator ");
2994  tmp1 = tmpStack.top();
2995  tmpStack.pop();
2996  tmpStack.push( "("+ tmp1 + ")^2");
2997  break;
2998 
2999  case OS_LN :
3000  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing ln operator");
3001  tmp1 = tmpStack.top();
3002  tmpStack.pop();
3003  tmpStack.push( "ln( "+ tmp1 + ")");
3004  break;
3005 
3006  case OS_EXP :
3007  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing exp operator");
3008  tmp1 = tmpStack.top();
3009  tmpStack.pop();
3010  tmpStack.push( "exp( "+ tmp1 + ")");
3011  break;
3012 
3013  case OS_SIN :
3014  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing sin operator");
3015  tmp1 = tmpStack.top();
3016  tmpStack.pop();
3017  tmpStack.push( "sin( "+ tmp1 + ")");
3018  break;
3019 
3020  case OS_COS :
3021  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing cos operator ");
3022  tmp1 = tmpStack.top();
3023  tmpStack.pop();
3024  tmpStack.push( "cos( "+ tmp1 + ")");
3025  break;
3026 
3027  case OS_SQRT :
3028  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing sqrt operator ");
3029  tmp1 = tmpStack.top();
3030  tmpStack.pop();
3031  tmpStack.push( "sqrt( "+ tmp1 + ")");
3032  break;
3033 
3034  case OS_MIN :
3035  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing min operator");
3036  //std::cout << "INSIDE Min NODE " << std::endl;
3037  nlnodeMin = (OSnLNodeMin*)nlnode;
3038  outStr.str("");
3039  for(j = 0; j < nlnodeMin->inumberOfChildren; j++)
3040  {
3041  minStack.push( tmpStack.top() );
3042  tmpStack.pop();
3043  }
3044  outStr << "min(";
3045  for(j = 0; j < nlnodeMin->inumberOfChildren; j++)
3046  {
3047  outStr << minStack.top();
3048  if (j < nlnodeMin->inumberOfChildren - 1) outStr << " , ";
3049  minStack.pop();
3050  }
3051  outStr << ")";
3052  tmpStack.push( outStr.str() );
3053  break;
3054 
3055 
3056  case OS_MAX :
3057  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing max operator");
3058  //std::cout << "INSIDE Max NODE " << std::endl;
3059  nlnodeMax = (OSnLNodeMax*)nlnode;
3060  outStr.str("");
3061  for(j = 0; j < nlnodeMax->inumberOfChildren; j++)
3062  {
3063  maxStack.push( tmpStack.top() );
3064  tmpStack.pop();
3065  }
3066  outStr << "max(";
3067  for(j = 0; j < nlnodeMax->inumberOfChildren; j++)
3068  {
3069  outStr << maxStack.top();
3070  if (j < nlnodeMax->inumberOfChildren - 1) outStr << " , ";
3071  maxStack.pop();
3072  }
3073  outStr << ")";
3074  tmpStack.push( outStr.str() );
3075  break;
3076 
3077  case OS_IF :
3078 
3079  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing if operator ");
3080  if(nlnode->inumberOfChildren != 3)throw ErrorClass("The if node must have three children");
3081  tmp1 = tmpStack.top();
3082  tmpStack.pop();
3083  tmp2 = tmpStack.top();
3084  tmpStack.pop();
3085  tmp3 = tmpStack.top();
3086  tmpStack.pop();
3087  tmpStack.push( "if(" + tmp3 + "," + tmp2 + "," + tmp1 +")" );
3088  break;
3089 
3090 
3091  case OS_PRODUCT :
3092  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing product operator");
3093  //std::cout << "INSIDE Product NODE " << std::endl;
3094  nlnodeProduct = (OSnLNodeProduct*)nlnode;
3095  outStr.str("");
3096  for(j = 0; j < nlnodeProduct->inumberOfChildren; j++)
3097  {
3098  productStack.push( tmpStack.top() );
3099  tmpStack.pop();
3100  }
3101  outStr << "(";
3102  for(j = 0; j < nlnodeProduct->inumberOfChildren; j++)
3103  {
3104  outStr << productStack.top();
3105  if (j < nlnodeProduct->inumberOfChildren - 1) outStr << " * ";
3106  productStack.pop();
3107  }
3108  outStr << ")";
3109  tmpStack.push( outStr.str() );
3110  //std::cout << outStr.str() << std::endl;
3111  break;
3112 
3113  default:
3114  throw ErrorClass("operator " + nlnode->getTokenName() + " not supported");
3115  break;
3116  }
3117  opStack.pop();
3118  }
3119  postfixVec.clear();
3120  if(tmpStack.size() != 1) throw ErrorClass( "There is an error in the OSExpression Tree -- stack size should be 1 at end");
3121  resultString = tmpStack.top();
3122  //std::cout << resultString << std::endl;
3123  tmpStack.pop();
3124 
3125  return resultString;
3126  }
3127  else
3128  {
3129  //throw ErrorClass("Error in getNonlinearExpressionTreeInInfix, there is no expression tree for this index");
3130  return "";
3131  }
3132  }
3133  else
3134  {
3135  throw ErrorClass("Error in getNonlinearExpressionTreeInInfix, rowIdx not valid");
3136  }
3137  return resultString;
3138  }
3139  catch(const ErrorClass& eclass)
3140  {
3141  throw ErrorClass( eclass.errormsg);
3142  }
3143 }//getNonlinearExpressionTreeInInfix
3144 
3145 
3146 std::vector<ExprNode*> OSInstance::getNonlinearExpressionTreeModInPostfix( int rowIdx)
3147 {
3148  //if( m_binitForAlgDiff == false) this->initForAlgDiff();
3150  std::vector<ExprNode*> postfixVec;
3151  try
3152  {
3153  if( m_mapExpressionTreesMod.find( rowIdx) != m_mapExpressionTreesMod.end())
3154  {
3156  postfixVec = expTree->m_treeRoot->getPostfixFromExpressionTree();
3157 
3158  }
3159  else
3160  {
3161  throw ErrorClass("Error in getNonlinearExpressionTreeModInPostfix, rowIdx not valid");
3162  }
3163  return postfixVec;
3164  }
3165  catch(const ErrorClass& eclass)
3166  {
3167  throw ErrorClass( eclass.errormsg);
3168  }
3169 }//getNonlinearExpressionTreeModInPostfix
3170 
3171 
3172 std::vector<ExprNode*> OSInstance::getNonlinearExpressionTreeInPrefix( int rowIdx)
3173 {
3174  //if( m_binitForAlgDiff == false) this->initForAlgDiff();
3176  std::vector<ExprNode*> prefixVec;
3177  try
3178  {
3179  if( m_mapExpressionTrees.find( rowIdx) != m_mapExpressionTrees.end())
3180  {
3182  prefixVec = expTree->m_treeRoot->getPrefixFromExpressionTree();
3183  }
3184  else
3185  {
3186  throw ErrorClass("Error in getNonlinearExpressionTreeInPrefix, rowIdx not valid");
3187  }
3188  return prefixVec;
3189  }
3190  catch(const ErrorClass& eclass)
3191  {
3192  throw ErrorClass( eclass.errormsg);
3193  }
3194 }//getNonlinearExpressionTreeInPrefix
3195 
3196 std::vector<ExprNode*> OSInstance::getNonlinearExpressionTreeModInPrefix( int rowIdx)
3197 {
3198 
3199  //if( m_binitForAlgDiff == false) this->initForAlgDiff();
3201  std::vector<ExprNode*> prefixVec;
3202  try
3203  {
3204  if( m_mapExpressionTreesMod.find( rowIdx) != m_mapExpressionTreesMod.end())
3205  {
3207  prefixVec = expTree->m_treeRoot->getPrefixFromExpressionTree();
3208  }
3209  else
3210  {
3211  throw ErrorClass("Error in getNonlinearExpressionTreeInPrefix, rowIdx not valid");
3212  }
3213  return prefixVec;
3214  }
3215  catch(const ErrorClass& eclass)
3216  {
3217  throw ErrorClass( eclass.errormsg);
3218  }
3219 }//getNonlinearExpressionTreeInPrefix
3220 
3221 std::map<int, ScalarExpressionTree*> OSInstance::getAllNonlinearExpressionTrees()
3222 {
3223  //if( m_binitForAlgDiff == false) this->initForAlgDiff();
3225  std::map<int, int> foundIdx;
3226  std::map<int, int>::iterator pos;
3227  OSnLNodePlus *nlNodePlus;
3228  ScalarExpressionTree *expTree;
3231  int i;
3232  // important -- tell the nl nodes not to destroy the OSExpression Objects
3233  if (instanceData->nonlinearExpressions != NULL)
3234  {
3237  {
3239  {
3241  }
3242  }
3243  int index;
3244  // kipp -- what should we return if instanceData->nonlinearExpressions->numberOfNonlinearExpressions is zero
3246  {
3247  index = instanceData->nonlinearExpressions->nl[ i]->idx;
3248  if(foundIdx.find( index) != foundIdx.end() )
3249  {
3250  nlNodePlus = new OSnLNodePlus();
3251  //expTree = new OSExpressionTree();
3253  // set left child to old index and right child to new one
3254  nlNodePlus->m_mChildren[ 0] = m_mapExpressionTrees[ index]->m_treeRoot;
3256  // we must delete the Expression tree corresponding to the old index value but not the nl nodes
3257  instanceData->nonlinearExpressions->nl[ foundIdx[ index] ]->m_bDeleteExpressionTree = true;
3258  instanceData->nonlinearExpressions->nl[ foundIdx[ index] ]->osExpressionTree->bDestroyNlNodes = false;
3259  //point to the new expression tree
3260  m_mapExpressionTrees[ index] = expTree;
3261  m_mapExpressionTrees[ index]->m_treeRoot = nlNodePlus;
3262  foundIdx[ index] = i;
3263  }
3264  else
3265  {
3266  // we have a new index
3269  foundIdx[ index] = i;
3270  }
3271  //foundIdx[ index]++;
3272  }
3273  }
3274  // count the number of constraints and objective functions with nonlinear terms.
3275  for(pos = foundIdx.begin(); pos != foundIdx.end(); ++pos)
3276  {
3277  if(pos->first < 0)
3278  {
3280  }
3281  else
3282  {
3284  }
3285  }
3287  return m_mapExpressionTrees;
3288 }// getAllNonlinearExpressionTrees
3289 
3290 std::map<int, ScalarExpressionTree*> OSInstance::getAllNonlinearExpressionTreesMod()
3291 {
3294  // make sure we have the modified map available
3296  return m_mapExpressionTreesMod;
3297 }// getAllNonlinearExpressionTreesMod
3298 
3299 
3300 
3302 {
3303  if(m_iMatrixNumber == -1)
3304  {
3305  if (instanceData == NULL)
3306  throw ErrorClass("data object undefined in method getMatrixNumber()");
3307  if (instanceData->matrices == NULL)
3308  m_iMatrixNumber = 0;
3309  else
3311  }
3312  return m_iMatrixNumber;
3313 }//getMatrixNumber
3314 
3316 {
3317  if (m_bProcessMatrices == true) return true;
3318  //m_bProcessMatrices = true;
3319  int n = getMatrixNumber();
3320  if((instanceData->matrices == NULL ) || (n == 0) ) return true;
3321 
3322  try
3323  {
3324 // bool haveElements;
3325 // bool haveBlocks;
3326 // bool haveTransformation;
3327 // bool rowMajor;
3328 
3329  if (n > 0)
3330  {
3331  if(m_bProcessMatrices != true)
3332  {
3333  //allocate space
3336  m_miMatrixNumberOfColumns = new int[n];
3337  m_miMatrixNumberOfRows = new int[n];
3338  m_msMatrixNames = new std::string[n];
3339  m_mMatrix = new OSMatrix*[n];
3340 // m_mExpandedMatricesInColumnMajor = new GeneralSparseMatrix*[n];
3341 // m_mExpandedMatricesInRowMajor = new GeneralSparseMatrix*[n];
3342 // m_mMatrixBlocksInColumnMajor = new ExpandedMatrixBlocks*[n];
3343 // m_mMatrixTransformation = new OSnLMNode*[n];
3344  m_bProcessMatrices = true;
3345  }
3346 
3347  //process each matrix
3348  for (int i=0; i < n; i++)
3349  {
3350  int nCh = ((OSMatrix*)instanceData->matrices->matrix[i])->inumberOfChildren;
3351 
3352  for (int j=0; j < nCh; j++)
3353  {
3361 
3362 #if 0
3363 /*
3364 Find the most suitable representation of the matrix.
3365 a matrix is essentially a sequence of constructors. The shape of each matrix depends on the shape of the constructors.
3366 If all constructors are elements, matrix form is elements
3367  if first constructor is column-wise, matrix is column-wise, else row-wise
3368  if any constructor is given as symmetric, check if other constructors are symmetric as well
3369  if all constructors are symmetric, matrix is symmetric, else it is not
3370 If all constructors are blocks, matrix form is blocks (assume column-wise for now)
3371  if any constructor is given as symmetric, check if other constructors are symmetric as well
3372  if all constructors are symmetric, matrix is symmetric blocks, else it is not
3373 If all constructors are transformations, matrix is a single transformation: combine transformations by superposition(?)
3374 NOTE: question of symmetry and/or rowMajor does not arise in this case.
3375 Mixed constructors.
3376 a. Elements and blocks: convert elements to block-wise representation.
3377 b. Elements and transformations: process elements and combine with transformations using matrixPlus
3378 c. transformations and blocks:
3379  if the transformation has block structure (check how?) combine into blockwise transformations (how?)
3380  else convert blocks to elements and combine using matrixPlus
3381 If there is a baseMatrix in addition to this
3382 i. baseMatrix would have been processed before
3383  */
3384  if (nCh == 0)
3385  {
3386  m_miMatrixNumberOfValues[i] = 0;
3387  m_miMatrixNumberOfBlocks[i] = 0;
3388  break;
3389  }
3390 
3393  {
3394  int bm;
3395  bm = (BaseMatrix*)instanceData->matrices->matrix[i]->m_mChildren[j])->baseMatrixIdx;
3396  if (bm >= i)
3397  throw ErrorClass("Illegal reference to baseMatrix while processing matrices");
3398  else
3399  {
3400  if (m_mExpandedMatricesInColumnMajor[bm] != NULL)
3401  haveElements = true;
3402  if (m_mExpandedMatricesInRowMajor[bm] != NULL)
3403  {
3404  rowMajor = true;
3405  haveElements = true;
3406  }
3407  if (m_mMatrixBlocksInColumnMajor != NULL)
3408  haveBlocks = true;
3409  if (m_mMatrixTransformation != NULL)
3410  haveTransformation = true;
3411  }
3412  }
3413  else if (instanceData->matrices->matrix[i]->m_mChildren[j]->nType
3414  == ENUM_MATRIX_CONSTRUCTOR_TYPE_elements)
3415  {
3416  haveElements = true;
3417  }
3418  else if (instanceData->matrices->matrix[i]->m_mChildren[j]->nType
3420  haveTransformation = true;
3421  else if (instanceData->matrices->matrix[i]->m_mChildren[j]->nType
3423  haveBlocks = true;
3424  }
3425  m_miMatrixNumberOfValues[i] = new int[n];
3426  m_miMatrixNumberOfBlocks[i] = new int[n];
3427 #endif
3428 
3429  }//end for j (number of the matrix constructor)
3430 
3431  }// end for on i (number of the matrix)
3432  }// end if (n > 0)
3433  return true;
3434  }// end try
3435  catch(const ErrorClass& eclass)
3436  {
3437  throw ErrorClass( eclass.errormsg);
3438  }
3439 }//processMatrices
3440 
3441 
3443 {
3444  int nMatrices = getMatrixNumber();
3445  if ( (instanceData->matrices == NULL) || (nMatrices == 0) ) return false;
3446  if ( (n < 0) || (n >= nMatrices) ) return false;
3448 }//matrixHasBase
3449 
3451 {
3452  int nMatrices = getMatrixNumber();
3453  if ( (instanceData->matrices == NULL) || (nMatrices == 0) ) return false;
3454  if ( (n < 0) || (n >= nMatrices) ) return false;
3456 }//matrixHasElements
3457 
3459 {
3460  int nMatrices = getMatrixNumber();
3461  if ( (instanceData->matrices == NULL) || (nMatrices == 0) ) return false;
3462  if ( (n < 0) || (n >= nMatrices) ) return false;
3464 }//matrixHasTransformations
3465 
3467 {
3468  int nMatrices = getMatrixNumber();
3469  if ( (instanceData->matrices == NULL) || (nMatrices == 0) ) return false;
3470  if ( (n < 0) || (n >= nMatrices) ) return false;
3472 }//matrixHasBlocks
3473 
3475 {
3476  int nMatrices = getMatrixNumber();
3477  if ( (instanceData->matrices == NULL) || (nMatrices == 0) ) return 0;
3478  if ( (n < 0) || (n >= nMatrices) ) return false;
3480 }//getNumberOfElementConstructors
3481 
3483 {
3484  int nMatrices = getMatrixNumber();
3485  if ( (instanceData->matrices == NULL) || (nMatrices == 0) ) return 0;
3486  if ( (n < 0) || (n >= nMatrices) ) return false;
3488 }//getNumberOfTransformationConstructors
3489 
3491 {
3492  int nMatrices = getMatrixNumber();
3493  if ( (instanceData->matrices == NULL) || (nMatrices == 0) ) return 0;
3494  if ( (n < 0) || (n >= nMatrices) ) return false;
3496 }//getNumberOfBlocksConstructors
3497 
3498 
3500 {
3501  try
3502  {
3503  int nMatrices = getMatrixNumber();
3504  if ( (instanceData->matrices == NULL) || (nMatrices == 0) )
3505  throw ErrorClass("no matrices defined in method getMatrixCoefficientsInColumnMajor()");
3506  if ( (n < 0) || (n >= nMatrices) )
3507  throw ErrorClass("invalid matrix index in method getMatrixCoefficientsInColumnMajor()");
3509  }
3510  catch(const ErrorClass& eclass)
3511  {
3512  throw ErrorClass( eclass.errormsg);
3513  }
3514 }//getMatrixCoefficientsInColumnMajor
3515 
3516 
3518 {
3519  try
3520  {
3521  int nMatrices = getMatrixNumber();
3522  if ( (instanceData->matrices == NULL) || (nMatrices == 0) )
3523  throw ErrorClass("no matrices defined in method getMatrixCoefficientsInRowMajor()");
3524  if ( (n < 0) || (n >= nMatrices) )
3525  throw ErrorClass("invalid matrix index in method getMatrixCoefficientsInRowMajor()");
3527  }
3528  catch(const ErrorClass& eclass)
3529  {
3530  throw ErrorClass( eclass.errormsg);
3531  }
3532 }//getMatrixCoefficientsInRowMajor
3533 
3534 //===========================================================================
3535 
3537 {
3538  if(m_iMatrixVarNumber == -1)
3539  {
3540  if (instanceData == NULL)
3541  throw ErrorClass("data object undefined in method getNumberOfMatrixVariables()");
3542  if (instanceData->matrixProgramming == NULL ||
3544  m_iMatrixVarNumber = 0;
3545  else
3547  }
3548  return m_iMatrixVarNumber;
3549 }//getNumberOfMatrixVariables
3550 
3552 {
3553  if(m_iMatrixObjNumber == -1)
3554  {
3555  if (instanceData == NULL)
3556  throw ErrorClass("data object undefined in method getNumberOfMatrixObjectives()");
3557  if (instanceData->matrixProgramming == NULL ||
3559  m_iMatrixObjNumber = 0;
3560  else
3562  }
3563  return m_iMatrixObjNumber;
3564 }//getNumberOfMatrixObjectives
3565 
3567 {
3568  if(m_iMatrixObjNumber == -1)
3569  {
3570  if (instanceData == NULL)
3571  throw ErrorClass("data object undefined in method getNumberOfMatrixConstraints()");
3572  if (instanceData->matrixProgramming == NULL ||
3574  m_iMatrixConNumber = 0;
3575  else
3577  }
3578  return m_iMatrixConNumber;
3579 }//getNumberOfMatrixConstraints
3580 
3582 {
3583  if(m_iMatrixExpressionNumber == -1)
3584  {
3585  if (instanceData == NULL)
3586  throw ErrorClass("data object undefined in method getNumberOfMatrixExpressions()");
3587  if (instanceData->matrixProgramming == NULL||
3590  else
3592  }
3594 }//getNumberOfMatrixExpressions
3595 
3596 
3597 //--------------------------------------------------------
3598 #if 0
3600 {
3601  if(m_iMatrixExpressionNumber == -1)
3602  {
3603  if (instanceData == NULL || instanceData->matrixProgramming == NULL
3605  throw ErrorClass("data object undefined in method getNumberOfMatrixExpressions()");
3607  }
3609 }//getNumberOfMatrixExpressions
3610 
3612 {
3614  for (int i=0; i < getNumberOfMatrixExpressions(); i++)
3615  {
3617  }
3618  return root;
3619 }//getNonlinearExpressions
3620 
3621 
3623 {
3624  if(m_bMatrixExpressionTreeIndexesProcessed == false) getMatrixExpressionTreeIndexes();
3625  return m_iNumberOfMatrixExpressionTreeIndexes;
3626 }//getNumberOfMatrixExpressionTreeIndexes
3627 
3629 {
3630  if(m_bMatrixExpressionTreeIndexesProcessed == true) return m_miMatrixExpressionTreeIndexes;
3631  m_bMatrixExpressionTreeIndexesProcessed = true;
3632  std::map<int, MatrixExpressionTree*> expTrees;
3633  expTrees = getAllMatrixExpressionTrees();
3634  std::map<int, MatrixExpressionTree*>::iterator pos;
3635  try
3636  {
3637  // now put the term into an array
3638  m_iNumberOfMatrixExpressionTreeIndexes = expTrees.size();
3639  m_miMatrixExpressionTreeIndexes = new int[ m_iNumberOfMatrixExpressionTreeIndexes ] ;
3640  int i = 0;
3641  for(pos = expTrees.begin(); pos != expTrees.end(); ++pos)
3642  {
3643  m_miMatrixExpressionTreeIndexes[ i++] = pos->first;
3644  }
3645  expTrees.clear();
3646  return m_miMatrixExpressionTreeIndexes;
3647  }
3648  catch(const ErrorClass& eclass)
3649  {
3650  throw ErrorClass( eclass.errormsg);
3651  }
3652 }//getMatrixExpressionTreeIndexes
3653 
3655 {
3656  // check to make sure rowIdx has a nonlinear term and is in the map
3657  if( m_bProcessMatrixExpressionTrees == false )
3658  {
3660  }
3661  if( m_mapMatrixExpressionTrees.find( rowIdx) != m_mapMatrixExpressionTrees.end())
3662  return m_mapMatrixExpressionTrees[ rowIdx];
3663  else return NULL ;
3664 }// getMatrixExpressionTree for a specific index
3665 
3666 MatrixExpressionTree* OSInstance::getMatrixExpressionTreeMod(int rowIdx)
3667 {
3668  // check to make sure rowIdx has a nonlinear term and is in the map
3669  if( m_bProcessMatrixExpressionTreesMod == false )
3670  {
3672  }
3673  if( m_mapMatrixExpressionTreesMod.find( rowIdx) != m_mapMatrixExpressionTreesMod.end())
3674  return m_mapMatrixExpressionTreesMod[ rowIdx];
3675  else return NULL ;
3676 }// getMatrixExpressionTreeMod for a specific index
3677 
3678 std::vector<ExprNode*> OSInstance::getMatrixExpressionTreeInPostfix( int rowIdx)
3679 {
3680  //if( m_binitForAlgDiff == false) this->initForAlgDiff();
3681  if( m_bProcessMatrixExpressionTrees == false ) getAllMatrixExpressionTrees();
3682  std::vector<ExprNode*> postfixVec;
3683  try
3684  {
3685  if( m_mapMatrixExpressionTrees.find( rowIdx) != m_mapMatrixExpressionTrees.end())
3686  {
3687  MatrixExpressionTree* expTree = getMatrixExpressionTree( rowIdx);
3688  postfixVec = expTree->m_treeRoot->getPostfixFromExpressionTree();
3689  }
3690  else
3691  {
3692  throw ErrorClass("Error in getMatrixExpressionTreeInPostfix, rowIdx not valid");
3693  }
3694  return postfixVec;
3695  }
3696  catch(const ErrorClass& eclass)
3697  {
3698  throw ErrorClass( eclass.errormsg);
3699  }
3700 }//getMatrixExpressionTreeInPostfix
3701 
3702 std::string OSInstance::getMatrixExpressionTreeInInfix( int rowIdx_)
3703 {
3704  if( m_binitForAlgDiff == false) this->initForAlgDiff();
3706  std::string resultString;
3707  resultString = "";
3708  unsigned int i;
3709  unsigned int j;
3710  unsigned int n;
3711  ostringstream outStr;
3712  std::vector<ExprNode*> postfixVec;
3713  int rowIdx = rowIdx_;
3714  OSnLNode *nlnode = NULL ;
3715  OSnLNodeNumber *nlnodeNum = NULL;
3716  OSnLNodeVariable *nlnodeVar = NULL;
3717  OSnLNodeSum *nlnodeSum = NULL;
3718  OSnLNodeProduct *nlnodeProduct = NULL;
3719  OSnLNodeMin *nlnodeMin = NULL;
3720  OSnLNodeMax *nlnodeMax = NULL;
3721  std::string tmp1 = "";
3722  std::string tmp2 = "";
3723  std::string tmp3 = "";
3724  std::stack<OSnLNode*> opStack;
3725  std::stack<std::string> tmpStack;
3726  std::stack<std::string> sumStack;
3727  std::stack<std::string> productStack;
3728  std::stack<std::string> minStack;
3729  std::stack<std::string> maxStack;
3730 
3731  try
3732  {
3733  if( m_mapMatrixExpressionTrees.find( rowIdx) != m_mapMatrixExpressionTrees.end())
3734  {
3735  // get the nodes and separate into operators and operands,
3736  // for now only the number and variable nodes are operator nodes
3737 
3738  MatrixExpressionTree* exptree = this->getMatrixExpressionTree( rowIdx);
3739  if(exptree != NULL)
3740  {
3741  postfixVec = this->getMatrixExpressionTreeInPostfix( rowIdx);
3742  n = postfixVec.size();
3743  //put vector in reverse order
3744  for (i = 0 ; i < n; i++)
3745  {
3746  nlnode = postfixVec[ n - 1 - i];
3747  opStack.push( nlnode);
3748 
3749  //std::cout << postfixVec[ i]->snodeName << std::endl;
3750  }
3751 
3752  n = opStack.size();
3753  for(i = 0; i < n; i++)
3754  {
3755  //std::cout << "NUMBER OF NODES LEFT = " << operatorVec.size() << std::endl;
3756  nlnode = opStack.top();
3757  //std::cout << "EVALUATING NODE: " << nlnode->snodeName << std::endl;
3758  switch (nlnode->inodeInt)
3759  {
3760  case OS_NUMBER:
3761  nlnodeNum = (OSnLNodeNumber*)nlnode;
3762  tmpStack.push( os_dtoa_format(nlnodeNum->value) );
3763  break;
3764 
3765  case OS_PI:
3766  tmpStack.push( "PI" );
3767  break;
3768 
3769  case OS_E:
3770  tmpStack.push( "E" );
3771  break;
3772 
3773  case OS_VARIABLE:
3774  outStr.str("");
3775  // handle a variable
3776  nlnodeVar = (OSnLNodeVariable*)nlnode;
3777  // see if the coefficient is specified
3778  if( (nlnodeVar->coef > 1.0) || (nlnodeVar->coef < 1.0) )
3779  {
3780  outStr << "(";
3781  outStr << os_dtoa_format(nlnodeVar->coef);
3782  outStr << "*x_";
3783  outStr << nlnodeVar->idx;
3784  outStr << ")";
3785  tmpStack.push(outStr.str() );
3786  //std::cout << "WE JUST PUSHED " << outStr.str() << std::endl;
3787  }
3788  else
3789  {
3790  outStr << "x_";
3791  outStr << nlnodeVar->idx;
3792  tmpStack.push(outStr.str() );
3793  //std::cout << "WE JUST PUSHED " << outStr.str() << std::endl;
3794  }
3795  break;
3796 
3797  case OS_PLUS :
3798  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing plus operator");
3799  tmp1 = tmpStack.top();
3800  tmpStack.pop();
3801  tmp2 = tmpStack.top();
3802  tmpStack.pop();
3803  tmpStack.push("(" + tmp2 + " + " + tmp1 + ")");
3804  break;
3805 
3806  case OS_SUM :
3807  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing sum operator");
3808  //std::cout << "INSIDE SUM NODE " << std::endl;
3809  nlnodeSum = (OSnLNodeSum*)nlnode;
3810  outStr.str("");
3811  for(j = 0; j < nlnodeSum->inumberOfChildren; j++)
3812  {
3813  sumStack.push( tmpStack.top() );
3814  tmpStack.pop();
3815  }
3816  outStr << "(";
3817  for(j = 0; j < nlnodeSum->inumberOfChildren; j++)
3818  {
3819  outStr << sumStack.top();
3820  if (j < nlnodeSum->inumberOfChildren - 1) outStr << " + ";
3821  sumStack.pop();
3822  }
3823  outStr << ")";
3824  tmpStack.push( outStr.str() );
3825  //std::cout << outStr.str() << std::endl;
3826  break;
3827 
3828  case OS_MINUS :
3829  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing minus operator");
3830  tmp1 = tmpStack.top();
3831  tmpStack.pop();
3832  tmp2 = tmpStack.top();
3833  tmpStack.pop();
3834  tmpStack.push("(" + tmp2 + " - " + tmp1 + ")");
3835  break;
3836 
3837  case OS_NEGATE :
3838  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- -- Problem writing negate operator");
3839  tmp1 = tmpStack.top();
3840  tmpStack.pop();
3841  tmpStack.push( "-"+ tmp1 );
3842 
3843 
3844  break;
3845 
3846  case OS_TIMES :
3847  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing times operator");
3848  tmp1 = tmpStack.top();
3849  tmpStack.pop();
3850  tmp2 = tmpStack.top();
3851  tmpStack.pop();
3852  tmpStack.push("(" + tmp2 + "*" + tmp1 + ")");
3853  break;
3854 
3855  case OS_DIVIDE :
3856  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing divide operator");
3857  tmp1 = tmpStack.top();
3858  tmpStack.pop();
3859  tmp2 = tmpStack.top();
3860  tmpStack.pop();
3861  tmpStack.push("(" + tmp2 + " / " + tmp1 + ")");
3862  break;
3863 
3864  case OS_POWER :
3865  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing power operator");
3866  tmp1 = tmpStack.top();
3867  tmpStack.pop();
3868  tmp2 = tmpStack.top();
3869  tmpStack.pop();
3870  tmpStack.push("(" + tmp2 + " ^ " + tmp1 + ")");
3871  break;
3872 
3873 
3874  case OS_ABS :
3875  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing abs operator");
3876  tmp1 = tmpStack.top();
3877  tmpStack.pop();
3878  tmpStack.push( "abs( "+ tmp1 + ")");
3879  break;
3880 
3881  case OS_ERF :
3882  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing erf operator");
3883  tmp1 = tmpStack.top();
3884  tmpStack.pop();
3885  tmpStack.push( "erf( "+ tmp1 + ")");
3886  break;
3887 
3888 
3889  case OS_SQUARE :
3890  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing square operator ");
3891  tmp1 = tmpStack.top();
3892  tmpStack.pop();
3893  tmpStack.push( "("+ tmp1 + ")^2");
3894  break;
3895 
3896  case OS_LN :
3897  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing ln operator");
3898  tmp1 = tmpStack.top();
3899  tmpStack.pop();
3900  tmpStack.push( "ln( "+ tmp1 + ")");
3901  break;
3902 
3903  case OS_EXP :
3904 
3905  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing exp operator");
3906  tmp1 = tmpStack.top();
3907  tmpStack.pop();
3908  tmpStack.push( "exp( "+ tmp1 + ")");
3909  break;
3910 
3911  case OS_SIN :
3912  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing sin operator");
3913  tmp1 = tmpStack.top();
3914  tmpStack.pop();
3915  tmpStack.push( "sin( "+ tmp1 + ")");
3916  break;
3917 
3918  case OS_COS :
3919  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing cos operator ");
3920  tmp1 = tmpStack.top();
3921  tmpStack.pop();
3922  tmpStack.push( "cos( "+ tmp1 + ")");
3923  break;
3924 
3925  case OS_SQRT :
3926  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing sqrt operator ");
3927  tmp1 = tmpStack.top();
3928  tmpStack.pop();
3929  tmpStack.push( "sqrt( "+ tmp1 + ")");
3930  break;
3931 
3932  case OS_MIN :
3933  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing min operator");
3934  //std::cout << "INSIDE Min NODE " << std::endl;
3935  nlnodeMin = (OSnLNodeMin*)nlnode;
3936  outStr.str("");
3937  for(j = 0; j < nlnodeMin->inumberOfChildren; j++)
3938  {
3939  minStack.push( tmpStack.top() );
3940  tmpStack.pop();
3941  }
3942  outStr << "min(";
3943  for(j = 0; j < nlnodeMin->inumberOfChildren; j++)
3944  {
3945  outStr << minStack.top();
3946  if (j < nlnodeMin->inumberOfChildren - 1) outStr << " , ";
3947  minStack.pop();
3948  }
3949  outStr << ")";
3950  tmpStack.push( outStr.str() );
3951  break;
3952 
3953  case OS_MAX :
3954  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing max operator");
3955  //std::cout << "INSIDE Max NODE " << std::endl;
3956  nlnodeMax = (OSnLNodeMax*)nlnode;
3957  outStr.str("");
3958  for(j = 0; j < nlnodeMax->inumberOfChildren; j++)
3959  {
3960  maxStack.push( tmpStack.top() );
3961  tmpStack.pop();
3962  }
3963  outStr << "max(";
3964  for(j = 0; j < nlnodeMax->inumberOfChildren; j++)
3965  {
3966  outStr << maxStack.top();
3967  if (j < nlnodeMax->inumberOfChildren - 1) outStr << " , ";
3968  maxStack.pop();
3969  }
3970  outStr << ")";
3971  tmpStack.push( outStr.str() );
3972  break;
3973 
3974  case OS_IF :
3975 
3976  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing if operator ");
3977  if(nlnode->inumberOfChildren != 3)throw ErrorClass("The if node must have three children");
3978  tmp1 = tmpStack.top();
3979  tmpStack.pop();
3980  tmp2 = tmpStack.top();
3981  tmpStack.pop();
3982  tmp3 = tmpStack.top();
3983  tmpStack.pop();
3984  tmpStack.push( "if(" + tmp3 + "," + tmp2 + "," + tmp1 +")" );
3985  break;
3986 
3987  case OS_PRODUCT :
3988  if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing product operator");
3989  //std::cout << "INSIDE Product NODE " << std::endl;
3990  nlnodeProduct = (OSnLNodeProduct*)nlnode;
3991  outStr.str("");
3992  for(j = 0; j < nlnodeProduct->inumberOfChildren; j++)
3993  {
3994  productStack.push( tmpStack.top() );
3995  tmpStack.pop();
3996  }
3997  outStr << "(";
3998  for(j = 0; j < nlnodeProduct->inumberOfChildren; j++)
3999  {
4000  outStr << productStack.top();
4001  if (j < nlnodeProduct->inumberOfChildren - 1) outStr << " * ";
4002  productStack.pop();
4003  }
4004  outStr << ")";
4005  tmpStack.push( outStr.str() );
4006  //std::cout << outStr.str() << std::endl;
4007  break;
4008 
4009  default:
4010  throw ErrorClass("operator " + nlnode->getTokenName() + " not supported");
4011  break;
4012  }
4013  opStack.pop();
4014  }
4015  postfixVec.clear();
4016  if(tmpStack.size() != 1) throw ErrorClass( "There is an error in the OSExpression Tree -- stack size should be 1 at end");
4017  resultString = tmpStack.top();
4018  //std::cout << resultString << std::endl;
4019  tmpStack.pop();
4020 
4021  return resultString;
4022  }
4023  else
4024  {
4025  //throw ErrorClass("Error in getNonlinearExpressionTreeInInfix, there is no expression tree for this index");
4026  return "";
4027  }
4028  }
4029  else
4030  {
4031  throw ErrorClass("Error in getNonlinearExpressionTreeInInfix, rowIdx not valid");
4032  }
4033  return resultString;
4034  }
4035  catch(const ErrorClass& eclass)
4036  {
4037  throw ErrorClass( eclass.errormsg);
4038  }
4039 }//getMatrixExpressionTreeInInfix
4040 
4041 
4042 std::vector<ExprNode*> OSInstance::getMatrixExpressionTreeModInPostfix( int rowIdx)
4043 {
4044  //if( m_binitForAlgDiff == false) this->initForAlgDiff();
4045  if( m_bProcessMatrixExpressionTreesMod == false ) getAllMatrixExpressionTreesMod();
4046  std::vector<ExprNode*> postfixVec;
4047  try
4048  {
4049  if( m_mapMatrixExpressionTreesMod.find( rowIdx) != m_mapMatrixExpressionTreesMod.end())
4050  {
4051  MatrixExpressionTree* expTree = getMatrixExpressionTreeMod( rowIdx);
4052  postfixVec = expTree->m_treeRoot->getPostfixFromExpressionTree();
4053 
4054  }
4055  else
4056  {
4057  throw ErrorClass("Error in getMatrixExpressionTreeModInPostfix, rowIdx not valid");
4058  }
4059  return postfixVec;
4060  }
4061  catch(const ErrorClass& eclass)
4062  {
4063  throw ErrorClass( eclass.errormsg);
4064  }
4065 }//getMatrixExpressionTreeModInPostfix
4066 
4067 
4068 std::vector<ExprNode*> OSInstance::getMatrixExpressionTreeInPrefix( int rowIdx)
4069 {
4070  //if( m_binitForAlgDiff == false) this->initForAlgDiff();
4071  if( m_bProcessMatrixExpressionTrees == false ) getAllMatrixExpressionTrees();
4072  std::vector<ExprNode*> prefixVec;
4073  try
4074  {
4075  if( m_mapMatrixExpressionTrees.find( rowIdx) != m_mapMatrixExpressionTrees.end())
4076  {
4077  MatrixExpressionTree* expTree = getMatrixExpressionTree( rowIdx);
4078  prefixVec = expTree->m_treeRoot->getPrefixFromExpressionTree();
4079  }
4080  else
4081  {
4082  throw ErrorClass("Error in getMatrixExpressionTreeInPrefix, rowIdx not valid");
4083  }
4084  return prefixVec;
4085  }
4086  catch(const ErrorClass& eclass)
4087  {
4088  throw ErrorClass( eclass.errormsg);
4089  }
4090 }//getMatrixExpressionTreeInPrefix
4091 
4092 std::vector<ExprNode*> OSInstance::getMatrixExpressionTreeModInPrefix( int rowIdx)
4093 {
4094 
4095  //if( m_binitForAlgDiff == false) this->initForAlgDiff();
4096  if( m_bProcessMatrixExpressionTreesMod == false ) getAllMatrixExpressionTreesMod();
4097  std::vector<ExprNode*> prefixVec;
4098  try
4099  {
4100  if( m_mapMatrixExpressionTreesMod.find( rowIdx) != m_mapMatrixExpressionTreesMod.end())
4101  {
4102  MatrixExpressionTree* expTree = getMatrixExpressionTreeMod( rowIdx);
4103  prefixVec = expTree->m_treeRoot->getPrefixFromExpressionTree();
4104  }
4105  else
4106  {
4107  throw ErrorClass("Error in getMatrixExpressionTreeInPrefix, rowIdx not valid");
4108  }
4109  return prefixVec;
4110  }
4111  catch(const ErrorClass& eclass)
4112  {
4113  throw ErrorClass( eclass.errormsg);
4114  }
4115 }//getMatrixExpressionTreeInPrefix
4116 
4117 std::map<int, MatrixExpressionTree*> OSInstance::getAllMatrixExpressionTrees()
4118 {
4119  //if( m_binitForAlgDiff == false) this->initForAlgDiff();
4120  if(m_bProcessMatrixExpressionTrees == true) return m_mapMatrixExpressionTrees;
4121  std::map<int, int> foundIdx;
4122  std::map<int, int>::iterator pos;
4123  OSnLNodePlus *nlNodePlus;
4124  MatrixExpressionTree *expTree;
4125 
4126 
4129  int i;
4130  // important -- tell the nl nodes not to destroy the OSExpression Objects
4132  {
4134  {
4136 
4137 
4138 
4139 
4140  }
4141  }
4142  int index;
4143  // kipp -- what should we return if instanceData->nonlinearExpressions->numberOfNonlinearExpressions is zero
4145  {
4146  index = instanceData->nonlinearExpressions->nl[ i]->idx;
4147  if(foundIdx.find( index) != foundIdx.end() )
4148  {
4149  //if(foundIdx[ index] > 0 ){
4150  //std::cout << "OLD INDEX FOUND " << index << std::endl;
4151  //std::cout << "foundIdx[ index] " << index << std::endl;
4152  // found an existing index
4153  // important -- at this time m_mapExpressionTrees[ index] points to
4154  // the last OSExpressionTree with this index, it does not point to the
4155  // the just found OSExpressionTree with this index
4156  nlNodePlus = new OSnLNodePlus();
4157  //expTree = new OSExpressionTree();
4159  // set left child to old index and right child to new one
4160  nlNodePlus->m_mChildren[ 0] = m_mapExpressionTrees[ index]->m_treeRoot;
4162  // we must delete the Expression tree corresponding to the old index value but not the nl nodes
4163  instanceData->nonlinearExpressions->nl[ foundIdx[ index] ]->m_bDeleteExpressionTree = true;
4164  instanceData->nonlinearExpressions->nl[ foundIdx[ index] ]->osExpressionTree->bDestroyNlNodes = false;
4165  //point to the new expression tree
4166  m_mapExpressionTrees[ index] = expTree;
4167  m_mapExpressionTrees[ index]->m_treeRoot = nlNodePlus;
4168  foundIdx[ index] = i;
4169  }
4170  else
4171  {
4172  // we have a new index
4175  foundIdx[ index] = i;
4176  }
4177  //foundIdx[ index]++;
4178  }
4179  // count the number of constraints and objective functions with nonlinear terms.
4180  for(pos = foundIdx.begin(); pos != foundIdx.end(); ++pos)
4181  {
4182  if(pos->first < 0)
4183  {
4184  m_iMatrixObjectiveNumberNonlinear++;
4185  }
4186  else
4187  {
4188  m_iMatrixConstraintNumberNonlinear++;
4189  }
4190  }
4191  m_bProcessMatrixExpressionTrees = true;
4193 }// getAllMatrixExpressionTrees
4194 #endif
4195 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4196 
4198 {
4199  if (instanceData->timeDomain == NULL)
4200  return "";
4201  if (instanceData->timeDomain->interval != NULL)
4202  return "interval";
4203  if (instanceData->timeDomain->stages != NULL)
4204  return "stages";
4205  return "";
4206 }// getTimeDomainFormat
4207 
4209 {
4210  try
4211  {
4212  if (instanceData->timeDomain == NULL)
4213  return 1;
4214  if (instanceData->timeDomain->interval != NULL)
4215  throw ErrorClass("getTimeDomainStageNumber: Continuous time not implemented yet");
4216  if (instanceData->timeDomain->stages == NULL)
4217  return 1;
4219  }
4220  catch(const ErrorClass& eclass)
4221  {
4222  throw ErrorClass( eclass.errormsg);
4223  }
4224 }// getTimeDomainStageNumber
4225 
4227 {
4228  if (instanceData->timeDomain == NULL)
4229  return NULL;
4230  if (instanceData->timeDomain->interval != NULL)
4231  return NULL; //throw an error
4232  if (instanceData->timeDomain->stages == NULL)
4233  return NULL;
4234  if (m_msTimeDomainStageNames != NULL)
4235  delete [] m_msTimeDomainStageNames;
4237  return NULL;
4239  for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
4241  return m_msTimeDomainStageNames;
4242 }// getTimeDomainStageNames
4243 
4244 
4246 {
4247  if (instanceData->timeDomain == NULL)
4248  return NULL;
4249  if (instanceData->timeDomain->interval != NULL)
4250  return NULL; //throw an error
4251  if (instanceData->timeDomain->stages == NULL)
4252  return NULL;
4256  return NULL;
4258  for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
4261 }// getTimeDomainStageNumberOfVariables
4262 
4264 {
4265  if (instanceData->timeDomain == NULL)
4266  return NULL;
4267  if (instanceData->timeDomain->interval != NULL)
4268  return NULL; //throw an error
4269  if (instanceData->timeDomain->stages == NULL)
4270  return NULL;
4274  return NULL;
4276  for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
4279 }// getTimeDomainStageNumberOfConstraints
4280 
4282 {
4283  if (instanceData->timeDomain == NULL)
4284  return NULL;
4285  if (instanceData->timeDomain->interval != NULL)
4286  return NULL; //throw an error
4287  if (instanceData->timeDomain->stages == NULL)
4288  return NULL;
4292  return NULL;
4294  for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
4297 }// getTimeDomainStageNumberOfObjectives
4298 
4300 {
4301  if (instanceData->timeDomain == NULL)
4302  return NULL;
4303  if (instanceData->timeDomain->interval != NULL)
4304  return NULL; //throw an error
4305  if (instanceData->timeDomain->stages == NULL)
4306  return NULL;
4308  return NULL;
4309  if (m_mmiTimeDomainStageVarList != NULL)
4310  {
4311  for (int i = 0; i < m_iNumberOfTimeStages; i ++)
4312  delete[] m_mmiTimeDomainStageVarList[i];
4313  delete[] m_mmiTimeDomainStageVarList;
4315  }
4316 
4317  //delete [] m_mmiTimeDomainStageVarList;
4319  return NULL;
4322  int timeDomainStageNumberVar;
4323  for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
4324  {
4325  timeDomainStageNumberVar = m_miTimeDomainStageVariableNumber[i];
4326  m_mmiTimeDomainStageVarList[i] = new int[ timeDomainStageNumberVar ];
4328  for (int j = 0; j < m_miTimeDomainStageVariableNumber[i]; j++)
4330  else
4331  for (int j = 0; j < m_miTimeDomainStageVariableNumber[i]; j++)
4333  }
4335 }// getTimeDomainStageVarList
4336 
4338 {
4339  if (instanceData->timeDomain == NULL)
4340  return NULL;
4341  if (instanceData->timeDomain->interval != NULL)
4342  return NULL; //throw an error
4343  if (instanceData->timeDomain->stages == NULL)
4344  return NULL;
4346  return NULL;
4347  if (m_mmiTimeDomainStageConList != NULL)
4348  {
4349 
4350  for (int i = 0; i < m_iNumberOfTimeStages; i ++)
4351  delete[] m_mmiTimeDomainStageConList[i];
4352  delete[] m_mmiTimeDomainStageConList;
4354  }
4355 
4357  return NULL;
4360  int numTimeDomainStageCon;
4361  for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
4362  {
4363  numTimeDomainStageCon = m_miTimeDomainStageConstraintNumber[i];
4364  m_mmiTimeDomainStageConList[i] = new int[ numTimeDomainStageCon];
4366  for (int j = 0; j < m_miTimeDomainStageConstraintNumber[i]; j++)
4368  else
4369  for (int j = 0; j < m_miTimeDomainStageConstraintNumber[i]; j++)
4371  }
4373 }// getTimeDomainStageConList
4374 
4376 {
4377  if (instanceData->timeDomain == NULL)
4378  return NULL;
4379  if (instanceData->timeDomain->interval != NULL)
4380  return NULL; //throw an error
4381  if (instanceData->timeDomain->stages == NULL)
4382  return NULL;
4384  return NULL;
4385  if (m_mmiTimeDomainStageObjList != NULL)
4386  {
4387  for (int i = 0; i < m_iNumberOfTimeStages; i ++)
4388  delete[] m_mmiTimeDomainStageObjList[i];
4389  delete[] m_mmiTimeDomainStageObjList;
4391  }
4393  return NULL;
4396  int numTimeDomainStageObjNum;
4397  for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
4398  {
4399  numTimeDomainStageObjNum = m_miTimeDomainStageObjectiveNumber[i];
4400  m_mmiTimeDomainStageObjList[i] = new int[ numTimeDomainStageObjNum];
4402  for (int j = 0; j < m_miTimeDomainStageObjectiveNumber[i]; j++)
4404  else
4405  for (int j = 0; j < m_miTimeDomainStageObjectiveNumber[i]; j++)
4407  }
4409 }// getTimeDomainStageObjList
4410 
4412 {
4413  if (instanceData->timeDomain == NULL)
4414  return 0.0;
4415  if (instanceData->timeDomain->stages != NULL)
4416  return 0.0; //throw an error
4417  if (instanceData->timeDomain->interval == NULL)
4418  return 0.0;
4420 }// getTimeDomainIntervalStart
4421 
4423 {
4424  if (instanceData->timeDomain == NULL)
4425  return 0.0;
4426  if (instanceData->timeDomain->stages != NULL)
4427  return 0.0; //throw an error
4428  if (instanceData->timeDomain->interval == NULL)
4429  return 0.0;
4431 }// getTimeDomainIntervalHorizon
4432 
4433 
4434 
4435 /* the set() methods
4436  ================= */
4437 
4438 bool OSInstance::setInstanceName(string name)
4439 {
4440  instanceHeader->name = name;
4441  return true;
4442 }//setInstanceName
4443 
4444 bool OSInstance::setInstanceSource(string source)
4445 {
4446  instanceHeader->source = source;
4447  return true;
4448 }//setInstanceSource
4449 
4450 bool OSInstance::setInstanceDescription(string description)
4451 {
4452  instanceHeader->description = description;
4453  return true;
4454 }//setInstanceDescription
4455 
4456 bool OSInstance::setInstanceCreator(string fileCreator)
4457 {
4458  instanceHeader->fileCreator = fileCreator;
4459  return true;
4460 }//setInstanceSource
4461 
4463 {
4464  instanceHeader->licence = licence;
4465  return true;
4466 }//setInstanceLicence
4467 
4468 
4470 {
4471  // this method assume osinstance->instanceData->variables is not null
4472  if(number < 0) return false;
4473  //if(instanceData->variables->numberOfVariables != -1 && instanceData->variables->numberOfVariables != number){
4474  // delete[] instanceData->variables->var;
4475  // instanceData->variables->var = NULL;
4476  //}
4477  if(instanceData->variables == NULL) instanceData->variables = new Variables();
4479  if(instanceData->variables->var == NULL && number > 0)
4480  {
4481  instanceData->variables->var = new Variable*[number];
4482  }
4483  return true;
4484 }//setVariableNumber
4485 
4486 
4487 bool OSInstance::addVariable(int index, string name, double lowerBound, double upperBound, char type)
4488 {
4489  if (verifyVarType(type) == false) type = 'C';
4490  instanceData->variables->var[index] = new Variable();
4491  if(index < 0 || instanceData->variables->numberOfVariables <= 0 || index >= instanceData->variables->numberOfVariables) return false;
4492  instanceData->variables->var[index]->name = name;
4493  instanceData->variables->var[index]->lb = lowerBound;
4494  instanceData->variables->var[index]->ub = upperBound;
4495  instanceData->variables->var[index]->type = type;
4496  //if(init != OSNaN()) instanceData->variables->var[index]->init = init;
4497  //instanceData->variables->var[index]->initString = initString;
4498  return true;
4499 }//addVariable
4500 
4501 
4502 bool OSInstance::setVariables(int number, string *names, double *lowerBounds,
4503  double *upperBounds, char *types)
4504 {
4505  if(number <= 0) return false;
4506  try
4507  {
4508  if(instanceData->variables == NULL)
4509  {
4510  throw ErrorClass("There is no variables object");
4511  }
4512  if(instanceData->variables->numberOfVariables != number)
4513  {
4514  throw ErrorClass("input number of variables not equal to number in class");
4515  }
4516  //instanceData->variables->var = new Variable*[number];
4517  int i;
4518  for(i = 0; i < number; i++)
4519  {
4520  instanceData->variables->var[ i] = new Variable();
4521  }
4522  if(names != NULL)
4523  {
4524  for(i = 0; i < number; i++) instanceData->variables->var[i]->name = names[i];
4525  }
4526  if(lowerBounds != NULL)
4527  {
4528  for(i = 0; i < number; i++)
4529  {
4530  instanceData->variables->var[i]->lb = lowerBounds[i];
4531  }
4532  }
4533  if(upperBounds != NULL)
4534  {
4535  for(i = 0; i < number; i++)
4536  {
4537  instanceData->variables->var[i]->ub = upperBounds[i];
4538  }
4539  }
4540  if(types != NULL)
4541  {
4542  for(i = 0; i < number; i++)
4543  {
4544  if(verifyVarType(types[i]) == false) types[i] = 'C';
4545  instanceData->variables->var[i]->type = types[i];
4546  }
4547  }
4548  return true;
4549  }
4550  catch(const ErrorClass& eclass)
4551  {
4552  throw ErrorClass( eclass.errormsg);
4553  }
4554 }//setVariables
4555 
4556 // begin checking again with Jun Ma
4557 
4559 {
4560  if(number < 0) return false;
4562  if(number == 0)
4563  {
4565  instanceData->objectives->obj = 0;
4566  return true;
4567  }
4569  instanceData->objectives->obj = new Objective*[number];
4570  return true;
4571 }//setObjectiveNumber
4572 
4573 bool OSInstance::addObjective(int index, string name, string maxOrMin, double constant, double weight, SparseVector *objectiveCoefficients)
4574 {
4575  if(index >= 0 || instanceData->objectives->numberOfObjectives <= 0 || abs(index) > instanceData->objectives->numberOfObjectives) return false;
4576  int arrayIndex = abs(index) -1;
4577  if(instanceData->objectives->obj == NULL) return false;
4578  instanceData->objectives->obj[arrayIndex] = new Objective();
4579  instanceData->objectives->obj[arrayIndex]->name = name;
4580  if( (maxOrMin != "max") && (maxOrMin != "min") ) return false;
4581  else instanceData->objectives->obj[arrayIndex]->maxOrMin = maxOrMin;
4582  instanceData->objectives->obj[arrayIndex]->constant = constant;
4583  instanceData->objectives->obj[arrayIndex]->weight = weight;
4584  int n = objectiveCoefficients->number;
4585  instanceData->objectives->obj[arrayIndex]->numberOfObjCoef = n;
4586  if(n == 0)
4587  {
4588  instanceData->objectives->obj[arrayIndex]->coef = 0;
4589  }
4590  else
4591  {
4592  int i = 0;
4593  instanceData->objectives->obj[arrayIndex]->coef = new ObjCoef*[n];
4594  for(i = 0; i < n; i++) instanceData->objectives->obj[arrayIndex]->coef[i] = new ObjCoef();
4595  for(i = 0; i < n; i++)
4596  {
4597  instanceData->objectives->obj[arrayIndex]->coef[i]->idx = objectiveCoefficients->indexes[i];
4598  instanceData->objectives->obj[arrayIndex]->coef[i]->value = objectiveCoefficients->values[i];
4599  }
4600  }
4601  return true;
4602 }//addObjective
4603 
4604 bool OSInstance::setObjectives(int number, string *names, string *maxOrMins, double *constants, double *weights, SparseVector **objectiveCoefficients)
4605 {
4606  if(number < 0) return false;
4607  try
4608  {
4609  if(instanceData->objectives == NULL)
4610  {
4611  throw ErrorClass("there is no objectives object");
4612  }
4614  {
4615  throw ErrorClass("input number of objective not equal to number in class");
4616  }
4617  if(number == 0) return true;
4618  int i = 0;
4619  for(i = 0; i < number; i++)instanceData->objectives->obj[i] = new Objective();
4620  int j = 0;
4621  if(names != NULL)
4622  {
4623  for(i = 0; i < number; i++) instanceData->objectives->obj[i]->name = names[i];
4624  }
4625  if(maxOrMins != NULL)
4626  {
4627  for(i = 0; i < number; i++)
4628  {
4629  if(maxOrMins[i] == "" || (maxOrMins[i].compare("max") != 0 && maxOrMins[i].compare("min") !=0)) return false;
4630  instanceData->objectives->obj[i]->maxOrMin = maxOrMins[i];
4631  }
4632  }
4633  if(constants != NULL)
4634  {
4635  for(i = 0; i < number; i++) instanceData->objectives->obj[i]->constant = constants[i];
4636  }
4637  if(weights != NULL)
4638  {
4639  for(i = 0; i < number; i++) instanceData->objectives->obj[i]->weight = weights[i];
4640  }
4641  if(objectiveCoefficients != NULL)
4642  {
4643  for(i = 0; i < number; i++)
4644  {
4645  int n = (&objectiveCoefficients[i] == NULL || objectiveCoefficients[i]->indexes == NULL)?0:objectiveCoefficients[i]->number;
4647  if(n == 0)
4648  {
4649  instanceData->objectives->obj[i]->coef = NULL;
4650  }
4651  else
4652  {
4653  instanceData->objectives->obj[i]->coef = new ObjCoef*[n];
4654  for(j = 0; j < n; j++)
4655  {
4656  instanceData->objectives->obj[i]->coef[j] = new ObjCoef();
4657  instanceData->objectives->obj[i]->coef[j]->idx = objectiveCoefficients[i]->indexes[j];
4658  instanceData->objectives->obj[i]->coef[j]->value = objectiveCoefficients[i]->values[j];
4659  }
4660  }
4661  }
4662  }
4663  return true;
4664  }
4665  catch(const ErrorClass& eclass)
4666  {
4667  throw ErrorClass( eclass.errormsg);
4668  }
4669 }//setObjectives
4670 
4671 
4673 {
4674  if(number < 0) return false;
4676  if(number == 0)
4677  {
4680  return true;
4681  }
4683  if(instanceData->constraints->con == 0 )
4684  {
4685  instanceData->constraints->con = new Constraint*[number];
4686  }
4687  return true;
4688 }//setConstraintNumber
4689 
4690 bool OSInstance::addConstraint(int index, string name, double lowerBound, double upperBound, double constant)
4691 {
4692  instanceData->constraints->con[ index] = new Constraint();
4693  if(index < 0 || instanceData->constraints->numberOfConstraints <= 0 || index >= instanceData->constraints->numberOfConstraints) return false;
4694  instanceData->constraints->con[ index]->name = name;
4695  if(lowerBound != -OSDBL_MAX && lowerBound != -OSDBL_MAX) instanceData->constraints->con[ index]->lb = lowerBound;
4696  if(upperBound != OSDBL_MAX && upperBound != OSDBL_MAX)instanceData->constraints->con[ index]->ub = upperBound;
4697  instanceData->constraints->con[ index]->constant = constant;
4698  return true;
4699 }//addConstraint
4700 
4701 
4702 bool OSInstance::setConstraints(int number, string* names, double* lowerBounds, double* upperBounds, double* constants)
4703 {
4704  if(number < 0) return false;
4705  if(number == 0)
4706  {
4707  return true;
4708  }
4709  try
4710  {
4711 
4712  if(instanceData->constraints == NULL)
4713  {
4714  throw ErrorClass("there is no constraints object");
4715  }
4717  {
4718  throw ErrorClass("input number of constraints not equal to number in class");
4719  }
4720  int i = 0;
4721  for(i = 0; i < number; i++)
4722  {
4723  instanceData->constraints->con[i] = new Constraint();
4724  }
4725  if(names != NULL)
4726  {
4727  for(i = 0; i < number; i++) instanceData->constraints->con[i]->name = names[i];
4728  }
4729  if(lowerBounds != NULL)
4730  {
4731  for(i = 0; i < number; i++)
4732  {
4733  if(lowerBounds[i] != -OSDBL_MAX && lowerBounds[i] != -OSDBL_MAX)instanceData->constraints->con[i]->lb = lowerBounds[i];
4734  }
4735  }
4736  if(upperBounds != NULL)
4737  {
4738  for(i = 0; i < number; i++)
4739  {
4740  if(upperBounds[i] != OSDBL_MAX && upperBounds[i] != OSDBL_MAX)instanceData->constraints->con[i]->ub = upperBounds[i];
4741  }
4742  }
4743  if(constants != NULL)
4744  {
4745  for(i = 0; i < number; i++) instanceData->constraints->con[i]->constant = constants[i];
4746  }
4747  return true;
4748  }
4749  catch(const ErrorClass& eclass)
4750  {
4751  throw ErrorClass( eclass.errormsg);
4752  }
4753 }//setConstraints
4754 
4755 bool OSInstance::setLinearConstraintCoefficients(int numberOfValues, bool isColumnMajor,
4756  double* values, int valuesBegin, int valuesEnd,
4757  int* indexes, int indexesBegin, int indexesEnd,
4758  int* starts, int startsBegin, int startsEnd)
4759 {
4760  if(numberOfValues < 0) return false;
4763  if(numberOfValues == 0) return true;
4764  if((values == 0 ) ||
4765  (valuesBegin < 0 || (valuesEnd - valuesBegin + 1) != numberOfValues) ||
4766  (indexes == 0) ||
4767  (indexesBegin < 0 || (indexesEnd - indexesBegin + 1) != numberOfValues) ||
4768  (starts == 0 ) ||
4769  (startsBegin < 0 || startsBegin >= startsEnd)) return false;
4771 
4772  //starts
4775  else
4778 
4779  instanceData->linearConstraintCoefficients->start->el = (starts+startsBegin);
4780  instanceData->linearConstraintCoefficients->start->numberOfEl = startsEnd - startsBegin + 1;
4781  instanceData->linearConstraintCoefficients->iNumberOfStartElements = startsEnd - startsBegin + 1;
4782 
4783  //values
4786  else
4789 
4790  instanceData->linearConstraintCoefficients->value->el = (values+valuesBegin);
4792 
4793  //indexes
4794  if(isColumnMajor)
4795  {
4798  else
4801 
4802  instanceData->linearConstraintCoefficients->rowIdx->el = (indexes+indexesBegin);
4804  }
4805  else
4806  {
4809  else
4812 
4813  instanceData->linearConstraintCoefficients->colIdx->el = (indexes+indexesBegin);
4815  }
4816  return true;
4817 }//setLinearConstraintCoefficients
4818 
4819 
4820 bool OSInstance::copyLinearConstraintCoefficients(int numberOfValues, bool isColumnMajor,
4821  double* values, int valuesBegin, int valuesEnd,
4822  int* indexes, int indexesBegin, int indexesEnd,
4823  int* starts, int startsBegin, int startsEnd)
4824 {
4825  if (numberOfValues < 0) return false;
4828  if (numberOfValues == 0) return true;
4829  if ((values == 0 ) ||
4830  (valuesBegin < 0 || (valuesEnd - valuesBegin + 1) != numberOfValues) ||
4831  (indexes == 0) ||
4832  (indexesBegin < 0 || (indexesEnd - indexesBegin + 1) != numberOfValues) ||
4833  (starts == 0 ) ||
4834  (startsBegin < 0 || startsBegin >= startsEnd)) return false;
4836  int i = 0;
4837  int k;
4838 
4839  //starts
4842  else
4844 
4845  instanceData->linearConstraintCoefficients->start->el = new int[startsEnd - startsBegin + 1];
4846  k = 0;
4847  for(i = startsBegin; i <= startsEnd; i++)
4848  {
4850  k++;
4851  }
4852 
4853  instanceData->linearConstraintCoefficients->start->numberOfEl = startsEnd - startsBegin + 1;
4854 
4855  //values
4858  else
4860 
4861  instanceData->linearConstraintCoefficients->value->el = new double[numberOfValues];
4862  k = 0;
4863  for(i = valuesBegin; i <= valuesEnd; i++)
4864  {
4866  k++;
4867  }
4869 
4870  //indexes
4871  if(isColumnMajor)
4872  {
4875  else
4877 
4878  instanceData->linearConstraintCoefficients->rowIdx->el = new int[numberOfValues];
4879  k = 0;
4880  for(i = indexesBegin; i <= indexesEnd; i++)
4881  {
4883  k++;
4884  }
4886  }
4887  else
4888  {
4891  else
4893 
4894  instanceData->linearConstraintCoefficients->colIdx->el = new int[numberOfValues];
4895  k = 0;
4896  for(i = indexesBegin; i <= indexesEnd; i++)
4897  {
4899  k++;
4900  }
4902  }
4903  return true;
4904 }//copyLinearConstraintCoefficients
4905 
4906 
4908 {
4909  if (nq < 0)
4910  throw ErrorClass("number of quadratic terms cannot be negative");
4911  if (instanceData == NULL) instanceData = new InstanceData();
4912  if (instanceData->quadraticCoefficients == NULL)
4916  return true;
4917 }//setNumberOfQuadraticTerms
4918 
4919 
4921  int* rowIndexes, int* varOneIndexes, int* varTwoIndexes,
4922  double* coefficients, int begin, int end)
4923 {
4924  if(number < 0) return false;
4925  if(number != (end - begin) + 1) return false;
4926  if(number == 0)
4927  {
4929  return true;
4930  }
4931  if( (rowIndexes == 0) ||
4932  (varOneIndexes == 0) ||
4933  (varTwoIndexes == 0) ||
4934  (coefficients == 0) ) return false;
4935  if (instanceData->quadraticCoefficients == NULL)
4937 
4939  int i = 0;
4940 
4943 
4945  for(i = 0; i < number; i++) instanceData->quadraticCoefficients->qTerm[i] = new QuadraticTerm();
4946  int k = 0;
4947  for(i = begin; i <= end; i++)
4948  {
4949  instanceData->quadraticCoefficients->qTerm[k]->idx = rowIndexes[i];
4950  instanceData->quadraticCoefficients->qTerm[k]->idxOne = varOneIndexes[i];
4951  instanceData->quadraticCoefficients->qTerm[k]->idxTwo = varTwoIndexes[i];
4952  instanceData->quadraticCoefficients->qTerm[k]->coef = coefficients[i];
4953  k++;
4954  }
4955  return true;
4956 }//setQuadraticCoefficients
4957 
4958 bool OSInstance::setQuadraticTermsInNonlinearExpressions(int numQPTerms, int* rowIndexes, int* varOneIndexes, int* varTwoIndexes, double* coefficients)
4959 {
4961  instanceData->nonlinearExpressions->nl = new Nl*[ numQPTerms ];
4962  // define the vectors
4963  OSnLNode *nlNodePoint;
4964  OSnLNodeVariable *nlNodeVariablePoint;
4965  std::vector<ExprNode*> nlNodeVec;
4966  //
4967  //
4968  int i;
4969  for(i = 0; i < numQPTerms; i++)
4970  {
4971  instanceData->nonlinearExpressions->nl[ i] = new Nl();
4972  instanceData->nonlinearExpressions->nl[ i]->idx = rowIndexes[ i];
4974  // create a variable nl node for x0
4975  nlNodeVariablePoint = new OSnLNodeVariable();
4976  nlNodeVariablePoint->idx = varOneIndexes[ i];
4977  // give this variable the coefficient
4978  nlNodeVariablePoint->coef = coefficients[ i];
4979  nlNodeVec.push_back( nlNodeVariablePoint);
4980  // create the nl node for x1
4981  nlNodeVariablePoint = new OSnLNodeVariable();
4982  nlNodeVariablePoint->idx = varTwoIndexes[ i];
4983  nlNodeVec.push_back( nlNodeVariablePoint);
4984  // create the nl node for *
4985  nlNodePoint = new OSnLNodeTimes();
4986  nlNodeVec.push_back( (OSnLNode*)nlNodePoint);
4987  // the vectors are in postfix format
4988  // now the expression tree
4990  ((OSnLNode*)nlNodeVec[ 0])->createExpressionTreeFromPostfix( nlNodeVec);
4991  nlNodeVec.clear();
4992  }
4993  return true;
4994 }//setQuadraticTermsInNonlinearExpressions
4995 
4997 {
4998  if(nexpr < 0) return false;
4999 
5000  if(nexpr == 0)
5001  {
5003  return true;
5004  }
5005 
5006  if (instanceData->nonlinearExpressions == NULL)
5009  instanceData->nonlinearExpressions->nl = new Nl*[nexpr];
5010 
5011  for (int i=0; i < nexpr; i++)
5012  {
5013  instanceData->nonlinearExpressions->nl[i] = new Nl();
5014  instanceData->nonlinearExpressions->nl[i]->idx = root[i]->idx;
5017  = (OSnLNode*)root[i]->osExpressionTree->m_treeRoot->copyNodeAndDescendants();
5018  }
5019  return true;
5020 }//setNonlinearExpressions
5021 
5023 {
5024  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
5025  if( m_bNonLinearStructuresInitialized == true) return true;
5026  if( m_bProcessVariables == false) processVariables();
5027  if( m_bProcessObjectives == false) processObjectives();
5028  if( m_bProcessConstraints == false) processConstraints();
5032  // get all of the expression trees
5034  // before proceeding get a copy of the map of the Expression Trees
5036  // now create all of the variable maps for each expression tree
5037  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
5038  {
5039  (posMapExpTree->second)->getVariableIndicesMap() ;
5040  }
5041  // add the quadratic terms if necessary
5043  // now get the map of all nonlinear variables
5046  m_mdConstraintFunctionValues = new double[ this->getConstraintNumber()];
5047  m_mdObjectiveFunctionValues = new double[ this->getObjectiveNumber()];
5048  //m_mdObjGradient = new double[ this->instanceData->variables->numberOfVariables];
5050  m_bProcessVariables = true;
5051  m_bProcessObjectives = true;
5052  m_bProcessConstraints = true;
5055  return true;
5056 }
5057 
5059 {
5060  // it is important that this method NOT get called twice -- if
5061  // there are linear terms in <linearConstraintCoefficients> that
5062  // also appear in <nonlinearExpressions> then they will keep getting added
5063  // to the modified expession tree with each call to this method
5064 #ifndef NDEBUG
5066  "in getJacobianSparsityPattern");
5067 #endif
5068  if( m_bSparseJacobianCalculated == true) return m_sparseJacMatrix;
5069  // determine if we are in column or row major
5071  // make sure the data structures have been inialized
5073  try
5074  {
5075  if( m_bColumnMajor == true)
5076  {
5077  if( getSparseJacobianFromColumnMajor( ) == false) throw ErrorClass("An error occurred in getSpareJacobianFromColumnMajor");
5078  }
5079  else
5080  {
5081  if( getSparseJacobianFromRowMajor( ) == false) throw ErrorClass("An error occurred in getSpareJacobianFromRowMajor");
5082  }
5083  }
5084  catch(const ErrorClass& eclass)
5085  {
5086  throw ErrorClass( eclass.errormsg);
5087  }
5088  // now fill in the arrays of the sparseJacMatrix
5090  // we point to memory already created so don't
5091  // destroy during garbage collection
5099  return m_sparseJacMatrix;
5100 }//getJacobianSparsityPattern
5101 
5102 bool OSInstance::addQTermsToExressionTree() // obsolescent --- replaced by addQTermsToExpressionTree
5103 {
5104  return addQTermsToExpressionTree();
5105 }
5106 
5108 {
5109  std::ostringstream outStr;
5110  int i, k, idx;
5111  // get the number of qTerms
5113  if(numQTerms <= 0 || m_bQTermsAdded == true) return true;
5114  OSnLNodeVariable* nlNodeVariableOne;
5115  OSnLNodeVariable* nlNodeVariableTwo;
5116  OSnLNodeTimes* nlNodeTimes;
5117  OSnLNodePlus* nlNodePlus;
5118  ScalarExpressionTree* expTree;
5120 #ifndef NDEBUG
5121  //std::cout << "PROCESSING QUADRATIC TERMS" << std::endl;
5122  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "PROCESSING QUADRATIC TERMS");
5123 #endif
5124  for(i = 0; i < numQTerms; i++)
5125  {
5126  idx = m_quadraticTerms->rowIndexes[ i];
5127  //std::cout << "PROCESSING QTERM = " << i <<std::endl;
5128 #ifndef NDEBUG
5129  outStr.str("");
5130  outStr.clear();
5131  outStr << "PROCESSING QTERM " << i << std::endl;
5133 #endif
5134  // see if row idx is in the expression tree
5135  if( m_mapExpressionTreesMod.find( idx) != m_mapExpressionTreesMod.end() )
5136  {
5137  // row idx is in the expression tree
5138  // add the qTerm in row idx to the expression tree
5139  // define two new OSnLVariable nodes, an OSnLnodeTimes, and OSnLnodePlus
5140  nlNodeVariableOne = new OSnLNodeVariable();
5141  nlNodeVariableOne->idx = m_quadraticTerms->varOneIndexes[ i];
5142  // see if the variable indexed by nlNodeVariableOne->idx is in the expression tree for row idx
5143  // if not, add to mapVarIdx
5144  expTree = m_mapExpressionTreesMod[ idx];
5145  if( expTree->m_bIndexMapGenerated == false) expTree->getVariableIndicesMap();
5146  if( (*expTree->mapVarIdx).find( nlNodeVariableOne->idx) == (*expTree->mapVarIdx).end() )
5147  {
5148  // add placeholder to map
5149  (*expTree->mapVarIdx)[ nlNodeVariableOne->idx] = 1;
5150 #ifndef NDEBUG
5151  outStr.str("");
5152  outStr.clear();
5153  outStr << "ADDED THE FOLLOWING VARIABLE TO THE MAP: " << nlNodeVariableOne->idx << std::endl;
5155 #endif
5156  }
5157  nlNodeVariableOne->coef = m_quadraticTerms->coefficients[ i];
5158  nlNodeVariableTwo = new OSnLNodeVariable();
5159  nlNodeVariableTwo->idx = m_quadraticTerms->varTwoIndexes[ i];
5160  // see if the variable indexed by nlNodeVariableTwo->idx is in the expression tree for row idx
5161  // if not, add to mapVarIdx
5162  if( (*expTree->mapVarIdx).find( nlNodeVariableTwo->idx) == (*expTree->mapVarIdx).end() )
5163  {
5164  // add to map
5165  k = (*expTree->mapVarIdx).size();
5166  (*expTree->mapVarIdx)[ nlNodeVariableTwo->idx] = k + 1;
5167 #ifndef NDEBUG
5168  outStr.str("");
5169  outStr.clear();
5170  outStr << "ADDED THE FOLLOWING VARIABLE TO THE MAP" << nlNodeVariableTwo->idx << std::endl;
5172 #endif
5173  }
5174  nlNodeVariableTwo->coef = 1.;
5175  // now multiply the two new variable nodes together
5176  nlNodeTimes = new OSnLNodeTimes();
5177  nlNodeTimes->m_mChildren[ 0] = nlNodeVariableOne;
5178  nlNodeTimes->m_mChildren[ 1] = nlNodeVariableTwo;
5179  // now add the result to the expression tree
5180  nlNodePlus = new OSnLNodePlus();
5181  nlNodePlus->m_mChildren[ 0] = (OSnLNode*)expTree->m_treeRoot;
5182  nlNodePlus->m_mChildren[ 1] = nlNodeTimes;
5183  //expTree = new ScalarExpressionTree();
5184  expTree->m_treeRoot = nlNodePlus ;
5185  // get rid of old variable map
5186  if(expTree->m_bIndexMapGenerated == true)
5187  {
5188  delete expTree->mapVarIdx;
5189  expTree->mapVarIdx = NULL;
5190  expTree->m_bIndexMapGenerated = false;
5191  }
5192  //expTree->m_bIndexMapGenerated = false;
5193  //m_mapExpressionTreesMod[ idx ] = expTree;
5194  //expTree->mapVarIdx = m_mapExpressionTreesMod[ idx]->mapVarIdx;
5195  }
5196  else
5197  {
5198  // create the quadratic expression to add to the expression tree
5199  nlNodeVariableOne = new OSnLNodeVariable();
5200  nlNodeVariableOne->idx = m_quadraticTerms->varOneIndexes[ i];
5201  nlNodeVariableOne->coef = m_quadraticTerms->coefficients[ i];
5202  nlNodeVariableTwo = new OSnLNodeVariable();
5203  nlNodeVariableTwo->idx = m_quadraticTerms->varTwoIndexes[ i];
5204  nlNodeVariableTwo->coef = 1.;
5205  // now multiply the two new variable nodes together
5206  nlNodeTimes = new OSnLNodeTimes();
5207  nlNodeTimes->m_mChildren[ 0] = nlNodeVariableOne;
5208  nlNodeTimes->m_mChildren[ 1] = nlNodeVariableTwo;
5209  // create a new expression tree corresponding to row idx.
5210  expTree = new ScalarExpressionTree();
5211  expTree->m_treeRoot = nlNodeTimes ;
5212  expTree->mapVarIdx = expTree->getVariableIndicesMap();
5213  m_mapExpressionTreesMod[ idx ] = expTree;
5214  if(idx < 0)
5215  {
5218  }
5219  else
5220  {
5223  }
5224 #ifndef NDEBUG
5225  outStr.str("");
5226  outStr.clear();
5227  outStr << "NUMBER OF EXPRESSION TREES = " << m_mapExpressionTreesMod.size() <<std::endl;
5228  outStr << "NUMBER OF NONLINEAR OBJECTIVES = " << getNumberOfNonlinearObjectives() <<std::endl;
5230 #endif
5231  }
5232  // if there were no nonlinear terms make this the expression tree
5234  m_bQTermsAdded =true;
5235  }
5236  return true;
5237 } //addQTermsToExpressionTree
5238 
5239 
5241 {
5242  if(number < 0) return false;
5243  if(instanceData->matrices == NULL) instanceData->matrices = new Matrices();
5244  if(number == 0)
5245  {
5247  instanceData->matrices->matrix = NULL;
5248  return true;
5249  }
5251  instanceData->matrices->matrix = new OSMatrix*[number];
5252  return true;
5253 }//setMatrixNumber
5254 
5255 bool OSInstance::addMatrix(int arrayIndex, std::string name, int numberOfRows, int numberOfColumns,
5256  ENUM_MATRIX_SYMMETRY symmetry, ENUM_MATRIX_TYPE matrixType,
5257  unsigned int inumberOfChildren, MatrixNode **m_mChildren)
5258 {
5259  if (instanceData->matrices->numberOfMatrices <= 0) return false;
5260  if (arrayIndex < 0 || arrayIndex > instanceData->matrices->numberOfMatrices) return false;
5261  if (instanceData->matrices->matrix == NULL) return false;
5262  instanceData->matrices->matrix[arrayIndex] = new OSMatrix();
5263  return instanceData->matrices->matrix[arrayIndex]->setMatrix(name,numberOfRows,numberOfColumns,symmetry,
5264  matrixType,inumberOfChildren,m_mChildren);
5265 }//addMatrix
5266 
5268 {
5269  if (number < 0) return false;
5270  if (instanceData->cones == NULL) instanceData->cones = new Cones();
5271  instanceData->cones->numberOfCones = number;
5272 
5273  if (number == 0)
5274  instanceData->cones->cone = NULL;
5275  else
5276  instanceData->cones->cone = new Cone*[number];
5277  return true;
5278 }//setConeNumber
5279 
5280 bool OSInstance::addCone(int arrayIndex, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType,
5281  std::string name, int numberOfOtherIndexes, int* otherIndexes)
5282 {
5283  if (instanceData->cones->numberOfCones <= 0) return false;
5284  if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
5285  if (instanceData->cones->cone == NULL) return false;
5286 
5287  switch (coneType)
5288  {
5289 
5291  instanceData->cones->cone[arrayIndex] = new NonnegativeCone();
5292  ((NonnegativeCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
5293  ((NonnegativeCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
5294  ((NonnegativeCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
5295  ((NonnegativeCone*)instanceData->cones->cone[arrayIndex])->name = name;
5296  ((NonnegativeCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
5297  ((NonnegativeCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
5298  break;
5300  instanceData->cones->cone[arrayIndex] = new NonpositiveCone();
5301  ((NonpositiveCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
5302  ((NonpositiveCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
5303  ((NonpositiveCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
5304  ((NonpositiveCone*)instanceData->cones->cone[arrayIndex])->name = name;
5305  ((NonpositiveCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
5306  ((NonpositiveCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
5307  break;
5309  instanceData->cones->cone[arrayIndex] = new CopositiveMatricesCone();
5310  ((CopositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
5311  ((CopositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
5312  ((CopositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
5313  ((CopositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->name = name;
5314  ((CopositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
5315  ((CopositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
5316  break;
5318  instanceData->cones->cone[arrayIndex] = new CompletelyPositiveMatricesCone();
5319  ((CompletelyPositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
5320  ((CompletelyPositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
5321  ((CompletelyPositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
5322  ((CompletelyPositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->name = name;
5323  ((CompletelyPositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes
5324  = numberOfOtherIndexes;
5325  ((CompletelyPositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
5326  break;
5327  default:
5328  return false;
5329  }
5330  return true;
5331 }//addCone --- nonnegative or nonpositive orthant, copositive matrices or completely positive matrices cone
5332 
5333 bool OSInstance::addCone(int arrayIndex, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType,
5334  std::string name, int numberOfComponents, int* components,
5335  int numberOfOtherIndexes, int* otherIndexes)
5336 {
5337  if (instanceData->cones->numberOfCones <= 0) return false;
5338  if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
5339  if (instanceData->cones->cone == NULL) return false;
5340 
5341  switch (coneType)
5342  {
5343  case ENUM_CONE_TYPE_product:
5344  instanceData->cones->cone[arrayIndex] = new ProductCone();
5345  ((ProductCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
5346  ((ProductCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
5347  ((ProductCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
5348  ((ProductCone*)instanceData->cones->cone[arrayIndex])->name = name;
5349  ((ProductCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
5350  ((ProductCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
5351 
5352  ((ProductCone*)instanceData->cones->cone[arrayIndex])->factors = new IntVector();
5353  ((ProductCone*)instanceData->cones->cone[arrayIndex])->factors->numberOfEl = numberOfComponents;
5354  ((ProductCone*)instanceData->cones->cone[arrayIndex])->factors->el = components;
5355  break;
5357  instanceData->cones->cone[arrayIndex] = new IntersectionCone();
5358  ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
5359  ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
5360  ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
5361  ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->name = name;
5362  ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
5363  ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
5364 
5365  ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->components = new IntVector();
5366  ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->components->numberOfEl = numberOfComponents;
5367  ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->components->el = components;
5368  break;
5369  default:
5370  return false;
5371  }
5372  return true;
5373 }//addCone -- product or intersection cone
5374 
5375 bool OSInstance::addCone(int arrayIndex, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType,
5376  std::string name, int referenceIdx, int numberOfOtherIndexes, int* otherIndexes)
5377 {
5378  if (instanceData->cones->numberOfCones <= 0) return false;
5379  if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
5380  if (instanceData->cones->cone == NULL) return false;
5381 
5382  switch (coneType)
5383 
5384  {
5385 /*
5386  case ENUM_CONE_TYPE_dual:
5387  instanceData->cones->cone[arrayIndex] = new DualCone();
5388  ((DualCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
5389  ((DualCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
5390  ((DualCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
5391  ((DualCone*)instanceData->cones->cone[arrayIndex])->name = name;
5392  ((DualCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
5393  ((DualCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
5394  ((DualCone*)instanceData->cones->cone[arrayIndex])->referenceConeIdx = referenceIdx;
5395  break;
5396  case ENUM_CONE_TYPE_polar:
5397  instanceData->cones->cone[arrayIndex] = new PolarCone();
5398  ((PolarCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
5399  ((PolarCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
5400  ((PolarCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
5401  ((PolarCone*)instanceData->cones->cone[arrayIndex])->name = name;
5402  ((PolarCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
5403  ((PolarCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
5404  ((PolarCone*)instanceData->cones->cone[arrayIndex])->referenceConeIdx = referenceIdx;
5405  break;
5406 */
5408  instanceData->cones->cone[arrayIndex] = new PolyhedralCone();
5409  ((PolyhedralCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
5410  ((PolyhedralCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
5411  ((PolyhedralCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
5412  ((PolyhedralCone*)instanceData->cones->cone[arrayIndex])->name = name;
5413  ((PolyhedralCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
5414  ((PolyhedralCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
5415  ((PolyhedralCone*)instanceData->cones->cone[arrayIndex])->referenceMatrixIdx = referenceIdx;
5416  break;
5417  default:
5418  return false;
5419  }
5420 
5421  return true;
5422 }//addCone -- dual, polar or polyhedral cone
5423 
5424 bool OSInstance::addCone(int arrayIndex, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType,
5425  std::string name, std::string semidefiniteness, int numberOfOtherIndexes, int* otherIndexes)
5426 {
5427  if (instanceData->cones->numberOfCones <= 0) return false;
5428  if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
5429  if (instanceData->cones->cone == NULL) return false;
5430 
5431  if (coneType == ENUM_CONE_TYPE_semidefinite)
5432  {
5433  instanceData->cones->cone[arrayIndex] = new SemidefiniteCone();
5434  ((SemidefiniteCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
5435  ((SemidefiniteCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
5436  ((SemidefiniteCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
5437  ((SemidefiniteCone*)instanceData->cones->cone[arrayIndex])->name = name;
5438  ((SemidefiniteCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
5439  ((SemidefiniteCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
5440  ((SemidefiniteCone*)instanceData->cones->cone[arrayIndex])->semidefiniteness = semidefiniteness;
5441  return true;
5442  }
5443  else
5444  return false;
5445 }//addCone --- semidefinite cone
5446 
5447 bool OSInstance::addCone(int arrayIndex, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType,
5448  std::string name, int distortionMatrixIdx, double normFactor, int axisDirection,
5449  int numberOfOtherIndexes, int* otherIndexes)
5450 {
5451  if (instanceData->cones->numberOfCones <= 0) return false;
5452  if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
5453  if (instanceData->cones->cone == NULL) return false;
5454 
5455  if (coneType == ENUM_CONE_TYPE_quadratic)
5456  {
5457  instanceData->cones->cone[arrayIndex] = new QuadraticCone();
5458  ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
5459  ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
5460  ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
5461  ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->name = name;
5462  ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
5463  ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
5464  ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->distortionMatrixIdx = distortionMatrixIdx;
5465  ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->normScaleFactor = normFactor;
5466  ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->axisDirection = axisDirection;
5467  return true;
5468  }
5469  else
5470  return false;
5471 }//addCone -- quadratic cone
5472 
5473 bool OSInstance::addCone(int arrayIndex, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType,
5474  std::string name, int distortionMatrixIdx, double normFactor, int firstAxisDirection,
5475  int secondAxisDirection, int numberOfOtherIndexes, int* otherIndexes)
5476 {
5477  if (instanceData->cones->numberOfCones <= 0) return false;
5478  if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
5479  if (instanceData->cones->cone == NULL) return false;
5480 
5481  if (instanceData->cones->numberOfCones <= 0) return false;
5482  if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
5483  if (instanceData->cones->cone == NULL) return false;
5484 
5485  if (coneType == ENUM_CONE_TYPE_rotatedQuadratic)
5486  {
5487  instanceData->cones->cone[arrayIndex] = new RotatedQuadraticCone();
5488  ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
5489  ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
5490  ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
5491  ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->name = name;
5492  ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
5493  ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
5494  ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->distortionMatrixIdx = distortionMatrixIdx;
5495  ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->normScaleFactor = normFactor;
5496  ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->firstAxisDirection = firstAxisDirection;
5497  ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->secondAxisDirection = secondAxisDirection;
5498  return true;
5499  }
5500  else
5501  return false;
5502 }//addCone -- rotated quadratic cone
5503 
5504 bool OSInstance::addCone(int arrayIndex, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType,
5505  std::string name, int distortionMatrixIdx, double normFactor, int axisDirection, double pNorm,
5506  int numberOfOtherIndexes, int* otherIndexes)
5507 {
5508  if (instanceData->cones->numberOfCones <= 0) return false;
5509  if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
5510  if (instanceData->cones->cone == NULL) return false;
5511 
5512 /*
5513  if (coneType == ENUM_CONE_TYPE_normed)
5514  {
5515  instanceData->cones->cone[arrayIndex] = new NormedCone();
5516  ((NormedCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
5517  ((NormedCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
5518  ((NormedCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
5519  ((NormedCone*)instanceData->cones->cone[arrayIndex])->name = name;
5520  ((NormedCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
5521  ((NormedCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
5522  ((NormedCone*)instanceData->cones->cone[arrayIndex])->distortionMatrixIdx = distortionMatrixIdx;
5523  ((NormedCone*)instanceData->cones->cone[arrayIndex])->normFactor = normFactor;
5524  ((NormedCone*)instanceData->cones->cone[arrayIndex])->axisDirectionIndex = axisDirection;
5525  ((NormedCone*)instanceData->cones->cone[arrayIndex])->pNorm = pNorm;
5526  return true;
5527  }
5528  else
5529 */
5530  return false;
5531 }//addCone -- normed cone
5532 
5533 bool OSInstance::addCone(int arrayIndex, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType,
5534  std::string name, int maxDegree, int numberOfUB, double* ub, int numberOfLB, double* lb,
5535  int numberOfOtherIndexes, int* otherIndexes)
5536 {
5537  if (instanceData->cones->numberOfCones <= 0) return false;
5538  if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
5539  if (instanceData->cones->cone == NULL) return false;
5540 
5541  switch (coneType)
5542  {
5543 /*
5544  case ENUM_CONE_TYPE_nonnegativePolynomials:
5545  instanceData->cones->cone[arrayIndex] = new NonnegativePolynomialsCone();
5546  ((NonnegativePolynomialsCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
5547  ((NonnegativePolynomialsCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
5548  ((NonnegativePolynomialsCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
5549  ((NonnegativePolynomialsCone*)instanceData->cones->cone[arrayIndex])->name = name;
5550  ((NonnegativePolynomialsCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes
5551  = numberOfOtherIndexes;
5552  ((NonnegativePolynomialsCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
5553  ((NonnegativePolynomialsCone*)instanceData->cones->cone[arrayIndex])->maxDegree = maxDegree;
5554  ((NonnegativePolynomialsCone*)instanceData->cones->cone[arrayIndex])->maxDegree = maxDegree;
5555  ((NonnegativePolynomialsCone*)instanceData->cones->cone[arrayIndex])->maxDegree = maxDegree;
5556  ((NonnegativePolynomialsCone*)instanceData->cones->cone[arrayIndex])->maxDegree = maxDegree;
5557  ((NonnegativePolynomialsCone*)instanceData->cones->cone[arrayIndex])->maxDegree = maxDegree;
5558  break;
5559  case ENUM_CONE_TYPE_sumOfSquaresPolynomials:
5560  instanceData->cones->cone[arrayIndex] = new SumOfSquaresPolynomialsCone();
5561  ((SumOfSquaresPolynomialsCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
5562  ((SumOfSquaresPolynomialsCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
5563  ((SumOfSquaresPolynomialsCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
5564  ((SumOfSquaresPolynomialsCone*)instanceData->cones->cone[arrayIndex])->name = name;
5565  ((SumOfSquaresPolynomialsCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes
5566  = numberOfOtherIndexes;
5567  ((SumOfSquaresPolynomialsCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
5568  break;
5569  case ENUM_CONE_TYPE_moment:
5570  instanceData->cones->cone[arrayIndex] = new MomentCone();
5571  ((MomentCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
5572  ((MomentCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
5573  ((MomentCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
5574  ((MomentCone*)instanceData->cones->cone[arrayIndex])->name = name;
5575  ((MomentCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
5576  ((MomentCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
5577  break;
5578 */
5579  default:
5580  return false;
5581  }
5582  return true;
5583 }//addCone -- sum of squares polynomials, nonnegative polynomials or moment cone
5584 
5586 {
5587  std::string resultString = "";
5588  ostringstream outStr;
5589  outStr << "";
5590  int numCon;
5591  int numObj;
5592  int numVar;
5593  int i;
5594  numCon = this->getConstraintNumber();
5595  numObj = this->getObjectiveNumber();
5596  numVar = this->getVariableNumber();
5597  this->initForAlgDiff( );
5598  outStr << std::endl;
5599  std::string *objMaxOrMin = getObjectiveMaxOrMins();
5600  outStr << "Objectives:" << std::endl;
5601  for(i = 0; i < numObj; i++)
5602  {
5603  outStr << objMaxOrMin[i] << ' ';
5604  outStr << this->printModel(-i-1);
5605  }
5606  outStr << std::endl;
5607  outStr << "Constraints:" << std::endl;
5608  for(i = 0; i < numCon; i++)
5609  {
5610  outStr << this->printModel( i);
5611  }
5612 
5613  outStr << std::endl;
5614  outStr << "Variables:" << std::endl;
5615  if(m_bProcessVariables != true || bVariablesModified == true ) this->processVariables();
5616  for(i = 0; i < numVar; i++)
5617  {
5618  if(this->instanceData->variables->numberOfVariables > 0 && this->instanceData->variables->var[ i ]->name.size() > 0)
5619  {
5620  outStr << this->instanceData->variables->var[ i ]->name << ": ";
5621  }
5622 // else
5623  {
5624  outStr << "x_";
5625  outStr << i;
5626  }
5627 
5628 
5629  //outStr << "x_";
5630  //outStr << i;
5631  outStr << " Type = " ;
5632  outStr << m_mcVariableTypes[i];
5633  outStr << " Lower Bound = ";
5634  outStr << os_dtoa_format( m_mdVariableLowerBounds[i]) ;
5635  outStr << " Upper Bound = ";
5636  outStr << os_dtoa_format( m_mdVariableUpperBounds[i]) ;
5637  outStr << std::endl;
5638  }
5639 
5640  // if model was originally in column matrix form we need to delete the new
5641  // matrix stored by row
5642 
5643  //if( this->instanceData->linearConstraintCoefficients != NULL && this->instanceData->linearConstraintCoefficients->numberOfValues > 0){
5644  // if(m_bColumnMajor == true){// we now have a duplication
5645  // delete m_linearConstraintCoefficientsInRowMajor;
5646  // }
5647  //}
5648  return outStr.str() ;
5649 }//printModel( )
5650 
5651 
5652 std::string OSInstance::printModel(int rowIdx )
5653 {
5654  std::string resultString = "";
5655 
5656 
5657  ostringstream outStr;
5658  outStr << "";
5659  //loop over the constraints first;
5660  int j;
5661  int row_nonz = 0;
5662  int obj_nonz = 0;
5663  int varIdx = 0;
5664  bool addedLinearTerm = false;
5665 
5666  // initialize all of the necessary nonlinear stuff
5667  this->initForAlgDiff( );
5668 
5669  if( rowIdx >= 0)
5670  {
5671  if (rowIdx < this->getConstraintNumber())
5672  {
5673  outStr << this->getConstraintNames()[ rowIdx] ;
5674  outStr << " ";
5675  if( m_bProcessConstraints != true || bConstraintsModified == true) this->processConstraints() ;
5676  if( m_mdConstraintLowerBounds[ rowIdx] > -OSDBL_MAX)
5677  {
5679  {
5680  outStr << os_dtoa_format( m_mdConstraintLowerBounds[ rowIdx] );
5681  outStr << " <= ";
5682  }
5683  }
5684  //
5685  if(this->instanceData->linearConstraintCoefficients != NULL && this->instanceData->linearConstraintCoefficients->numberOfValues > 0)
5686  {
5690 
5691  for(j = 0; j < row_nonz; j++)
5692  {
5694 
5695  if(m_bSparseJacobianCalculated == false || (m_mapExpressionTreesMod.find( rowIdx) == m_mapExpressionTreesMod.end() ) ||
5696  ( (*m_mapExpressionTreesMod[ rowIdx]->mapVarIdx).find( varIdx) == (*m_mapExpressionTreesMod[ rowIdx]->mapVarIdx).end()) )
5697  {
5699  outStr << "*";
5700 
5701 // if(this->instanceData->variables->numberOfVariables > 0 && this->instanceData->variables->var[ varIdx ]->name.size() > 0)
5702 // {
5703 // outStr << this->instanceData->variables->var[ varIdx ]->name;
5704 // }
5705 // else
5706  {
5707  outStr << "x_";
5708  outStr << varIdx;
5709  }
5710 
5711 
5712  if( j < row_nonz - 1) outStr << " + ";
5713  addedLinearTerm = true;
5714  }
5715  }
5716  }
5717  }
5718  else
5719  return "row index not found; print command ignored\n";
5720  }
5721  else // process an objective function
5722  {
5723  if(m_bProcessObjectives != true || bObjectivesModified == true) this->processObjectives() ;
5724  int obj_idx = -rowIdx - 1;
5725  if (obj_idx < this->getObjectiveNumber())
5726  {
5727  obj_nonz = m_miNumberOfObjCoef[ obj_idx];
5728  for(j = 0; j < obj_nonz; j++)
5729  {
5730  outStr << os_dtoa_format( m_mObjectiveCoefficients[obj_idx]->values[j] );
5731  outStr << "*";
5732  outStr << "x_";
5733  outStr << m_mObjectiveCoefficients[obj_idx]->indexes[j] ;
5734  if( j < obj_nonz - 1) outStr << " + ";
5735  }
5736  }
5737  else
5738  return "row index not found; print command ignored\n";
5739  }
5740  if( this->getNonlinearExpressionTree( rowIdx) != NULL)
5741  {
5742  if( (addedLinearTerm == true) || (obj_nonz > 0) ) outStr << " + " ;
5743  outStr << getNonlinearExpressionTreeInInfix( rowIdx);
5744  //outStr << ")";
5745  }
5746 
5747  if( rowIdx >= 0)
5748  {
5749  if( m_bProcessConstraints != true ) this->processConstraints() ;
5750  if( m_mdConstraintUpperBounds[ rowIdx] < OSDBL_MAX)
5751  {
5753  {
5754  outStr << " <= ";
5755  }
5756  else
5757  {
5758  outStr << " = ";
5759  }
5760  outStr << os_dtoa_format( m_mdConstraintUpperBounds[ rowIdx] );
5761  }
5762  }
5763  outStr << std::endl;
5764  resultString = outStr.str();
5765  return resultString;
5766 }//printModel( rowIdx )
5767 
5768 
5769 double OSInstance::calculateFunctionValue(int idx, double *x, bool new_x)
5770 {
5771  try
5772  {
5773  int i, j;
5774  double dvalue = 0;
5775  if( m_binitForAlgDiff == false) initForAlgDiff();
5777  if(idx >= 0) // we have a constraint
5778  {
5779  // make sure the index idx is valid
5780  if( getConstraintNumber() <= idx ) throw
5781  ErrorClass("constraint index not valid in OSInstance::calculateFunctionValue");
5782  if( new_x == false) return *(m_mdConstraintFunctionValues + idx);
5783  // get the nonlinear part
5784  if( m_mapExpressionTreesMod.find( idx) != m_mapExpressionTreesMod.end() )
5785  {
5786  dvalue = m_mapExpressionTreesMod[ idx]->calculateFunction( x, new_x);
5787  }
5788  // now the linear part
5789  // be careful, loop over only the constant terms in sparseJacMatrix
5790  i = m_sparseJacMatrix->starts[ idx];
5791  j = m_sparseJacMatrix->starts[ idx + 1 ];
5792  while ( (i - m_sparseJacMatrix->starts[ idx]) < m_sparseJacMatrix->conVals[ idx] )
5793  {
5794  dvalue += m_sparseJacMatrix->values[ i]*x[ m_sparseJacMatrix->indexes[ i] ];
5795  i++;
5796  }
5797  // add in the constraint function constant
5798  dvalue += m_mdConstraintConstants[ idx ];
5799  return dvalue;
5800  }
5801  else // we have an objective function
5802  {
5803  // make sure the index idx is valid
5804  if( getObjectiveNumber() <= ( abs( idx) - 1) ) throw
5805  ErrorClass("objective function index not valid in OSInstance::calculateFunctionValue");
5806  if( new_x == false) return *(m_mdObjectiveFunctionValues + ( abs( idx) - 1));
5807  // get the nonlinear part
5808  if( m_mapExpressionTreesMod.find( idx) != m_mapExpressionTreesMod.end() )
5809  {
5810  dvalue = m_mapExpressionTreesMod[ idx]->calculateFunction( x, new_x);
5811  }
5812  // get linear part
5813  SparseVector **objCoef = getObjectiveCoefficients();
5814  SparseVector *obj = objCoef[ abs( idx) - 1];
5815  for(i = 0; i < obj->number; i++)
5816  {
5817  dvalue += x[ obj->indexes[i]]*(obj->values[ i]);
5818  }
5819  // add in the objective function constant
5820  dvalue += m_mdObjectiveConstants[ abs( idx) - 1 ];
5821  // get the coefficients for objective function idx
5822  *(m_mdObjectiveFunctionValues + ( abs( idx) - 1)) = dvalue;
5823  return *(m_mdObjectiveFunctionValues + ( abs( idx) - 1));
5824  }
5825  }
5826 
5827  catch(const ErrorClass& eclass)
5828  {
5829  throw ErrorClass( eclass.errormsg);
5830  }
5831 }//calculateFunctionValue
5832 
5833 
5834 double *OSInstance::calculateAllConstraintFunctionValues( double* x, double *objLambda, double *conLambda,
5835  bool new_x, int highestOrder)
5836 {
5837  try
5838  {
5839  if( new_x == true || (highestOrder > m_iHighestOrderEvaluated) )
5840  getIterateResults(x, objLambda, conLambda, new_x, highestOrder);
5841  }
5842  catch(const ErrorClass& eclass)
5843  {
5844  throw ErrorClass( eclass.errormsg);
5845  }
5847 }//calculateAllConstraintFunctionValues
5848 
5849 
5851 {
5852  try
5853  {
5855  if( new_x == false) return m_mdConstraintFunctionValues;
5856  int idx, numConstraints;
5857  numConstraints = getConstraintNumber();
5858  // loop over all constraints
5859  for(idx = 0; idx < numConstraints; idx++)
5860  {
5862  }
5863 
5864  }
5865  catch(const ErrorClass& eclass)
5866  {
5867  throw ErrorClass( eclass.errormsg);
5868  }
5870 }//end calculateAllConstraintFunctionValues
5871 
5872 
5873 double *OSInstance::calculateAllObjectiveFunctionValues( double* x, double *objLambda, double *conLambda,
5874  bool new_x, int highestOrder)
5875 {
5876  try
5877  {
5878  if( new_x == true || (highestOrder > m_iHighestOrderEvaluated) )
5879  getIterateResults(x, objLambda, conLambda, new_x, highestOrder);
5880  }
5881  catch(const ErrorClass& eclass)
5882  {
5883  throw ErrorClass( eclass.errormsg);
5884  }
5886 }//calculateAllObjectiveFunctionValues
5887 
5888 
5890 {
5891  try
5892  {
5894 
5895  if( new_x == false) return m_mdObjectiveFunctionValues;
5896  int idx, numObjectives;
5897  numObjectives = getObjectiveNumber();
5898  // loop over all objectives
5899  for(idx = 0; idx < numObjectives; idx++)
5900  {
5901  m_mdObjectiveFunctionValues[ idx] = calculateFunctionValue(-idx -1, x, new_x);
5902  }
5903  }
5904  catch(const ErrorClass& eclass)
5905  {
5906  throw ErrorClass( eclass.errormsg);
5907  }
5909 }//calculateAllObjectiveFunctionValues
5910 
5911 
5912 SparseJacobianMatrix *OSInstance::calculateAllConstraintFunctionGradients(double* x, double *objLambda, double *conLambda,
5913  bool new_x, int highestOrder)
5914 {
5915  try
5916 
5917  {
5918  if(highestOrder < 1 ) throw ErrorClass("When calling calculateAllConstraintFunctionGradients highestOrder should be 1 or 2");
5919 
5920  if( new_x == true || (highestOrder > m_iHighestOrderEvaluated) )
5921  getIterateResults(x, objLambda, conLambda, new_x, highestOrder);
5922  }//end try
5923  catch(const ErrorClass& eclass)
5924  {
5925  throw ErrorClass( eclass.errormsg);
5926  }
5927  return m_sparseJacMatrix;
5928 }//calculateAllConstraintFunctionGradients
5929 
5930 
5931 SparseVector *OSInstance::calculateConstraintFunctionGradient(double* x, double *objLambda, double *conLambda,
5932  int idx, bool new_x, int highestOrder)
5933 {
5934  try
5935  {
5936  if(highestOrder < 1 ) throw ErrorClass("When calling calculateConstraintFunctionGradient highestOrder should be 1 or 2");
5937  if(idx < 0 || idx >= instanceData->constraints->numberOfConstraints )
5938  throw ErrorClass("invalid index passed to calculateConstraintFunctionGrad");
5939  SparseVector *sp;
5940  sp = new SparseVector();
5941  sp->bDeleteArrays = true;
5942  int i;
5943  if( new_x == true || (highestOrder > m_iHighestOrderEvaluated) )
5944  getIterateResults(x, objLambda, conLambda, new_x, highestOrder);
5945  sp->number = m_miJacStart[ idx + 1] - m_miJacStart[ idx];
5946  sp->values = new double[ sp->number];
5947  sp->indexes = new int[ sp->number];
5948  for(i = 0; i < sp->number; i++)
5949  {
5950  sp->values[ i] = m_mdJacValue[ m_miJacStart[ idx] + i];
5951  sp->indexes[ i] = m_miJacIndex[ m_miJacStart[ idx] + i];
5952  }
5953  return sp;
5954  }
5955  catch(const ErrorClass& eclass)
5956  {
5957  throw ErrorClass( eclass.errormsg);
5958  }
5959 }//calculateConstraintFunctionGradient
5960 
5961 
5963 {
5964  try
5965  {
5966  if(idx < 0 || idx >= instanceData->constraints->numberOfConstraints )
5967  throw ErrorClass("invalid index passed to calculateConstraintFunctionGrad");
5968  SparseVector *sp;
5969  sp = new SparseVector();
5970  sp->bDeleteArrays = true;
5971  int i;
5972  if( new_x == true || (1 > m_iHighestOrderEvaluated) )
5973  getIterateResults(x, NULL, NULL, new_x, 1);
5974  sp->number = m_miJacStart[ idx + 1] - m_miJacStart[ idx];
5975  sp->values = new double[ sp->number];
5976  sp->indexes = new int[ sp->number];
5977  for(i = 0; i < sp->number; i++)
5978  {
5979  sp->values[ i] = m_mdJacValue[ m_miJacStart[ idx] + i];
5980  sp->indexes[i] = m_miJacIndex[ m_miJacStart[ idx] + i];
5981  }
5982  return sp;
5983  }
5984  catch(const ErrorClass& eclass)
5985  {
5986  throw ErrorClass( eclass.errormsg);
5987  }
5988 }//calculateConstraintFunctionGradient
5989 
5990 
5991 double **OSInstance::calculateAllObjectiveFunctionGradients(double* x, double *objLambda, double *conLambda,
5992  bool new_x, int highestOrder)
5993 {
5994  try
5995  {
5996  if(highestOrder < 1 ) throw ErrorClass("When calling calculateAllObjectiveFunctionGradients highestOrder should be 1 or 2");
5997  if( new_x == true || (highestOrder > m_iHighestOrderEvaluated) )
5998  {
5999  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
6000  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
6001  {
6002  if(posMapExpTree->first < 0) // this nonlinear expression indexes an objective function
6003  {
6004  m_mmdObjGradient[ abs( posMapExpTree->first) - 1 ] = calculateObjectiveFunctionGradient(x, objLambda, conLambda,
6005  posMapExpTree->first, new_x, highestOrder);
6006  }
6007  }
6008  }
6009  }
6010  catch(const ErrorClass& eclass)
6011  {
6012  throw ErrorClass( eclass.errormsg);
6013  }
6014  return m_mmdObjGradient;
6015 }// calculateAllObjectiveFunctionGradients
6016 
6017 double *OSInstance::calculateObjectiveFunctionGradient(double* x, double *objLambda, double *conLambda,
6018  int objIdx, bool new_x, int highestOrder)
6019 {
6020  /* if we are just doing an objective function gradient we should do a zero order forward sweep
6021  * and a reverse first order reverse sweep
6022  */
6023  try
6024  {
6025  if(highestOrder < 1 ) throw ErrorClass("When calling calculateObjectiveFunctionGradient highestOrder should be 1 or 2");
6026  if( new_x == true || (highestOrder > m_iHighestOrderEvaluated) )
6027  {
6028  int domainIdx = 0;
6029  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
6030  std::map<int, int>::iterator posVarIndexMap;
6031  int iHighestOrderEvaluatedStore;
6032  unsigned int i;
6033  iHighestOrderEvaluatedStore = m_iHighestOrderEvaluated;
6034  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
6035  {
6036  //kipp: modify for more than one obj
6037  if(posMapExpTree->first == objIdx)
6038  {
6039  if( new_x == true )
6040  {
6041  if( m_vdX.size() > 0) m_vdX.clear();
6042  for(posVarIndexMap = m_mapAllNonlinearVariablesIndex.begin(); posVarIndexMap != m_mapAllNonlinearVariablesIndex.end(); ++posVarIndexMap)
6043  {
6044  m_vdX.push_back( x[ posVarIndexMap->first]) ;
6045  }
6046  if( (m_bOSADFunIsCreated == false || m_bCppADMustReTape == true ) && (m_mapExpressionTreesMod.size() > 0) )
6047  {
6048  createOSADFun( m_vdX);
6049  }
6050  }
6051 
6052  if(( new_x == true ) || (m_iHighestOrderEvaluated < 0) )this->forwardAD(0, m_vdX);
6053 
6054  if(( new_x == true ) || (m_iHighestOrderEvaluated < 1) )
6055  {
6056  m_vdRangeUnitVec[ domainIdx] = 1.;
6058  for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
6059  {
6060  m_mmdObjGradient[ abs( objIdx) - 1 ][ m_miNonLinearVarsReverseMap[ i]] = m_vdYjacval[ i] +
6061  m_mmdDenseObjectiveCoefficients[ abs( objIdx) - 1][ m_miNonLinearVarsReverseMap[ i]];
6062  }
6063  }
6064  m_iHighestOrderEvaluated = iHighestOrderEvaluatedStore;
6065  m_vdRangeUnitVec[ domainIdx] = 0.;
6066  // exit the loop
6067  break;
6068  }
6069  domainIdx++;
6070  }
6071  }
6072  }
6073  catch(const ErrorClass& eclass)
6074  {
6075  throw ErrorClass( eclass.errormsg);
6076  }
6077  return m_mmdObjGradient[abs( objIdx) - 1];
6078 }//calculateObjectiveFunctionGradient
6079 
6080 
6081 double *OSInstance::calculateObjectiveFunctionGradient(double* x, int objIdx, bool new_x)
6082 {
6083  try
6084  {
6085  int domainIdx = 0;
6086  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
6087  std::map<int, int>::iterator posVarIndexMap;
6088  unsigned int i;
6089  int iHighestOrderEvaluatedStore;
6090  iHighestOrderEvaluatedStore = m_iHighestOrderEvaluated;
6091  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
6092  {
6093  if(posMapExpTree->first == objIdx)
6094  {
6095  if( new_x == true )
6096  {
6097  if( m_vdX.size() > 0) m_vdX.clear();
6098  for(posVarIndexMap = m_mapAllNonlinearVariablesIndex.begin(); posVarIndexMap != m_mapAllNonlinearVariablesIndex.end(); ++posVarIndexMap)
6099  {
6100  m_vdX.push_back( x[ posVarIndexMap->first]) ;
6101  }
6102  if( (m_bOSADFunIsCreated == false || m_bCppADMustReTape == true ) && (m_mapExpressionTreesMod.size() > 0) )
6103  {
6104  createOSADFun( m_vdX);
6105  }
6106  }
6107 
6108  if(( new_x == true ) || (m_iHighestOrderEvaluated < 0) ) this->forwardAD(0, m_vdX);
6109 
6110  if(( new_x == true ) || (m_iHighestOrderEvaluated < 1) )
6111  {
6112  m_vdRangeUnitVec[ domainIdx] = 1.;
6114  for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
6115  {
6116  m_mmdObjGradient[ abs( objIdx) - 1 ][ m_miNonLinearVarsReverseMap[ i]] = m_vdYjacval[ i] +
6117  m_mmdDenseObjectiveCoefficients[ abs( objIdx) - 1][ m_miNonLinearVarsReverseMap[ i]];
6118  }
6119  }
6120  m_iHighestOrderEvaluated = iHighestOrderEvaluatedStore;
6121  m_vdRangeUnitVec[ domainIdx] = 0.;
6122  // exit the loop
6123  break;
6124  }
6125  domainIdx++;
6126  }
6127  }
6128  catch(const ErrorClass& eclass)
6129  {
6130  throw ErrorClass( eclass.errormsg);
6131  }
6132  return m_mmdObjGradient[abs( objIdx) - 1];
6133 }//calculateObjectiveFunctionGradient
6134 
6135 SparseHessianMatrix *OSInstance::calculateLagrangianHessian( double* x, double *objLambda, double *conLambda,
6136  bool new_x, int highestOrder)
6137 {
6138  try
6139  {
6140  if(highestOrder != 2 ) throw ErrorClass("When calling calculateLagrangianHessian highestOrder should be 2");
6141  if( new_x == true || (highestOrder > m_iHighestOrderEvaluated) )
6142  {
6143  getIterateResults(x, objLambda, conLambda, new_x, highestOrder);
6144  }
6145  }
6146  catch(const ErrorClass& eclass)
6147  {
6148  throw ErrorClass( eclass.errormsg);
6149  }
6151 }//calculateLagrangianHessian
6152 
6154 {
6155  try
6156  {
6157  if(idx < -instanceData->objectives->numberOfObjectives || idx >= instanceData->constraints->numberOfConstraints )
6158  throw ErrorClass("invalid index passed to calculateHessian");
6159  double *objLambda = new double[ getObjectiveNumber() ];
6160  double *conLambda = new double[ getConstraintNumber() ];
6161  int i;
6162  // initialize all to zero
6163  for(i = 0; i < getObjectiveNumber(); i++)
6164  {
6165  objLambda[ i] = 0.0;
6166  }
6167  for(i = 0; i < getConstraintNumber(); i++)
6168  {
6169  conLambda[ i] = 0.0;
6170  }
6171  // see if we have the index of an objective function or a constraint
6172  // and make corresponding component 1.0
6173  if(idx < 0)
6174  {
6175  objLambda[ abs(idx) - 1] = 1.0;
6176  }
6177  else
6178  {
6179  conLambda[ idx] = 1.0;
6180  }
6181 
6182  if( new_x == true || (2 > m_iHighestOrderEvaluated) )
6183  {
6184  getIterateResults(x, objLambda, conLambda, new_x, 2);
6185  }
6186  delete[] objLambda;
6187  delete[] conLambda;
6188  }
6189  catch(const ErrorClass& eclass)
6190  {
6191  throw ErrorClass( eclass.errormsg);
6192  }
6194 }//calculateHessian
6195 
6196 
6198 {
6199  std::ostringstream outStr;
6200 
6201  // we assume column major matrix
6202  if( m_bColumnMajor == false) return false;
6203  int iNumRowStarts = getConstraintNumber() + 1;
6204  int i,j, iTemp;
6205  int iNumVariableStarts = getVariableNumber();
6206  int *start = NULL;
6207  int *index = NULL;
6208  double *value = NULL;
6209 
6210  if(this->instanceData->linearConstraintCoefficients != NULL)
6211  {
6215  }
6216  m_miJacStart = new int[ iNumRowStarts];
6218  OSnLNodePlus *nlNodePlus;
6219  OSnLNodeVariable *nlNodeVariable;
6220  ScalarExpressionTree *expTree = NULL;
6221  // now initialize starts and variable index maps
6222  for ( i = 0; i < iNumRowStarts; i++)
6223  {
6224  m_miJacStart [ i ] = 0;
6225  // map the variables in the nonlinear rows
6226  if( m_mapExpressionTreesMod.find( i) != m_mapExpressionTreesMod.end() )
6227  {
6228  // the following is equivalent to m_treeRoot->getVariableIndexMap( i);
6229  m_mapExpressionTreesMod[ i]->getVariableIndicesMap();
6230 
6231  }
6232  }
6233  // only execute the following code if there are linear constraint coefficients
6234  if (this->instanceData->linearConstraintCoefficients != NULL &&
6235  this->instanceData->linearConstraintCoefficients->numberOfValues > 0)
6236  {
6237  // i is indexing columns (variables) and j is indexing row numbers
6238  for (i = 0; i < iNumVariableStarts; i++)
6239  {
6240  for (j = start[i]; j < start[ i + 1 ]; j++)
6241  {
6242  // index[ j] is a row index, we have just found an occurance of row index[j]
6243  // therefore we increase by 1 (or push back) the start of the row indexed by index[j] + 1,
6244  // i.e. the start of the next row
6245  // check to see if variable i is linear/constant in the row index[ j]
6246  // if so, increment m_miJacStart[ index[j] + 1]
6247  //
6248  if( (m_mapExpressionTreesMod.find( index[ j]) != m_mapExpressionTreesMod.end() ) &&
6249  ( (*m_mapExpressionTreesMod[ index[ j]]->mapVarIdx).find( i) != (*m_mapExpressionTreesMod[ index[ j]]->mapVarIdx).end()) )
6250  {
6251  // variable i appears in the expression tree for row index[ j]
6252  // add the coefficient corresponding to variable i in row index[ j] to the expression tree
6253  // define a new OSnLVariable and OSnLnodePlus
6254  // don't add a zero
6255  if( value[j] > 0 || value[j] < 0)
6256  {
6257  expTree = m_mapExpressionTreesMod[ index[j] ];
6258  nlNodeVariable = new OSnLNodeVariable();
6259  nlNodeVariable->coef = value[ j];
6260  nlNodeVariable->idx = i;
6261  nlNodePlus = new OSnLNodePlus();
6262  nlNodePlus->m_mChildren[ 0] = m_mapExpressionTreesMod[ index[ j] ]->m_treeRoot;
6263  nlNodePlus->m_mChildren[ 1] = nlNodeVariable;
6264  expTree->m_treeRoot = nlNodePlus ;
6265  }
6266  }
6267  else
6268  {
6269  m_miJacStart[ index[j] + 1] ++;
6270  }
6271  }
6272  }
6273  }
6274  // at this point, m_miJacStart[ i] holds the number of columns with a linear/constant nonzero in row i - 1
6275  // we are not done with the start indices, if we are here, and we
6276  // knew the correct starting point of row i -1, the correct starting point
6277  // for row i is m_miJacStart[i] + m_miJacStart [i - 1]
6278  m_miJacStart[0] = 0;
6279  for (i = 1; i < iNumRowStarts; i++ )
6280  {
6281  m_miJacNumConTerms[ i - 1] = m_miJacStart[i];
6282  if( m_mapExpressionTreesMod.find( i - 1) != m_mapExpressionTreesMod.end() )
6283  {
6284  m_miJacStart[i] += (m_miJacStart[i - 1] + (*m_mapExpressionTreesMod[ i - 1]->mapVarIdx).size() );
6285  }
6286  else
6287  {
6288  m_miJacStart[i] += m_miJacStart[i - 1];
6289  }
6290  }
6291  // dimension miIndex and mdValue here
6292  m_iJacValueSize = m_miJacStart[ iNumRowStarts - 1];
6293  m_miJacIndex = new int[ m_iJacValueSize];
6294  m_mdJacValue = new double[ m_iJacValueSize ];
6295  // now get the values of the constant terms if there are any
6296  if (this->instanceData->linearConstraintCoefficients != NULL &&
6297  this->instanceData->linearConstraintCoefficients->numberOfValues > 0)
6298 
6299  {
6300  // loop over variables
6301  for (i = 0; i < iNumVariableStarts; i++)
6302  {
6303  // get row indices and values of the A matrix
6304  // kipp -- should we have a check to see if start[i+1] > start[i]
6305  for (j = start[i]; j < start[ i + 1 ]; j++)
6306  {
6307  // store this variable index in every row where the variable appears
6308  // however, don't store this as constant term if it appears in mapVarIdx
6309  if( (m_mapExpressionTreesMod.find( index[ j]) == m_mapExpressionTreesMod.end() ) ||
6310  ( (*m_mapExpressionTreesMod[ index[ j]]->mapVarIdx).find( i) == (*m_mapExpressionTreesMod[ index[ j]]->mapVarIdx).end()) )
6311  {
6312  iTemp = m_miJacStart[ index[j]];
6313  m_miJacIndex[ iTemp] = i;
6314  m_mdJacValue[ iTemp] = value[j];
6315  m_miJacStart[ index[j]]++;
6316  }
6317  }
6318  }
6319  }
6320  //
6321  std::map<int, int>::iterator posVarIdx;
6322  // m_miJacStart[ i] is now equal to the correct m_miJacStart[ i] + m_miJacNumConTerms[ i], so readjust
6323  for (i = 0; i < iNumRowStarts - 1; i++ )
6324  {
6325  m_miJacStart[ i] = m_miJacStart [ i] - m_miJacNumConTerms[ i] ;
6326  iTemp = m_miJacStart[ i] + m_miJacNumConTerms[ i];
6327  // if the row is in the list of expression trees read in indices and values
6328  if( m_mapExpressionTreesMod.find( i) != m_mapExpressionTreesMod.end() )
6329  {
6330  for(posVarIdx = (*m_mapExpressionTreesMod[ i]->mapVarIdx).begin(); posVarIdx
6331  != (*m_mapExpressionTreesMod[ i]->mapVarIdx).end(); ++posVarIdx)
6332  {
6333  m_miJacIndex[ iTemp] = posVarIdx->first;
6334  m_mdJacValue[ iTemp] = 0;
6335  iTemp++;
6336  }
6337  }
6338  }
6339 #ifndef NDEBUG
6340  outStr.str("");
6341  outStr.clear();
6342  outStr << "HERE ARE ROW STARTS:" << std::endl;
6343  for (i = 0; i < iNumRowStarts; i++ )
6344  {
6345  outStr << m_miJacStart[ i] << " ";
6346  }
6347  outStr << std::endl << std::endl;
6348  outStr << "HERE ARE VARIABLE INDICES:" << std::endl;
6349  for (i = 0; i < m_miJacStart[ iNumRowStarts - 1]; i++ )
6350  {
6351  outStr << m_miJacIndex[ i] << " ";
6352  }
6353  outStr << std::endl << std::endl;
6354  outStr << "HERE ARE VALUES:" << std::endl;
6355  for (i = 0; i < m_miJacStart[ iNumRowStarts - 1]; i++ )
6356  {
6357  outStr << m_mdJacValue[ i] << " ";
6358  }
6359  outStr << std::endl << std::endl;
6360 
6361  outStr << "HERE ARE NUMBER OF CONSTANT TERMS:" << std::endl;
6362  for (i = 0; i < iNumRowStarts - 1; i++ )
6363 
6364  {
6365  outStr << m_miJacNumConTerms[ i ] << " ";
6366  }
6367  outStr << std::endl << std::endl;
6369 #endif
6370  return true;
6371 }//getSparseJacobianFromColumnMajor
6372 
6373 
6375 {
6376  std::ostringstream outStr;
6377 
6378  // we assume row major matrix
6379  if( m_bColumnMajor == true) return false;
6380  int iNumJacRowStarts = getConstraintNumber() + 1;
6381  std::map<int, int>::iterator posVarIdx;
6382  int i,j, k;
6383  int *start = NULL;
6384  int *index = NULL;
6385  double *value = NULL;
6386 
6387  if (this->instanceData->linearConstraintCoefficients != NULL &&
6388  this->instanceData->linearConstraintCoefficients->numberOfValues > 0)
6389  {
6393  }
6394 
6395  m_miJacStart = new int[ iNumJacRowStarts];
6397  OSnLNodePlus *nlNodePlus;
6398  OSnLNodeVariable *nlNodeVariable;
6399  // now initialize starts and variable index maps
6400  for ( i = 0; i < iNumJacRowStarts; i++)
6401  {
6402  m_miJacStart [ i ] = 0;
6403  // map the variables in the nonlinear rows
6404  if( m_mapExpressionTreesMod.find( i) != m_mapExpressionTreesMod.end() )
6405  {
6406  // the following is equivalent to m_treeRoot->getVariableIndexMap( i);
6407  m_mapExpressionTreesMod[ i]->getVariableIndicesMap();
6408 
6409  }
6410  }
6411  int loopLimit = getConstraintNumber();
6412  // only execute the following code if there are linear constraint coefficients
6413  // determine the number of terms in constraint with constant partial derivative
6414  if (this->instanceData->linearConstraintCoefficients != NULL &&
6415  this->instanceData->linearConstraintCoefficients->numberOfValues > 0)
6416  {
6417  // i is indexing rows (constrains) and j is indexing column numbers
6418  for (i = 0; i < loopLimit; i++)
6419  {
6420  m_miJacNumConTerms[ i] = 0;
6421  for (j = start[i]; j < start[ i + 1 ]; j++)
6422  {
6423  // determine if variable index[j] appears in the Expression Tree for row i
6424  // if we pass if test below then variable i is in the expresssion tree and we add
6425  // the linear term to the expession tree
6426  if( (m_mapExpressionTreesMod.find( i) != m_mapExpressionTreesMod.end() ) &&
6427  ( (*m_mapExpressionTreesMod[ i]->mapVarIdx).find( index[ j]) != (*m_mapExpressionTreesMod[ i]->mapVarIdx).end()) )
6428  {
6429  // variable index[ j] appears in the expression tree for row i
6430  // add the coefficient corresponding to variable index[j] in row i to the expression tree
6431  // define a new OSnLVariable and OSnLnodePlus
6432  if(value[ j] > 0 || value[j] < 0)
6433  {
6434  nlNodeVariable = new OSnLNodeVariable();
6435  nlNodeVariable->coef = value[ j];
6436  nlNodeVariable->idx = index[ j];
6437  nlNodePlus = new OSnLNodePlus();
6438  nlNodePlus->m_mChildren[ 0] = m_mapExpressionTreesMod[ i ]->m_treeRoot;
6439  nlNodePlus->m_mChildren[ 1] = nlNodeVariable;
6440  m_mapExpressionTreesMod[ i ]->m_treeRoot = nlNodePlus;
6441  }
6442  }
6443  else
6444  {
6445  //the partial derivative of variable j in row i is constant
6446  m_miJacNumConTerms[ i]++;
6447  }
6448  }
6449  }
6450  }
6451  //
6452  m_miJacStart[0] = 0;
6453  for (i = 1; i < iNumJacRowStarts; i++ )
6454  {
6455  if( m_mapExpressionTreesMod.find( i - 1) != m_mapExpressionTreesMod.end() )
6456  {
6457  m_miJacStart[i] = m_miJacStart[i - 1] + (m_miJacNumConTerms[ i - 1] + (*m_mapExpressionTreesMod[ i - 1]->mapVarIdx).size() );
6458  }
6459  else
6460  {
6461  m_miJacStart[i] = m_miJacStart[i - 1] + m_miJacNumConTerms[ i - 1];
6462  }
6463  }
6464  // we know how many constant terms and size of arrays
6465  // dimension miIndex and mdValue here
6466  m_iJacValueSize = m_miJacStart[ iNumJacRowStarts - 1];
6467  m_miJacIndex = new int[ m_iJacValueSize];
6468  m_mdJacValue = new double[ m_iJacValueSize ];
6469  // now loop again and put in values and indices
6470  // first put in the constant terms
6471  if (this->instanceData->linearConstraintCoefficients != NULL &&
6472  this->instanceData->linearConstraintCoefficients->numberOfValues > 0)
6473  {
6474  for (i = 0; i < loopLimit; i++)
6475  {
6476  k = 0;
6477  for (j = start[i]; j < start[ i + 1 ]; j++)
6478  {
6479  if( (m_mapExpressionTreesMod.find( i) == m_mapExpressionTreesMod.end() ) ||
6480  ( (*m_mapExpressionTreesMod[ i]->mapVarIdx).find( index[ j]) == (*m_mapExpressionTreesMod[ i]->mapVarIdx).end()) )
6481  {
6482  m_miJacIndex[ m_miJacStart[i] + k ] = index[ j];
6483  m_mdJacValue[ m_miJacStart[i] + k ] = value[ j];
6484  k++;
6485  }
6486  }
6487  }
6488  }
6489  // put in terms from the modified nonlinear expression tree
6490  for (i = 0; i < loopLimit; i++ )
6491  {
6492  k = m_miJacStart[i] + m_miJacNumConTerms[ i ];
6493  // if the row is in the list of expression trees read in indices and values
6494  if( m_mapExpressionTreesMod.find( i) != m_mapExpressionTreesMod.end() )
6495  {
6496  for(posVarIdx = (*m_mapExpressionTreesMod[ i]->mapVarIdx).begin(); posVarIdx
6497  != (*m_mapExpressionTreesMod[ i]->mapVarIdx).end(); ++posVarIdx)
6498  {
6499  m_miJacIndex[ k] = posVarIdx->first;
6500  m_mdJacValue[ k] = 0;
6501  k++;
6502  }
6503  }
6504  }
6505 #ifndef NDEBUG
6506  outStr.str("");
6507  outStr.clear();
6508  outStr << "HERE ARE ROW STARTS:" << std::endl;
6509  for (i = 0; i < iNumJacRowStarts; i++ )
6510  {
6511  outStr << m_miJacStart[ i] << " ";
6512  }
6513  outStr << std::endl << std::endl;
6514  outStr << "HERE ARE VARIABLE INDICES:" << std::endl;
6515  for (i = 0; i < m_miJacStart[ iNumJacRowStarts - 1]; i++ )
6516  {
6517  outStr << m_miJacIndex[ i] << " ";
6518  }
6519  outStr << std::endl << std::endl;
6520  outStr << "HERE ARE VALUES:" << std::endl;
6521  for (i = 0; i < m_miJacStart[ iNumJacRowStarts - 1]; i++ )
6522  {
6523  outStr << m_mdJacValue[ i] << " ";
6524  }
6525  outStr << std::endl << std::endl;
6526 
6527  outStr << "HERE ARE NUMBER OF CONSTANT TERMS:" << std::endl;
6528  for (i = 0; i < iNumJacRowStarts - 1; i++ )
6529  {
6530  outStr << m_miJacNumConTerms[ i ] << " ";
6531  }
6532  outStr << std::endl << std::endl;
6534 #endif
6535  return true;
6536 }//getSparseJacobianFromRowMajor
6537 
6539 {
6541  // we calculate the Lagrangian for all the objectives and constraints
6542  // with nonlinear terms
6543  // first initialize everything for nonlinear work
6545  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
6546  OSnLNodeTimes* nlNodeTimes = NULL;
6547  OSnLNodeVariable* nlNodeVariable = NULL;
6548  OSnLNodeSum* nlNodeSum = NULL;
6549  int numChildren = 0;
6550  int rowIdx;
6551  // create the sum node
6552  nlNodeSum = new OSnLNodeSum();
6553  nlNodeSum->inumberOfChildren = m_mapExpressionTreesMod.size();
6554  nlNodeSum->m_mChildren = new OSnLNode*[ nlNodeSum->inumberOfChildren];
6555  // create and expression tree for the sum node
6557  m_LagrangianExpTree->m_treeRoot = nlNodeSum;
6558  // now create the children of the sum node
6559  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
6560  {
6561  // this variable is the Lagrange multiplier
6562  nlNodeVariable = new OSnLNodeVariable();
6563  nlNodeVariable->coef = 1.;
6564  // get the correct index --
6565  // for rowIdx = 0, ..., m - 1 set idx = numVar + rowIdx
6566  rowIdx = posMapExpTree->first;
6567  if(rowIdx >= 0)
6568  {
6569  nlNodeVariable->idx = instanceData->variables->numberOfVariables + rowIdx;
6570  }
6571  else
6572  {
6573  nlNodeVariable->idx = instanceData->variables->numberOfVariables +
6574  instanceData->constraints->numberOfConstraints + (abs(rowIdx) - 1);
6575  }
6576 
6577  // now create a times multiply the new variable times the root of the expression tree
6578  nlNodeTimes = new OSnLNodeTimes();
6579  nlNodeTimes->m_mChildren[ 0] = nlNodeVariable;
6580  nlNodeTimes->m_mChildren[ 1] = m_mapExpressionTreesMod[ posMapExpTree->first ]->m_treeRoot;
6581  // the times node is the new child
6582  nlNodeSum->m_mChildren[ numChildren] = nlNodeTimes;
6583  numChildren++;
6584  }
6585  // get a variable index map for the expression tree
6588  return m_LagrangianExpTree;
6589 }//getLagrangianExpTree
6590 
6592 {
6593  std::ostringstream outStr;
6594 
6596  // loop over the map of expression tree and get a unique listing of all variables
6597  // put these in the map m_mapAllNonlinearVariablesIndex
6598  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
6599  std::map<int, int>::iterator posVarIdx;
6600  ScalarExpressionTree *expTree;
6601  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
6602  {
6603  // get the index map for the expression tree
6604 
6605  expTree = posMapExpTree->second;
6606  if(expTree->m_bIndexMapGenerated == false)expTree->getVariableIndicesMap();
6607  for(posVarIdx = (*expTree->mapVarIdx).begin(); posVarIdx != (*expTree->mapVarIdx).end(); ++posVarIdx)
6608  {
6609  if( m_mapAllNonlinearVariablesIndex.find( posVarIdx->first) == m_mapAllNonlinearVariablesIndex.end() )
6610  {
6611  // add the variable to the Lagragian map
6612  m_mapAllNonlinearVariablesIndex[ posVarIdx->first] = 1;
6613  }
6614  }
6615  }
6617  // now order appropriately
6618  int kount = 0;
6619  for(posVarIdx = m_mapAllNonlinearVariablesIndex.begin(); posVarIdx !=m_mapAllNonlinearVariablesIndex.end(); ++posVarIdx)
6620  {
6621  posVarIdx->second = kount;
6622  m_miNonLinearVarsReverseMap[ kount] = posVarIdx->first;
6623  kount++;
6624 #ifndef NDEBUG
6625  outStr.str("");
6626  outStr.clear();
6627  outStr << "POSITION FIRST = " << posVarIdx->first ;
6628  outStr << " POSITION SECOND = " << posVarIdx->second << std::endl;
6630 #endif
6631  }
6635 }//getAllNonlinearVariablesIndexMap
6636 
6638 {
6639  std::ostringstream outStr;
6640 
6641  // fill in the nonzeros in the sparse Hessian
6643  if( m_iNumberOfNonlinearVariables == 0) return NULL;
6644  if( m_binitForAlgDiff == false ) initForAlgDiff();
6645  unsigned int i = 0;
6646  unsigned int j;
6647  int numNonz = 0;
6648  // Create the CppAD function if necessary
6649  //
6650  std::vector<double> vx;
6651  std::map<int, int>::iterator posMap1, posMap2;
6652  if( (m_bOSADFunIsCreated == false || m_bCppADMustReTape == true ) && (m_mapExpressionTreesMod.size() > 0) )
6653  {
6654  for(posMap1 = m_mapAllNonlinearVariablesIndex.begin(); posMap1 != m_mapAllNonlinearVariablesIndex.end(); ++posMap1)
6655  {
6656  vx.push_back( 1.0) ;
6657  }
6658  createOSADFun( vx);
6659  }
6660 
6661  // note this function call also fills in m_vbLagHessNonz
6662  numNonz = getADSparsityHessian();
6663 
6664  i = 0;
6665  // now that we have the dimension create SparseHessianMatrix (upper triangular)
6672  numNonz = 0;
6673  for(posMap1 = m_mapAllNonlinearVariablesIndex.begin(); posMap1 != m_mapAllNonlinearVariablesIndex.end(); ++posMap1)
6674  {
6675  j = i;
6676  for(posMap2 = posMap1; posMap2 != m_mapAllNonlinearVariablesIndex.end(); ++posMap2)
6677  {
6679  {
6680  *(m_LagrangianSparseHessian->hessRowIdx + numNonz) = posMap1->first;
6681  *(m_LagrangianSparseHessian->hessColIdx + numNonz) = posMap2->first;
6682  numNonz++;
6683  }
6684  j++;
6685  }
6686  i++;
6687  }
6688 #ifndef NDEBUG
6689  outStr.str("");
6690  outStr.clear();
6691  outStr << "HESSIAN SPARSITY PATTERN" << std::endl;
6692  int kj;
6693  for(kj = 0; kj < m_LagrangianSparseHessian->hessDimension; kj++)
6694  {
6695  outStr << "Row Index = " << *(m_LagrangianSparseHessian->hessRowIdx + kj) << std::endl;
6696  outStr << "Column Index = " << *(m_LagrangianSparseHessian->hessColIdx + kj) << std::endl;
6697  }
6699 #endif
6700  //
6703 }//getLagrangianHessianSparsityPattern
6704 
6705 
6707 {
6708  // we do this so that we can keep the integrity of the original formulation
6709  if(m_bDuplicateExpressionTreesMap == false)
6710  {
6711  // first make sure the map was created
6715  return;
6716  }
6717  else
6718  {
6719  return;
6720  }
6721 }//duplicateExpressionTreesMap
6722 
6723 
6724 bool OSInstance::getIterateResults( double *x, double *objLambda, double* conMultipliers,
6725  bool new_x, int highestOrder)
6726 {
6727  try
6728  {
6729  if( m_binitForAlgDiff == false) initForAlgDiff();
6730  std::map<int, int>::iterator posVarIndexMap;
6731 
6732  if(new_x == true)
6733  {
6734  if( m_vdX.size() > 0) m_vdX.clear();
6735  for(posVarIndexMap = m_mapAllNonlinearVariablesIndex.begin(); posVarIndexMap != m_mapAllNonlinearVariablesIndex.end(); ++posVarIndexMap)
6736  {
6737  m_vdX.push_back( x[ posVarIndexMap->first]) ;
6738  }
6739  if( (m_bOSADFunIsCreated == false || m_bCppADMustReTape == true ) && (m_mapExpressionTreesMod.size() > 0) )
6740  {
6741  createOSADFun( m_vdX);
6742  }
6743  }
6744  else // make sure vector not empty -- this could happen if we have linear obj and nonlinear constraints
6745 
6746  {
6747  if( m_vdX.size() == 0)
6748  {
6749  for(posVarIndexMap = m_mapAllNonlinearVariablesIndex.begin(); posVarIndexMap != m_mapAllNonlinearVariablesIndex.end(); ++posVarIndexMap)
6750  {
6751  m_vdX.push_back( x[ posVarIndexMap->first]) ;
6752  }
6753  if( (m_bOSADFunIsCreated == false || m_bCppADMustReTape == true ) && (m_mapExpressionTreesMod.size() > 0) )
6754  {
6755  createOSADFun( m_vdX);
6756  }
6757  }
6758  }
6759  switch( highestOrder)
6760  {
6761  case 0:
6762  if(new_x == true || m_iHighestOrderEvaluated < 0)
6763  {
6764  if(bUseExpTreeForFunEval == true)
6765  {
6768  }
6769  else
6770  {
6771  getZeroOrderResults(x, objLambda, conMultipliers);
6772  }
6773 
6774  }
6775  break;
6776  case 1:
6777  if(new_x == true || m_iHighestOrderEvaluated < 0)
6778  getZeroOrderResults(x, objLambda, conMultipliers);
6779  if(new_x == true || m_iHighestOrderEvaluated < 1)
6780  getFirstOrderResults(x, objLambda, conMultipliers);
6781  break;
6782  case 2:
6783  if(new_x == true || m_iHighestOrderEvaluated < 0)
6784  getZeroOrderResults(x, objLambda, conMultipliers);
6785  if(new_x == true || m_iHighestOrderEvaluated < 2)
6786  getSecondOrderResults(x, objLambda, conMultipliers);
6787  break;
6788  default:
6789  throw ErrorClass("Derivative should be order 0, 1, or 2");
6790  }//end switch
6791  return true;
6792  }
6793  catch(const ErrorClass& eclass)
6794  {
6795  throw ErrorClass( eclass.errormsg);
6796  }
6797 }//end getIterateResults
6798 
6799 
6800 bool OSInstance::getZeroOrderResults(double *x, double *objLambda, double *conMultipliers)
6801 {
6802  std::ostringstream outStr;
6803 
6804  try
6805  {
6806  // initialize everything
6807  int i, j, rowNum, objNum;
6808  if( m_mapExpressionTreesMod.size() > 0)
6809  {
6810  m_vdYval = this->forwardAD(0, m_vdX);
6811  }
6812  // now get all function and constraint values using forward result
6813  for(rowNum = 0; rowNum < m_iConstraintNumber; rowNum++)
6814  {
6815  m_mdConstraintFunctionValues[ rowNum] = 0.0;
6816  if( m_mapExpressionTreesMod.find( rowNum) != m_mapExpressionTreesMod.end() )
6817  {
6819  }
6820  // now the linear part
6821  // be careful, loop over only the constant terms in sparseJacMatrix
6822  i = m_sparseJacMatrix->starts[ rowNum];
6823  j = m_sparseJacMatrix->starts[ rowNum + 1 ];
6824  while ( (i - m_sparseJacMatrix->starts[ rowNum]) < m_sparseJacMatrix->conVals[ rowNum] )
6825  {
6827  i++;
6828  }
6829  // add in the constraint function constant
6831 #ifndef NDEBUG
6832  outStr.str("");
6833  outStr.clear();
6834  outStr << "Constraint " << rowNum << " function value = " << m_mdConstraintFunctionValues[ rowNum ] << std::endl;
6836 #endif
6837  }
6838  // now get the objective function values from the forward result
6839  for(objNum = 0; objNum < m_iObjectiveNumber; objNum++)
6840  {
6841  m_mdObjectiveFunctionValues[ objNum] = 0.0;
6842  if( m_mapExpressionTreesMod.find( -objNum -1) != m_mapExpressionTreesMod.end() )
6843  {
6844  m_mdObjectiveFunctionValues[ objNum] = m_vdYval[ objNum];
6845  }
6846  for(i = 0; i < m_iVariableNumber; i++)
6847  {
6848  m_mdObjectiveFunctionValues[ objNum] += m_mmdDenseObjectiveCoefficients[ objNum][i]*x[ i];
6849  }
6850 #ifndef NDEBUG
6851  outStr.str("");
6852  outStr.clear();
6853  outStr << "Objective " << objNum << " function value = " << m_mdObjectiveFunctionValues[ objNum] << std::endl;
6855 #endif
6856  }
6857  return true;
6858  }//end try
6859  catch(const ErrorClass& eclass)
6860  {
6861  throw ErrorClass( eclass.errormsg);
6862  }
6863 }//end getZeroOrderResults
6864 
6865 
6866 bool OSInstance::getFirstOrderResults(double *x, double *objLambda, double *conMultipliers)
6867 {
6868  std::ostringstream outStr;
6869 
6870  try
6871  {
6872  // initialize everything
6873  unsigned int i, j;
6874  int rowNum, jacIndex;
6875  unsigned int jstart, jend;
6876  int idx;
6877  ScalarExpressionTree *expTree = NULL;
6878  int domainIdx = 0;
6879  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
6880  std::map<int, int>::iterator posVarIdx;
6881 
6888  {
6889  // calculate the gradient by doing a reverse sweep over each row
6890  // loop over the constraints that have a nonlinear term and get their gradients
6891  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
6892  {
6893  idx = posMapExpTree->first;
6894  // we are considering only constraints, not objective function
6895  if(idx >= 0)
6896  {
6897  m_vdRangeUnitVec[ domainIdx] = 1.;
6898  m_mapExpressionTreesMod[ idx]->getVariableIndicesMap();
6900  // check size
6901  jstart = m_miJacStart[ idx] + m_miJacNumConTerms[ idx];
6902  jend = m_miJacStart[ idx + 1 ];
6903  if( (*m_mapExpressionTreesMod[ idx]->mapVarIdx).size() != (jend - jstart)) throw
6904  ErrorClass("number of partials not consistent");
6905  j = 0;
6906  jacIndex = 0;
6907  for(posVarIdx = m_mapAllNonlinearVariablesIndex.begin(); posVarIdx
6908  != m_mapAllNonlinearVariablesIndex.end(); ++posVarIdx)
6909  {
6910  // we are working with variable posVarIdx->first in the original variable space
6911  // we need to see which variable this is in the individual constraint map
6912  if( (*m_mapExpressionTreesMod[ idx]->mapVarIdx).find( posVarIdx->first) != (*m_mapExpressionTreesMod[ idx]->mapVarIdx).end())
6913  {
6914  m_mdJacValue[ jstart] = m_vdYjacval[ jacIndex];
6915  jstart++;
6916  j++;
6917  }
6918  jacIndex++;
6919  }
6920 
6921  m_vdRangeUnitVec[ domainIdx] = 0.;
6922  domainIdx++;
6923  }
6924  else // we have an objective function
6925  {
6926  domainIdx++;
6927  }
6928  }
6929  }
6930  else
6931  {
6932  // calculate the gradients using a forward sweep over all the variables.
6933  for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
6934  {
6935  m_vdDomainUnitVec[i] = 1.;
6936  rowNum = 0;
6937  if( m_mapExpressionTreesMod.size() > 0)
6938  {
6940  }
6941  // fill in Jacobian here, we have column i
6942  // start Jacobian calculation
6943  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
6944  {
6945  idx = posMapExpTree->first;
6946  // we are considering only constraints, not objective function
6947  if(idx >= 0)
6948  {
6949  //figure out original variable this corresponds to
6950  //then use (*m_mapExpressionTreesMod[ idx]->mapVarIdx) to figure out which variable it is within row idx
6951  //m_mapAllNonlinearVariablesIndex
6952  expTree = m_mapExpressionTreesMod[ idx];
6953  if( (*expTree->mapVarIdx).find( m_miNonLinearVarsReverseMap[ i]) != (*expTree->mapVarIdx).end() )
6954  {
6955  jacIndex = (*m_mapExpressionTreesMod[ idx]->mapVarIdx)[ m_miNonLinearVarsReverseMap[ i]];
6956  jstart = m_miJacStart[ idx] + m_miJacNumConTerms[ idx];
6957  // kipp change 1 to number of objective functions
6958  m_mdJacValue[ jstart + jacIndex] = m_vdYjacval[m_iObjectiveNumberNonlinear + rowNum];
6959  }
6960  rowNum++;
6961  }//end Jacobian calculation
6962  }
6963  //
6964  m_vdDomainUnitVec[i] = 0.;
6965  }
6966  }
6967 #ifndef NDEBUG
6968  outStr.str("");
6969  outStr.clear();
6970  int k;
6971  outStr << "JACOBIAN DATA " << std::endl;
6972  for(idx = 0; idx < m_iConstraintNumber; idx++)
6973  {
6974  for(k = *(m_sparseJacMatrix->starts + idx); k < *(m_sparseJacMatrix->starts + idx + 1); k++)
6975  {
6976  outStr << "row idx = " << idx << " col idx = "<< *(m_sparseJacMatrix->indexes + k)
6977  << " value = " << *(m_sparseJacMatrix->values + k) << std::endl;
6978  }
6979  }
6981 #endif
6982  return true;
6983  }//end try
6984  catch(const ErrorClass& eclass)
6985  {
6986  throw ErrorClass( eclass.errormsg);
6987  }
6988 }// end getFirstOrderResults
6989 
6990 
6991 bool OSInstance::getSecondOrderResults(double *x, double *objLambda, double *conMultipliers)
6992 {
6993  std::ostringstream outStr;
6994 
6995  try
6996  {
6997  // initialize everything
6998  unsigned int i, j;
6999  int rowNum, jacIndex;
7000  int jstart, idx;
7001  ScalarExpressionTree *expTree = NULL;
7002  int hessValuesIdx = 0;
7004  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
7005  std::map<int, int>::iterator posVarIndexMap;
7006  if( objLambda == NULL) throw ErrorClass("must have a multiplier for the objective function even if zero when calling getSecondOrderResults");
7007 
7008  if( conMultipliers == NULL) throw ErrorClass("cannot have a null vector of lagrange multipliers when calling getSecondOrderResults -- okay if zero");
7009  if( m_vdLambda.size() > 0) m_vdLambda.clear();
7010  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
7011  {
7012  if( posMapExpTree->first >= 0)
7013  {
7014  m_vdLambda.push_back( conMultipliers[ posMapExpTree->first]);
7015  }
7016  else
7017  {
7018  // kipp correct when there is more than one obj
7019  m_vdLambda.push_back( objLambda[ abs(posMapExpTree->first) - 1] );
7020  }
7021  }
7022  for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
7023  {
7024  m_vdDomainUnitVec[i] = 1.;
7025  rowNum = 0;
7026  if( m_mapExpressionTreesMod.size() > 0)
7027  {
7029  }
7030  // fill in Jacobian here, we have column i
7031  // start Jacobian calculation
7032  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
7033  {
7034  idx = posMapExpTree->first;
7035  // we are considering only constraints, not objective function
7036  if(idx >= 0)
7037  {
7038  //figure out original variable this corresponds to
7039  //then use (*m_mapExpressionTreesMod[ idx]->mapVarIdx)
7040  //to figure out which variable it is within row idx
7041  //m_mapAllNonlinearVariablesIndex
7042  expTree = m_mapExpressionTreesMod[ idx];
7043  if( (*expTree->mapVarIdx).find( m_miNonLinearVarsReverseMap[ i]) != (*expTree->mapVarIdx).end() )
7044  {
7045  jacIndex = (*m_mapExpressionTreesMod[ idx]->mapVarIdx)[ m_miNonLinearVarsReverseMap[ i]];
7046  jstart = m_miJacStart[ idx] + m_miJacNumConTerms[ idx];
7047  m_mdJacValue[ jstart + jacIndex] = m_vdYjacval[m_iObjectiveNumberNonlinear + rowNum];
7048  }
7049  rowNum++;
7050  }//end Jacobian calculation
7051  else
7052  {
7053  // see if we have the objective function of interest
7054  //kipp fix if more than one obj
7055  m_mmdObjGradient[ (abs( idx) - 1)][ m_miNonLinearVarsReverseMap[ i]] = m_vdYjacval[ (abs( idx) - 1)] +
7057  }//end Obj gradient calculation
7058  }
7059  // now calculate the Hessian
7060  if( m_mapExpressionTreesMod.size() > 0)
7061  {
7062  m_vdw = reverseAD(2, m_vdLambda); // derivative of partial
7063  }
7064  for(j = i; j < m_iNumberOfNonlinearVariables; j++)
7065  {
7066  if( m_vbLagHessNonz[i*m_iNumberOfNonlinearVariables + j] == true)
7067  {
7068  m_LagrangianSparseHessian->hessValues[ hessValuesIdx] = m_vdw[ j*2 + 1];
7069 #ifndef NDEBUG
7070  outStr.str("");
7071  outStr.clear();
7072  outStr << "reverse 2 " << m_LagrangianSparseHessian->hessValues[ hessValuesIdx] << std::endl;
7074 #endif
7075  hessValuesIdx++;
7076  }
7077  }
7078  //
7079  //
7080  m_vdDomainUnitVec[i] = 0.;
7081  }
7082 #ifndef NDEBUG
7083  outStr.str("");
7084  outStr.clear();
7085  int k;
7086  outStr << "JACOBIAN DATA " << std::endl;
7087  for(idx = 0; idx < m_iConstraintNumber; idx++)
7088  {
7089  for(k = *(m_sparseJacMatrix->starts + idx); k < *(m_sparseJacMatrix->starts + idx + 1); k++)
7090  {
7091  outStr << "row idx = " << idx << " col idx = "<< *(m_sparseJacMatrix->indexes + k)
7092  << " value = " << *(m_sparseJacMatrix->values + k) << std::endl;
7093  }
7094  }
7096 #endif
7097  return true;
7098  }//end try
7099  catch(const ErrorClass& eclass)
7100  {
7101  throw ErrorClass( eclass.errormsg);
7102  }
7103 }// end getSecondOrderResults
7104 
7106 {
7107  std::ostringstream outStr;
7108 
7109  if( m_binitForAlgDiff == true ) return true;
7111  initObjGradients();
7113  //if(m_bSparseJacobianCalculated == false) getJacobianSparsityPattern();
7114  //see if we need to retape
7115  //loop over expression tree and see if one requires it
7116  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
7117  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
7118  {
7119  if(posMapExpTree->second->bADMustReTape == true) m_bCppADMustReTape = true;
7120  }
7121 
7122 #ifndef NDEBUG
7123  outStr << "RETAPE == " << m_bCppADMustReTape << std::endl;
7125 #endif
7126  unsigned int i;
7127  for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
7128  {
7129  m_vdDomainUnitVec.push_back( 0.0 );
7130  }
7131  for(i = 0; i < m_mapExpressionTreesMod.size(); i++)
7132  {
7133  m_vdRangeUnitVec.push_back( 0.0 );
7134  }
7135  m_binitForAlgDiff = true;
7136  //m_bSparseJacobianCalculated = true;
7137  //m_bProcessExpressionTrees = true;
7138  return true;
7139 }//end initForAlgDiff
7140 
7142 {
7143  std::ostringstream outStr;
7144 
7145  int i, j;
7146  int m, n;
7147  m = getObjectiveNumber();
7148  n = getVariableNumber();
7150  if(m <= 0)
7151  {
7152  m_mmdObjGradient = NULL;
7153  return true;
7154  }
7155  m_mmdObjGradient = new double*[m];
7156  for(i = 0; i < m; i++)
7157  {
7158  m_mmdObjGradient[i] = new double[n];
7159  for(j = 0; j < n; j++)
7160  {
7162 #ifndef NDEBUG
7163  outStr << "m_mmdObjGradient[i][j] = " << m_mmdObjGradient[i][j] << std::endl;
7165 #endif
7166  }
7167  }
7168  return true;
7169 }//end initObjGradients
7185 bool OSInstance::setTimeDomain(std::string format)
7186 {
7187  if ((format != "stages") && (format != "interval") && (format != "none"))
7188  return false;
7189  if (instanceData->timeDomain == NULL)
7190  {
7192  }
7193  if (format == "stages")
7194  {
7195  if (instanceData->timeDomain->interval != NULL)
7196  {
7197  delete instanceData->timeDomain->interval;
7198  instanceData->timeDomain->interval = NULL;
7199  }
7200  if (instanceData->timeDomain->stages == NULL)
7202  m_sTimeDomainFormat = format;
7203  }
7204  if (format == "interval")
7205  {
7206  if (instanceData->timeDomain->stages != NULL)
7207  {
7208  delete instanceData->timeDomain->stages;
7209  instanceData->timeDomain->stages = NULL;
7210  }
7211  if (instanceData->timeDomain->interval == NULL)
7213  m_sTimeDomainFormat = format;
7214  }
7215  if (format == "none")
7216  {
7217  if (instanceData->timeDomain->stages != NULL)
7218  {
7219  delete instanceData->timeDomain->stages;
7220  instanceData->timeDomain->stages = NULL;
7221  }
7222  if (instanceData->timeDomain->interval != NULL)
7223  {
7224  delete instanceData->timeDomain->interval;
7225  instanceData->timeDomain->interval = NULL;
7226  }
7227  m_sTimeDomainFormat = "";
7228  }
7229  return true;
7230 } //end setTimeDomain
7231 
7235 bool OSInstance::setTimeDomainStages(int number, std::string *names)
7236 {
7237  if (instanceData->timeDomain == NULL)
7239  if (instanceData->timeDomain->interval != NULL)
7240  return false;
7241  if (instanceData->timeDomain->stages == NULL)
7242  {
7244  }
7245  else
7246  {
7247  if (instanceData->timeDomain->stages->numberOfStages != number)
7248  {
7249  for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
7250  {
7251  if (instanceData->timeDomain->stages->stage[i]->variables != NULL)
7252  {
7255  }
7256  if (instanceData->timeDomain->stages->stage[i]->constraints != NULL)
7257  {
7260 
7261  }
7262  if (instanceData->timeDomain->stages->stage[i]->objectives != NULL)
7263  {
7266  }
7267  delete instanceData->timeDomain->stages->stage[i];
7268  instanceData->timeDomain->stages->stage[i] = NULL;
7269  }
7270  delete []instanceData->timeDomain->stages->stage;
7271  instanceData->timeDomain->stages->stage = NULL;
7272  }
7273  }
7274  if (number != 0 )
7275  {
7276  if (instanceData->timeDomain->stages->stage == NULL)
7278  for (int i = 0; i < number; i++)
7279  {
7281  }
7283  }
7284  for (int i = 0; i < number; i++)
7285  //initial or empty vars, cons, objectives and set default to all objectives
7286  {
7287  if (instanceData->timeDomain->stages->stage[i]->variables != NULL)
7288  {
7291  }
7293  if (instanceData->timeDomain->stages->stage[i]->constraints != NULL)
7294  {
7297  }
7299  if (instanceData->timeDomain->stages->stage[i]->objectives != NULL)
7300  {
7303  }
7307  for (int j = 0; j < instanceData->objectives->numberOfObjectives; j++)
7308  {
7310  instanceData->timeDomain->stages->stage[i]->objectives->obj[j]->idx = -(j+1);
7311  }
7312  if (names != NULL)
7313  instanceData->timeDomain->stages->stage[i]->name = names[i];
7314  }
7315  return true;
7316 } //end setTimeDomainStages
7317 
7321 bool OSInstance::setTimeDomainStageVariablesOrdered(int numberOfStages, int *numberOfVariables, int *startIdx)
7322 {
7323  if (instanceData->timeDomain == NULL)
7325  if (instanceData->timeDomain->interval != NULL)
7326  return false;
7327  if (instanceData->timeDomain->stages == NULL)
7329  if (instanceData->timeDomain->stages != NULL)
7330  {
7331  if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
7333  return false;
7334  }
7336  {
7337  instanceData->timeDomain->stages->numberOfStages = numberOfStages;
7338  if (instanceData->timeDomain->stages->stage == NULL)
7339  instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
7340  for (int i = 0; i < numberOfStages; i++)
7342  }
7343  int checksum = 0;
7344  for (int i = 0; i < numberOfStages; i++)
7345  //initial or empty vars, cons, objectives and set default to all objectives
7346  {
7347  if (instanceData->timeDomain->stages->stage[i]->variables != NULL)
7348  {
7351  }
7353  instanceData->timeDomain->stages->stage[i]->variables->startIdx = startIdx[i];
7354  instanceData->timeDomain->stages->stage[i]->variables->numberOfVariables = numberOfVariables[i];
7355  checksum += numberOfVariables[i];
7356  }
7357  return (checksum == instanceData->variables->numberOfVariables);
7358 } //end setTimeDomainVariablesOrdered
7359 
7363 bool OSInstance::setTimeDomainStageVariablesUnordered(int numberOfStages, int *numberOfVariables, int **varIndex)
7364 {
7365  if (instanceData->timeDomain == NULL)
7367  if (instanceData->timeDomain->interval != NULL)
7368  return false;
7369  if (instanceData->timeDomain->stages == NULL)
7371  if (instanceData->timeDomain->stages != NULL)
7372  {
7373  if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
7375  return false;
7376  }
7378  {
7379  instanceData->timeDomain->stages->numberOfStages = numberOfStages;
7380  if (instanceData->timeDomain->stages->stage == NULL)
7381  instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
7382  for (int i = 0; i < numberOfStages; i++)
7384  }
7385  int checksum = 0;
7386  for (int i = 0; i < numberOfStages; i++)
7387  //initial or empty vars, cons, objectives and set default to all objectives
7388  {
7389  if (instanceData->timeDomain->stages->stage[i]->variables != NULL)
7390  {
7393  }
7395  instanceData->timeDomain->stages->stage[i]->variables->numberOfVariables = numberOfVariables[i];
7396  instanceData->timeDomain->stages->stage[i]->variables->var = new TimeDomainStageVar*[numberOfVariables[i]];
7397  for (int j = 0; j < numberOfVariables[i]; j++)
7398  {
7400  instanceData->timeDomain->stages->stage[i]->variables->var[j]->idx = varIndex[i][j];
7401  }
7402  checksum += numberOfVariables[i];
7403  }
7404  if (checksum != instanceData->variables->numberOfVariables) return false;
7405  int *checkvar = new int[instanceData->variables->numberOfVariables];
7406  for (int j = 0; j < instanceData->variables->numberOfVariables; j++)
7407  checkvar[j] = -1;
7408  int k;
7409  for (int i = 0; i < numberOfStages; i++)
7410  for (int j = 0; j < instanceData->timeDomain->stages->stage[i]->variables->numberOfVariables; j++)
7411  {
7413  if (checkvar[k] != -1)
7414  {
7415  delete [] checkvar;
7416  checkvar = NULL;
7417  return false;
7418  }
7419  checkvar[k] = instanceData->timeDomain->stages->stage[i]->variables->var[j]->idx;
7420  }
7421  delete [] checkvar;
7422  checkvar = NULL;
7423  return true;
7424 } //end setTimeDomainVariablesUnordered
7425 
7429 bool OSInstance::setTimeDomainStageConstraintsOrdered(int numberOfStages, int *numberOfConstraints, int *startIdx)
7430 {
7431  if (instanceData->timeDomain == NULL)
7433  if (instanceData->timeDomain->interval != NULL)
7434  return false;
7435  if (instanceData->timeDomain->stages == NULL)
7437  if (instanceData->timeDomain->stages != NULL)
7438  {
7439  if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
7441  return false;
7442  }
7444  {
7445  instanceData->timeDomain->stages->numberOfStages = numberOfStages;
7446  if (instanceData->timeDomain->stages->stage == NULL)
7447  instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
7448  for (int i = 0; i < numberOfStages; i++)
7450  }
7451  int checksum = 0;
7452  for (int i = 0; i < numberOfStages; i++)
7453  //initial or empty vars, cons, objectives and set default to all objectives
7454  {
7455  if (instanceData->timeDomain->stages->stage[i]->constraints != NULL)
7456  {
7459  }
7461  instanceData->timeDomain->stages->stage[i]->constraints->startIdx = startIdx[i];
7462  instanceData->timeDomain->stages->stage[i]->constraints->numberOfConstraints = numberOfConstraints[i];
7463  checksum += numberOfConstraints[i];
7464  }
7465  return (checksum == instanceData->constraints->numberOfConstraints);
7466 } // end of setTimeStageConstraintsOrdered
7467 
7471 bool OSInstance::setTimeDomainStageConstraintsUnordered(int numberOfStages, int *numberOfConstraints, int **conIndex)
7472 {
7473  if (instanceData->timeDomain == NULL)
7475  if (instanceData->timeDomain->interval != NULL)
7476  return false;
7477  if (instanceData->timeDomain->stages == NULL)
7479  if (instanceData->timeDomain->stages != NULL)
7480  {
7481  if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
7483  return false;
7484  }
7486  {
7487  instanceData->timeDomain->stages->numberOfStages = numberOfStages;
7488  if (instanceData->timeDomain->stages->stage == NULL)
7489  instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
7490  for (int i = 0; i < numberOfStages; i++)
7492  }
7493  int checksum = 0;
7494  for (int i = 0; i < numberOfStages; i++)
7495  //initial or empty vars, cons, objectives and set default to all objectives
7496  {
7497  if (instanceData->timeDomain->stages->stage[i]->constraints != NULL)
7498  {
7501  }
7503  instanceData->timeDomain->stages->stage[i]->constraints->numberOfConstraints = numberOfConstraints[i];
7504  instanceData->timeDomain->stages->stage[i]->constraints->con = new TimeDomainStageCon*[numberOfConstraints[i]];
7505  for (int j = 0; j < numberOfConstraints[i]; j++)
7506  {
7508  instanceData->timeDomain->stages->stage[i]->constraints->con[j]->idx = conIndex[i][j];
7509  }
7510  checksum += numberOfConstraints[i];
7511  }
7512  if (checksum != instanceData->constraints->numberOfConstraints) return false;
7513  int *checkvar = new int[instanceData->constraints->numberOfConstraints];
7514  for (int j = 0; j < instanceData->constraints->numberOfConstraints; j++)
7515  checkvar[j] = -1;
7516  int k;
7517  for (int i = 0; i < numberOfStages; i++)
7518  for (int j = 0; j < instanceData->timeDomain->stages->stage[i]->constraints->numberOfConstraints; j++)
7519  {
7521  if (checkvar[k] != -1)
7522  {
7523  delete [] checkvar;
7524  checkvar = NULL;
7525  return false;
7526  }
7527  checkvar[k] = instanceData->timeDomain->stages->stage[i]->constraints->con[j]->idx;
7528  }
7529  delete [] checkvar;
7530  checkvar = NULL;
7531  return true;
7532 }// end setTimeDomainStageConstraintsUnordered()
7533 
7537 bool OSInstance::setTimeDomainStageObjectivesOrdered(int numberOfStages, int *numberOfObjectives, int *startIdx)
7538 {
7539  if (instanceData->timeDomain == NULL)
7541  if (instanceData->timeDomain->interval != NULL)
7542  return false;
7543  if (instanceData->timeDomain->stages == NULL)
7544 
7546  if (instanceData->timeDomain->stages != NULL)
7547  {
7548  if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
7550  return false;
7551  }
7553 
7554  {
7555  instanceData->timeDomain->stages->numberOfStages = numberOfStages;
7556  if (instanceData->timeDomain->stages->stage == NULL)
7557  instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
7558  for (int i = 0; i < numberOfStages; i++)
7560  }
7561  for (int i = 0; i < numberOfStages; i++)
7562  //initial or empty vars, cons, objectives and set default to all objectives
7563  {
7564 
7565  if (instanceData->timeDomain->stages->stage[i]->objectives != NULL)
7566  {
7569  }
7571  instanceData->timeDomain->stages->stage[i]->objectives->startIdx = startIdx[i];
7572  instanceData->timeDomain->stages->stage[i]->objectives->numberOfObjectives = numberOfObjectives[i];
7573  }
7574  return true;
7575 }
7576 
7580 bool OSInstance::setTimeDomainStageObjectivesUnordered(int numberOfStages, int *numberOfObjectives, int **objIndex)
7581 {
7582  if (instanceData->timeDomain == NULL)
7584  if (instanceData->timeDomain->interval != NULL)
7585  return false;
7586  if (instanceData->timeDomain->stages == NULL)
7588  if (instanceData->timeDomain->stages != NULL)
7589  {
7590  if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
7592  return false;
7593  }
7595  {
7596  instanceData->timeDomain->stages->numberOfStages = numberOfStages;
7597  if (instanceData->timeDomain->stages->stage == NULL)
7598  instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
7599  for (int i = 0; i < numberOfStages; i++)
7601  }
7602  for (int i = 0; i < numberOfStages; i++)
7603  //initial or empty vars, cons, objectives and set default to all objectives
7604  {
7605  if (instanceData->timeDomain->stages->stage[i]->objectives != NULL)
7606  {
7609  }
7611  instanceData->timeDomain->stages->stage[i]->objectives->numberOfObjectives = numberOfObjectives[i];
7612  instanceData->timeDomain->stages->stage[i]->objectives->obj = new TimeDomainStageObj*[numberOfObjectives[i]];
7613  for (int j = 0; j < numberOfObjectives[i]; j++)
7614  {
7616  instanceData->timeDomain->stages->stage[i]->objectives->obj[j]->idx = objIndex[i][j];
7617  }
7618  }
7619  int *checkvar = new int[instanceData->objectives->numberOfObjectives];
7620  for (int j = 0; j < instanceData->objectives->numberOfObjectives; j++)
7621  checkvar[j] = 0;
7622  int k;
7623  for (int i = 0; i < numberOfStages; i++)
7624  for (int j = 0; j < instanceData->timeDomain->stages->stage[i]->objectives->numberOfObjectives; j++)
7625  {
7627  checkvar[k] = instanceData->timeDomain->stages->stage[i]->objectives->obj[j]->idx;
7628  }
7629  for (int i = 0; i < instanceData->objectives->numberOfObjectives; i++)
7630  if (checkvar[i] == 0)
7631  {
7632  delete [] checkvar;
7633  checkvar = NULL;
7634  return false;
7635  }
7636  delete [] checkvar;
7637  checkvar = NULL;
7638  return true;
7639 }
7640 
7644 bool OSInstance::setTimeDomainInterval(double start, double horizon)
7645 {
7646  if (instanceData->timeDomain == NULL)
7648  if (instanceData->timeDomain->stages != NULL)
7649  return false;
7650  if (instanceData->timeDomain->interval == NULL)
7653  instanceData->timeDomain->interval->horizon = horizon;
7654  return true;
7655 } //end setTimeDomainInterval
7656 
7657 
7658 bool OSInstance::createOSADFun(std::vector<double> vdX)
7659 {
7660  try
7661  {
7662  if(m_bOSADFunIsCreated == true) return true;
7663  //if( m_bNonLinearStructuresInitialized == false) initializeNonLinearStructures( );
7664  if(m_binitForAlgDiff == false) initForAlgDiff();
7665 
7666  //if( m_bAllNonlinearVariablesIndex == false) getAllNonlinearVariablesIndexMap( );
7667  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
7668  unsigned int i;
7669  size_t n = vdX.size();
7670 #ifdef COIN_HAS_CPPAD
7671  // declare a CppAD vector and fill it in
7672  CppAD::vector< CppAD::AD<double> > vdaX( n );
7673  for(i = 0; i < n; i++)
7674  {
7675  vdaX[ i] = vdX[ i];
7676  }
7677  // declare the independent variables and start recording
7678  CppAD::Independent( vdaX);
7684  CppAD::vector< CppAD::AD<double> > m_vFG;
7685  int kount = 0;
7686  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
7687  {
7688  m_vFG.push_back( (posMapExpTree->second)->m_treeRoot->constructADTape(&m_mapAllNonlinearVariablesIndex, &vdaX) );
7689  if( m_mapOSADFunRangeIndex.find( posMapExpTree->first) == m_mapOSADFunRangeIndex.end() )
7690  {
7691  // count which nonlinear obj/constraint this is
7692  m_mapOSADFunRangeIndex[ posMapExpTree->first] = kount;
7693  kount++;
7694  }
7695  }
7696  //create the function and stop recording
7697 
7698  Fad = new CppAD::ADFun<double>(vdaX, m_vFG);
7699  // no forward sweeps done yet
7701  m_bOSADFunIsCreated = true;
7702 #else
7703  throw ErrorClass( "Error: An Algorithmic Differentiation Package Not Available");
7704 #endif
7705 
7706  return true;
7707  }
7708  catch(const ErrorClass& eclass)
7709  {
7710  throw ErrorClass( eclass.errormsg);
7711  }
7712 }//end createOSADFun
7713 
7714 
7715 std::vector<double> OSInstance::forwardAD(int p, std::vector<double> vdX)
7716 {
7717  try
7718  {
7719  // make sure a OSADFun has been created
7720  if(m_bOSADFunIsCreated == false) createOSADFun( vdX);
7721  if(p > (m_iHighestTaylorCoeffOrder + 1) ) throw
7722  ErrorClass( "trying to calculate a p order forward when p-1 Taylor coefficient not available");
7723  // adjust the order of the Taylor coefficient
7726 #ifdef COIN_HAS_CPPAD
7727  return (*Fad).Forward(p, vdX);
7728 #else
7729  throw ErrorClass( "Error: An Algorithmic Differentiation Package Not Available");
7730 #endif
7731 
7732  }
7733  catch(const ErrorClass& eclass)
7734  {
7735  throw ErrorClass( eclass.errormsg);
7736  }
7737 }//end forwardAD
7738 
7739 
7740 std::vector<double> OSInstance::reverseAD(int p, std::vector<double> vdlambda)
7741 {
7742  try
7743  {
7744 #ifndef COIN_HAS_CPPAD
7745  throw ErrorClass( "Error: An Algorithmic Differentiation Package Not Available");
7746 #endif
7747  if(p == 0) throw
7748  ErrorClass( "reverseAD must have p >= 1");
7749  if(p > (m_iHighestTaylorCoeffOrder + 1) ) throw
7750  ErrorClass( "trying to calculate a p order reverse when p-1 Taylor coefficient not available");
7752 #ifdef COIN_HAS_CPPAD
7753  return (*Fad).Reverse(p, vdlambda);
7754 #endif
7755 
7756  }
7757  catch(const ErrorClass& eclass)
7758  {
7759  throw ErrorClass( eclass.errormsg);
7760  }
7761 }//end forwardAD
7762 
7763 
7765 {
7766  unsigned int i;
7767  int numNonz;
7768  numNonz = 0;
7769  try
7770  {
7772  unsigned int j;
7773  for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
7774  {
7775  for(j = 0; j < m_iNumberOfNonlinearVariables; j++)
7776  r[ i * m_iNumberOfNonlinearVariables + j ] = false;
7777  r[ i * m_iNumberOfNonlinearVariables + i] = true;
7778  }
7779  // compute sparsity pattern for J(x) = F^{(1)} (x)
7780  //should only be here if we have CppAD
7781 #ifdef COIN_HAS_CPPAD
7782  (*Fad).ForSparseJac(m_iNumberOfNonlinearVariables, r);
7783 #else
7784  throw ErrorClass( "Error: An Algorithmic Differentiation Package Not Available");
7785 #endif
7786  //
7787  //now the second derivative
7788  unsigned int m = m_mapExpressionTreesMod.size();
7789  std::vector<bool> e( m);
7790  //Vector s(m);
7791  for(i = 0; i < m; i++) e[i] = true;
7792 #ifndef NDEBUG
7793  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Computing Sparse Hessian");
7794 #endif
7795  //m_vbLagHessNonz holds the sparsity pattern Lagrangian of the Hessian
7796 #ifdef COIN_HAS_CPPAD
7797  m_vbLagHessNonz = (*Fad).RevSparseHes(m_iNumberOfNonlinearVariables, e);
7798 #endif
7799 
7800  for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
7801  {
7802  for(j = i; j < m_iNumberOfNonlinearVariables; j++)
7803  {
7804  if(m_vbLagHessNonz[ i*m_iNumberOfNonlinearVariables + j] == true) numNonz++;
7805  }
7806  }
7807  return numNonz;
7808  }
7809  catch(const ErrorClass& eclass)
7810  {
7811  throw ErrorClass( eclass.errormsg);
7812  }
7813 }//end getADSparsityHessian()
7814 
7815 
7816 /***************************************************
7817  * methods to print out cone objects as XML strings
7818  ***************************************************/
7819 std::string Cone::getConeInXML()
7820 {
7821  ostringstream outStr;
7822  outStr << "<cone";
7823  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7824  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7825  if (name != "")
7826  outStr << " name=\"" << name << "\"";
7827  outStr << "/>" << std::endl;
7828  return outStr.str();
7829 }// end of Cone::getConeInXML()
7830 
7832 {
7833  ostringstream outStr;
7834  outStr << "<nonnegativeCone";
7835  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7836  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7837  if (name != "")
7838  outStr << " name=\"" << name << "\"";
7839  outStr << "/>" << std::endl;
7840  return outStr.str();
7841 }// end of NonnegativeCone::getConeInXML()
7842 
7844 {
7845  ostringstream outStr;
7846  outStr << "<nonpositiveCone";
7847  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7848  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7849  if (name != "")
7850  outStr << " name=\"" << name << "\"";
7851  outStr << "/>" << std::endl;
7852  return outStr.str();
7853 }// end of NonpositiveCone::getConeInXML()
7854 
7856 {
7857  ostringstream outStr;
7858  outStr << "<generalOrthantCone";
7859  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7860  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7861  if (name != "")
7862  outStr << " name=\"" << name << "\"";
7863  outStr << ">" << std::endl;
7864  int i = 0;
7865  int mult = 1;
7866  double ubt;
7867  double lbt;
7868  while (i < numberOfRows*numberOfColumns)
7869  {
7870  ubt = ub[i];
7871  lbt = lb[i];
7872  if (i+mult < numberOfRows*numberOfColumns && ubt == ub[i+mult] && lbt == lb[i+mult])
7873  {
7874  mult++;
7875  }
7876  else
7877  {
7878  outStr << "<direction";
7879  if (ubt == 0.0)
7880  if (lbt == 0.0)
7881  outStr << " type=\"zero\"";
7882  else
7883  outStr << " type=\"nonpositive\"";
7884  else if(lbt == 0.0)
7885  outStr << " type=\"nonnegative\"";
7886  else
7887  outStr << " type=\"free\"";
7888  if (mult > 1)
7889  outStr <<" mult=\"" << mult << "\"";
7890  outStr << "/>";
7891  i += mult;
7892  mult = 1;
7893  }
7894  }
7895  outStr << "</generalOrthantCone>" << std::endl;
7896  return outStr.str();
7897 }// end of OrthantCone::getConeInXML()
7898 
7900 {
7901  ostringstream outStr;
7902  outStr << "<polyhedralCone";
7903  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7904  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7905  outStr << " referenceMatrixIdx=\"" << referenceMatrixIdx << "\"";
7906  if (name != "")
7907  outStr << " name=\"" << name << "\"";
7908  outStr << "/>" << std::endl;
7909  return outStr.str();
7910 }// end of PolyhedralCone::getConeInXML()
7911 
7913 {
7914  ostringstream outStr;
7915  outStr << "<quadraticCone";
7916  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7917  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7918  if (name != "")
7919  outStr << " name=\"" << name << "\"";
7920  if (normScaleFactor != 1.0)
7921  outStr << " normScaleFactor=\"" << normScaleFactor << "\"";
7922  if (distortionMatrixIdx != -1)
7923  outStr << " distortionMatrixIdx=\"" << distortionMatrixIdx << "\"";
7924  if (axisDirection != 0)
7925  outStr << " axisDirection=\"" << axisDirection << "\"";
7926  outStr << "/>" << std::endl;
7927  return outStr.str();
7928 }// end of QuadraticCone::getConeInXML()
7929 
7931 {
7932  ostringstream outStr;
7933  outStr << "<rotatedQuadraticCone";
7934  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7935  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7936  if (name != "")
7937  outStr << " name=\"" << name << "\"";
7938  if (normScaleFactor != 1.0)
7939  outStr << " normScaleFactor=\"" << normScaleFactor << "\"";
7940  if (distortionMatrixIdx != -1)
7941  outStr << " distortionMatrixIdx=\"" << distortionMatrixIdx << "\"";
7942  if (firstAxisDirection != 0)
7943  outStr << " firstAxisDirection=\"" << firstAxisDirection << "\"";
7944  if (secondAxisDirection != 1)
7945  outStr << " secondAxisDirection=\"" << secondAxisDirection << "\"";
7946  outStr << "/>" << std::endl;
7947  return outStr.str();
7948 }// end of RotatedQuadraticCone::getConeInXML()
7949 
7951 {
7952  ostringstream outStr;
7953  outStr << "<semidefiniteCone";
7954  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7955  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7956  if (semidefiniteness != "positive")
7957  outStr << " semidefiniteness=\"" << semidefiniteness << "\"";
7958  outStr << "/>" << std::endl;
7959 
7960  return outStr.str();
7961 }// end of SemidefiniteCone::getConeInXML()
7962 
7964 {
7965  ostringstream outStr;
7966  outStr << "<nonnegativeCone";
7967  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7968  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7969  if (name != "")
7970  outStr << " name=\"" << name << "\"";
7971  outStr << "/>" << std::endl;
7972  return outStr.str();
7973 }// end of CopositiveMatricesCone::getConeInXML()
7974 
7976 {
7977  ostringstream outStr;
7978  outStr << "<nonnegativeCone";
7979  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7980  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7981  if (name != "")
7982  outStr << " name=\"" << name << "\"";
7983  outStr << "/>" << std::endl;
7984  return outStr.str();
7985 }// end of CompletelyPositiveMatricesCone::getConeInXML()
7986 
7988 {
7989  ostringstream outStr;
7990  outStr << "<productCone";
7991  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7992  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7993  if (name != "")
7994  outStr << " name=\"" << name << "\"";
7995  outStr << ">" << std::endl;
7996 
7997  outStr << "<factors numberOfEl=\"" << factors->numberOfEl << "\">" << std::endl;
7998  outStr << writeIntVectorData(factors, true, false);
7999  outStr << "</factors>" << std::endl;
8000 
8001  outStr << "</productCone>" << std::endl;
8002  return outStr.str();
8003 }// end of ProductCone::getConeInXML()
8004 
8006 {
8007  ostringstream outStr;
8008  outStr << "<intersectionCone";
8009  outStr << " numberOfRows=\"" << numberOfRows << "\"";
8010  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
8011  if (name != "")
8012  outStr << " name=\"" << name << "\"";
8013  outStr << ">" << std::endl;
8014 
8015  outStr << "<components numberOfEl=\"" << components->numberOfEl << "\">";
8016  outStr << writeIntVectorData(components, true, false);
8017  outStr << "</components>" << std::endl;
8018 
8019  outStr << "</intersectionCone>" << std::endl;
8020  return outStr.str();
8021 }// end of IntersectionCone::getConeInXML()
8022 
8023 
8024 /***************************************************
8025  * methods to test whether two OSInstance objects
8026  * or their components are equal to each other
8027  ***************************************************/
8029 {
8030 #ifndef NDEBUG
8031  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in OSInstance");
8032 #endif
8033  if (this == NULL)
8034  {
8035  if (that == NULL)
8036  return true;
8037  else
8038  {
8039 #ifndef NDEBUG
8041  "First object is NULL, second is not");
8042 #endif
8043  return false;
8044  }
8045  }
8046  else
8047  {
8048  if (that == NULL)
8049  {
8050 #ifndef NDEBUG
8052  "Second object is NULL, first is not");
8053 #endif
8054  return false;
8055  }
8056  else
8057  {
8058  if (!this->instanceHeader->IsEqual(that->instanceHeader))
8059  return false;
8060  if (!this->instanceData->IsEqual(that->instanceData))
8061  return false;
8062 
8063  return true;
8064  }
8065  }
8066 }//OSInstance::IsEqual
8067 
8068 
8070 {
8071 #ifndef NDEBUG
8072  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in InstanceData");
8073 #endif
8074  if (this == NULL)
8075  {
8076  if (that == NULL)
8077  return true;
8078  else
8079  {
8080 #ifndef NDEBUG
8082  "First object is NULL, second is not");
8083 #endif
8084  return false;
8085  }
8086  }
8087  else
8088  {
8089  if (that == NULL)
8090  {
8091 #ifndef NDEBUG
8093  "Second object is NULL, first is not");
8094 #endif
8095  return false;
8096  }
8097  else
8098  {
8099  if (!this->variables->IsEqual(that->variables))
8100  return false;
8101  if (!this->objectives->IsEqual(that->objectives))
8102  return false;
8103  if (!this->constraints->IsEqual(that->constraints))
8104  return false;
8106  return false;
8108  return false;
8110  return false;
8111  if (!this->matrices->IsEqual(that->matrices))
8112  return false;
8113  if (!this->cones->IsEqual(that->cones))
8114  return false;
8115  if (!this->matrixProgramming->IsEqual(that->matrixProgramming))
8116  return false;
8117 
8118  return true;
8119  }
8120  }
8121 }//InstanceData::IsEqual
8122 
8124 {
8125 #ifndef NDEBUG
8126  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Variables");
8127 
8128 #endif
8129  if (this == NULL)
8130  {
8131  if (that == NULL)
8132  return true;
8133  else
8134  {
8135 #ifndef NDEBUG
8137  "First object is NULL, second is not");
8138 #endif
8139  return false;
8140  }
8141  }
8142  else
8143  {
8144  if (that == NULL)
8145  {
8146 #ifndef NDEBUG
8148  "Second object is NULL, first is not");
8149 #endif
8150  return false;
8151  }
8152  else
8153  {
8154  if (this->numberOfVariables != that->numberOfVariables)
8155  return false;
8156  for (int i=0; i<this->numberOfVariables; i++)
8157  if (!this->var[i]->IsEqual(that->var[i]))
8158  return false;
8159 
8160  return true;
8161  }
8162  }
8163 }//Variables::IsEqual
8164 
8166 {
8167 #ifndef NDEBUG
8168  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Variable");
8169 #endif
8170  if (this == NULL)
8171  {
8172  if (that == NULL)
8173  return true;
8174  else
8175  {
8176 #ifndef NDEBUG
8178  "First object is NULL, second is not");
8179 #endif
8180  return false;
8181  }
8182  }
8183  else
8184  {
8185  if (that == NULL)
8186  {
8187 #ifndef NDEBUG
8189  "Second object is NULL, first is not");
8190 #endif
8191  return false;
8192  }
8193  else
8194  {
8195  if (this->lb != that->lb)
8196  return false;
8197  if (this->ub != that->ub)
8198  return false;
8199  if (this->type != that->type)
8200  return false;
8201  if (this->name != that->name)
8202  return false;
8203 
8204  return true;
8205  }
8206  }
8207 }//Variable::IsEqual
8208 
8210 {
8211 #ifndef NDEBUG
8212  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Objectives");
8213 #endif
8214  if (this == NULL)
8215  {
8216  if (that == NULL)
8217  return true;
8218  else
8219  {
8220 #ifndef NDEBUG
8222  "First object is NULL, second is not");
8223 #endif
8224  return false;
8225  }
8226  }
8227  else
8228  {
8229  if (that == NULL)
8230  {
8231 #ifndef NDEBUG
8233  "Second object is NULL, first is not");
8234 #endif
8235  return false;
8236  }
8237  else
8238  {
8239  if (this->numberOfObjectives != that->numberOfObjectives)
8240  return false;
8241  for (int i=0; i<this->numberOfObjectives; i++)
8242  if (!this->obj[i]->IsEqual(that->obj[i]))
8243  return false;
8244 
8245  return true;
8246  }
8247  }
8248 }//Objectives::IsEqual
8249 
8251 {
8252 #ifndef NDEBUG
8253  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Objective");
8254 #endif
8255  if (this == NULL)
8256  {
8257  if (that == NULL)
8258  return true;
8259  else
8260  {
8261 #ifndef NDEBUG
8263  "First object is NULL, second is not");
8264 #endif
8265  return false;
8266  }
8267  }
8268  else
8269  {
8270  if (that == NULL)
8271  {
8272 #ifndef NDEBUG
8274  "Second object is NULL, first is not");
8275 #endif
8276  return false;
8277  }
8278  else
8279  {
8280  if (this->name != that->name)
8281  return false;
8282  if (this->maxOrMin != that->maxOrMin)
8283  return false;
8284  if (this->constant != that->constant)
8285  return false;
8286  if (!OSIsEqual(this->weight, that->weight))
8287  return false;
8288  if (this->numberOfObjCoef != that->numberOfObjCoef)
8289  return false;
8290 
8291  for (int i=0; i<this->numberOfObjCoef; i++)
8292  if (!this->coef[i]->IsEqual(that->coef[i]))
8293  return false;
8294 
8295  return true;
8296  }
8297  }
8298 }//Objective::IsEqual
8299 
8301 {
8302 #ifndef NDEBUG
8303  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in ObjCoef");
8304 #endif
8305  if (this == NULL)
8306  {
8307  if (that == NULL)
8308  return true;
8309  else
8310  {
8311 #ifndef NDEBUG
8313  "First object is NULL, second is not");
8314 #endif
8315  return false;
8316  }
8317  }
8318  else
8319  {
8320  if (that == NULL)
8321  {
8322 #ifndef NDEBUG
8324  "Second object is NULL, first is not");
8325 #endif
8326  return false;
8327  }
8328  else
8329  {
8330  if (this->idx != that->idx)
8331  return false;
8332  if (this->value != that->value)
8333  return false;
8334 
8335  return true;
8336  }
8337  }
8338 }//ObjCoef::IsEqual
8339 
8341 {
8342 #ifndef NDEBUG
8343  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Constraints");
8344 #endif
8345  if (this == NULL)
8346  {
8347  if (that == NULL)
8348  return true;
8349  else
8350  {
8351 #ifndef NDEBUG
8353  "First object is NULL, second is not");
8354 #endif
8355  return false;
8356  }
8357  }
8358  else
8359  {
8360  if (that == NULL)
8361  {
8362 #ifndef NDEBUG
8364  "Second object is NULL, first is not");
8365 #endif
8366  return false;
8367  }
8368  else
8369  {
8370  if (this->numberOfConstraints != that->numberOfConstraints)
8371  return false;
8372  for (int i=0; i<this->numberOfConstraints; i++)
8373  if (!this->con[i]->IsEqual(that->con[i]))
8374  return false;
8375 
8376  return true;
8377  }
8378  }
8379 }//Constraints::IsEqual
8380 
8382 {
8383 #ifndef NDEBUG
8384  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Constraint");
8385 #endif
8386  if (this == NULL)
8387  {
8388  if (that == NULL)
8389  return true;
8390  else
8391  {
8392 #ifndef NDEBUG
8394  "First object is NULL, second is not");
8395 #endif
8396  return false;
8397  }
8398  }
8399  else
8400  {
8401  if (that == NULL)
8402  {
8403 #ifndef NDEBUG
8405  "Second object is NULL, first is not");
8406 #endif
8407  return false;
8408  }
8409  else
8410  {
8411  if (this->name != that->name)
8412  return false;
8413  if (this->constant != that->constant)
8414  return false;
8415  if (this->lb != that->lb)
8416  return false;
8417  if (this->ub != that->ub)
8418  return false;
8419 
8420  return true;
8421 
8422  }
8423  }
8424 }//Constraint::IsEqual
8425 
8427 {
8428 #ifndef NDEBUG
8429  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in LinearConstraintCoefficients");
8430 #endif
8431  if (this == NULL)
8432  {
8433  if (that == NULL)
8434  return true;
8435  else
8436  {
8437 #ifndef NDEBUG
8439  "First object is NULL, second is not");
8440 #endif
8441  return false;
8442  }
8443  }
8444  else
8445  {
8446  if (that == NULL)
8447  {
8448 #ifndef NDEBUG
8450  "Second object is NULL, first is not");
8451 #endif
8452  return false;
8453  }
8454  else
8455  {
8456  if (this->numberOfValues != that->numberOfValues)
8457  return false;
8458 
8459  if (!this->start->IsEqual(that->start))
8460  return false;
8461  if (!this->rowIdx->IsEqual(that->rowIdx))
8462  return false;
8463  if (!this->colIdx->IsEqual(that->colIdx))
8464  return false;
8465  if (!this->value->IsEqual(that->value))
8466  return false;
8467 
8468  return true;
8469  }
8470  }
8471 }//LinearConstraintCoefficients::IsEqual
8472 
8474 {
8475 #ifndef NDEBUG
8476  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in QuadraticCoefficients");
8477 #endif
8478  if (this == NULL)
8479  {
8480  if (that == NULL)
8481  return true;
8482  else
8483  {
8484 #ifndef NDEBUG
8486  "First object is NULL, second is not");
8487 
8488 #endif
8489  return false;
8490  }
8491  }
8492  else
8493  {
8494  if (that == NULL)
8495  {
8496 #ifndef NDEBUG
8498  "Second object is NULL, first is not");
8499 #endif
8500  return false;
8501  }
8502  else
8503 
8504  {
8506  return false;
8507  for (int i=0; i<this->numberOfQuadraticTerms; i++)
8508  if (!this->qTerm[i]->IsEqual(that->qTerm[i]))
8509  return false;
8510 
8511  return true;
8512  }
8513  }
8514 }//QuadraticCoefficients::IsEqual
8515 
8516 
8518 {
8519 #ifndef NDEBUG
8520  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in QuadraticTerm");
8521 #endif
8522  if (this == NULL)
8523  {
8524  if (that == NULL)
8525  return true;
8526  else
8527  {
8528 #ifndef NDEBUG
8530  "First object is NULL, second is not");
8531 #endif
8532  return false;
8533  }
8534  }
8535  else
8536  {
8537  if (that == NULL)
8538  {
8539 #ifndef NDEBUG
8541  "Second object is NULL, first is not");
8542 #endif
8543  return false;
8544  }
8545  else
8546  {
8547  if (this->idx != that->idx)
8548  return false;
8549  if (this->idxOne != that->idxOne)
8550  return false;
8551  if (this->idxTwo != that->idxTwo)
8552  return false;
8553  if (this->coef != that->coef)
8554  return false;
8555 
8556  return true;
8557  }
8558  }
8559 }//QuadraticTerm::IsEqual
8560 
8562 {
8563 #ifndef NDEBUG
8564  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in NonlinearExpressions");
8565 #endif
8566  if (this == NULL)
8567  {
8568  if (that == NULL)
8569  return true;
8570  else
8571  {
8572 #ifndef NDEBUG
8574  "First object is NULL, second is not");
8575 #endif
8576  return false;
8577  }
8578  }
8579  else
8580  {
8581  if (that == NULL)
8582  {
8583 #ifndef NDEBUG
8585  "Second object is NULL, first is not");
8586 #endif
8587  return false;
8588  }
8589  else
8590  {
8592  return false;
8593 
8594  for (int i=0; i<this->numberOfNonlinearExpressions; i++)
8595  if (!this->nl[i]->IsEqual(that->nl[i]))
8596  return false;
8597 
8598  return true;
8599  }
8600  }
8601 }//NonlinearExpressions::IsEqual
8602 
8603 
8604 bool Nl::IsEqual(Nl *that)
8605 {
8606 #ifndef NDEBUG
8607  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Nl");
8608 #endif
8609  if (this == NULL)
8610  {
8611  if (that == NULL)
8612  return true;
8613  else
8614  {
8615 #ifndef NDEBUG
8617  "First object is NULL, second is not");
8618 #endif
8619  return false;
8620  }
8621  }
8622  else
8623  {
8624  if (that == NULL)
8625  {
8626 #ifndef NDEBUG
8628  "Second object is NULL, first is not");
8629 #endif
8630  return false;
8631  }
8632  else
8633  {
8634  if (this->idx != that->idx)
8635  return false;
8636  if (!this->osExpressionTree->IsEqual(that->osExpressionTree))
8637  return false;
8638 
8639  return true;
8640  }
8641  }
8642 }//Nl::IsEqual
8643 
8645 {
8646 #ifndef NDEBUG
8647  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Matrices");
8648 #endif
8649  if (this == NULL)
8650  {
8651  if (that == NULL)
8652  return true;
8653  else
8654  {
8655 #ifndef NDEBUG
8657  "First object is NULL, second is not");
8658 #endif
8659  return false;
8660  }
8661  }
8662  else
8663  {
8664  if (that == NULL)
8665  {
8666 #ifndef NDEBUG
8668  "Second object is NULL, first is not");
8669 #endif
8670  return false;
8671  }
8672  else
8673  {
8674  if (this->numberOfMatrices != that->numberOfMatrices)
8675  return false;
8676  for (int i=0; i<this->numberOfMatrices; i++)
8677  if (!this->matrix[i]->IsEqual(that->matrix[i]))
8678  return false;
8679 
8680  return true;
8681  }
8682  }
8683 }//Matrices::IsEqual
8684 
8686 {
8687 #ifndef NDEBUG
8688  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Cones");
8689 #endif
8690  if (this == NULL)
8691  {
8692  if (that == NULL)
8693  return true;
8694  else
8695  {
8696 #ifndef NDEBUG
8698  "First object is NULL, second is not");
8699 #endif
8700  return false;
8701  }
8702  }
8703  else
8704  {
8705  if (that == NULL)
8706  {
8707 #ifndef NDEBUG
8709  "Second object is NULL, first is not");
8710 #endif
8711  return false;
8712  }
8713  else
8714  {
8715  if (this->numberOfCones != that->numberOfCones)
8716  return false;
8717  for (int i=0; i<this->numberOfCones; i++)
8718  if (!this->cone[i]->IsEqual(that->cone[i]))
8719  return false;
8720 
8721  return true;
8722  }
8723  }
8724 }//Cones::IsEqual
8725 
8726 bool Cone::IsEqual(Cone *that)
8727 {
8728 #ifndef NDEBUG
8729  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Cone");
8730 #endif
8731  if (this == NULL)
8732  {
8733  if (that == NULL)
8734  return true;
8735  else
8736  {
8737 #ifndef NDEBUG
8739  "First object is NULL, second is not");
8740 #endif
8741  return false;
8742  }
8743  }
8744  else
8745  {
8746  if (that == NULL)
8747  {
8748 #ifndef NDEBUG
8750  "Second object is NULL, first is not");
8751 #endif
8752  return false;
8753  }
8754  else
8755  {
8756  if (this->coneType != that->coneType)
8757  return false;
8758  if (this->numberOfColumns != that->numberOfColumns)
8759  return false;
8760  if (this->numberOfRows != that->numberOfRows)
8761  return false;
8762  if (this->numberOfOtherIndexes != that->numberOfOtherIndexes)
8763  return false;
8764  for (int i=0; i<this->numberOfOtherIndexes; i++)
8765  if (this->otherIndexes[i] != that->otherIndexes[i])
8766  return false;
8767  }
8768  }
8769  return true;
8770 }//Cone::IsEqual
8771 
8773 {
8774 #ifndef NDEBUG
8775  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in PolyhedralCone");
8776 #endif
8777  if (this == NULL)
8778  {
8779  if (that == NULL)
8780  return true;
8781  else
8782  {
8783 #ifndef NDEBUG
8785  "First object is NULL, second is not");
8786 #endif
8787  return false;
8788  }
8789  }
8790  else
8791  {
8792  if (that == NULL)
8793  {
8794 #ifndef NDEBUG
8796  "Second object is NULL, first is not");
8797 #endif
8798  return false;
8799  }
8800  else
8801  {
8802  if (this->referenceMatrixIdx != that->referenceMatrixIdx)
8803  return false;
8804 
8805  return this->Cone::IsEqual(that);
8806  }
8807  }
8808 }//PolyhedralCone::IsEqual
8809 
8810 
8812 {
8813 #ifndef NDEBUG
8814  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in QuadraticCone");
8815 #endif
8816  if (this == NULL)
8817  {
8818  if (that == NULL)
8819  return true;
8820  else
8821  {
8822 #ifndef NDEBUG
8824  "First object is NULL, second is not");
8825 #endif
8826  return false;
8827  }
8828  }
8829  else
8830  {
8831  if (that == NULL)
8832  {
8833 #ifndef NDEBUG
8835  "Second object is NULL, first is not");
8836 #endif
8837  return false;
8838  }
8839  else
8840  {
8841  if (this->normScaleFactor != that->normScaleFactor)
8842  return false;
8843  if (this->distortionMatrixIdx != that->distortionMatrixIdx)
8844  return false;
8845  if (this->axisDirection != that->axisDirection)
8846  return false;
8847 
8848  return this->Cone::IsEqual(that);
8849  }
8850  }
8851 }//QuadraticCone::IsEqual
8852 
8853 
8854 
8856 {
8857 #ifndef NDEBUG
8858  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in RotatedQuadraticCone");
8859 #endif
8860  if (this == NULL)
8861  {
8862  if (that == NULL)
8863  return true;
8864  else
8865  {
8866 #ifndef NDEBUG
8868  "First object is NULL, second is not");
8869 #endif
8870  return false;
8871  }
8872  }
8873  else
8874  {
8875  if (that == NULL)
8876  {
8877 #ifndef NDEBUG
8879  "Second object is NULL, first is not");
8880 #endif
8881  return false;
8882  }
8883  else
8884  {
8885  if (this->normScaleFactor != that->normScaleFactor)
8886  return false;
8887  if (this->distortionMatrixIdx != that->distortionMatrixIdx)
8888  return false;
8889  if (this->firstAxisDirection != that->firstAxisDirection)
8890  return false;
8891  if (this->secondAxisDirection != that->secondAxisDirection)
8892  return false;
8893 
8894  return this->Cone::IsEqual(that);
8895  }
8896  }
8897 }//RotatedQuadraticCone::IsEqual
8898 
8900 {
8901 #ifndef NDEBUG
8902  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in SemidefiniteCone");
8903 #endif
8904  if (this == NULL)
8905  {
8906  if (that == NULL)
8907  return true;
8908  else
8909  {
8910 #ifndef NDEBUG
8912  "First object is NULL, second is not");
8913 #endif
8914  return false;
8915  }
8916  }
8917  else
8918  {
8919  if (that == NULL)
8920  {
8921 #ifndef NDEBUG
8923  "Second object is NULL, first is not");
8924 #endif
8925  return false;
8926  }
8927  else
8928  {
8929  if (this->semidefiniteness != that->semidefiniteness)
8930  return false;
8931  return this->Cone::IsEqual(that);
8932  }
8933  }
8934  return true;
8935 }//SemidefiniteCone::IsEqual
8936 
8938 {
8939 #ifndef NDEBUG
8940  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in ProductCone");
8941 #endif
8942  if (this == NULL)
8943  {
8944  if (that == NULL)
8945  return true;
8946  else
8947  {
8948 #ifndef NDEBUG
8950  "First object is NULL, second is not");
8951 #endif
8952  return false;
8953  }
8954  }
8955  else
8956  {
8957  if (that == NULL)
8958  {
8959 #ifndef NDEBUG
8961  "Second object is NULL, first is not");
8962 #endif
8963  return false;
8964  }
8965  else
8966  {
8967  if (!this->factors->IsEqual(that->factors))
8968  return false;
8969  return this->Cone::IsEqual(that);
8970  }
8971  }
8972  return true;
8973 }//ProductCone::IsEqual
8974 
8976 {
8977 #ifndef NDEBUG
8978  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in IntersectionCone");
8979 #endif
8980  if (this == NULL)
8981  {
8982  if (that == NULL)
8983  return true;
8984  else
8985  {
8986 #ifndef NDEBUG
8988  "First object is NULL, second is not");
8989 #endif
8990  return false;
8991  }
8992  }
8993  else
8994  {
8995  if (that == NULL)
8996  {
8997 #ifndef NDEBUG
8999  "Second object is NULL, first is not");
9000 #endif
9001  return false;
9002  }
9003  else
9004  {
9005  if (!this->components->IsEqual(that->components))
9006  return false;
9007  return this->Cone::IsEqual(that);
9008  }
9009  }
9010  return true;
9011 }//IntersectionCone::IsEqual
9012 
9014 {
9015 #ifndef NDEBUG
9016  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in DualCone");
9017 #endif
9018  if (this == NULL)
9019  {
9020  if (that == NULL)
9021  return true;
9022  else
9023  {
9024 #ifndef NDEBUG
9026  "First object is NULL, second is not");
9027 #endif
9028  return false;
9029  }
9030  }
9031  else
9032  {
9033  if (that == NULL)
9034  {
9035 #ifndef NDEBUG
9037  "Second object is NULL, first is not");
9038 #endif
9039  return false;
9040  }
9041  else
9042  {
9043  if (this->referenceConeIdx != that->referenceConeIdx)
9044  return false;
9045 
9046  return this->Cone::IsEqual(that);
9047  }
9048  }
9049 }//DualCone::IsEqual
9050 
9051 
9053 {
9054 #ifndef NDEBUG
9055  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in PolarCone");
9056 #endif
9057  if (this == NULL)
9058  {
9059  if (that == NULL)
9060  return true;
9061  else
9062 
9063  {
9064 #ifndef NDEBUG
9066  "First object is NULL, second is not");
9067 #endif
9068  return false;
9069  }
9070  }
9071  else
9072  {
9073  if (that == NULL)
9074  {
9075 #ifndef NDEBUG
9077  "Second object is NULL, first is not");
9078 #endif
9079  return false;
9080  }
9081  else
9082  {
9083  if (this->referenceConeIdx != that->referenceConeIdx)
9084  return false;
9085 
9086  return this->Cone::IsEqual(that);
9087  }
9088  }
9089 }//PolarCone::IsEqual
9090 
9091 
9093 {
9094 #ifndef NDEBUG
9095  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixProgramming");
9096 #endif
9097 
9098  if (this == NULL)
9099  {
9100  if (that == NULL)
9101  return true;
9102  else
9103  {
9104 #ifndef NDEBUG
9106  "First object is NULL, second is not");
9107 #endif
9108  return false;
9109  }
9110  }
9111  else
9112  {
9113  if (that == NULL)
9114  {
9115 #ifndef NDEBUG
9117  "Second object is NULL, first is not");
9118 #endif
9119  return false;
9120  }
9121  else
9122  {
9123  if (this->matrixVariables != NULL)
9124  {
9125  if (!(this->matrixVariables->IsEqual(that->matrixVariables)))
9126  return false;
9127  }
9128  else
9129  {
9130  if (that->matrixVariables != NULL) return false;
9131  }
9132 
9133  if (this->matrixObjectives != NULL)
9134  {
9135  if (!(this->matrixObjectives->IsEqual(that->matrixObjectives)))
9136  return false;
9137  }
9138  else
9139  {
9140  if (that->matrixObjectives != NULL) return false;
9141  }
9142 
9143  if (this->matrixConstraints != NULL)
9144  {
9145  if (!(this->matrixConstraints->IsEqual(that->matrixConstraints)))
9146  return false;
9147  }
9148  else
9149  {
9150  if (that->matrixConstraints != NULL) return false;
9151  }
9152 
9153  if (this->matrixExpressions != NULL)
9154  {
9155  if (!(this->matrixExpressions->IsEqual(that->matrixExpressions)))
9156  return false;
9157  }
9158  else
9159  {
9160  if (that->matrixExpressions != NULL) return false;
9161  }
9162 
9163  return true;
9164  }
9165 
9166  }
9167 }//MatrixProgramming::IsEqual
9168 
9169 
9171 {
9172 #ifndef NDEBUG
9173  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixVariables");
9174 #endif
9175 
9176  if (this == NULL)
9177  {
9178  if (that == NULL)
9179  return true;
9180  else
9181  {
9182 #ifndef NDEBUG
9184  "First object is NULL, second is not");
9185 #endif
9186  return false;
9187  }
9188  }
9189  else
9190  {
9191  if (that == NULL)
9192  {
9193 #ifndef NDEBUG
9195  "Second object is NULL, first is not");
9196 #endif
9197  return false;
9198  }
9199  else
9200  {
9201  if (this->numberOfMatrixVar != that->numberOfMatrixVar) return false;
9202 
9203  for (int i=0; i<numberOfMatrixVar; i++)
9204  {
9205  if (this->matrixVar[i] != NULL)
9206  {
9207  if (!(this->matrixVar[i]->IsEqual(that->matrixVar[i]))) return false;
9208  }
9209  else
9210  if (that->matrixVar[i] != NULL) return false;
9211  }
9212 
9213  return true;
9214  }
9215  }
9216 }//MatrixVariables::IsEqual
9217 
9219 {
9220 #ifndef NDEBUG
9221  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixVar");
9222 #endif
9223 
9224  if (this == NULL)
9225  {
9226  if (that == NULL)
9227  return true;
9228  else
9229  {
9230 #ifndef NDEBUG
9232  "First object is NULL, second is not");
9233 #endif
9234  return false;
9235  }
9236  }
9237  else
9238  {
9239  if (that == NULL)
9240  {
9241 #ifndef NDEBUG
9243  "Second object is NULL, first is not");
9244 #endif
9245  return false;
9246  }
9247  else
9248  {
9249  if (this->numberOfRows != that->numberOfRows)
9250  return false;
9251  if (this->numberOfColumns != that->numberOfColumns)
9252  return false;
9253  if (this->templateMatrixIdx != that->templateMatrixIdx)
9254  return false;
9255  if (this->varReferenceMatrixIdx != that->varReferenceMatrixIdx)
9256  return false;
9257  if (this->lbMatrixIdx != that->lbMatrixIdx)
9258  return false;
9259  if (this->lbConeIdx != that->lbConeIdx)
9260  return false;
9261  if (this->ubMatrixIdx != that->ubMatrixIdx)
9262  return false;
9263  if (this->ubConeIdx != that->ubConeIdx)
9264  return false;
9265  if (this->name != that->name)
9266  return false;
9267  if (this->varType != that->varType)
9268  return false;
9269 
9270  return true;
9271  }
9272  }
9273 }//MatrixVar::IsEqual
9274 
9276 {
9277 #ifndef NDEBUG
9278  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixProgramming");
9279 #endif
9280 
9281  if (this == NULL)
9282  {
9283  if (that == NULL)
9284  return true;
9285  else
9286  {
9287 #ifndef NDEBUG
9289  "First object is NULL, second is not");
9290 #endif
9291  return false;
9292  }
9293  }
9294  else
9295  {
9296  if (that == NULL)
9297  {
9298 #ifndef NDEBUG
9300  "Second object is NULL, first is not");
9301 #endif
9302  return false;
9303  }
9304  else
9305  {
9306  if (this->numberOfMatrixObj != that->numberOfMatrixObj) return false;
9307 
9308  for (int i=0; i<numberOfMatrixObj; i++)
9309  {
9310  if (this->matrixObj[i] != NULL)
9311  {
9312  if (!(this->matrixObj[i]->IsEqual(that->matrixObj[i]))) return false;
9313  }
9314  else
9315  if (that->matrixObj[i] != NULL) return false;
9316  }
9317 
9318  return true;
9319 
9320  }
9321  }
9322 }//MatrixObjectives::IsEqual
9323 
9325 {
9326 #ifndef NDEBUG
9327  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixObj");
9328 #endif
9329 
9330  if (this == NULL)
9331  {
9332  if (that == NULL)
9333  return true;
9334  else
9335  {
9336 #ifndef NDEBUG
9338  "First object is NULL, second is not");
9339 
9340 #endif
9341  return false;
9342  }
9343  }
9344  else
9345  {
9346  if (that == NULL)
9347  {
9348 #ifndef NDEBUG
9350  "Second object is NULL, first is not");
9351 #endif
9352  return false;
9353  }
9354  else
9355  {
9356  if (this->numberOfRows != that->numberOfRows)
9357  return false;
9358  if (this->numberOfColumns != that->numberOfColumns)
9359  return false;
9360  if (this->templateMatrixIdx != that->templateMatrixIdx)
9361  return false;
9362  if (this->objReferenceMatrixIdx != that->objReferenceMatrixIdx)
9363  return false;
9364  if (this->orderConeIdx != that->orderConeIdx)
9365  return false;
9366  if (this->constantMatrixIdx != that->constantMatrixIdx)
9367  return false;
9368  if (this->name != that->name)
9369  return false;
9370 
9371  return true;
9372  }
9373  }
9374 }//MatrixObj::IsEqual
9375 
9377 {
9378 #ifndef NDEBUG
9379  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixConstraints");
9380 #endif
9381 
9382  if (this == NULL)
9383  {
9384  if (that == NULL)
9385  return true;
9386  else
9387  {
9388 #ifndef NDEBUG
9390  "First object is NULL, second is not");
9391 #endif
9392  return false;
9393  }
9394  }
9395  else
9396  {
9397  if (that == NULL)
9398  {
9399 #ifndef NDEBUG
9401  "Second object is NULL, first is not");
9402 #endif
9403  return false;
9404  }
9405  else
9406  {
9407  if (this->numberOfMatrixCon != that->numberOfMatrixCon) return false;
9408 
9409  for (int i=0; i<numberOfMatrixCon; i++)
9410  {
9411  if (this->matrixCon[i] != NULL)
9412  {
9413  if (!(this->matrixCon[i]->IsEqual(that->matrixCon[i]))) return false;
9414  }
9415  else
9416  if (that->matrixCon[i] != NULL) return false;
9417  }
9418 
9419  return true;
9420  }
9421  }
9422 }//MatrixConstraints::IsEqual
9423 
9425 {
9426 #ifndef NDEBUG
9427  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixCon");
9428 #endif
9429 
9430  if (this == NULL)
9431  {
9432  if (that == NULL)
9433  return true;
9434  else
9435  {
9436 #ifndef NDEBUG
9438  "First object is NULL, second is not");
9439 #endif
9440  return false;
9441  }
9442  }
9443  else
9444  {
9445  if (that == NULL)
9446  {
9447 #ifndef NDEBUG
9449  "Second object is NULL, first is not");
9450 #endif
9451  return false;
9452  }
9453  else
9454  {
9455  if (this->numberOfRows != that->numberOfRows)
9456  return false;
9457  if (this->numberOfColumns != that->numberOfColumns)
9458  return false;
9459  if (this->templateMatrixIdx != that->templateMatrixIdx)
9460  return false;
9461  if (this->conReferenceMatrixIdx != that->conReferenceMatrixIdx)
9462  return false;
9463  if (this->lbMatrixIdx != that->lbMatrixIdx)
9464  return false;
9465  if (this->lbConeIdx != that->lbConeIdx)
9466  return false;
9467  if (this->ubMatrixIdx != that->ubMatrixIdx)
9468  return false;
9469  if (this->ubConeIdx != that->ubConeIdx)
9470  return false;
9471  if (this->name != that->name)
9472  return false;
9473 
9474  return true;
9475  }
9476  }
9477 }//MatrixCon::IsEqual
9478 
9480 {
9481 #ifndef NDEBUG
9482  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixExpressions");
9483 #endif
9484 
9485  if (this == NULL)
9486  {
9487  if (that == NULL)
9488  return true;
9489  else
9490  {
9491 #ifndef NDEBUG
9493  "First object is NULL, second is not");
9494 #endif
9495  return false;
9496  }
9497  }
9498  else
9499  {
9500  if (that == NULL)
9501  {
9502 #ifndef NDEBUG
9504  "Second object is NULL, first is not");
9505 #endif
9506  return false;
9507  }
9508  else
9509  {
9510  if (this->numberOfExpr != that->numberOfExpr) return false;
9511 
9512  for (int i=0; i<numberOfExpr; i++)
9513  {
9514  if (this->expr[i] != NULL)
9515  {
9516  if (!(this->expr[i]->IsEqual(that->expr[i]))) return false;
9517  }
9518  else
9519  if (that->expr[i] != NULL) return false;
9520  }
9521 
9522  return true;
9523  }
9524  }
9525 }//MatrixExpressions::IsEqual
9526 
9528 {
9529 #ifndef NDEBUG
9530  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixExpression");
9531 #endif
9532 
9533  if (this == NULL)
9534  {
9535  if (that == NULL)
9536  return true;
9537  else
9538  {
9539 #ifndef NDEBUG
9541  "First object is NULL, second is not");
9542 #endif
9543  return false;
9544  }
9545  }
9546  else
9547  {
9548  if (that == NULL)
9549  {
9550 #ifndef NDEBUG
9552  "Second object is NULL, first is not");
9553 #endif
9554  return false;
9555  }
9556  else
9557  {
9558  if (this->idx != that->idx ) return false;
9559  if (this->shape != that->shape) return false;
9560 
9561  if (this->matrixExpressionTree != NULL)
9562  {
9563  if (!(this->matrixExpressionTree->IsEqual(that->matrixExpressionTree)))
9564  return false;
9565  }
9566  else
9567  if (that->matrixExpressionTree != NULL) return false;
9568 
9569  return true;
9570  }
9571  }
9572 }//MatrixExpression::IsEqual
9573 
int numberOfExpr
numberOfExpr gives the number of expressions
Definition: OSInstance.h:1859
The OSnLNodeTimes Class.
Definition: OSnLNode.h:617
a data structure for holding quadratic terms
Definition: OSGeneral.h:431
double * getConstraintLowerBounds()
Get constraint lower bounds.
bool setTimeDomainStageVariablesOrdered(int numberOfStages, int *numberOfVariables, int *startIdx)
This sets the variables associated with each time domain stage in temporal order. ...
TimeDomain()
The TimeDomain class constructor.
~TimeDomainStageCon()
The TimeDomainStageCon class destructor.
double * getVariableLowerBounds()
Get variable lower bounds.
bool setMatrix(std::string name, int numberOfRows, int numberOfColumns, ENUM_MATRIX_SYMMETRY symmetry, ENUM_MATRIX_TYPE matrixType, unsigned int inumberOfChildren, MatrixNode **m_mChildren)
add values to this matrix.
Definition: OSMatrix.cpp:3668
double * getConstraintUpperBounds()
Get constraint upper bounds.
ENUM_NL_EXPR_SHAPE shape
shape holds the shape of the nonlinear expression (linear/quadratic/convex/general) (see further up i...
Definition: OSInstance.h:1826
double * values
ScalarExpressionTree * getNonlinearExpressionTreeMod(int rowIdx)
Get the expression tree for a given row index for the modified expression trees (quadratic terms adde...
~TimeDomainStageVariables()
The TimeDomainStageVariables class destructor.
~TimeDomainStageObjectives()
The TimeDomainStageObjectives class destructor.
MatrixVar ** matrixVar
matrixVar is an array of pointers to the &lt;matrixVar&gt; children
Definition: OSInstance.h:1642
int * getTimeDomainStageNumberOfConstraints()
Get the number of constraints contained in each time stage.
bool IsEqual(Cones *that)
A function to check for the equality of two objects.
int numberOfMatrixCon
numberOfMatrixCon gives the number of &lt;matrixCon&gt; children
Definition: OSInstance.h:1798
double coef
coef is an option coefficient on the variable, the default value is 1.0
Definition: OSnLNode.h:1485
bool m_bCppADMustReTape
is true if a CppAD Expresion Tree has an expression that can change depending on the value of the inp...
Definition: OSInstance.h:2780
std::string name
name corresponds to the optional attribute that holds the variable name, the default value is empty ...
Definition: OSInstance.h:71
Constraints * constraints
constraints is a pointer to a Constraints object
Definition: OSInstance.h:2191
bool setQuadraticCoefficients(int number, int *rowIndexes, int *varOneIndexes, int *varTwoIndexes, double *coefficients, int begin, int end)
set quadratic coefficients into the QuadraticCoefficients-&gt;qTerm data structure
int getNumberOfIntegerVariables()
getNumberOfIntegerVariables
~TimeDomainStageConstraints()
The TimeDomainStageConstraints class destructor.
bool m_bProcessLinearConstraintCoefficients
-—— data items for linear constraint coefficients -——
Definition: OSInstance.h:2495
bool processConstraints()
process constraints.
int numberOfColumns
Definition: OSInstance.h:1262
bool getSparseJacobianFromColumnMajor()
~QuadraticCone()
The QuadraticCone class destructor.
virtual std::string getConeInXML()
Write a SemidefiniteCone object in XML format.
~MatrixObjectives()
The MatrixObjectives class destructor.
char * getVariableTypes()
Get variable initial values.
bool m_bProcessMatrices
-—— data items for matrices -——
Definition: OSInstance.h:2864
int getNumberOfMatrixVariables()
Get the number of matrix variables.
ENUM_MATRIX_TYPE * m_miMatrixType
m_miMatrixType holds the type of each matrix.
Definition: OSInstance.h:2881
virtual ~Cone()
The Cone class destructor.
bool isColumnMajor
isColumnMajor holds whether the coefMatrix (AMatrix) holding linear program data is stored by column...
Definition: OSGeneral.h:236
* sp
Definition: OSdtoa.cpp:1934
std::string name
the name of the objective function
Definition: OSInstance.h:152
bool setConeNumber(int number)
set the number of cones
bool matrixHasBase()
Several tools to parse the constructor list of a matrix.
Definition: OSMatrix.cpp:196
bool m_bDuplicateExpressionTreesMap
m_bDuplicateExpressionTreeMap is true if m_mapExpressionTrees was duplicated.
Definition: OSInstance.h:2785
bool IsEqual(RotatedQuadraticCone *that)
A function to check for the equality of two objects.
ScalarExpressionTree * getNonlinearExpressionTree(int rowIdx)
Get the expression tree for a given row index.
The in-memory representation of a polyhedral cone.
Definition: OSInstance.h:786
The in-memory representation of a rotated quadratic cone.
Definition: OSInstance.h:951
bool addVariable(int index, std::string name, double lowerBound, double upperBound, char type)
add a variable.
~MatrixVariables()
The MatrixVariables class destructor.
virtual std::string getConeInXML()
Write an IntersectionCone object in XML format.
The in-memory representation of the &lt;matrices&gt; element.
Definition: OSInstance.h:482
std::string name
name corresponds to the optional attribute that holds the name of the stage; the default value is emp...
Definition: OSInstance.h:2075
bool bConstraintsModified
bConstraintsModified is true if the constraints data has been modified.
Definition: OSInstance.h:2298
InstanceData()
The InstanceData class constructor.
~Constraints()
The Constraints class destructor.
Definition: OSInstance.cpp:713
a sparse matrix data structure for matrices that can hold nonconstant values
Definition: OSMatrix.h:1654
ENUM_CONE_TYPE
Definition: OSParameters.h:865
int numberOfColumns
numberOfColumns gives the number of columns of this matrix
Definition: OSInstance.h:1743
The in-memory representation of the &lt;obj&gt; element.
Definition: OSInstance.h:2019
SparseHessianMatrix * calculateLagrangianHessian(double *x, double *objLambda, double *conLambda, bool new_x, int highestOrder)
Calculate the Hessian of the Lagrangian Expression Tree This method will build the CppAD expression t...
bool IsEqual(Nl *that)
A function to check for the equality of two objects.
int idx
idx gives the index of this variable
Definition: OSInstance.h:1944
bool bAMatrixModified
bAMatrixModified is true if the A matrix data has been modified.
Definition: OSInstance.h:2303
bool addQTermsToExpressionTree()
This method adds quadratic terms into the array of expression trees.
#define OS_MAX
Definition: OSParameters.h:44
~Variables()
The Variables class destructor.
Definition: OSInstance.cpp:586
bool getIterateResults(double *x, double *objLambda, double *conLambda, bool new_x, int highestOrder)
end revised AD code
int numberOfMatrixVar
numberOfMatrixVar gives the number of &lt;matrixVar&gt; children
Definition: OSInstance.h:1639
const OSSmartPtr< OSOutput > osoutput
Definition: OSOutput.cpp:39
int * getTimeDomainStageNumberOfVariables()
Get the number of variables contained in each time stage.
The in-memory representation of the &lt;matrixObj&gt; element.
Definition: OSInstance.h:1661
LinearConstraintCoefficients()
The LinearConstraintCoefficients class constructor.
Definition: OSInstance.cpp:734
IntVector * rowIdx
a pointer of row indices if the problem is stored by column
Definition: OSInstance.h:309
double * values
values holds a double array of nonzero partial derivatives
Definition: OSGeneral.h:340
bool bDestroyNlNodes
m_bDestroyNlNodes is true if the destructor deletes the nodes in the Expression tree ...
int getNumberOfElementConstructors()
Definition: OSMatrix.cpp:237
double calculateFunctionValue(int idx, double *x, bool new_x)
Calculate the function value for function (constraint or objective) indexed by idx.
~SemidefiniteCone()
The SemidefiniteCone class destructor.
virtual std::string getConeInXML()
Write a NonnegativeCone object in XML format.
int numberOfRows
Every cone has (at least) two dimensions; no distinction is made between vector cones and matrix cone...
Definition: OSInstance.h:1059
int m_iMatrixConNumber
m_iMatrixConNumber holds the number of matrix constraints
Definition: OSInstance.h:2966
int m_iNumberOfStringVariables
m_iNumberOfStringVariables holds the number of string-valued variables.
Definition: OSInstance.h:2363
int m_iConstraintNumber
m_iConstraintNumber is the number of constraints.
Definition: OSInstance.h:2455
bool IsEqual(MatrixVariables *that)
A function to check for the equality of two objects.
int m_iJacValueSize
m_iJacValueSize is the number of nonzero partial derivates in the Jacobian.
Definition: OSInstance.h:2655
virtual std::string getConeName()
std::string * m_msVariableNames
m_msVariableNames holds an array of variable names.
Definition: OSInstance.h:2368
bool bUseExpTreeForFunEval
bUseExpTreeForFunEval is set to true if you wish to use the OS Expression Tree for function evaluatio...
Definition: OSInstance.h:4899
int ubConeIdx
ubConeIdx gives a cone that must contain ubMatrix - matrixCon
Definition: OSInstance.h:1765
int getNumberOfElementConstructors(int n)
NonlinearExpressions * nonlinearExpressions
nonlinearExpressions is a pointer to a NonlinearExpressions object
Definition: OSInstance.h:2206
int orderConeIdx
orderConeIdx gives a cone that expresses preferences during the optimization x is (weakly) preferred ...
Definition: OSInstance.h:1683
bool setLinearConstraintCoefficients(int numberOfValues, bool isColumnMajor, double *values, int valuesBegin, int valuesEnd, int *indexes, int indexesBegin, int indexesEnd, int *starts, int startsBegin, int startsEnd)
set linear constraint coefficients
bool setTimeDomainStageObjectivesOrdered(int numberOfStages, int *numberOfObjectives, int *startIdx)
This sets the objectives associated with each time domain stage in temporal order.
Variable()
The Variable class constructor.
Definition: OSInstance.cpp:557
bool IsEqual(GeneralFileHeader *that)
A function to check for the equality of two objects.
Definition: OSGeneral.cpp:46
bool IsEqual(Objectives *that)
A function to check for the equality of two objects.
pos
position where the operator should be printed when printing the expression
int getVariableNumber()
Get number of variables.
bool verifyVarType(char vt)
Definition: OSParameters.h:580
MatrixExpression ** expr
a pointer to an array of linear and nonlinear expressions that evaluate to matrices ...
Definition: OSInstance.h:1864
std::vector< double > m_vdw
m_vdYval is a vector of derivatives – output from a reverse sweep
Definition: OSInstance.h:2842
std::string printModel()
Print the infix representation of the problem.
double * m_mdObjectiveConstants
m_mdObjectiveConstants holds an array of objective constants (default = 0.0).
Definition: OSInstance.h:2421
#define OS_COS
Definition: OSParameters.h:42
bool m_bLagrangianSparseHessianCreated
m_bLagrangianSparseHessianCreated is true if the sparse Hessian Matrix for the Lagrangian was created...
Definition: OSInstance.h:2735
bool setTimeDomainStageVariablesUnordered(int numberOfStages, int *numberOfVariables, int **varIndex)
This sets the variables associated with each time domain stage in srbitrary order.
SparseHessianMatrix * m_LagrangianSparseHessian
m_LagrangianSparseHessian is the Hessian Matrix of the Lagrangian function in sparse format ...
Definition: OSInstance.h:2729
int numberOfMatrixObj
numberOfMatrixObj gives the number of &lt;matrixObj&gt; children
Definition: OSInstance.h:1719
TimeDomain * timeDomain
timeDomain is a pointer to a TimeDomain object
Definition: OSInstance.h:2226
GeneralSparseMatrix * getMatrixCoefficientsInRowMajor(int n)
Get the (nonzero) elements of the matrix in row major form.
int idx
idx gives the index of this variable
Definition: OSInstance.h:2030
int getNumberOfSemiContinuousVariables()
getNumberOfSemiContinuousVariables
ENUM_MATRIX_TYPE
An enum to track the many different types of values that a matrix can contain Note that these types a...
Definition: OSParameters.h:599
int numberOfEl
Definition: OSGeneral.h:483
#define OS_NUMBER
Definition: OSParameters.h:45
OrthantCone()
default constructor.
int ** m_mmiTimeDomainStageVarList
m_mmiTimeDomainStageVarList holds the list of variables in each stage.
Definition: OSInstance.h:3021
MatrixNode ** m_mChildren
m_mChildren holds all the children, that is, nodes used in the definition or construction of the curr...
Definition: OSMatrix.h:76
int referenceMatrixIdx
Polyhedral cones use a reference to a previously defined matrix for the extreme rays.
Definition: OSInstance.h:817
int numberOfColumns
Definition: OSMatrix.h:1905
IntVector * factors
the list of &quot;factors&quot; contributing to the product each factor contains a reference to a previously de...
Definition: OSInstance.h:1281
The OSnLNodeMin Class.
Definition: OSnLNode.h:463
std::string m_sInstanceDescription
m_sInstanceDescription holds the instance description.
Definition: OSInstance.h:2318
bool setObjectives(int number, std::string *names, std::string *maxOrMins, double *constants, double *weights, SparseVector **objectitiveCoefficients)
set all the objectives related elements.
SparseHessianMatrix * calculateHessian(double *x, int idx, bool new_x)
Calculate the Hessian of a constraint or objective function.
unsigned int inumberOfChildren
inumberOfChildren is the number of OSnLNode child elements If this number is not fixed, e.g., for a sum node, it is temporarily set to 0
Definition: OSnLNode.h:74
int idx
idx is the index of the variable
Definition: OSnLNode.h:1488
CompletelyPositiveMatricesCone()
default constructor.
std::string errormsg
errormsg is the error that is causing the exception to be thrown
Definition: OSErrorClass.h:42
bool m_bProcessQuadraticTerms
m_bProcessQuadraticTerms holds whether the quadratic terms are processed.
Definition: OSInstance.h:2543
bool IsEqual(Constraints *that)
A function to check for the equality of two objects.
virtual std::string getConeName()
The in-memory representation of the &lt;matrixProgramming&gt; element.
Definition: OSInstance.h:1882
virtual std::vector< ExprNode * > getPostfixFromExpressionTree()
Get a vector of pointers to ExprNodes that correspond to the expression tree in postfix format...
Definition: OSnLNode.cpp:468
TimeDomainStageObj ** obj
obj is a pointer to an array of TimeDomainStageObj object pointers
Definition: OSInstance.h:2054
int numberOfRows
Every cone has (at least) two dimensions; no distinction is made between vector cones and matrix cone...
Definition: OSInstance.h:799
std::string description
further information about the file or the problem contained within it
Definition: OSGeneral.h:50
bool IsEqual(Objective *that)
A function to check for the equality of two objects.
static SparseMatrix * convertLinearConstraintCoefficientMatrixToTheOtherMajor(bool isColumnMajor, int startSize, int valueSize, int *start, int *index, double *value, int dimension)
Round a double number to the precision specified.
Definition: OSMathUtil.cpp:57
int getLinearConstraintCoefficientNumber()
Get number of specified (usually nonzero) linear constraint coefficient values.
virtual std::string getConeName()
int * getNonlinearExpressionTreeModIndexes()
Get all the nonlinear expression tree indexes, i.e., indexes of rows (objectives or constraints) that...
ENUM_MATRIX_SYMMETRY * m_miMatrixSymmetry
m_miMatrixSymmetry holds the symmetry property of each matrix.
Definition: OSInstance.h:2875
IntVector * colIdx
a pointer of column indices if the problem is stored by row
Definition: OSInstance.h:312
std::string maxOrMin
declare the objective function to be a max or a min
Definition: OSInstance.h:157
~TimeDomainInterval()
The Interval class destructor.
std::string name
an optional name to this matrixObj
Definition: OSInstance.h:1689
QuadraticCoefficients()
The QuadraticCoefficients class constructor.
Definition: OSInstance.cpp:786
The in-memory representation of the &lt;linearConstraintCoefficients&gt; element.
Definition: OSInstance.h:288
SparseVector ** getObjectiveCoefficients()
Get objective coefficients.
#define OS_PI
Definition: OSParameters.h:46
TimeDomainStageConstraints()
The TimeDomainStageConstraints class constructor.
bool getFirstOrderResults(double *x, double *objLambda, double *conLambda)
Calculate first derivatives.
ObjCoef ** coef
coef is pointer to an array of ObjCoef object pointers
Definition: OSInstance.h:176
ENUM_CONE_TYPE coneType
The type of the cone.
Definition: OSInstance.h:556
bool setQuadraticTermsInNonlinearExpressions(int number, int *rowIndexes, int *varOneIndexes, int *varTwoIndexes, double *coefficients)
set quadratic terms in nonlinearExpressions
bool m_bSparseJacobianCalculated
m_bSparseJacobianCalculated is true if getJacobianSparsityPattern() has been called.
Definition: OSInstance.h:2795
bool m_bProcessObjectives
-—— data items for Objectives -——
Definition: OSInstance.h:2391
~MatrixObj()
The MatrixVar class destructor.
The in-memory representation of the objective function &lt;coef&gt; element.
Definition: OSInstance.h:110
MatrixCon ** matrixCon
matrixCon is an array of pointers to the &lt;matrixCon&gt; children
Definition: OSInstance.h:1801
std::string fileCreator
name(s) of author(s) who created this file
Definition: OSGeneral.h:55
int idxTwo
idxTwo is the index of the second variable in the quadratic term
Definition: OSInstance.h:363
QuadraticTerm ** qTerm
qTerm is a pointer to an array of QuadraticTerm object pointers
Definition: OSInstance.h:397
Constraint ** con
con is pointer to an array of Constraint object pointers
Definition: OSInstance.h:268
bool IsEqual(MatrixExpressions *that)
A function to check for the equality of two objects.
bool m_bProcessExpressionTrees
m_bProcessExpressionTrees is true if the expression trees have been processed.
Definition: OSInstance.h:2633
std::string writeIntVectorData(IntVector *v, bool addWhiteSpace, bool writeBase64)
Take an IntVector object and write a string that validates against the OSgL schema.
Definition: OSgLWriter.cpp:104
MatrixConstraints * matrixConstraints
a pointer to the matrixConstraints object
Definition: OSInstance.h:1898
bool matrixHasBlocks(int n)
int * getNonlinearExpressionTreeIndexes()
Get all the nonlinear expression tree indexes, i.e., indexes of rows (objectives or constraints) that...
MatrixVar()
The MatrixVar class constructor.
if(!yyg->yy_init)
SparseJacobianMatrix * calculateAllConstraintFunctionGradients(double *x, double *objLambda, double *conLambda, bool new_x, int highestOrder)
Calculate the gradient of all constraint functions.
double * m_mdConstraintConstants
m_mdConstraintConstants holds an array of constraint constants (default = 0.0).
Definition: OSInstance.h:2481
TimeDomainStageVariables * variables
variables is a pointer to a TimeDomainVariables object
Definition: OSInstance.h:2078
std::string m_sInstanceSource
m_sInstanceSource holds the instance source.
Definition: OSInstance.h:2314
bool IsEqual(NonlinearExpressions *that)
A function to check for the equality of two objects.
~PolyhedralCone()
The PolyhedralCone class destructor.
MatrixCon()
The MatrixCon class constructor.
TimeDomainInterval()
The Interval class constructor.
int numberOfConstraints
numberOfConstraints gives the number of constraints contained in this stage
Definition: OSInstance.h:2005
bool IsEqual(OSInstance *that)
A function to check for the equality of two objects.
TimeDomainStageCon ** con
con is a pointer to an array of TimeDomainStageCon object pointers
Definition: OSInstance.h:2011
Cone()
The Cone class constructor.
Definition: OSInstance.cpp:987
std::string getMatrixExpressionTreeInInfix(int rowIdx)
Get the infix representation for a given row (or objective function) index.
~Cones()
The Cones class destructor.
Definition: OSInstance.cpp:948
ObjCoef()
The ObjCoef class constructor.
Definition: OSInstance.cpp:608
std::map< int, int > * getVariableIndicesMap()
Retrieve a map of the indices of the variables that are in the expression tree.
std::string name
used to give a name to the file or the problem contained within it
Definition: OSGeneral.h:39
std::vector< ExprNode * > getNonlinearExpressionTreeModInPrefix(int rowIdx)
Get the prefix tokens for a given row index for the modified Expression Tree (quadratic terms added)...
TimeDomainStageObjectives()
The TimeDomainStageObjectives class constructor.
The in-memory representation of a generic cone Specific cone types are derived from this generic clas...
Definition: OSInstance.h:530
double * m_mdConstraintUpperBounds
m_mdConstraintUpperBounds holds an array of constraint upper bounds (default = INF).
Definition: OSInstance.h:2475
bool IsEqual(ObjCoef *that)
A function to check for the equality of two objects.
int numberOfRows
Every cone has (at least) two dimensions; no distinction is made between vector cones and matrix cone...
Definition: OSInstance.h:873
int numberOfColumns
Definition: OSInstance.h:874
std::vector< double > m_vdDomainUnitVec
m_vdDomainUnitVec is a unit vector in the domain space
Definition: OSInstance.h:2852
MatrixExpression ** getMatrixExpressions()
Get the pointers to the roots of all matrix expression trees.
void duplicateExpressionTreesMap()
duplicate the map of expression trees.
int getNumberOfNonlinearExpressionTreeModIndexes()
Get the number of unique nonlinear expression tree indexes after modifying the expression tree to con...
int returnVarType(char vt)
Definition: OSParameters.h:569
int numberOfRows
numberOfRows gives the number of rows of this matrix
Definition: OSInstance.h:1665
Variables()
The Variables class constructor.
Definition: OSInstance.cpp:577
~ObjCoef()
The ObjCoef class destructor.
Definition: OSInstance.cpp:617
int * hessColIdx
hessColIdx is an integer array of column indices in the range 0, ..., n - 1.
Definition: OSGeneral.h:399
std::string * m_msMaxOrMins
m_msMaxOrMins holds a std::string array of objective maxOrMins (&quot;max&quot; or &quot;min&quot;).
Definition: OSInstance.h:2411
a generic class from which we derive matrix constructors (BaseMatrix, MatrixElements, MatrixTransformation and MatrixBlocks) as well as matrix types (OSMatrix and MatrixBlock).
Definition: OSMatrix.h:50
The in-memory representation of the element.
Definition: OSInstance.h:1933
int getObjectiveNumber()
Get number of objectives.
char type
type corresponds to the attribute that holds the variable type: C (Continuous), B (binary)...
Definition: OSInstance.h:66
int m_iVariableNumber
m_iVariableNumber holds the variable number.
Definition: OSInstance.h:2338
bool m_bNonlinearExpressionTreeIndexesProcessed
m_bNonlinearExpressionTreeIndexesProcessed is true if getNonlinearExpressionTreeIndexes() has been ca...
Definition: OSInstance.h:2573
bool IsEqual(MatrixExpression *that)
A function to check for the equality of two objects.
QuadraticCone()
The QuadraticCone class constructor.
bool m_bIndexMapGenerated
Retrieve a map of the indices of the variables that are in the expression tree.
int numberOfVariables
numberOfVariables is the number of variables in the instance
Definition: OSInstance.h:94
int lbConeIdx
lbConeIdx gives a cone that must contain matrixCon - lbMatrix
Definition: OSInstance.h:1759
~Nl()
default destructor.
Definition: OSInstance.cpp:828
int m_iObjectiveNumberNonlinear
m_iObjectiveNumber is the number of objective functions with a nonlinear term.
Definition: OSInstance.h:2401
bool IsEqual(QuadraticCoefficients *that)
A function to check for the equality of two objects.
The in-memory representation of the &lt;instanceData&gt; element.
Definition: OSInstance.h:2174
bool IsEqual(SemidefiniteCone *that)
A function to check for the equality of two objects.
std::map< int, int > getAllNonlinearVariablesIndexMap()
~Objective()
The Objective class destructor.
Definition: OSInstance.cpp:638
std::string * getVariableNames()
Get variable names.
int * hessRowIdx
hessRowIdx is an integer array of row indices in the range 0, ..., n - 1.
Definition: OSGeneral.h:394
bool IsEqual(MatrixVar *that)
A function to check for the equality of two objects.
ENUM_NL_EXPR_SHAPE shape
shape holds the shape of the nonlinear expression (linear/quadratic/convex/general) (see further up i...
Definition: OSInstance.h:420
~OSInstance()
The OSInstance class destructor.
Definition: OSInstance.cpp:167
std::map< int, ScalarExpressionTree * > m_mapExpressionTreesMod
m_mapExpressionTreesMod holds a map of expression trees, with the key being the row index and value b...
Definition: OSInstance.h:2761
virtual std::string getConeInXML()
Write a CopositiveMatricesCone object in XML format.
bool m_bProcessConstraints
-—— data items for Constraints -——
Definition: OSInstance.h:2450
The in-memory representation of the &lt;constraints&gt; child of the &lt;stage&gt; element.
Definition: OSInstance.h:1994
#define OS_MINUS
Definition: OSParameters.h:29
int inodeInt
inodeInt is the unique integer assigned to the OSnLNode or OSnLMNode in OSParameters.h.
Definition: OSnLNode.h:62
std::map< int, ScalarExpressionTree * > m_mapExpressionTrees
m_mapExpressionTrees holds a hash map of scalar-valued expression tree pointers.
Definition: OSInstance.h:2697
int getNumberOfNonlinearExpressions()
Get number of nonlinear expressions.
bool IsEqual(DoubleVector *that)
Definition: OSGeneral.cpp:736
std::vector< double > m_vdX
-—— data vectors for nonlinear optimization -——
Definition: OSInstance.h:2821
int distortionMatrixIdx
Definition: OSInstance.h:897
a data structure that holds general information about files that conform to one of the OSxL schemas ...
Definition: OSGeneral.h:32
int numberOfRows
Every cone has (at least) two dimensions; no distinction is made between vector cones and matrix cone...
Definition: OSInstance.h:1337
int ** m_mmiTimeDomainStageObjList
m_mmiTimeDomainStageObjList holds the list of objectives in each stage.
Definition: OSInstance.h:3041
int * m_miJacNumConTerms
m_miJacNumConTerms holds a int array of the number of constant terms (gradient does not change) for t...
Definition: OSInstance.h:2676
int getNumberOfMatrixExpressionTreeIndexes()
Get the number of unique matrix expression tree indexes.
double lb
lb is the lower bound on the constraint
Definition: OSInstance.h:235
bool IsEqual(IntersectionCone *that)
A function to check for the equality of two objects.
The in-memory representation of the &lt;constraints&gt; element.
Definition: OSInstance.h:251
int numberOfObjectives
numberOfObjectives is the number of objective functions in the instance
Definition: OSInstance.h:201
bool getZeroOrderResults(double *x, double *objLambda, double *conLambda)
Calculate function values.
int startSize
startSize is the dimension of the starts array
Definition: OSGeneral.h:241
static char * j
Definition: OSdtoa.cpp:3622
double ** m_mmdObjGradient
m_mdObjGradient holds an array of pointers, each pointer points to gradient of one objective function...
Definition: OSInstance.h:2814
int ** m_mmiTimeDomainStageConList
m_mmiTimeDomainStageConList holds the list of constraints in each stage.
Definition: OSInstance.h:3031
int numberOfRows
Every cone has (at least) two dimensions; no distinction is made between vector cones and matrix cone...
Definition: OSInstance.h:1261
NonlinearExpressions()
The NonlinearExpressions class constructor.
Definition: OSInstance.cpp:844
ENUM_MATRIX_SYMMETRY
Definition: OSParameters.h:735
std::string * m_msTimeDomainStageNames
m_msTimeDomainStageNames holds the names of the time stages.
Definition: OSInstance.h:3008
int * m_miNonlinearExpressionTreeIndexes
m_miNonlinearExpressionTreeIndexes is an integer pointer to the distinct rows indexes in the nonlinea...
Definition: OSInstance.h:2580
std::vector< double > m_vdLambda
m_vdYval is a vector of Lagrange multipliers
Definition: OSInstance.h:2847
int numberOfObjectives
numberOfObjectives gives the number of objectives contained in this stage
Definition: OSInstance.h:2048
std::map< int, int > m_mapAllNonlinearVariablesIndex
m_mapAllNonlinearVariablesIndexMap is a map of the variables in the Lagrangian function ...
Definition: OSInstance.h:2740
int numberOfEl
Definition: OSGeneral.h:620
std::string m_sInstanceLicence
m_sInstanceDescription holds the instance fileCreator info.
Definition: OSInstance.h:2326
bool setTimeDomainStages(int number, std::string *names)
This sets the number (and optionally names) of the time stages.
int referenceConeIdx
Polar cones use a reference to another, previously defined cone.
Definition: OSInstance.h:1496
TimeDomainStageVar()
The TimeDomainStageVar class constructor.
int * m_miTimeDomainStageObjectiveNumber
m_miTimeDomainStageObjectiveNumber holds the number of objectives in each stage.
Definition: OSInstance.h:3036
IntVector * start
a pointer to the start of each row or column stored in sparse format
Definition: OSInstance.h:306
GeneralSparseMatrix * getMatrixCoefficientsInRowMajor()
Definition: OSMatrix.cpp:1028
ProductCone()
The ProductCone class constructor.
double * getObjectiveWeights()
Get objective weights.
int * indexes
indexes holds an integer array of rowIdx (or colIdx) elements in coefMatrix (AMatrix).
Definition: OSGeneral.h:258
double ub
ub is the upper bound on the constraint
Definition: OSInstance.h:238
~LinearConstraintCoefficients()
The LinearConstraintCoefficients class destructor.
Definition: OSInstance.cpp:748
bool setTimeDomainStageConstraintsUnordered(int numberOfStages, int *numberOfConstraints, int **conIndex)
This sets the constraints associated with each time domain stage in srbitrary order.
double * m_mdJacValue
m_mdJacValue holds a double array of partial derivatives for the Jacobian matrix in sparse form (row ...
Definition: OSInstance.h:2670
~MatrixVar()
The MatrixVar class destructor.
virtual std::string getConeName()
int getNumberOfStringVariables()
getNumberOfStringVariables
bool setInstanceName(std::string name)
set the instance name.
The in-memory representation of an intersection cone.
Definition: OSInstance.h:1324
OSInstance()
The OSInstance class constructor.
Definition: OSInstance.cpp:36
virtual std::string getConeName()
TimeDomainStages * stages
stages is a pointer to a Stages object
Definition: OSInstance.h:2151
MatrixObjectives * matrixObjectives
a pointer to the matrixObjectives object
Definition: OSInstance.h:1895
int m_iMatrixExpressionNumber
m_iMatrixExpressionNumber holds the number of matrix expressions
Definition: OSInstance.h:2971
double ** getDenseObjectiveCoefficients()
getDenseObjectiveCoefficients.
bool initObjGradients()
This should be called by initForAlgDiff()
OSMatrix ** m_mMatrix
m_mMatrix holds the list of constructors for each matrix.
Definition: OSInstance.h:2905
double OSNaN()
returns the value for NaN used in OS
The in-memory representation of the &lt;nonlinearExpressions&gt; element.
Definition: OSInstance.h:452
virtual std::string getConeName()
virtual std::string getConeName()
The OSnLNodeNumber Class.
Definition: OSnLNode.h:1262
int m_iHighestTaylorCoeffOrder
m_iHighestTaylorCoeffOrder is the order of highest calculated Taylor coefficient
Definition: OSInstance.h:2687
PolyhedralCone()
The PolyhedralCone class constructor.
double normScaleFactor
quadratic cones normally are of the form x0 &gt;= x1^2 + x2^2 + ...
Definition: OSInstance.h:896
bool IsEqual(MatrixProgramming *that)
A function to check for the equality of two objects.
bool getSecondOrderResults(double *x, double *objLambda, double *conLambda)
Calculate second derivatives.
SparseJacobianMatrix * getJacobianSparsityPattern()
Used to hold part of the instance in memory.
void fint fint fint real fint real real real real real real real real real * e
std::map< int, MatrixExpressionTree * > getAllMatrixExpressionTrees()
double getTimeDomainIntervalStart()
Get the start for the time domain interval.
~CompletelyPositiveMatricesCone()
default destructor.
int * m_miJacStart
m_miJacStart holds a int array of starts for the Jacobian matrix in sparse form (row major)...
Definition: OSInstance.h:2660
bool matrixHasBase(int n)
Several tools to parse the constructor list of a matrix.
int numberOfVariables
numberOfVariables gives the number of variables contained in this stage
Definition: OSInstance.h:1962
bool bObjectivesModified
bObjectivesModified is true if the objective function data has been modified.
Definition: OSInstance.h:2293
CopositiveMatricesCone()
default constructor.
std::string * m_msObjectiveNames
m_msObjectiveNames holds an array of objective names.
Definition: OSInstance.h:2406
int * m_miTimeDomainStageVariableNumber
m_miTimeDomainStageVariableNumber holds the number of variables in each stage.
Definition: OSInstance.h:3016
TimeDomainStage ** stage
stage is pointer to an array of stage object pointers
Definition: OSInstance.h:2107
bool setMatrixNumber(int number)
set the number of matrices
double * m_mdConstraintFunctionValues
m_mdConstraintFunctionValues holds a double array of constraint function values – the size of the arr...
Definition: OSInstance.h:2644
bool IsEqual(MatrixExpressionTree *that)
A function to check for the equality of two objects.
bool IsEqual(ProductCone *that)
A function to check for the equality of two objects.
virtual std::string getConeName()
int getNumberOfNonlinearConstraints()
double normScaleFactor
rotated quadratic cones normally are of the form x0x1 &gt;= x2^2 + x3^2 + ...
Definition: OSInstance.h:987
a data structure to represent a point of departure for constructing a matrix by modifying parts of a ...
Definition: OSMatrix.h:1536
The in-memory representation of the &lt;matrixCon&gt; element.
Definition: OSInstance.h:1736
double * m_mdConstraintLowerBounds
m_mdConstraintLowerBounds holds an array of constraint lower bounds (default = -INF).
Definition: OSInstance.h:2470
int m_iObjectiveNumber
m_iObjectiveNumber is the number of objective functions.
Definition: OSInstance.h:2396
bool setInstanceCreator(std::string fileCreator)
set the instance creator.
double weight
weight is the weight applied to the given objective function, 1.0 by default
Definition: OSInstance.h:167
bool setConstraintNumber(int number)
set the number of constraints.
std::string name
an optional name to this matrixVar
Definition: OSInstance.h:1611
int valueSize
valueSize is the dimension of the values array
Definition: OSGeneral.h:318
a double vector data structure
Definition: OSGeneral.h:609
bool m_bNonlinearExpressionTreeModIndexesProcessed
m_bNonlinearExpressionTreeModIndexesProcessed is true if getNonlinearExpressionTreeModIndexes has bee...
Definition: OSInstance.h:2593
MatrixObj()
The MatrixVar class constructor.
The in-memory representation of the &lt;obj&gt; element.
Definition: OSInstance.h:141
bool bDeleteArrays
bDeleteArrays is true if we delete the arrays in garbage collection set to true by default ...
Definition: OSGeneral.h:384
MatrixExpressions()
The MatrixExpressions class constructor.
int * getMatrixExpressionTreeIndexes()
Get all the matrix expression tree indexes, i.e.
A generic class from which we derive both OSnLNode and OSnLMNode.
Definition: OSnLNode.h:56
~InstanceData()
The InstanceData class destructor.
int valueSize
valueSize is the dimension of the indexes and values arrays
Definition: OSGeneral.h:246
Nl ** nl
nl is pointer to an array of Nl object pointers
Definition: OSInstance.h:469
bool IsEqual(Variables *that)
A function to check for the equality of two objects.
std::string name
an optional name to this MatrixCon
Definition: OSInstance.h:1768
bool IsEqual(DualCone *that)
A function to check for the equality of two objects.
int * indexes
indexes holds an integer array of variable indices.
Definition: OSGeneral.h:335
virtual std::string getConeName()
DoubleVector * value
a pointer to the array of nonzero values being stored
Definition: OSInstance.h:315
bool bDeleteArrays
bDeleteArrays is true if we delete the arrays in garbage collection set to true by default ...
Definition: OSGeneral.h:149
MatrixProgramming()
The MatrixProgramming class constructor.
std::string * m_msMatrixNames
m_msMatrixNames holds the names of the matrices
Definition: OSInstance.h:2896
double * calculateAllConstraintFunctionValues(double *x, double *objLambda, double *conLambda, bool new_x, int highestOrder)
Calculate all of the constraint function values.
The in-memory representation of the &lt;objectives&gt; element.
Definition: OSInstance.h:188
int constantMatrixIdx
constantMatrixIdx gives a constant added to the matrixObj
Definition: OSInstance.h:1686
fint end
The OSnLNodePlus Class.
Definition: OSnLNode.h:315
Nl ** getNonlinearExpressions()
Get the pointers to the roots of all expression trees.
double lb
lb corresponds to the optional attribute that holds the variable lower bound.
Definition: OSInstance.h:56
double horizon
horizon is the end of the planning period in the &lt;interval&gt; element.
Definition: OSInstance.h:2132
std::map< int, MatrixExpressionTree * > m_mapMatrixExpressionTrees
m_mapMatrixExpressionTrees holds a hash map of matrix-valued expression tree pointers.
Definition: OSInstance.h:2713
a sparse matrix data structure
Definition: OSGeneral.h:223
double ** calculateAllObjectiveFunctionGradients(double *x, double *objLambda, double *conLambda, bool new_x, int highestOrder)
Calculate the gradient of all objective functions.
double constant
constant is the constant term added to the objective function, 0 by default
Definition: OSInstance.h:162
int lbMatrixIdx
lbMatrixIdx gives a lower bound for this matrixVar
Definition: OSInstance.h:1599
int m_iConstraintNumberNonlinear
m_iConstraintNumberNonlinear is the number of constraints that have a nonlinear term.
Definition: OSInstance.h:2460
PolarCone()
The PolarCone class constructor.
char * getConstraintTypes()
Get constraint types.
int numberOfRows
Every cone has (at least) two dimensions; no distinction is made between vector cones and matrix cone...
Definition: OSInstance.h:964
#define OS_LN
Definition: OSParameters.h:38
Variable ** var
Here we define a pointer to an array of var pointers.
Definition: OSInstance.h:97
std::vector< double > m_vdRangeUnitVec
m_vdRangeUnitVec is a unit vector in the range space
Definition: OSInstance.h:2857
int lbConeIdx
lbConeIdx gives a cone that must contain matrixVar - lbMatrix
Definition: OSInstance.h:1602
int numberOfColumns
numberOfColumns gives the number of columns of this matrix
Definition: OSInstance.h:1586
virtual std::string getConeInXML()
Write a NonpositiveCone object in XML format.
bool IsEqual(Constraint *that)
A function to check for the equality of two objects.
bool IsEqual(Matrices *that)
A function to check for the equality of two objects.
~MatrixCon()
The MatrixCon class destructor.
~ProductCone()
The ProductCone class destructor.
int m_iMatrixVarNumber
-—— data items for matrix programming -——
Definition: OSInstance.h:2956
bool m_bProcessExpressionTreesMod
m_bProcessExpressionTreesMod is true if the modified expression trees have been processed.
Definition: OSInstance.h:2638
int hessDimension
hessDimension is the number of nonzeros in each array.
Definition: OSGeneral.h:389
OSnLNode * createExpressionTreeFromPostfix(std::vector< ExprNode * > nlNodeVec)
Take a vector of ExprNodes (OSnLNodes and OSnLMNodes) in postfix format and create a scalar-valued OS...
Definition: OSnLNode.cpp:413
bool IsEqual(QuadraticTerm *that)
A function to check for the equality of two objects.
double start
start is the start of the planning period in the &lt;interval&gt; element.
Definition: OSInstance.h:2127
int * varOneIndexes
varOneIndexes holds an integer array of the first variable indexes of all the quadratic terms...
Definition: OSGeneral.h:445
The in-memory representation of the &lt;matrixVariables&gt; element.
Definition: OSInstance.h:1635
double * m_mdVariableUpperBounds
m_mdVariableUpperBounds holds a double array of variable upper bounds (default = INF).
Definition: OSInstance.h:2384
The in-memory representation of a dual cone.
Definition: OSInstance.h:1400
bool IsEqual(PolyhedralCone *that)
A function to check for the equality of two objects.
int m_iNumberOfIntegerVariables
m_iNumberOfIntegerVariables holds the number of integer variables.
Definition: OSInstance.h:2343
SparseMatrix * getLinearConstraintCoefficientsInRowMajor()
Get linear constraint coefficients in row major.
double * ub
For each dimension of the cone, give the upper and lower bounds The upper bound can be only zero or +...
Definition: OSInstance.h:733
int getNumberOfMatrixObjectives()
Get the number of matrix objectives.
The in-memory representation of a quadratic cone.
Definition: OSInstance.h:860
double * m_mdObjectiveWeights
m_mdObjectiveWeights holds an array of objective weights (default = 1.0).
Definition: OSInstance.h:2426
The OSnLNodeVariable Class.
Definition: OSnLNode.h:1478
MatrixExpressions * matrixExpressions
a pointer to the matrixExpressions object
Definition: OSInstance.h:1901
#define OS_MIN
Definition: OSParameters.h:43
virtual std::string getConeName()
bool IsEqual(MatrixConstraints *that)
A function to check for the equality of two objects.
Cones()
The Cones class constructor.
Definition: OSInstance.cpp:939
virtual std::string getConeInXML()
Write a CompletelyPositiveMatricesCone object in XML format.
GeneralSparseMatrix * getMatrixCoefficientsInColumnMajor()
Definition: OSMatrix.cpp:275
double value
value is the value of the objective function coefficient corresponding to the variable with index idx...
Definition: OSInstance.h:128
The in-memory representation of the &lt;quadraticCoefficients&gt; element.
Definition: OSInstance.h:380
SparseVector * calculateConstraintFunctionGradient(double *x, double *objLambda, double *conLambda, int idx, bool new_x, int highestOrder)
Calculate the gradient of the constraint function indexed by idx.
The in-memory representation of the &lt;stages&gt; element.
Definition: OSInstance.h:2091
SparseHessianMatrix * getLagrangianHessianSparsityPattern()
bool setObjectiveNumber(int number)
set the number of objectives.
bool createOSADFun(std::vector< double > vdX)
Create the a CppAD Function object: this is a function where the domain is the set of variables for t...
bool m_bAllNonlinearVariablesIndex
m_bAllNonlinearVariablesIndexMap is true if the map of the variables in the Lagrangian function has b...
Definition: OSInstance.h:2752
bool setNonlinearExpressions(int nexpr, Nl **root)
set nonlinear expressions
int idxOne
idxOne is the index of the first variable in the quadratic term
Definition: OSInstance.h:358
#define OS_PLUS
Definition: OSParameters.h:27
Objective()
The Objective class constructor.
Definition: OSInstance.cpp:624
#define OS_ABS
Definition: OSParameters.h:35
bool setTimeDomainStageObjectivesUnordered(int numberOfStages, int *numberOfObjectives, int **varIndex)
This sets the objectives associated with each time domain stage in arbitrary order.
void fint fint * k
GeneralSparseMatrix * getMatrixCoefficientsInColumnMajor(int n)
Get the (nonzero) elements of the matrix in column major form.
SparseVector ** m_mObjectiveCoefficients
m_mObjectiveCoefficients holds an array of objective coefficients, one set of objective coefficients ...
Definition: OSInstance.h:2432
bool m_bQuadraticRowIndexesProcessed
m_bQuadraticRowIndexesProcessed is true if getQuadraticRowIndexes() has been called.
Definition: OSInstance.h:2533
int numberOfValues
numberOfValues is the number of nonzero elements stored in the &lt;linearConstraintCoefficients&gt; element...
Definition: OSInstance.h:301
bool addConstraint(int index, std::string name, double lowerBound, double upperBound, double constant)
add a constraint.
Constraints()
The Constraints class constructor.
Definition: OSInstance.cpp:704
MatrixObj ** matrixObj
matrixObj is an array of pointers to the &lt;matrixObj&gt; children
Definition: OSInstance.h:1722
TimeDomainStageCon()
The TimeDomainStageCon class constructor.
bool addObjective(int index, std::string name, std::string maxOrMin, double constant, double weight, SparseVector *objectiveCoefficients)
add an objective.
int ubMatrixIdx
ubMatrixIdx gives an upper bound for this matrixCon
Definition: OSInstance.h:1762
const double OSDBL_MAX
Definition: OSParameters.h:93
bool IsEqual(ScalarExpressionTree *that)
A function to check for the equality of two objects.
The OSnLNodeMax Class.
Definition: OSnLNode.h:414
int * m_miNonLinearVarsReverseMap
m_miNonLinearVarsReverseMap maps the nonlinear variable number back into the original variable space ...
Definition: OSInstance.h:2746
int firstAxisDirection
The indices of the first two component can be changed Since there are possibly many dimensions...
Definition: OSInstance.h:999
int m_iNumberOfTimeStages
m_iNumberOfTimeStages holds the number of discrete stages
Definition: OSInstance.h:2998
virtual std::string getConeInXML()
Write a QuadraticCone object in XML format.
~Matrices()
The Matrices class destructor.
Definition: OSInstance.cpp:902
bool setTimeDomain(std::string format)
This sets the format of the time domain (&quot;stages&quot;/&quot;interval&quot;/&quot;none&quot;)
std::string * getObjectiveMaxOrMins()
Get objective maxOrMins.
bool setTimeDomainStageConstraintsOrdered(int numberOfStages, int *numberOfConstraints, int *startIdx)
This sets the constraints associated with each time domain stage in temporal order.
double value
value is the value of the number
Definition: OSnLNode.h:1266
double ub
ub corresponds to the optional attribute that holds the variable upper bound.
Definition: OSInstance.h:61
int * m_miNumberOfObjCoef
m_miNumberOfObjCoef holds an integer array of number of objective coefficients (default = 0)...
Definition: OSInstance.h:2416
#define OS_SQUARE
Definition: OSParameters.h:36
int idx
idx gives the index of this constraint
Definition: OSInstance.h:1987
a sparse vector data structure
Definition: OSGeneral.h:122
double * hessValues
hessValues is a double array of the Hessian values.
Definition: OSGeneral.h:404
Variables * variables
variables is a pointer to a Variables object
Definition: OSInstance.h:2185
TimeDomainStage()
The TimeDomainStage class constructor.
~NonnegativeCone()
default destructor.
virtual std::string getConeInXML()=0
Write a Cone object in XML format.
ScalarExpressionTree * m_LagrangianExpTree
m_LagrangianExpTree is an ScalarExpressionTree object that is the expression tree for the Lagrangian ...
Definition: OSInstance.h:2719
MatrixVariables * matrixVariables
a pointer to the matrixVariables object
Definition: OSInstance.h:1892
ScalarExpressionTree * getLagrangianExpTree()
SparseMatrix * getLinearConstraintCoefficientsInColumnMajor()
Get linear constraint coefficients in column major.
OSnLNode ** m_mChildren
m_mChildren holds all the operands, that is, nodes that the current node operates on...
Definition: OSnLNode.h:84
MatrixExpressionTree * getMatrixExpressionTree(int rowIdx)
Get the matrix expression tree for a given row index.
int getTimeDomainStageNumber()
Get the number of stages that make up the time domain.
The in-memory representation of the &lt;timeDomain&gt; element.
Definition: OSInstance.h:2139
bool IsEqual(MatrixCon *that)
A function to check for the equality of two objects.
int getMatrixNumber()
Get the number of matrices.
The in-memory representation of the &lt;con&gt; element.
Definition: OSInstance.h:1976
virtual std::string getConeInXML()
Write an OrthantCone object in XML format.
void fint fint fint real fint real real real real real real real * r
int m_iLinearConstraintCoefficientNumber
m_iLinearConstraintCoefficientNumber holds the number of specified (usually nonzero) linear constrain...
Definition: OSInstance.h:2501
bool setVariables(int number, std::string *names, double *lowerBounds, double *upperBounds, char *types)
set all the variable related elements.
~QuadraticCoefficients()
The QuadraticCoefficients class destructor.
Definition: OSInstance.cpp:796
NonpositiveCone()
default constructor.
double * values
values holds a double array of value elements in coefMatrix (AMatrix), which contains nonzero element...
Definition: OSGeneral.h:264
int templateMatrixIdx
templateMatrixIdx refers to a matrix that describes the locations in this matrixVar that are allowed ...
Definition: OSInstance.h:1748
~DualCone()
The DualCone class destructor.
double * getConstraintConstants()
Get constraint constants.
GeneralFileHeader * instanceHeader
the instanceHeader is implemented as a general file header object to allow sharing of classes between...
Definition: OSInstance.h:2275
MatrixExpressionTree * matrixExpressionTree
matrixExpressionTree contains the root of the MatrixExpressionTree
Definition: OSInstance.h:1829
The in-memory representation of the &lt;matrixObjectives&gt; element.
Definition: OSInstance.h:1708
IntersectionCone()
The IntersectionCone class constructor.
double * getObjectiveConstants()
Get objective constants.
int numberOfConstraints
numberOfConstraints is the number of constraints in the instance
Definition: OSInstance.h:264
SemidefiniteCone()
The SemidefiniteCone class constructor.
#define OS_SIN
Definition: OSParameters.h:41
OSnLNode * m_treeRoot
m_treeRoot holds the root node (of OSnLNode type) of the expression tree.
~TimeDomainStageObj()
The TimeDomainStageObj class destructor.
MatrixObjectives()
The MatrixObjectives class constructor.
int m_iHighestOrderEvaluated
m_iHighestOrderEvaluated is the highest order derivative of the current iterate
Definition: OSInstance.h:2808
int varReferenceMatrixIdx
varReferenceMatrixIdx allows some or all of the components of this matrix variable to be copied from ...
Definition: OSInstance.h:1596
The OSnLNodeSum Class.
Definition: OSnLNode.h:365
int startIdx
startdIdx gives the number of the first variable contained in this stage
Definition: OSInstance.h:1965
a sparse Jacobian matrix data structure
Definition: OSGeneral.h:300
bool bDeleteArrays
bDeleteArrays is true if we delete the arrays in garbage collection set to true by default ...
Definition: OSGeneral.h:308
std::string getInstanceName()
Get instance name.
bool m_bProcessVariables
-—— data items for Variables -——
Definition: OSInstance.h:2333
int numberOfRows
numberOfRows gives the number of rows of this matrix
Definition: OSInstance.h:1583
int getADSparsityHessian()
end revised AD code
InstanceData * instanceData
A pointer to an InstanceData object.
Definition: OSInstance.h:2278
int m_iQuadraticTermNumber
m_iQuadraticTermNumber holds the number of specified (usually nonzero) qTerms in the quadratic coeffi...
Definition: OSInstance.h:2549
int numberOfRows
Every cone has (at least) two dimensions; no distinction is made between vector cones and matrix cone...
Definition: OSInstance.h:543
Matrices()
The Matrices class constructor.
Definition: OSInstance.cpp:893
virtual std::string getConeInXML()
Write a PolyhedralCone object in XML format.
DualCone()
The DualCone class constructor.
std::vector< ExprNode * > getPrefixFromExpressionTree()
Get a vector of pointers to OSnLNodes and OSnLMNodes that correspond to the (matrix-valued) expressio...
Definition: OSnLNode.cpp:2542
int startIdx
startdIdx gives the number of the first constraint contained in this stage
Definition: OSInstance.h:2008
bool addQTermsToExressionTree()
OSnLMNode * m_treeRoot
m_treeRoot holds the root node (of OSnLMNode type) of the expression tree.
The in-memory representation of the &lt;nl&gt; element.
Definition: OSInstance.h:410
#define OS_SUM
Definition: OSParameters.h:28
int ** getTimeDomainStageConList()
Get the list of constraints in each stage.
int m_iNumberOfSemiIntegerVariables
m_iNumberOfSemiIntegerVariables holds the number of semi-integer variables.
Definition: OSInstance.h:2358
bool matrixHasElements(int n)
virtual std::string getConeName()
int * m_miMatrixNumberOfRows
m_miMatrixNumberOfRows holds the number of rows for each matrix.
Definition: OSInstance.h:2891
int m_iNumberOfSemiContinuousVariables
m_iNumberOfSemiContinuousVariables holds the number of semi-continuous variables. ...
Definition: OSInstance.h:2353
an integer Vector data structure
Definition: OSGeneral.h:469
static Bigint * mult(Bigint *a, Bigint *b)
Definition: OSdtoa.cpp:857
MatrixVariables()
The MatrixVariables class constructor.
int idx
idx holds the row index of the nonlinear expression
Definition: OSInstance.h:414
std::vector< double > m_vdYval
m_vdYval is a vector of function values
Definition: OSInstance.h:2826
int number
number is the number of elements in the indexes and values arrays.
Definition: OSGeneral.h:154
bool processVariables()
process variables.
char * m_mcConstraintTypes
m_mcConstraintTypes holds a char array of constraint types (R for range; L for &lt;=; G for &gt;=; E for =;...
Definition: OSInstance.h:2487
~MatrixConstraints()
The MatrixConstraints class destructor.
std::string * getObjectiveNames()
Get objective names.
int * starts
starts holds an integer array of start elements, each start element points to the start of partials f...
Definition: OSGeneral.h:324
double ** m_mmdDenseObjectiveCoefficients
m_mmdDenseObjectiveCoefficients holds an array of pointers, each pointer points to a vector of dense ...
Definition: OSInstance.h:2443
int m_iNonlinearExpressionNumber
m_iNonlinearExpressionNumber holds the number of nonlinear expressions.
Definition: OSInstance.h:2622
bool matrixHasElements()
Definition: OSMatrix.cpp:202
int getConstraintNumber()
Get number of constraints.
Objective ** obj
coef is pointer to an array of ObjCoef object pointers
Definition: OSInstance.h:205
std::string source
used when the file or problem appeared in the literature (could be in BiBTeX format or similar) ...
Definition: OSGeneral.h:45
bool getLinearConstraintCoefficientMajor()
Get whether the constraint coefficients is in column major (true) or row major (false).
int startIdx
startdIdx gives the number of the first objective contained in this stage
Definition: OSInstance.h:2051
int axisDirection
The index of the first component can be changed Since there are possibly many dimensions, the index is coded as i0*n1*n2*...
Definition: OSInstance.h:908
double getTimeDomainIntervalHorizon()
Get the horizon for the time domain interval.
bool setInstanceSource(std::string source)
set the instance source.
Matrices * matrices
matrices is a pointer to a Matrices object
Definition: OSInstance.h:2211
#define OS_POWER
Definition: OSParameters.h:33
bool IsEqual(Variable *that)
A function to check for the equality of two objects.
double * m_mdVariableLowerBounds
m_mdVariableLowerBounds holds a double array of variable lower bounds (default = 0.0).
Definition: OSInstance.h:2379
~MatrixExpression()
The MatrixExpression class destructor.
int getNumberOfQuadraticRowIndexes()
Get the number of rows which have a quadratic term.
std::string * getTimeDomainStageNames()
Get the names of the stages (NULL or empty string (&quot;&quot;) if a stage has not been given a name...
std::string semidefiniteness
we need to distinguish positive and negative semidefiniteness
Definition: OSInstance.h:1077
bool setInstanceDescription(std::string description)
set the instance description.
bool IsEqual(IntVector *that)
A method to compare two invectors.
Definition: OSGeneral.cpp:495
The CompletelyPositiveMatricesCone Class.
Definition: OSInstance.h:1186
ENUM_MATRIX_TYPE mergeMatrixType(ENUM_MATRIX_TYPE type1, ENUM_MATRIX_TYPE type2)
A function to merge two matrix types so we can infer the type of a matrix recursively.
Definition: OSParameters.h:661
bool IsEqual(LinearConstraintCoefficients *that)
A function to check for the equality of two objects.
double coef
coef is the coefficient of the quadratic term
Definition: OSInstance.h:366
int numberOfColumns
numberOfColumns gives the number of columns of this matrix
Definition: OSInstance.h:1668
int getNumberOfQuadraticTerms()
Get the number of specified (usually nonzero) qTerms in the quadratic coefficients.
bool OSIsEqual(double x, double y)
Definition: OSGeneral.h:985
~TimeDomainStageVar()
The TimeDomainStageVar class destructor.
bool IsEqual(Cone *that)
A function to check for the equality of two objects.
int * m_miTimeDomainStageConstraintNumber
m_miTimeDomainStageConstraintNumber holds the number of constraints in each stage.
Definition: OSInstance.h:3026
bool m_bDeleteExpressionTree
m_bDeleteExpressionTree is true, if in garbage collection, we should delete the osExpression tree obj...
Definition: OSInstance.h:427
TimeDomainStageConstraints * constraints
constraints is a pointer to a TimeDomainConstraints object
Definition: OSInstance.h:2081
The CopositiveMatricesCone Class.
Definition: OSInstance.h:1127
The in-memory representation of the &lt;variables&gt; child of the &lt;stage&gt; element.
Definition: OSInstance.h:1951
#define OS_SQRT
Definition: OSParameters.h:37
int templateMatrixIdx
templateMatrixIdx refers to a matrix that describes the locations in this matrixObj that are allowed ...
Definition: OSInstance.h:1673
QuadraticTerms * m_quadraticTerms
m_quadraticTerms holds the data structure for all the quadratic terms in the instance.
Definition: OSInstance.h:2555
#define OS_TIMES
Definition: OSParameters.h:31
int getNumberOfMatrixExpressions()
Get the number of matrix-valued expressions.
The in-memory representation of a cone of semidefinite matrices.
Definition: OSInstance.h:1046
NonnegativeCone()
default constructor.
int ubMatrixIdx
ubMatrixIdx gives an upper bound for this matrixVar
Definition: OSInstance.h:1605
Nl()
default constructor.
Definition: OSInstance.cpp:816
Objectives * objectives
objectives is a pointer to a Objectives object
Definition: OSInstance.h:2188
TimeDomainStageVar ** var
var is a pointer to an array of TimeDomainStageVar object pointers
Definition: OSInstance.h:1968
~CopositiveMatricesCone()
default destructor.
~QuadraticTerm()
The QuadraticTerm class destructor.
Definition: OSInstance.cpp:777
The in-memory representation of the &lt;stage&gt; element.
Definition: OSInstance.h:2062
The in-memory representation of a polar cone.
Definition: OSInstance.h:1465
#define OS_E
Definition: OSParameters.h:47
The in-memory representation of the &lt;matrixVar&gt; element.
Definition: OSInstance.h:1579
std::vector< ExprNode * > getNonlinearExpressionTreeInPrefix(int rowIdx)
Get the prefix tokens for a given row index.
std::string getInstanceSource()
Get instance source.
int m_iMatrixObjNumber
m_iMatrixObjNumber holds the number of matrix objectives
Definition: OSInstance.h:2961
int getNumberOfTransformationConstructors(int n)
bool initForAlgDiff()
This should be called by nonlinear solvers using callback functions.
int ** getTimeDomainStageObjList()
Get the list of objectives in each stage.
The in-memory representation of the &lt;cones&gt; element.
Definition: OSInstance.h:1532
std::map< int, ScalarExpressionTree * > getAllNonlinearExpressionTrees()
int * rowIndexes
rowIndexes holds an integer array of row indexes of all the quadratic terms.
Definition: OSGeneral.h:440
std::string os_dtoa_format(double x)
Definition: OSMathUtil.cpp:154
bool IsEqual(QuadraticCone *that)
A function to check for the equality of two objects.
ScalarExpressionTree * osExpressionTree
osExpressionTree contains the root of the ScalarExpressionTree
Definition: OSInstance.h:430
std::vector< ExprNode * > getMatrixExpressionTreeInPrefix(int rowIdx)
Get the prefix tokens for a given row index.
MatrixProgramming * matrixProgramming
matrixProgramming is a pointer to a MatrixProgramming object
Definition: OSInstance.h:2221
int * starts
starts holds an integer array of start elements in coefMatrix (AMatrix), which points to the start of...
Definition: OSGeneral.h:252
TimeDomainStageVariables()
The TimeDomainStageVariables class constructor.
double * values
values holds a double array of nonzero values.
Definition: OSGeneral.h:164
~PolarCone()
The PolarCone class destructor.
int * m_miQuadRowIndexes
m_miQuadRowIndexes is an integer pointer to the distinct row indexes with a quadratic term...
Definition: OSInstance.h:2538
bool IsEqual(PolarCone *that)
A function to check for the equality of two objects.
double * calculateAllObjectiveFunctionValues(double *x, double *objLambda, double *conLambda, bool new_x, int highestOrder)
Calculate all of the objective function values.
int getNumberOfTransformationConstructors()
Definition: OSMatrix.cpp:253
QuadraticTerms * getQuadraticTerms()
Get all the quadratic terms in the instance.
int m_iNumberOfNonlinearExpressionTreeModIndexes
m_iNumberOfNonlinearExpressionTreeModIndexes holds the number of distinct rows and objectives with no...
Definition: OSInstance.h:2587
bool bVariablesModified
bVariablesModified is true if the variables data has been modified.
Definition: OSInstance.h:2288
int numberOfRows
Definition: OSMatrix.h:1904
IntVector * components
the list of components contributing to the intersection each component contains a reference to a prev...
Definition: OSInstance.h:1357
Cones * cones
cones is a pointer to a Cones object
Definition: OSInstance.h:2216
int * otherIndexes
Definition: OSInstance.h:553
virtual std::string getConeName()
double * getVariableUpperBounds()
Get variable upper bounds.
bool addMatrix(int index, std::string name, int numberOfRows, int numberOfColumns, ENUM_MATRIX_SYMMETRY symmetry, ENUM_MATRIX_TYPE matrixType, unsigned int inumberOfChildren, MatrixNode **m_mChildren)
add a matrix.
int ** getTimeDomainStageVarList()
Get the list of variables in each stage.
The in-memory representation of the &lt;matrixConstraints&gt; element.
Definition: OSInstance.h:1787
bool m_bColumnMajor
m_bColumnMajor holds whether the linear constraint coefficients are stored in column major (if m_bCol...
Definition: OSInstance.h:2507
The OSnLNodeProduct Class.
Definition: OSnLNode.h:766
double * el
Definition: OSGeneral.h:621
bool IsEqual(InstanceData *that)
A function to check for the equality of two objects.
bool matrixHasTransformations()
Definition: OSMatrix.cpp:217
The in-memory representation of the &lt;objectives&gt; child of the &lt;stage&gt; element.
Definition: OSInstance.h:2037
std::vector< double > reverseAD(int p, std::vector< double > vdlambda)
Perform an AD reverse sweep.
virtual ENUM_MATRIX_TYPE getMatrixType()
Definition: OSMatrix.cpp:3020
bool copyLinearConstraintCoefficients(int numberOfValues, bool isColumnMajor, double *values, int valuesBegin, int valuesEnd, int *indexes, int indexesBegin, int indexesEnd, int *starts, int startsBegin, int startsEnd)
copy linear constraint coefficients: perform a deep copy of the sparse matrix
RotatedQuadraticCone()
The RotatedQuadraticCone class constructor.
int numberOfNonlinearExpressions
numberOfNonlinearExpressions is the number of &lt;nl&gt; elements in the &lt;nonlinearExpressions&gt; element...
Definition: OSInstance.h:466
#define OS_IF
Definition: OSParameters.h:49
int numberOfObjCoef
numberOfObjCoef is the number of variables with a nonzero objective function coefficient ...
Definition: OSInstance.h:172
std::string m_sTimeDomainFormat
m_sTimeDomainFormat holds the format (&quot;stages&quot;/&quot;interval&quot;) of the time domain.
Definition: OSInstance.h:3003
bool setNumberOfQuadraticTerms(int nq)
set the number of quadratic terms
std::vector< bool > m_vbLagHessNonz
m_vbLagHessNonz is a boolean vector holding the nonzero pattern of the Lagrangian of the Hessian ...
Definition: OSInstance.h:2832
int numberOfQuadraticTerms
numberOfQuadraticTerms is the number of quadratic terms in the &lt;quadraticCoefficients&gt; element...
Definition: OSInstance.h:393
int * indexes
indexes holds an integer array of indexes whose corresponding values are nonzero. ...
Definition: OSGeneral.h:159
int m_iNumberOfQuadraticRowIndexes
-—— data items for quadratic coefficients -——
Definition: OSInstance.h:2528
int numberOfMatrices
numberOfMatrices is the number of &lt;nl&gt; elements in the &lt;matrices&gt; element.
Definition: OSInstance.h:496
int idx
idx holds the row index of the nonlinear expression
Definition: OSInstance.h:1820
TimeDomainInterval * interval
interval is a pointer to an Interval object
Definition: OSInstance.h:2155
~Constraint()
The Constraint class destructor.
Definition: OSInstance.cpp:697
Cone ** cone
cone is pointer to an array of Cone object pointers
Definition: OSInstance.h:1549
~TimeDomain()
The TimeDomain class destructor.
virtual std::string getConeName()
#define OS_PRODUCT
Definition: OSParameters.h:34
Objectives()
The Objectives class constructor.
Definition: OSInstance.cpp:657
~IntersectionCone()
The IntersectionCone class destructor.
bool bDeleteArrays
bDeleteArrays is true if we delete the arrays in garbage collection set to true by default ...
Definition: OSGeneral.h:230
ENUM_MATRIX_CONSTRUCTOR_TYPE nType
nType is a unique integer assigned to each type of matrix node (see OSParameters.h) ...
Definition: OSMatrix.h:64
~RotatedQuadraticCone()
The RotatedQuadraticCone class destructor.
#define OS_ERF
Definition: OSParameters.h:40
for(int i=0;i< nnz;i++)
bool getSparseJacobianFromRowMajor()
int * m_miMatrixNumberOfColumns
m_miMatrixNumberOfColumns holds the number of columns for each matrix.
Definition: OSInstance.h:2886
bool m_bOSADFunIsCreated
m_bOSADFunIsCreated is true if we have created the OSInstanc OSAD Function
Definition: OSInstance.h:2768
bool m_bNonLinearStructuresInitialized
m_bNonLinearStructuresInitialized is true if initializeNonLinearStructures() has been called...
Definition: OSInstance.h:2790
int getNumberOfBlocksConstructors(int n)
std::string * m_msConstraintNames
m_msConstraintNames holds an array of constraint names.
Definition: OSInstance.h:2465
void fint * m
std::string getInstanceCreator()
Get instance fileCreator.
std::string getInstanceLicence()
Get instance licence.
int conReferenceMatrixIdx
conReferenceMatrixIdx allows some or all of the components of this matrixCon to be copied from constr...
Definition: OSInstance.h:1753
TimeDomainStages()
The Stages class constructor.
int referenceConeIdx
Dual cones use a reference to another, previously defined cone.
Definition: OSInstance.h:1431
std::vector< ExprNode * > getNonlinearExpressionTreeModInPostfix(int rowIdx)
Get the postfix tokens for a given row index for the modified Expression Tree (quadratic terms added)...
TimeDomainStageObjectives * objectives
objectives is a pointer to a TimeDomainObjectives object
Definition: OSInstance.h:2084
bool setVariableNumber(int number)
set the number of variables.
The in-memory representation of an OSiL instance..
Definition: OSInstance.h:2262
std::vector< ExprNode * > getPostfixFromExpressionTree()
Get a vector of pointers to ExprNodes that correspond to the expression tree in postfix format...
Definition: OSnLNode.cpp:2564
int ubConeIdx
ubConeIdx gives a cone that must contain ubMatrix - matrixVar
Definition: OSInstance.h:1608
std::string getNonlinearExpressionTreeInInfix(int rowIdx)
Get the infix representation for a given row (or objective function) index.
~TimeDomainStages()
The Stages class destructor.
SparseMatrix * m_linearConstraintCoefficientsInColumnMajor
m_linearConstraintCoefficientsInColumnMajor holds the standard three-array data structure for linear ...
Definition: OSInstance.h:2514
The in-memory representation of the variables element.
Definition: OSInstance.h:83
bool m_bQTermsAdded
m_bQTermsAdded is true if we added the quadratic terms to the expression tree
Definition: OSInstance.h:2559
The OSnLNode Class for nonlinear expressions.
Definition: OSnLNode.h:179
int * conVals
conVals holds an integer array of integers, conVals[i] is the number of constant terms in the gradien...
Definition: OSGeneral.h:330
bool processObjectives()
process objectives.
~OrthantCone()
default destructor.
TimeDomainStageObj()
The TimeDomainStageObj class constructor.
double * lb
Definition: OSInstance.h:734
QuadraticCoefficients * quadraticCoefficients
quadraticCoefficients is a pointer to a QuadraticCoefficients object
Definition: OSInstance.h:2201
~TimeDomainStage()
The TimeDomainStage class destructor.
int * m_miJacIndex
m_miJacIndex holds a int array of variable indices for the Jacobian matrix in sparse form (row major)...
Definition: OSInstance.h:2665
virtual std::string getTokenName()=0
int idx
idx is the index of the variable corresponding to the coefficient
Definition: OSInstance.h:123
int getNumberOfMatrixConstraints()
Get the number of matrix constraints.
~NonlinearExpressions()
The NonlinearExpressions class destructor.
Definition: OSInstance.cpp:853
double * coefficients
coefficients holds a double array all the quadratic term coefficients.
Definition: OSGeneral.h:455
OSMatrix ** matrix
matrix is a pointer to an array of OSMatrix object pointers
Definition: OSInstance.h:499
#define OS_DIVIDE
Definition: OSParameters.h:32
char varType
an optional variable type (C, B, I, D, J, S).
Definition: OSInstance.h:1616
Constraint()
The Constraint class constructor.
Definition: OSInstance.cpp:685
int numberOfStages
numberOfStages is the number of stages in the &lt;stages&gt; element.
Definition: OSInstance.h:2104
int idx
idx is the index of the row in which the quadratic term appears
Definition: OSInstance.h:353
double * m_mdObjectiveFunctionValues
m_mdObjectiveFunctionValues holds a double array of objective function values – the size of the array...
Definition: OSInstance.h:2650
bool setConstraints(int number, std::string *names, double *lowerBounds, double *upperBounds, double *constants)
set all the constraint related elements.
bool setTimeDomainInterval(double start, double horizon)
This sets the start and end of the time interval.
std::string m_sInstanceName
-—— data items for InstanceHeader -——
Definition: OSInstance.h:2310
int * varTwoIndexes
varTwoIndexes holds an integer array of the second variable indexes of all the quadratic terms...
Definition: OSGeneral.h:450
std::vector< ExprNode * > getMatrixExpressionTreeModInPostfix(int rowIdx)
Get the postfix tokens for a given row index for the modified Expression Tree (quadratic terms added)...
int * getTimeDomainStageNumberOfObjectives()
Get the number of objectives contained in each time stage.
The in-memory representation of a SparseHessianMatrix..
Definition: OSGeneral.h:376
char * m_mcVariableTypes
m_mcVariableTypes holds a char array of variable types (default = &#39;C&#39;).
Definition: OSInstance.h:2374
int m_iNumberOfBinaryVariables
m_iNumberOfBinaryVariables holds the number of binary variables.
Definition: OSInstance.h:2348
The in-memory representation of a product cone.
Definition: OSInstance.h:1248
std::string * getConstraintNames()
Get constraint names.
bool IsEqual(MatrixObj *that)
A function to check for the equality of two objects.
std::vector< double > m_vdYjacval
m_vdYval is a vector equal to a column or row of the Jacobian
Definition: OSInstance.h:2837
bool m_bGetDenseObjectives
m_bGetDenseObjectives holds whether the dense objective functions are processed.
Definition: OSInstance.h:2437
bool setInstanceLicence(std::string licence)
set the instance licence.
int m_iNumberOfNonlinearExpressionTreeIndexes
-—— data items for nonlinear expressions -——
Definition: OSInstance.h:2567
bool initializeNonLinearStructures()
Initialize the data structures for the nonlinear API.
int * getObjectiveCoefficientNumbers()
Get objective coefficient number.
std::string m_sInstanceCreator
m_sInstanceSource holds the instance source.
Definition: OSInstance.h:2322
int numberOfColumns
Definition: OSInstance.h:544
bool addCone(int index, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType, std::string name, int numberOfOtherIndexes=0, int *otherIndexes=NULL)
add a cone.
used for throwing exceptions.
Definition: OSErrorClass.h:31
virtual std::vector< ExprNode * > getPrefixFromExpressionTree()
Get a vector of pointers to OSnLNodes and OSnLMNodes that correspond to the (scalar-valued or matrix-...
Definition: OSnLNode.cpp:446
int m_iMatrixNumber
m_iMatrixNumber holds the number of matrices
Definition: OSInstance.h:2869
~Objectives()
The Objectives class destructor.
Definition: OSInstance.cpp:666
void fint * n
bool matrixHasTransformations(int n)
std::map< int, int > * mapVarIdx
m_mapVarIdx is a map used to generate the infix expression for AD the key is idx, a variable number; ...
Used to hold the instance in memory.
int getNumberOfSemiIntegerVariables()
getNumberOfSemiIntegerVariables
#define OS_VARIABLE
Definition: OSParameters.h:48
LinearConstraintCoefficients * linearConstraintCoefficients
linearConstraintCoefficients is a pointer to a LinearConstraintCoefficients object ...
Definition: OSInstance.h:2196
virtual std::string getConeInXML()
Write a RotatedQuadraticCone object in XML format.
bool IsEqual(MatrixObjectives *that)
A function to check for the equality of two objects.
~NonpositiveCone()
default destructor.
ENUM_MATRIX_SYMMETRY symmetry
To track the type of symmetry present in the matrix or block.
Definition: OSMatrix.h:1896
int numberOfRows
numberOfRows gives the number of rows of this matrix
Definition: OSInstance.h:1740
int * m_miNonlinearExpressionTreeModIndexes
m_miNonlinearExpressionTreeModIndexes is an integer pointer to the distinct rows indexes in the modif...
Definition: OSInstance.h:2599
int numberOfCones
numberOfCones is the number of &lt;nl&gt; elements in the &lt;cones&gt; element.
Definition: OSInstance.h:1546
#define OS_EXP
Definition: OSParameters.h:39
std::map< int, int > m_mapOSADFunRangeIndex
m_mapOSADFunRangeIndex is an inverse of the previous map.
Definition: OSInstance.h:2703
The in-memory representation of the &lt;qTerm&gt; element.
Definition: OSInstance.h:340
The in-memory representation of the &lt;expr&gt; element, which is like a nonlinear expression, but since it involves matrices, the expression could be linear, so a &quot;shape&quot; attribute is added to distinguish linear and nonlinear expressions.
Definition: OSInstance.h:1816
a data structure to represent a matrix object (derived from MatrixType)
Definition: OSMatrix.h:2185
MatrixConstraints()
The MatrixConstraints class constructor.
int getNumberOfBlocksConstructors()
Definition: OSMatrix.cpp:264
~MatrixExpressions()
The MatrixExpressions class destructor.
int numberOfOtherIndexes
Cones can also be formed by Multidimensional tensors.
Definition: OSInstance.h:552
unsigned int m_iNumberOfNonlinearVariables
m_iNumberOfNonlinearVariables is the number of variables that appear in a nonlinear expression...
Definition: OSInstance.h:2612
double constant
constant is a value that is added to the constraint
Definition: OSInstance.h:232
std::vector< double > forwardAD(int p, std::vector< double > vdX)
Perform an AD forward sweep.
int * el
Definition: OSGeneral.h:484
The in-memory representation of the variable element.
Definition: OSInstance.h:44
SparseMatrix * m_linearConstraintCoefficientsInRowMajor
m_linearConstraintCoefficientsInRowMajor holds the standard three-array data structure for linear con...
Definition: OSInstance.h:2521
virtual std::string getConeName()
bool m_bLagrangianExpTreeCreated
m_bLagrangianHessionCreated is true if a Lagrangian function for the Hessian has been created ...
Definition: OSInstance.h:2724
std::string name
Definition: OSMatrix.h:2189
int * getQuadraticRowIndexes()
Get the indexes of rows which have a quadratic term.
The NonnegativeCone Class.
Definition: OSInstance.h:609
int iNumberOfStartElements
iNumberOfStartElements counts the number of elements in the &lt;start&gt; section of &lt;linearConstraintCoeff...
Definition: OSInstance.h:322
bool matrixHasBlocks()
Definition: OSMatrix.cpp:227
bool processLinearConstraintCoefficients()
process linear constraint coefficients.
int templateMatrixIdx
templateMatrixIdx refers to a matrix that describes the locations in this matrixVar that are allowed ...
Definition: OSInstance.h:1591
SparseJacobianMatrix * m_sparseJacMatrix
m_sparseJacMatrix is the Jacobian matrix stored in sparse matrix format
Definition: OSInstance.h:2681
~Variable()
The Variable class destructor.
Definition: OSInstance.cpp:570
int objReferenceMatrixIdx
objReferenceMatrixIdx allows some or all of the components of this matrixObj to be copied from object...
Definition: OSInstance.h:1678
virtual std::string getConeInXML()
Write a ProductCone object in XML format.
int getNumberOfBinaryVariables()
getNumberOfBinaryVariables
std::string getInstanceDescription()
Get instance description.
double * calculateObjectiveFunctionGradient(double *x, double *objLambda, double *conLambda, int objIdx, bool new_x, int highestOrder)
Calculate the gradient of the objective function indexed by objIdx.
std::map< int, ScalarExpressionTree * > getAllNonlinearExpressionTreesMod()
MatrixExpression()
The MatrixExpression class constructor.
void fint fint fint real fint real * x
The in-memory representation of the &lt;con&gt; element.
Definition: OSInstance.h:218
int getNumberOfNonlinearExpressionTreeIndexes()
Get the number of unique nonlinear expression tree indexes.
bool m_bDeleteExpressionTree
if m_bDeleteExpressionTree is true during garbage collection, we should delete the osExpression tree ...
Definition: OSInstance.h:1836
std::string name
name is the name of the constraint
Definition: OSInstance.h:229
int lbMatrixIdx
lbMatrixIdx gives a lower bound for this matrixCon
Definition: OSInstance.h:1756
int getNumberOfNonlinearObjectives()
std::string getTimeDomainFormat()
Get the format of the time domain (&quot;stages&quot;/&quot;interval&quot;)
std::map< int, MatrixExpressionTree * > getAllMatrixExpressionTreesMod()
std::vector< ExprNode * > getMatrixExpressionTreeInPostfix(int rowIdx)
Get the postfix tokens for a given row index.
bool m_binitForAlgDiff
-—— data items for automatic differentiation -——
Definition: OSInstance.h:2606
QuadraticTerm()
The QuadraticTerm class constructor.
Definition: OSInstance.cpp:763
The in-memory representation of the &lt;matrixExpressions&gt; element.
Definition: OSInstance.h:1855
~MatrixProgramming()
The MatrixProgramming class destructor.
bool processMatrices()
process matrices.
The NonpositiveCone Class.
Definition: OSInstance.h:667
std::vector< ExprNode * > getNonlinearExpressionTreeInPostfix(int rowIdx)
Get the postfix tokens for a given row index.
std::string licence
licensing information if applicable
Definition: OSGeneral.h:60
#define OS_NEGATE
Definition: OSParameters.h:30