OSInstance.cpp
Go to the documentation of this file.
1 /* $Id: OSInstance.cpp 5284 2017-12-08 13:52:50Z stefan $ */
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  //at this point we know where the original variable appears in the Jacobian; store location
6336  posVarIdx->second = iTemp;
6337  iTemp++;
6338  }
6339  }
6340  }
6341 #ifndef NDEBUG
6342  outStr.str("");
6343  outStr.clear();
6344  outStr << "HERE ARE ROW STARTS:" << std::endl;
6345  for (i = 0; i < iNumRowStarts; i++ )
6346  {
6347  outStr << m_miJacStart[ i] << " ";
6348  }
6349  outStr << std::endl << std::endl;
6350  outStr << "HERE ARE VARIABLE INDICES:" << std::endl;
6351  for (i = 0; i < m_miJacStart[ iNumRowStarts - 1]; i++ )
6352  {
6353  outStr << m_miJacIndex[ i] << " ";
6354  }
6355  outStr << std::endl << std::endl;
6356  outStr << "HERE ARE VALUES:" << std::endl;
6357  for (i = 0; i < m_miJacStart[ iNumRowStarts - 1]; i++ )
6358  {
6359  outStr << m_mdJacValue[ i] << " ";
6360  }
6361  outStr << std::endl << std::endl;
6362 
6363  outStr << "HERE ARE NUMBER OF CONSTANT TERMS:" << std::endl;
6364  for (i = 0; i < iNumRowStarts - 1; i++ )
6365 
6366  {
6367  outStr << m_miJacNumConTerms[ i ] << " ";
6368  }
6369  outStr << std::endl << std::endl;
6371 #endif
6372  return true;
6373 }//getSparseJacobianFromColumnMajor
6374 
6375 
6377 {
6378  std::ostringstream outStr;
6379 
6380  // we assume row major matrix
6381  if( m_bColumnMajor == true) return false;
6382  int iNumJacRowStarts = getConstraintNumber() + 1;
6383  std::map<int, int>::iterator posVarIdx;
6384  int i,j, k;
6385  int *start = NULL;
6386  int *index = NULL;
6387  double *value = NULL;
6388 
6389  if (this->instanceData->linearConstraintCoefficients != NULL &&
6390  this->instanceData->linearConstraintCoefficients->numberOfValues > 0)
6391  {
6395  }
6396 
6397  m_miJacStart = new int[ iNumJacRowStarts];
6399  OSnLNodePlus *nlNodePlus;
6400  OSnLNodeVariable *nlNodeVariable;
6401  // now initialize starts and variable index maps
6402  for ( i = 0; i < iNumJacRowStarts; i++)
6403  {
6404  m_miJacStart [ i ] = 0;
6405  // map the variables in the nonlinear rows
6406  if( m_mapExpressionTreesMod.find( i) != m_mapExpressionTreesMod.end() )
6407  {
6408  // the following is equivalent to m_treeRoot->getVariableIndexMap( i);
6409  m_mapExpressionTreesMod[ i]->getVariableIndicesMap();
6410 
6411  }
6412  }
6413  int loopLimit = getConstraintNumber();
6414  // only execute the following code if there are linear constraint coefficients
6415  // determine the number of terms in constraint with constant partial derivative
6416  if (this->instanceData->linearConstraintCoefficients != NULL &&
6417  this->instanceData->linearConstraintCoefficients->numberOfValues > 0)
6418  {
6419  // i is indexing rows (constrains) and j is indexing column numbers
6420  for (i = 0; i < loopLimit; i++)
6421  {
6422  m_miJacNumConTerms[ i] = 0;
6423  for (j = start[i]; j < start[ i + 1 ]; j++)
6424  {
6425  // determine if variable index[j] appears in the Expression Tree for row i
6426  // if we pass if test below then variable i is in the expresssion tree and we add
6427  // the linear term to the expession tree
6428  if( (m_mapExpressionTreesMod.find( i) != m_mapExpressionTreesMod.end() ) &&
6429  ( (*m_mapExpressionTreesMod[ i]->mapVarIdx).find( index[ j]) != (*m_mapExpressionTreesMod[ i]->mapVarIdx).end()) )
6430  {
6431  // variable index[ j] appears in the expression tree for row i
6432  // add the coefficient corresponding to variable index[j] in row i to the expression tree
6433  // define a new OSnLVariable and OSnLnodePlus
6434  if(value[ j] > 0 || value[j] < 0)
6435  {
6436  nlNodeVariable = new OSnLNodeVariable();
6437  nlNodeVariable->coef = value[ j];
6438  nlNodeVariable->idx = index[ j];
6439  nlNodePlus = new OSnLNodePlus();
6440  nlNodePlus->m_mChildren[ 0] = m_mapExpressionTreesMod[ i ]->m_treeRoot;
6441  nlNodePlus->m_mChildren[ 1] = nlNodeVariable;
6442  m_mapExpressionTreesMod[ i ]->m_treeRoot = nlNodePlus;
6443  }
6444  }
6445  else
6446  {
6447  //the partial derivative of variable j in row i is constant
6448  m_miJacNumConTerms[ i]++;
6449  }
6450  }
6451  }
6452  }
6453  //
6454  m_miJacStart[0] = 0;
6455  for (i = 1; i < iNumJacRowStarts; i++ )
6456  {
6457  if( m_mapExpressionTreesMod.find( i - 1) != m_mapExpressionTreesMod.end() )
6458  {
6459  m_miJacStart[i] = m_miJacStart[i - 1] + (m_miJacNumConTerms[ i - 1] + (*m_mapExpressionTreesMod[ i - 1]->mapVarIdx).size() );
6460  }
6461  else
6462  {
6463  m_miJacStart[i] = m_miJacStart[i - 1] + m_miJacNumConTerms[ i - 1];
6464  }
6465  }
6466  // we know how many constant terms and size of arrays
6467  // dimension miIndex and mdValue here
6468  m_iJacValueSize = m_miJacStart[ iNumJacRowStarts - 1];
6469  m_miJacIndex = new int[ m_iJacValueSize];
6470  m_mdJacValue = new double[ m_iJacValueSize ];
6471  // now loop again and put in values and indices
6472  // first put in the constant terms
6473  if (this->instanceData->linearConstraintCoefficients != NULL &&
6474  this->instanceData->linearConstraintCoefficients->numberOfValues > 0)
6475  {
6476  for (i = 0; i < loopLimit; i++)
6477  {
6478  k = 0;
6479  for (j = start[i]; j < start[ i + 1 ]; j++)
6480  {
6481  if( (m_mapExpressionTreesMod.find( i) == m_mapExpressionTreesMod.end() ) ||
6482  ( (*m_mapExpressionTreesMod[ i]->mapVarIdx).find( index[ j]) == (*m_mapExpressionTreesMod[ i]->mapVarIdx).end()) )
6483  {
6484  m_miJacIndex[ m_miJacStart[i] + k ] = index[ j];
6485  m_mdJacValue[ m_miJacStart[i] + k ] = value[ j];
6486  k++;
6487  }
6488  }
6489  }
6490  }
6491  // put in terms from the modified nonlinear expression tree
6492  for (i = 0; i < loopLimit; i++ )
6493  {
6494  k = m_miJacStart[i] + m_miJacNumConTerms[ i ];
6495  // if the row is in the list of expression trees read in indices and values
6496  if( m_mapExpressionTreesMod.find( i) != m_mapExpressionTreesMod.end() )
6497  {
6498  for(posVarIdx = (*m_mapExpressionTreesMod[ i]->mapVarIdx).begin(); posVarIdx
6499  != (*m_mapExpressionTreesMod[ i]->mapVarIdx).end(); ++posVarIdx)
6500  {
6501  m_miJacIndex[ k] = posVarIdx->first;
6502  m_mdJacValue[ k] = 0;
6503  //at this point we know where the original variable appears in the Jacobian; store location
6504  posVarIdx->second = k;
6505  k++;
6506  }
6507  }
6508  }
6509 #ifndef NDEBUG
6510  outStr.str("");
6511  outStr.clear();
6512  outStr << "HERE ARE ROW STARTS:" << std::endl;
6513  for (i = 0; i < iNumJacRowStarts; i++ )
6514  {
6515  outStr << m_miJacStart[ i] << " ";
6516  }
6517  outStr << std::endl << std::endl;
6518  outStr << "HERE ARE VARIABLE INDICES:" << std::endl;
6519  for (i = 0; i < m_miJacStart[ iNumJacRowStarts - 1]; i++ )
6520  {
6521  outStr << m_miJacIndex[ i] << " ";
6522  }
6523  outStr << std::endl << std::endl;
6524  outStr << "HERE ARE VALUES:" << std::endl;
6525  for (i = 0; i < m_miJacStart[ iNumJacRowStarts - 1]; i++ )
6526  {
6527  outStr << m_mdJacValue[ i] << " ";
6528  }
6529  outStr << std::endl << std::endl;
6530 
6531  outStr << "HERE ARE NUMBER OF CONSTANT TERMS:" << std::endl;
6532  for (i = 0; i < iNumJacRowStarts - 1; i++ )
6533  {
6534  outStr << m_miJacNumConTerms[ i ] << " ";
6535  }
6536  outStr << std::endl << std::endl;
6538 #endif
6539  return true;
6540 }//getSparseJacobianFromRowMajor
6541 
6543 {
6545  // we calculate the Lagrangian for all the objectives and constraints
6546  // with nonlinear terms
6547  // first initialize everything for nonlinear work
6549  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
6550  OSnLNodeTimes* nlNodeTimes = NULL;
6551  OSnLNodeVariable* nlNodeVariable = NULL;
6552  OSnLNodeSum* nlNodeSum = NULL;
6553  int numChildren = 0;
6554  int rowIdx;
6555  // create the sum node
6556  nlNodeSum = new OSnLNodeSum();
6557  nlNodeSum->inumberOfChildren = m_mapExpressionTreesMod.size();
6558  nlNodeSum->m_mChildren = new OSnLNode*[ nlNodeSum->inumberOfChildren];
6559  // create and expression tree for the sum node
6561  m_LagrangianExpTree->m_treeRoot = nlNodeSum;
6562  // now create the children of the sum node
6563  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
6564  {
6565  // this variable is the Lagrange multiplier
6566  nlNodeVariable = new OSnLNodeVariable();
6567  nlNodeVariable->coef = 1.;
6568  // get the correct index --
6569  // for rowIdx = 0, ..., m - 1 set idx = numVar + rowIdx
6570  rowIdx = posMapExpTree->first;
6571  if(rowIdx >= 0)
6572  {
6573  nlNodeVariable->idx = instanceData->variables->numberOfVariables + rowIdx;
6574  }
6575  else
6576  {
6577  nlNodeVariable->idx = instanceData->variables->numberOfVariables +
6578  instanceData->constraints->numberOfConstraints + (abs(rowIdx) - 1);
6579  }
6580 
6581  // now create a times multiply the new variable times the root of the expression tree
6582  nlNodeTimes = new OSnLNodeTimes();
6583  nlNodeTimes->m_mChildren[ 0] = nlNodeVariable;
6584  nlNodeTimes->m_mChildren[ 1] = m_mapExpressionTreesMod[ posMapExpTree->first ]->m_treeRoot;
6585  // the times node is the new child
6586  nlNodeSum->m_mChildren[ numChildren] = nlNodeTimes;
6587  numChildren++;
6588  }
6589  // get a variable index map for the expression tree
6592  return m_LagrangianExpTree;
6593 }//getLagrangianExpTree
6594 
6596 {
6597  std::ostringstream outStr;
6598 
6600  // loop over the map of expression tree and get a unique listing of all variables
6601  // put these in the map m_mapAllNonlinearVariablesIndex
6602  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
6603  std::map<int, int>::iterator posVarIdx;
6604  ScalarExpressionTree *expTree;
6605  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
6606  {
6607  // get the index map for the expression tree
6608 
6609  expTree = posMapExpTree->second;
6610  if(expTree->m_bIndexMapGenerated == false)expTree->getVariableIndicesMap();
6611  for(posVarIdx = (*expTree->mapVarIdx).begin(); posVarIdx != (*expTree->mapVarIdx).end(); ++posVarIdx)
6612  {
6613  if( m_mapAllNonlinearVariablesIndex.find( posVarIdx->first) == m_mapAllNonlinearVariablesIndex.end() )
6614  {
6615  // add the variable to the Lagragian map
6616  m_mapAllNonlinearVariablesIndex[ posVarIdx->first] = 1;
6617  }
6618  }
6619  }
6621  // now order appropriately
6622  int kount = 0;
6623  for(posVarIdx = m_mapAllNonlinearVariablesIndex.begin(); posVarIdx !=m_mapAllNonlinearVariablesIndex.end(); ++posVarIdx)
6624  {
6625  posVarIdx->second = kount;
6626  m_miNonLinearVarsReverseMap[ kount] = posVarIdx->first;
6627  kount++;
6628 #ifndef NDEBUG
6629  outStr.str("");
6630  outStr.clear();
6631  outStr << "POSITION FIRST = " << posVarIdx->first ;
6632  outStr << " POSITION SECOND = " << posVarIdx->second << std::endl;
6634 #endif
6635  }
6639 }//getAllNonlinearVariablesIndexMap
6640 
6642 {
6643  std::ostringstream outStr;
6644 
6645  // fill in the nonzeros in the sparse Hessian
6647  if( m_iNumberOfNonlinearVariables == 0) return NULL;
6648  if( m_binitForAlgDiff == false ) initForAlgDiff();
6649  unsigned int i = 0;
6650  unsigned int j;
6651  int numNonz = 0;
6652  // Create the CppAD function if necessary
6653  //
6654  std::vector<double> vx;
6655  std::map<int, int>::iterator posMap1, posMap2;
6656  if( (m_bOSADFunIsCreated == false || m_bCppADMustReTape == true ) && (m_mapExpressionTreesMod.size() > 0) )
6657  {
6658  for(posMap1 = m_mapAllNonlinearVariablesIndex.begin(); posMap1 != m_mapAllNonlinearVariablesIndex.end(); ++posMap1)
6659  {
6660  vx.push_back( 1.0) ;
6661  }
6662  createOSADFun( vx);
6663  }
6664 
6665  // note this function call also fills in m_vbLagHessNonz
6666  numNonz = getADSparsityHessian();
6667 
6668  i = 0;
6669  // now that we have the dimension create SparseHessianMatrix (upper triangular)
6676  numNonz = 0;
6677  for(posMap1 = m_mapAllNonlinearVariablesIndex.begin(); posMap1 != m_mapAllNonlinearVariablesIndex.end(); ++posMap1)
6678  {
6679  j = i;
6680  for(posMap2 = posMap1; posMap2 != m_mapAllNonlinearVariablesIndex.end(); ++posMap2)
6681  {
6683  {
6684  *(m_LagrangianSparseHessian->hessRowIdx + numNonz) = posMap1->first;
6685  *(m_LagrangianSparseHessian->hessColIdx + numNonz) = posMap2->first;
6686  numNonz++;
6687  }
6688  j++;
6689  }
6690  i++;
6691  }
6692 #ifndef NDEBUG
6693  outStr.str("");
6694  outStr.clear();
6695  outStr << "HESSIAN SPARSITY PATTERN" << std::endl;
6696  int kj;
6697  for(kj = 0; kj < m_LagrangianSparseHessian->hessDimension; kj++)
6698  {
6699  outStr << "Row Index = " << *(m_LagrangianSparseHessian->hessRowIdx + kj) << std::endl;
6700  outStr << "Column Index = " << *(m_LagrangianSparseHessian->hessColIdx + kj) << std::endl;
6701  }
6703 #endif
6704  //
6707 }//getLagrangianHessianSparsityPattern
6708 
6709 
6711 {
6712  // we do this so that we can keep the integrity of the original formulation
6713  if(m_bDuplicateExpressionTreesMap == false)
6714  {
6715  // first make sure the map was created
6719  return;
6720  }
6721  else
6722  {
6723  return;
6724  }
6725 }//duplicateExpressionTreesMap
6726 
6727 
6728 bool OSInstance::getIterateResults( double *x, double *objLambda, double* conMultipliers,
6729  bool new_x, int highestOrder)
6730 {
6731  try
6732  {
6733  if( m_binitForAlgDiff == false) initForAlgDiff();
6734  std::map<int, int>::iterator posVarIndexMap;
6735 
6736  if(new_x == true)
6737  {
6738  if( m_vdX.size() > 0) m_vdX.clear();
6739  for(posVarIndexMap = m_mapAllNonlinearVariablesIndex.begin(); posVarIndexMap != m_mapAllNonlinearVariablesIndex.end(); ++posVarIndexMap)
6740  {
6741  m_vdX.push_back( x[ posVarIndexMap->first]) ;
6742  }
6743  if( (m_bOSADFunIsCreated == false || m_bCppADMustReTape == true ) && (m_mapExpressionTreesMod.size() > 0) )
6744  {
6745  createOSADFun( m_vdX);
6746  }
6747  }
6748  else // make sure vector not empty -- this could happen if we have linear obj and nonlinear constraints
6749 
6750  {
6751  if( m_vdX.size() == 0)
6752  {
6753  for(posVarIndexMap = m_mapAllNonlinearVariablesIndex.begin(); posVarIndexMap != m_mapAllNonlinearVariablesIndex.end(); ++posVarIndexMap)
6754  {
6755  m_vdX.push_back( x[ posVarIndexMap->first]) ;
6756  }
6757  if( (m_bOSADFunIsCreated == false || m_bCppADMustReTape == true ) && (m_mapExpressionTreesMod.size() > 0) )
6758  {
6759  createOSADFun( m_vdX);
6760  }
6761  }
6762  }
6763  switch( highestOrder)
6764  {
6765  case 0:
6766  if(new_x == true || m_iHighestOrderEvaluated < 0)
6767  {
6768  if(bUseExpTreeForFunEval == true)
6769  {
6772  }
6773  else
6774  {
6775  getZeroOrderResults(x, objLambda, conMultipliers);
6776  }
6777 
6778  }
6779  break;
6780  case 1:
6781  if(new_x == true || m_iHighestOrderEvaluated < 0)
6782  getZeroOrderResults(x, objLambda, conMultipliers);
6783  if(new_x == true || m_iHighestOrderEvaluated < 1)
6784  getFirstOrderResults(x, objLambda, conMultipliers);
6785  break;
6786  case 2:
6787  if(new_x == true || m_iHighestOrderEvaluated < 0)
6788  getZeroOrderResults(x, objLambda, conMultipliers);
6789  if(new_x == true || m_iHighestOrderEvaluated < 2)
6790  getSecondOrderResults(x, objLambda, conMultipliers);
6791  break;
6792  default:
6793  throw ErrorClass("Derivative should be order 0, 1, or 2");
6794  }//end switch
6795  return true;
6796  }
6797  catch(const ErrorClass& eclass)
6798  {
6799  throw ErrorClass( eclass.errormsg);
6800  }
6801 }//end getIterateResults
6802 
6803 
6804 bool OSInstance::getZeroOrderResults(double *x, double *objLambda, double *conMultipliers)
6805 {
6806  std::ostringstream outStr;
6807 
6808  try
6809  {
6810  // initialize everything
6811  int i, j, rowNum, objNum;
6812  if( m_mapExpressionTreesMod.size() > 0)
6813  {
6814  m_vdYval = this->forwardAD(0, m_vdX);
6815  }
6816  // now get all function and constraint values using forward result
6817  for(rowNum = 0; rowNum < m_iConstraintNumber; rowNum++)
6818  {
6819  m_mdConstraintFunctionValues[ rowNum] = 0.0;
6820  if( m_mapExpressionTreesMod.find( rowNum) != m_mapExpressionTreesMod.end() )
6821  {
6823  }
6824  // now the linear part
6825  // be careful, loop over only the constant terms in sparseJacMatrix
6826  i = m_sparseJacMatrix->starts[ rowNum];
6827  j = m_sparseJacMatrix->starts[ rowNum + 1 ];
6828  while ( (i - m_sparseJacMatrix->starts[ rowNum]) < m_sparseJacMatrix->conVals[ rowNum] )
6829  {
6831  i++;
6832  }
6833  // add in the constraint function constant
6835 #ifndef NDEBUG
6836  outStr.str("");
6837  outStr.clear();
6838  outStr << "Constraint " << rowNum << " function value = " << m_mdConstraintFunctionValues[ rowNum ] << std::endl;
6840 #endif
6841  }
6842  // now get the objective function values from the forward result
6843  for(objNum = 0; objNum < m_iObjectiveNumber; objNum++)
6844  {
6845  m_mdObjectiveFunctionValues[ objNum] = 0.0;
6846  if( m_mapExpressionTreesMod.find( -objNum -1) != m_mapExpressionTreesMod.end() )
6847  {
6848  m_mdObjectiveFunctionValues[ objNum] = m_vdYval[ objNum];
6849  }
6850  for(i = 0; i < m_iVariableNumber; i++)
6851  {
6852  m_mdObjectiveFunctionValues[ objNum] += m_mmdDenseObjectiveCoefficients[ objNum][i]*x[ i];
6853  }
6854 #ifndef NDEBUG
6855  outStr.str("");
6856  outStr.clear();
6857  outStr << "Objective " << objNum << " function value = " << m_mdObjectiveFunctionValues[ objNum] << std::endl;
6859 #endif
6860  }
6861  return true;
6862  }//end try
6863  catch(const ErrorClass& eclass)
6864  {
6865  throw ErrorClass( eclass.errormsg);
6866  }
6867 }//end getZeroOrderResults
6868 
6869 
6870 bool OSInstance::getFirstOrderResults(double *x, double *objLambda, double *conMultipliers)
6871 {
6872  std::ostringstream outStr;
6873 
6874  try
6875  {
6876  // initialize everything
6877  unsigned int i, j;
6878  int rowNum, jacIndex;
6879  unsigned int jstart, jend;
6880  int idx;
6881  ScalarExpressionTree *expTree = NULL;
6882  int domainIdx = 0;
6883  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
6884  std::map<int, int>::iterator posVarIdx;
6885 
6892  {
6893  // calculate the gradient by doing a reverse sweep over each row
6894  // loop over the constraints that have a nonlinear term and get their gradients
6895  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
6896  {
6897  idx = posMapExpTree->first;
6898  // we are considering only constraints, not objective function
6899  if(idx >= 0)
6900  {
6901  m_vdRangeUnitVec[ domainIdx] = 1.;
6902  m_mapExpressionTreesMod[ idx]->getVariableIndicesMap();
6904  // check size
6905  jstart = m_miJacStart[ idx] + m_miJacNumConTerms[ idx];
6906  jend = m_miJacStart[ idx + 1 ];
6907  if( (*m_mapExpressionTreesMod[ idx]->mapVarIdx).size() != (jend - jstart)) throw
6908  ErrorClass("number of partials not consistent");
6909  j = 0;
6910  jacIndex = 0;
6911  for(posVarIdx = m_mapAllNonlinearVariablesIndex.begin(); posVarIdx
6912  != m_mapAllNonlinearVariablesIndex.end(); ++posVarIdx)
6913  {
6914  // we are working with variable posVarIdx->first in the original variable space
6915  // we need to see which variable this is in the individual constraint map
6916  if( (*m_mapExpressionTreesMod[ idx]->mapVarIdx).find( posVarIdx->first) != (*m_mapExpressionTreesMod[ idx]->mapVarIdx).end())
6917  {
6918  m_mdJacValue[ jstart] = m_vdYjacval[ jacIndex];
6919  jstart++;
6920  j++;
6921  }
6922  jacIndex++;
6923  }
6924 
6925  m_vdRangeUnitVec[ domainIdx] = 0.;
6926  domainIdx++;
6927  }
6928  else // we have an objective function
6929  {
6930  domainIdx++;
6931  }
6932  }
6933  }
6934  else
6935  {
6936  // calculate the gradients using a forward sweep over all the variables.
6937  for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
6938  {
6939  m_vdDomainUnitVec[i] = 1.;
6940  rowNum = 0;
6941  if( m_mapExpressionTreesMod.size() > 0)
6942  {
6944  }
6945  // fill in Jacobian here, we have column i
6946  // start Jacobian calculation
6947  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
6948  {
6949  idx = posMapExpTree->first;
6950  // we are considering only constraints, not objective function
6951  if(idx >= 0)
6952  {
6953  //figure out original variable this corresponds to
6954  //then use (*m_mapExpressionTreesMod[ idx]->mapVarIdx) to figure out which variable it is within row idx
6955  //m_mapAllNonlinearVariablesIndex
6956  expTree = m_mapExpressionTreesMod[ idx];
6957  if( (*expTree->mapVarIdx).find( m_miNonLinearVarsReverseMap[ i]) != (*expTree->mapVarIdx).end() )
6958  {
6959  jacIndex = (*m_mapExpressionTreesMod[ idx]->mapVarIdx)[ m_miNonLinearVarsReverseMap[ i]];
6960  // kipp change 1 to number of objective functions
6962  }
6963  rowNum++;
6964  }//end Jacobian calculation
6965  }
6966  //
6967  m_vdDomainUnitVec[i] = 0.;
6968  }
6969  }
6970 #ifndef NDEBUG
6971  outStr.str("");
6972  outStr.clear();
6973  int k;
6974  outStr << "JACOBIAN DATA " << std::endl;
6975  for(idx = 0; idx < m_iConstraintNumber; idx++)
6976  {
6977  for(k = *(m_sparseJacMatrix->starts + idx); k < *(m_sparseJacMatrix->starts + idx + 1); k++)
6978  {
6979  outStr << "row idx = " << idx << " col idx = "<< *(m_sparseJacMatrix->indexes + k)
6980  << " value = " << *(m_sparseJacMatrix->values + k) << std::endl;
6981  }
6982  }
6984 #endif
6985  return true;
6986  }//end try
6987  catch(const ErrorClass& eclass)
6988  {
6989  throw ErrorClass( eclass.errormsg);
6990  }
6991 }// end getFirstOrderResults
6992 
6993 
6994 bool OSInstance::getSecondOrderResults(double *x, double *objLambda, double *conMultipliers)
6995 {
6996  std::ostringstream outStr;
6997 
6998  try
6999  {
7000  // initialize everything
7001  unsigned int i, j;
7002  int rowNum, jacIndex;
7003  int jstart, idx;
7004  ScalarExpressionTree *expTree = NULL;
7005  int hessValuesIdx = 0;
7007  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
7008  std::map<int, int>::iterator posVarIndexMap;
7009  if( objLambda == NULL) throw ErrorClass("must have a multiplier for the objective function even if zero when calling getSecondOrderResults");
7010 
7011  if( conMultipliers == NULL) throw ErrorClass("cannot have a null vector of lagrange multipliers when calling getSecondOrderResults -- okay if zero");
7012  if( m_vdLambda.size() > 0) m_vdLambda.clear();
7013  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
7014  {
7015  if( posMapExpTree->first >= 0)
7016  {
7017  m_vdLambda.push_back( conMultipliers[ posMapExpTree->first]);
7018  }
7019  else
7020  {
7021  // kipp correct when there is more than one obj
7022  m_vdLambda.push_back( objLambda[ abs(posMapExpTree->first) - 1] );
7023  }
7024  }
7025  for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
7026  {
7027  m_vdDomainUnitVec[i] = 1.;
7028  rowNum = 0;
7029  if( m_mapExpressionTreesMod.size() > 0)
7030  {
7032  }
7033  // fill in Jacobian here, we have column i
7034  // start Jacobian calculation
7035  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
7036  {
7037  idx = posMapExpTree->first;
7038  // we are considering only constraints, not objective function
7039  if(idx >= 0)
7040  {
7041  //figure out original variable this corresponds to
7042  //then use (*m_mapExpressionTreesMod[ idx]->mapVarIdx)
7043  //to figure out which variable it is within row idx
7044  //m_mapAllNonlinearVariablesIndex
7045  expTree = m_mapExpressionTreesMod[ idx];
7046  if( (*expTree->mapVarIdx).find( m_miNonLinearVarsReverseMap[ i]) != (*expTree->mapVarIdx).end() )
7047  {
7048  jacIndex = (*m_mapExpressionTreesMod[ idx]->mapVarIdx)[ m_miNonLinearVarsReverseMap[ i]];
7050  }
7051  rowNum++;
7052  }//end Jacobian calculation
7053  else
7054  {
7055  // see if we have the objective function of interest
7056  //kipp fix if more than one obj
7057  m_mmdObjGradient[ (abs( idx) - 1)][ m_miNonLinearVarsReverseMap[ i]] = m_vdYjacval[ (abs( idx) - 1)] +
7059  }//end Obj gradient calculation
7060  }
7061  // now calculate the Hessian
7062  if( m_mapExpressionTreesMod.size() > 0)
7063  {
7064  m_vdw = reverseAD(2, m_vdLambda); // derivative of partial
7065  }
7066  for(j = i; j < m_iNumberOfNonlinearVariables; j++)
7067  {
7068  if( m_vbLagHessNonz[i*m_iNumberOfNonlinearVariables + j] == true)
7069  {
7070  m_LagrangianSparseHessian->hessValues[ hessValuesIdx] = m_vdw[ j*2 + 1];
7071 #ifndef NDEBUG
7072  outStr.str("");
7073  outStr.clear();
7074  outStr << "reverse 2 " << m_LagrangianSparseHessian->hessValues[ hessValuesIdx] << std::endl;
7076 #endif
7077  hessValuesIdx++;
7078  }
7079  }
7080  //
7081  //
7082  m_vdDomainUnitVec[i] = 0.;
7083  }
7084 #ifndef NDEBUG
7085  outStr.str("");
7086  outStr.clear();
7087  int k;
7088  outStr << "JACOBIAN DATA " << std::endl;
7089  for(idx = 0; idx < m_iConstraintNumber; idx++)
7090  {
7091  for(k = *(m_sparseJacMatrix->starts + idx); k < *(m_sparseJacMatrix->starts + idx + 1); k++)
7092  {
7093  outStr << "row idx = " << idx << " col idx = "<< *(m_sparseJacMatrix->indexes + k)
7094  << " value = " << *(m_sparseJacMatrix->values + k) << std::endl;
7095  }
7096  }
7098 #endif
7099  return true;
7100  }//end try
7101  catch(const ErrorClass& eclass)
7102  {
7103  throw ErrorClass( eclass.errormsg);
7104  }
7105 }// end getSecondOrderResults
7106 
7108 {
7109  std::ostringstream outStr;
7110 
7111  if( m_binitForAlgDiff == true ) return true;
7113  initObjGradients();
7115  //if(m_bSparseJacobianCalculated == false) getJacobianSparsityPattern();
7116  //see if we need to retape
7117  //loop over expression tree and see if one requires it
7118  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
7119  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
7120  {
7121  if(posMapExpTree->second->bADMustReTape == true) m_bCppADMustReTape = true;
7122  }
7123 
7124 #ifndef NDEBUG
7125  outStr << "RETAPE == " << m_bCppADMustReTape << std::endl;
7127 #endif
7128  unsigned int i;
7129  for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
7130  {
7131  m_vdDomainUnitVec.push_back( 0.0 );
7132  }
7133  for(i = 0; i < m_mapExpressionTreesMod.size(); i++)
7134  {
7135  m_vdRangeUnitVec.push_back( 0.0 );
7136  }
7137  m_binitForAlgDiff = true;
7138  //m_bSparseJacobianCalculated = true;
7139  //m_bProcessExpressionTrees = true;
7140  return true;
7141 }//end initForAlgDiff
7142 
7144 {
7145  std::ostringstream outStr;
7146 
7147  int i, j;
7148  int m, n;
7149  m = getObjectiveNumber();
7150  n = getVariableNumber();
7152  if(m <= 0)
7153  {
7154  m_mmdObjGradient = NULL;
7155  return true;
7156  }
7157  m_mmdObjGradient = new double*[m];
7158  for(i = 0; i < m; i++)
7159  {
7160  m_mmdObjGradient[i] = new double[n];
7161  for(j = 0; j < n; j++)
7162  {
7164 #ifndef NDEBUG
7165  outStr << "m_mmdObjGradient[i][j] = " << m_mmdObjGradient[i][j] << std::endl;
7167 #endif
7168  }
7169  }
7170  return true;
7171 }//end initObjGradients
7187 bool OSInstance::setTimeDomain(std::string format)
7188 {
7189  if ((format != "stages") && (format != "interval") && (format != "none"))
7190  return false;
7191  if (instanceData->timeDomain == NULL)
7192  {
7194  }
7195  if (format == "stages")
7196  {
7197  if (instanceData->timeDomain->interval != NULL)
7198  {
7199  delete instanceData->timeDomain->interval;
7200  instanceData->timeDomain->interval = NULL;
7201  }
7202  if (instanceData->timeDomain->stages == NULL)
7204  m_sTimeDomainFormat = format;
7205  }
7206  if (format == "interval")
7207  {
7208  if (instanceData->timeDomain->stages != NULL)
7209  {
7210  delete instanceData->timeDomain->stages;
7211  instanceData->timeDomain->stages = NULL;
7212  }
7213  if (instanceData->timeDomain->interval == NULL)
7215  m_sTimeDomainFormat = format;
7216  }
7217  if (format == "none")
7218  {
7219  if (instanceData->timeDomain->stages != NULL)
7220  {
7221  delete instanceData->timeDomain->stages;
7222  instanceData->timeDomain->stages = NULL;
7223  }
7224  if (instanceData->timeDomain->interval != NULL)
7225  {
7226  delete instanceData->timeDomain->interval;
7227  instanceData->timeDomain->interval = NULL;
7228  }
7229  m_sTimeDomainFormat = "";
7230  }
7231  return true;
7232 } //end setTimeDomain
7233 
7237 bool OSInstance::setTimeDomainStages(int number, std::string *names)
7238 {
7239  if (instanceData->timeDomain == NULL)
7241  if (instanceData->timeDomain->interval != NULL)
7242  return false;
7243  if (instanceData->timeDomain->stages == NULL)
7244  {
7246  }
7247  else
7248  {
7249  if (instanceData->timeDomain->stages->numberOfStages != number)
7250  {
7251  for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
7252  {
7253  if (instanceData->timeDomain->stages->stage[i]->variables != NULL)
7254  {
7257  }
7258  if (instanceData->timeDomain->stages->stage[i]->constraints != NULL)
7259  {
7262 
7263  }
7264  if (instanceData->timeDomain->stages->stage[i]->objectives != NULL)
7265  {
7268  }
7269  delete instanceData->timeDomain->stages->stage[i];
7270  instanceData->timeDomain->stages->stage[i] = NULL;
7271  }
7272  delete []instanceData->timeDomain->stages->stage;
7273  instanceData->timeDomain->stages->stage = NULL;
7274  }
7275  }
7276  if (number != 0 )
7277  {
7278  if (instanceData->timeDomain->stages->stage == NULL)
7280  for (int i = 0; i < number; i++)
7281  {
7283  }
7285  }
7286  for (int i = 0; i < number; i++)
7287  //initial or empty vars, cons, objectives and set default to all objectives
7288  {
7289  if (instanceData->timeDomain->stages->stage[i]->variables != NULL)
7290  {
7293  }
7295  if (instanceData->timeDomain->stages->stage[i]->constraints != NULL)
7296  {
7299  }
7301  if (instanceData->timeDomain->stages->stage[i]->objectives != NULL)
7302  {
7305  }
7309  for (int j = 0; j < instanceData->objectives->numberOfObjectives; j++)
7310  {
7312  instanceData->timeDomain->stages->stage[i]->objectives->obj[j]->idx = -(j+1);
7313  }
7314  if (names != NULL)
7315  instanceData->timeDomain->stages->stage[i]->name = names[i];
7316  }
7317  return true;
7318 } //end setTimeDomainStages
7319 
7323 bool OSInstance::setTimeDomainStageVariablesOrdered(int numberOfStages, int *numberOfVariables, int *startIdx)
7324 {
7325  if (instanceData->timeDomain == NULL)
7327  if (instanceData->timeDomain->interval != NULL)
7328  return false;
7329  if (instanceData->timeDomain->stages == NULL)
7331  if (instanceData->timeDomain->stages != NULL)
7332  {
7333  if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
7335  return false;
7336  }
7338  {
7339  instanceData->timeDomain->stages->numberOfStages = numberOfStages;
7340  if (instanceData->timeDomain->stages->stage == NULL)
7341  instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
7342  for (int i = 0; i < numberOfStages; i++)
7344  }
7345  int checksum = 0;
7346  for (int i = 0; i < numberOfStages; i++)
7347  //initial or empty vars, cons, objectives and set default to all objectives
7348  {
7349  if (instanceData->timeDomain->stages->stage[i]->variables != NULL)
7350  {
7353  }
7355  instanceData->timeDomain->stages->stage[i]->variables->startIdx = startIdx[i];
7356  instanceData->timeDomain->stages->stage[i]->variables->numberOfVariables = numberOfVariables[i];
7357  checksum += numberOfVariables[i];
7358  }
7359  return (checksum == instanceData->variables->numberOfVariables);
7360 } //end setTimeDomainVariablesOrdered
7361 
7365 bool OSInstance::setTimeDomainStageVariablesUnordered(int numberOfStages, int *numberOfVariables, int **varIndex)
7366 {
7367  if (instanceData->timeDomain == NULL)
7369  if (instanceData->timeDomain->interval != NULL)
7370  return false;
7371  if (instanceData->timeDomain->stages == NULL)
7373  if (instanceData->timeDomain->stages != NULL)
7374  {
7375  if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
7377  return false;
7378  }
7380  {
7381  instanceData->timeDomain->stages->numberOfStages = numberOfStages;
7382  if (instanceData->timeDomain->stages->stage == NULL)
7383  instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
7384  for (int i = 0; i < numberOfStages; i++)
7386  }
7387  int checksum = 0;
7388  for (int i = 0; i < numberOfStages; i++)
7389  //initial or empty vars, cons, objectives and set default to all objectives
7390  {
7391  if (instanceData->timeDomain->stages->stage[i]->variables != NULL)
7392  {
7395  }
7397  instanceData->timeDomain->stages->stage[i]->variables->numberOfVariables = numberOfVariables[i];
7398  instanceData->timeDomain->stages->stage[i]->variables->var = new TimeDomainStageVar*[numberOfVariables[i]];
7399  for (int j = 0; j < numberOfVariables[i]; j++)
7400  {
7402  instanceData->timeDomain->stages->stage[i]->variables->var[j]->idx = varIndex[i][j];
7403  }
7404  checksum += numberOfVariables[i];
7405  }
7406  if (checksum != instanceData->variables->numberOfVariables) return false;
7407  int *checkvar = new int[instanceData->variables->numberOfVariables];
7408  for (int j = 0; j < instanceData->variables->numberOfVariables; j++)
7409  checkvar[j] = -1;
7410  int k;
7411  for (int i = 0; i < numberOfStages; i++)
7412  for (int j = 0; j < instanceData->timeDomain->stages->stage[i]->variables->numberOfVariables; j++)
7413  {
7415  if (checkvar[k] != -1)
7416  {
7417  delete [] checkvar;
7418  checkvar = NULL;
7419  return false;
7420  }
7421  checkvar[k] = instanceData->timeDomain->stages->stage[i]->variables->var[j]->idx;
7422  }
7423  delete [] checkvar;
7424  checkvar = NULL;
7425  return true;
7426 } //end setTimeDomainVariablesUnordered
7427 
7431 bool OSInstance::setTimeDomainStageConstraintsOrdered(int numberOfStages, int *numberOfConstraints, int *startIdx)
7432 {
7433  if (instanceData->timeDomain == NULL)
7435  if (instanceData->timeDomain->interval != NULL)
7436  return false;
7437  if (instanceData->timeDomain->stages == NULL)
7439  if (instanceData->timeDomain->stages != NULL)
7440  {
7441  if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
7443  return false;
7444  }
7446  {
7447  instanceData->timeDomain->stages->numberOfStages = numberOfStages;
7448  if (instanceData->timeDomain->stages->stage == NULL)
7449  instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
7450  for (int i = 0; i < numberOfStages; i++)
7452  }
7453  int checksum = 0;
7454  for (int i = 0; i < numberOfStages; i++)
7455  //initial or empty vars, cons, objectives and set default to all objectives
7456  {
7457  if (instanceData->timeDomain->stages->stage[i]->constraints != NULL)
7458  {
7461  }
7463  instanceData->timeDomain->stages->stage[i]->constraints->startIdx = startIdx[i];
7464  instanceData->timeDomain->stages->stage[i]->constraints->numberOfConstraints = numberOfConstraints[i];
7465  checksum += numberOfConstraints[i];
7466  }
7467  return (checksum == instanceData->constraints->numberOfConstraints);
7468 } // end of setTimeStageConstraintsOrdered
7469 
7473 bool OSInstance::setTimeDomainStageConstraintsUnordered(int numberOfStages, int *numberOfConstraints, int **conIndex)
7474 {
7475  if (instanceData->timeDomain == NULL)
7477  if (instanceData->timeDomain->interval != NULL)
7478  return false;
7479  if (instanceData->timeDomain->stages == NULL)
7481  if (instanceData->timeDomain->stages != NULL)
7482  {
7483  if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
7485  return false;
7486  }
7488  {
7489  instanceData->timeDomain->stages->numberOfStages = numberOfStages;
7490  if (instanceData->timeDomain->stages->stage == NULL)
7491  instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
7492  for (int i = 0; i < numberOfStages; i++)
7494  }
7495  int checksum = 0;
7496  for (int i = 0; i < numberOfStages; i++)
7497  //initial or empty vars, cons, objectives and set default to all objectives
7498  {
7499  if (instanceData->timeDomain->stages->stage[i]->constraints != NULL)
7500  {
7503  }
7505  instanceData->timeDomain->stages->stage[i]->constraints->numberOfConstraints = numberOfConstraints[i];
7506  instanceData->timeDomain->stages->stage[i]->constraints->con = new TimeDomainStageCon*[numberOfConstraints[i]];
7507  for (int j = 0; j < numberOfConstraints[i]; j++)
7508  {
7510  instanceData->timeDomain->stages->stage[i]->constraints->con[j]->idx = conIndex[i][j];
7511  }
7512  checksum += numberOfConstraints[i];
7513  }
7514  if (checksum != instanceData->constraints->numberOfConstraints) return false;
7515  int *checkvar = new int[instanceData->constraints->numberOfConstraints];
7516  for (int j = 0; j < instanceData->constraints->numberOfConstraints; j++)
7517  checkvar[j] = -1;
7518  int k;
7519  for (int i = 0; i < numberOfStages; i++)
7520  for (int j = 0; j < instanceData->timeDomain->stages->stage[i]->constraints->numberOfConstraints; j++)
7521  {
7523  if (checkvar[k] != -1)
7524  {
7525  delete [] checkvar;
7526  checkvar = NULL;
7527  return false;
7528  }
7529  checkvar[k] = instanceData->timeDomain->stages->stage[i]->constraints->con[j]->idx;
7530  }
7531  delete [] checkvar;
7532  checkvar = NULL;
7533  return true;
7534 }// end setTimeDomainStageConstraintsUnordered()
7535 
7539 bool OSInstance::setTimeDomainStageObjectivesOrdered(int numberOfStages, int *numberOfObjectives, int *startIdx)
7540 {
7541  if (instanceData->timeDomain == NULL)
7543  if (instanceData->timeDomain->interval != NULL)
7544  return false;
7545  if (instanceData->timeDomain->stages == NULL)
7546 
7548  if (instanceData->timeDomain->stages != NULL)
7549  {
7550  if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
7552  return false;
7553  }
7555 
7556  {
7557  instanceData->timeDomain->stages->numberOfStages = numberOfStages;
7558  if (instanceData->timeDomain->stages->stage == NULL)
7559  instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
7560  for (int i = 0; i < numberOfStages; i++)
7562  }
7563  for (int i = 0; i < numberOfStages; i++)
7564  //initial or empty vars, cons, objectives and set default to all objectives
7565  {
7566 
7567  if (instanceData->timeDomain->stages->stage[i]->objectives != NULL)
7568  {
7571  }
7573  instanceData->timeDomain->stages->stage[i]->objectives->startIdx = startIdx[i];
7574  instanceData->timeDomain->stages->stage[i]->objectives->numberOfObjectives = numberOfObjectives[i];
7575  }
7576  return true;
7577 }
7578 
7582 bool OSInstance::setTimeDomainStageObjectivesUnordered(int numberOfStages, int *numberOfObjectives, int **objIndex)
7583 {
7584  if (instanceData->timeDomain == NULL)
7586  if (instanceData->timeDomain->interval != NULL)
7587  return false;
7588  if (instanceData->timeDomain->stages == NULL)
7590  if (instanceData->timeDomain->stages != NULL)
7591  {
7592  if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
7594  return false;
7595  }
7597  {
7598  instanceData->timeDomain->stages->numberOfStages = numberOfStages;
7599  if (instanceData->timeDomain->stages->stage == NULL)
7600  instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
7601  for (int i = 0; i < numberOfStages; i++)
7603  }
7604  for (int i = 0; i < numberOfStages; i++)
7605  //initial or empty vars, cons, objectives and set default to all objectives
7606  {
7607  if (instanceData->timeDomain->stages->stage[i]->objectives != NULL)
7608  {
7611  }
7613  instanceData->timeDomain->stages->stage[i]->objectives->numberOfObjectives = numberOfObjectives[i];
7614  instanceData->timeDomain->stages->stage[i]->objectives->obj = new TimeDomainStageObj*[numberOfObjectives[i]];
7615  for (int j = 0; j < numberOfObjectives[i]; j++)
7616  {
7618  instanceData->timeDomain->stages->stage[i]->objectives->obj[j]->idx = objIndex[i][j];
7619  }
7620  }
7621  int *checkvar = new int[instanceData->objectives->numberOfObjectives];
7622  for (int j = 0; j < instanceData->objectives->numberOfObjectives; j++)
7623  checkvar[j] = 0;
7624  int k;
7625  for (int i = 0; i < numberOfStages; i++)
7626  for (int j = 0; j < instanceData->timeDomain->stages->stage[i]->objectives->numberOfObjectives; j++)
7627  {
7629  checkvar[k] = instanceData->timeDomain->stages->stage[i]->objectives->obj[j]->idx;
7630  }
7631  for (int i = 0; i < instanceData->objectives->numberOfObjectives; i++)
7632  if (checkvar[i] == 0)
7633  {
7634  delete [] checkvar;
7635  checkvar = NULL;
7636  return false;
7637  }
7638  delete [] checkvar;
7639  checkvar = NULL;
7640  return true;
7641 }
7642 
7646 bool OSInstance::setTimeDomainInterval(double start, double horizon)
7647 {
7648  if (instanceData->timeDomain == NULL)
7650  if (instanceData->timeDomain->stages != NULL)
7651  return false;
7652  if (instanceData->timeDomain->interval == NULL)
7655  instanceData->timeDomain->interval->horizon = horizon;
7656  return true;
7657 } //end setTimeDomainInterval
7658 
7659 
7660 bool OSInstance::createOSADFun(std::vector<double> vdX)
7661 {
7662  try
7663  {
7664  if(m_bOSADFunIsCreated == true) return true;
7665  //if( m_bNonLinearStructuresInitialized == false) initializeNonLinearStructures( );
7666  if(m_binitForAlgDiff == false) initForAlgDiff();
7667 
7668  //if( m_bAllNonlinearVariablesIndex == false) getAllNonlinearVariablesIndexMap( );
7669  std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
7670  unsigned int i;
7671  size_t n = vdX.size();
7672 #ifdef COIN_HAS_CPPAD
7673  // declare a CppAD vector and fill it in
7674  CppAD::vector< CppAD::AD<double> > vdaX( n );
7675  for(i = 0; i < n; i++)
7676  {
7677  vdaX[ i] = vdX[ i];
7678  }
7679  // declare the independent variables and start recording
7680  CppAD::Independent( vdaX);
7686  CppAD::vector< CppAD::AD<double> > m_vFG;
7687  int kount = 0;
7688  for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
7689  {
7690  m_vFG.push_back( (posMapExpTree->second)->m_treeRoot->constructADTape(&m_mapAllNonlinearVariablesIndex, &vdaX) );
7691  if( m_mapOSADFunRangeIndex.find( posMapExpTree->first) == m_mapOSADFunRangeIndex.end() )
7692  {
7693  // count which nonlinear obj/constraint this is
7694  m_mapOSADFunRangeIndex[ posMapExpTree->first] = kount;
7695  kount++;
7696  }
7697  }
7698  //create the function and stop recording
7699 
7700  Fad = new CppAD::ADFun<double>(vdaX, m_vFG);
7701  // no forward sweeps done yet
7703  m_bOSADFunIsCreated = true;
7704 #else
7705  throw ErrorClass( "Error: An Algorithmic Differentiation Package Not Available");
7706 #endif
7707 
7708  return true;
7709  }
7710  catch(const ErrorClass& eclass)
7711  {
7712  throw ErrorClass( eclass.errormsg);
7713  }
7714 }//end createOSADFun
7715 
7716 
7717 std::vector<double> OSInstance::forwardAD(int p, std::vector<double> vdX)
7718 {
7719  try
7720  {
7721  // make sure a OSADFun has been created
7722  if(m_bOSADFunIsCreated == false) createOSADFun( vdX);
7723  if(p > (m_iHighestTaylorCoeffOrder + 1) ) throw
7724  ErrorClass( "trying to calculate a p order forward when p-1 Taylor coefficient not available");
7725  // adjust the order of the Taylor coefficient
7728 #ifdef COIN_HAS_CPPAD
7729  return (*Fad).Forward(p, vdX);
7730 #else
7731  throw ErrorClass( "Error: An Algorithmic Differentiation Package Not Available");
7732 #endif
7733 
7734  }
7735  catch(const ErrorClass& eclass)
7736  {
7737  throw ErrorClass( eclass.errormsg);
7738  }
7739 }//end forwardAD
7740 
7741 
7742 std::vector<double> OSInstance::reverseAD(int p, std::vector<double> vdlambda)
7743 {
7744  try
7745  {
7746 #ifndef COIN_HAS_CPPAD
7747  throw ErrorClass( "Error: An Algorithmic Differentiation Package Not Available");
7748 #endif
7749  if(p == 0) throw
7750  ErrorClass( "reverseAD must have p >= 1");
7751  if(p > (m_iHighestTaylorCoeffOrder + 1) ) throw
7752  ErrorClass( "trying to calculate a p order reverse when p-1 Taylor coefficient not available");
7754 #ifdef COIN_HAS_CPPAD
7755  return (*Fad).Reverse(p, vdlambda);
7756 #endif
7757 
7758  }
7759  catch(const ErrorClass& eclass)
7760  {
7761  throw ErrorClass( eclass.errormsg);
7762  }
7763 }//end forwardAD
7764 
7765 
7767 {
7768  unsigned int i;
7769  int numNonz;
7770  numNonz = 0;
7771  try
7772  {
7774  unsigned int j;
7775  for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
7776  {
7777  for(j = 0; j < m_iNumberOfNonlinearVariables; j++)
7778  r[ i * m_iNumberOfNonlinearVariables + j ] = false;
7779  r[ i * m_iNumberOfNonlinearVariables + i] = true;
7780  }
7781  // compute sparsity pattern for J(x) = F^{(1)} (x)
7782  //should only be here if we have CppAD
7783 #ifdef COIN_HAS_CPPAD
7784  (*Fad).ForSparseJac(m_iNumberOfNonlinearVariables, r);
7785 #else
7786  throw ErrorClass( "Error: An Algorithmic Differentiation Package Not Available");
7787 #endif
7788  //
7789  //now the second derivative
7790  unsigned int m = m_mapExpressionTreesMod.size();
7791  std::vector<bool> e( m);
7792  //Vector s(m);
7793  for(i = 0; i < m; i++) e[i] = true;
7794 #ifndef NDEBUG
7795  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Computing Sparse Hessian");
7796 #endif
7797  //m_vbLagHessNonz holds the sparsity pattern Lagrangian of the Hessian
7798 #ifdef COIN_HAS_CPPAD
7799  m_vbLagHessNonz = (*Fad).RevSparseHes(m_iNumberOfNonlinearVariables, e);
7800 #endif
7801 
7802  for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
7803  {
7804  for(j = i; j < m_iNumberOfNonlinearVariables; j++)
7805  {
7806  if(m_vbLagHessNonz[ i*m_iNumberOfNonlinearVariables + j] == true) numNonz++;
7807  }
7808  }
7809  return numNonz;
7810  }
7811  catch(const ErrorClass& eclass)
7812  {
7813  throw ErrorClass( eclass.errormsg);
7814  }
7815 }//end getADSparsityHessian()
7816 
7817 
7818 /***************************************************
7819  * methods to print out cone objects as XML strings
7820  ***************************************************/
7821 std::string Cone::getConeInXML()
7822 {
7823  ostringstream outStr;
7824  outStr << "<cone";
7825  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7826  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7827  if (name != "")
7828  outStr << " name=\"" << name << "\"";
7829  outStr << "/>" << std::endl;
7830  return outStr.str();
7831 }// end of Cone::getConeInXML()
7832 
7834 {
7835  ostringstream outStr;
7836  outStr << "<nonnegativeCone";
7837  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7838  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7839  if (name != "")
7840  outStr << " name=\"" << name << "\"";
7841  outStr << "/>" << std::endl;
7842  return outStr.str();
7843 }// end of NonnegativeCone::getConeInXML()
7844 
7846 {
7847  ostringstream outStr;
7848  outStr << "<nonpositiveCone";
7849  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7850  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7851  if (name != "")
7852  outStr << " name=\"" << name << "\"";
7853  outStr << "/>" << std::endl;
7854  return outStr.str();
7855 }// end of NonpositiveCone::getConeInXML()
7856 
7858 {
7859  ostringstream outStr;
7860  outStr << "<generalOrthantCone";
7861  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7862  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7863  if (name != "")
7864  outStr << " name=\"" << name << "\"";
7865  outStr << ">" << std::endl;
7866  int i = 0;
7867  int mult = 1;
7868  double ubt;
7869  double lbt;
7870  while (i < numberOfRows*numberOfColumns)
7871  {
7872  ubt = ub[i];
7873  lbt = lb[i];
7874  if (i+mult < numberOfRows*numberOfColumns && ubt == ub[i+mult] && lbt == lb[i+mult])
7875  {
7876  mult++;
7877  }
7878  else
7879  {
7880  outStr << "<direction";
7881  if (ubt == 0.0)
7882  if (lbt == 0.0)
7883  outStr << " type=\"zero\"";
7884  else
7885  outStr << " type=\"nonpositive\"";
7886  else if(lbt == 0.0)
7887  outStr << " type=\"nonnegative\"";
7888  else
7889  outStr << " type=\"free\"";
7890  if (mult > 1)
7891  outStr <<" mult=\"" << mult << "\"";
7892  outStr << "/>";
7893  i += mult;
7894  mult = 1;
7895  }
7896  }
7897  outStr << "</generalOrthantCone>" << std::endl;
7898  return outStr.str();
7899 }// end of OrthantCone::getConeInXML()
7900 
7902 {
7903  ostringstream outStr;
7904  outStr << "<polyhedralCone";
7905  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7906  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7907  outStr << " referenceMatrixIdx=\"" << referenceMatrixIdx << "\"";
7908  if (name != "")
7909  outStr << " name=\"" << name << "\"";
7910  outStr << "/>" << std::endl;
7911  return outStr.str();
7912 }// end of PolyhedralCone::getConeInXML()
7913 
7915 {
7916  ostringstream outStr;
7917  outStr << "<quadraticCone";
7918  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7919  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7920  if (name != "")
7921  outStr << " name=\"" << name << "\"";
7922  if (normScaleFactor != 1.0)
7923  outStr << " normScaleFactor=\"" << normScaleFactor << "\"";
7924  if (distortionMatrixIdx != -1)
7925  outStr << " distortionMatrixIdx=\"" << distortionMatrixIdx << "\"";
7926  if (axisDirection != 0)
7927  outStr << " axisDirection=\"" << axisDirection << "\"";
7928  outStr << "/>" << std::endl;
7929  return outStr.str();
7930 }// end of QuadraticCone::getConeInXML()
7931 
7933 {
7934  ostringstream outStr;
7935  outStr << "<rotatedQuadraticCone";
7936  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7937  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7938  if (name != "")
7939  outStr << " name=\"" << name << "\"";
7940  if (normScaleFactor != 1.0)
7941  outStr << " normScaleFactor=\"" << normScaleFactor << "\"";
7942  if (distortionMatrixIdx != -1)
7943  outStr << " distortionMatrixIdx=\"" << distortionMatrixIdx << "\"";
7944  if (firstAxisDirection != 0)
7945  outStr << " firstAxisDirection=\"" << firstAxisDirection << "\"";
7946  if (secondAxisDirection != 1)
7947  outStr << " secondAxisDirection=\"" << secondAxisDirection << "\"";
7948  outStr << "/>" << std::endl;
7949  return outStr.str();
7950 }// end of RotatedQuadraticCone::getConeInXML()
7951 
7953 {
7954  ostringstream outStr;
7955  outStr << "<semidefiniteCone";
7956  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7957  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7958  if (semidefiniteness != "positive")
7959  outStr << " semidefiniteness=\"" << semidefiniteness << "\"";
7960  outStr << "/>" << std::endl;
7961 
7962  return outStr.str();
7963 }// end of SemidefiniteCone::getConeInXML()
7964 
7966 {
7967  ostringstream outStr;
7968  outStr << "<nonnegativeCone";
7969  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7970  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7971  if (name != "")
7972  outStr << " name=\"" << name << "\"";
7973  outStr << "/>" << std::endl;
7974  return outStr.str();
7975 }// end of CopositiveMatricesCone::getConeInXML()
7976 
7978 {
7979  ostringstream outStr;
7980  outStr << "<nonnegativeCone";
7981  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7982  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7983  if (name != "")
7984  outStr << " name=\"" << name << "\"";
7985  outStr << "/>" << std::endl;
7986  return outStr.str();
7987 }// end of CompletelyPositiveMatricesCone::getConeInXML()
7988 
7990 {
7991  ostringstream outStr;
7992  outStr << "<productCone";
7993  outStr << " numberOfRows=\"" << numberOfRows << "\"";
7994  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
7995  if (name != "")
7996  outStr << " name=\"" << name << "\"";
7997  outStr << ">" << std::endl;
7998 
7999  outStr << "<factors numberOfEl=\"" << factors->numberOfEl << "\">" << std::endl;
8000  outStr << writeIntVectorData(factors, true, false);
8001  outStr << "</factors>" << std::endl;
8002 
8003  outStr << "</productCone>" << std::endl;
8004  return outStr.str();
8005 }// end of ProductCone::getConeInXML()
8006 
8008 {
8009  ostringstream outStr;
8010  outStr << "<intersectionCone";
8011  outStr << " numberOfRows=\"" << numberOfRows << "\"";
8012  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
8013  if (name != "")
8014  outStr << " name=\"" << name << "\"";
8015  outStr << ">" << std::endl;
8016 
8017  outStr << "<components numberOfEl=\"" << components->numberOfEl << "\">";
8018  outStr << writeIntVectorData(components, true, false);
8019  outStr << "</components>" << std::endl;
8020 
8021  outStr << "</intersectionCone>" << std::endl;
8022  return outStr.str();
8023 }// end of IntersectionCone::getConeInXML()
8024 
8025 
8026 /***************************************************
8027  * methods to test whether two OSInstance objects
8028  * or their components are equal to each other
8029  ***************************************************/
8031 {
8032 #ifndef NDEBUG
8033  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in OSInstance");
8034 #endif
8035  if (this == NULL)
8036  {
8037  if (that == NULL)
8038  return true;
8039  else
8040  {
8041 #ifndef NDEBUG
8043  "First object is NULL, second is not");
8044 #endif
8045  return false;
8046  }
8047  }
8048  else
8049  {
8050  if (that == NULL)
8051  {
8052 #ifndef NDEBUG
8054  "Second object is NULL, first is not");
8055 #endif
8056  return false;
8057  }
8058  else
8059  {
8060  if (!this->instanceHeader->IsEqual(that->instanceHeader))
8061  return false;
8062  if (!this->instanceData->IsEqual(that->instanceData))
8063  return false;
8064 
8065  return true;
8066  }
8067  }
8068 }//OSInstance::IsEqual
8069 
8070 
8072 {
8073 #ifndef NDEBUG
8074  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in InstanceData");
8075 #endif
8076  if (this == NULL)
8077  {
8078  if (that == NULL)
8079  return true;
8080  else
8081  {
8082 #ifndef NDEBUG
8084  "First object is NULL, second is not");
8085 #endif
8086  return false;
8087  }
8088  }
8089  else
8090  {
8091  if (that == NULL)
8092  {
8093 #ifndef NDEBUG
8095  "Second object is NULL, first is not");
8096 #endif
8097  return false;
8098  }
8099  else
8100  {
8101  if (!this->variables->IsEqual(that->variables))
8102  return false;
8103  if (!this->objectives->IsEqual(that->objectives))
8104  return false;
8105  if (!this->constraints->IsEqual(that->constraints))
8106  return false;
8108  return false;
8110  return false;
8112  return false;
8113  if (!this->matrices->IsEqual(that->matrices))
8114  return false;
8115  if (!this->cones->IsEqual(that->cones))
8116  return false;
8117  if (!this->matrixProgramming->IsEqual(that->matrixProgramming))
8118  return false;
8119 
8120  return true;
8121  }
8122  }
8123 }//InstanceData::IsEqual
8124 
8126 {
8127 #ifndef NDEBUG
8128  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Variables");
8129 
8130 #endif
8131  if (this == NULL)
8132  {
8133  if (that == NULL)
8134  return true;
8135  else
8136  {
8137 #ifndef NDEBUG
8139  "First object is NULL, second is not");
8140 #endif
8141  return false;
8142  }
8143  }
8144  else
8145  {
8146  if (that == NULL)
8147  {
8148 #ifndef NDEBUG
8150  "Second object is NULL, first is not");
8151 #endif
8152  return false;
8153  }
8154  else
8155  {
8156  if (this->numberOfVariables != that->numberOfVariables)
8157  return false;
8158  for (int i=0; i<this->numberOfVariables; i++)
8159  if (!this->var[i]->IsEqual(that->var[i]))
8160  return false;
8161 
8162  return true;
8163  }
8164  }
8165 }//Variables::IsEqual
8166 
8168 {
8169 #ifndef NDEBUG
8170  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Variable");
8171 #endif
8172  if (this == NULL)
8173  {
8174  if (that == NULL)
8175  return true;
8176  else
8177  {
8178 #ifndef NDEBUG
8180  "First object is NULL, second is not");
8181 #endif
8182  return false;
8183  }
8184  }
8185  else
8186  {
8187  if (that == NULL)
8188  {
8189 #ifndef NDEBUG
8191  "Second object is NULL, first is not");
8192 #endif
8193  return false;
8194  }
8195  else
8196  {
8197  if (this->lb != that->lb)
8198  return false;
8199  if (this->ub != that->ub)
8200  return false;
8201  if (this->type != that->type)
8202  return false;
8203  if (this->name != that->name)
8204  return false;
8205 
8206  return true;
8207  }
8208  }
8209 }//Variable::IsEqual
8210 
8212 {
8213 #ifndef NDEBUG
8214  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Objectives");
8215 #endif
8216  if (this == NULL)
8217  {
8218  if (that == NULL)
8219  return true;
8220  else
8221  {
8222 #ifndef NDEBUG
8224  "First object is NULL, second is not");
8225 #endif
8226  return false;
8227  }
8228  }
8229  else
8230  {
8231  if (that == NULL)
8232  {
8233 #ifndef NDEBUG
8235  "Second object is NULL, first is not");
8236 #endif
8237  return false;
8238  }
8239  else
8240  {
8241  if (this->numberOfObjectives != that->numberOfObjectives)
8242  return false;
8243  for (int i=0; i<this->numberOfObjectives; i++)
8244  if (!this->obj[i]->IsEqual(that->obj[i]))
8245  return false;
8246 
8247  return true;
8248  }
8249  }
8250 }//Objectives::IsEqual
8251 
8253 {
8254 #ifndef NDEBUG
8255  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Objective");
8256 #endif
8257  if (this == NULL)
8258  {
8259  if (that == NULL)
8260  return true;
8261  else
8262  {
8263 #ifndef NDEBUG
8265  "First object is NULL, second is not");
8266 #endif
8267  return false;
8268  }
8269  }
8270  else
8271  {
8272  if (that == NULL)
8273  {
8274 #ifndef NDEBUG
8276  "Second object is NULL, first is not");
8277 #endif
8278  return false;
8279  }
8280  else
8281  {
8282  if (this->name != that->name)
8283  return false;
8284  if (this->maxOrMin != that->maxOrMin)
8285  return false;
8286  if (this->constant != that->constant)
8287  return false;
8288  if (!OSIsEqual(this->weight, that->weight))
8289  return false;
8290  if (this->numberOfObjCoef != that->numberOfObjCoef)
8291  return false;
8292 
8293  for (int i=0; i<this->numberOfObjCoef; i++)
8294  if (!this->coef[i]->IsEqual(that->coef[i]))
8295  return false;
8296 
8297  return true;
8298  }
8299  }
8300 }//Objective::IsEqual
8301 
8303 {
8304 #ifndef NDEBUG
8305  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in ObjCoef");
8306 #endif
8307  if (this == NULL)
8308  {
8309  if (that == NULL)
8310  return true;
8311  else
8312  {
8313 #ifndef NDEBUG
8315  "First object is NULL, second is not");
8316 #endif
8317  return false;
8318  }
8319  }
8320  else
8321  {
8322  if (that == NULL)
8323  {
8324 #ifndef NDEBUG
8326  "Second object is NULL, first is not");
8327 #endif
8328  return false;
8329  }
8330  else
8331  {
8332  if (this->idx != that->idx)
8333  return false;
8334  if (this->value != that->value)
8335  return false;
8336 
8337  return true;
8338  }
8339  }
8340 }//ObjCoef::IsEqual
8341 
8343 {
8344 #ifndef NDEBUG
8345  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Constraints");
8346 #endif
8347  if (this == NULL)
8348  {
8349  if (that == NULL)
8350  return true;
8351  else
8352  {
8353 #ifndef NDEBUG
8355  "First object is NULL, second is not");
8356 #endif
8357  return false;
8358  }
8359  }
8360  else
8361  {
8362  if (that == NULL)
8363  {
8364 #ifndef NDEBUG
8366  "Second object is NULL, first is not");
8367 #endif
8368  return false;
8369  }
8370  else
8371  {
8372  if (this->numberOfConstraints != that->numberOfConstraints)
8373  return false;
8374  for (int i=0; i<this->numberOfConstraints; i++)
8375  if (!this->con[i]->IsEqual(that->con[i]))
8376  return false;
8377 
8378  return true;
8379  }
8380  }
8381 }//Constraints::IsEqual
8382 
8384 {
8385 #ifndef NDEBUG
8386  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Constraint");
8387 #endif
8388  if (this == NULL)
8389  {
8390  if (that == NULL)
8391  return true;
8392  else
8393  {
8394 #ifndef NDEBUG
8396  "First object is NULL, second is not");
8397 #endif
8398  return false;
8399  }
8400  }
8401  else
8402  {
8403  if (that == NULL)
8404  {
8405 #ifndef NDEBUG
8407  "Second object is NULL, first is not");
8408 #endif
8409  return false;
8410  }
8411  else
8412  {
8413  if (this->name != that->name)
8414  return false;
8415  if (this->constant != that->constant)
8416  return false;
8417  if (this->lb != that->lb)
8418  return false;
8419  if (this->ub != that->ub)
8420  return false;
8421 
8422  return true;
8423 
8424  }
8425  }
8426 }//Constraint::IsEqual
8427 
8429 {
8430 #ifndef NDEBUG
8431  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in LinearConstraintCoefficients");
8432 #endif
8433  if (this == NULL)
8434  {
8435  if (that == NULL)
8436  return true;
8437  else
8438  {
8439 #ifndef NDEBUG
8441  "First object is NULL, second is not");
8442 #endif
8443  return false;
8444  }
8445  }
8446  else
8447  {
8448  if (that == NULL)
8449  {
8450 #ifndef NDEBUG
8452  "Second object is NULL, first is not");
8453 #endif
8454  return false;
8455  }
8456  else
8457  {
8458  if (this->numberOfValues != that->numberOfValues)
8459  return false;
8460 
8461  if (!this->start->IsEqual(that->start))
8462  return false;
8463  if (!this->rowIdx->IsEqual(that->rowIdx))
8464  return false;
8465  if (!this->colIdx->IsEqual(that->colIdx))
8466  return false;
8467  if (!this->value->IsEqual(that->value))
8468  return false;
8469 
8470  return true;
8471  }
8472  }
8473 }//LinearConstraintCoefficients::IsEqual
8474 
8476 {
8477 #ifndef NDEBUG
8478  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in QuadraticCoefficients");
8479 #endif
8480  if (this == NULL)
8481  {
8482  if (that == NULL)
8483  return true;
8484  else
8485  {
8486 #ifndef NDEBUG
8488  "First object is NULL, second is not");
8489 
8490 #endif
8491  return false;
8492  }
8493  }
8494  else
8495  {
8496  if (that == NULL)
8497  {
8498 #ifndef NDEBUG
8500  "Second object is NULL, first is not");
8501 #endif
8502  return false;
8503  }
8504  else
8505 
8506  {
8508  return false;
8509  for (int i=0; i<this->numberOfQuadraticTerms; i++)
8510  if (!this->qTerm[i]->IsEqual(that->qTerm[i]))
8511  return false;
8512 
8513  return true;
8514  }
8515  }
8516 }//QuadraticCoefficients::IsEqual
8517 
8518 
8520 {
8521 #ifndef NDEBUG
8522  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in QuadraticTerm");
8523 #endif
8524  if (this == NULL)
8525  {
8526  if (that == NULL)
8527  return true;
8528  else
8529  {
8530 #ifndef NDEBUG
8532  "First object is NULL, second is not");
8533 #endif
8534  return false;
8535  }
8536  }
8537  else
8538  {
8539  if (that == NULL)
8540  {
8541 #ifndef NDEBUG
8543  "Second object is NULL, first is not");
8544 #endif
8545  return false;
8546  }
8547  else
8548  {
8549  if (this->idx != that->idx)
8550  return false;
8551  if (this->idxOne != that->idxOne)
8552  return false;
8553  if (this->idxTwo != that->idxTwo)
8554  return false;
8555  if (this->coef != that->coef)
8556  return false;
8557 
8558  return true;
8559  }
8560  }
8561 }//QuadraticTerm::IsEqual
8562 
8564 {
8565 #ifndef NDEBUG
8566  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in NonlinearExpressions");
8567 #endif
8568  if (this == NULL)
8569  {
8570  if (that == NULL)
8571  return true;
8572  else
8573  {
8574 #ifndef NDEBUG
8576  "First object is NULL, second is not");
8577 #endif
8578  return false;
8579  }
8580  }
8581  else
8582  {
8583  if (that == NULL)
8584  {
8585 #ifndef NDEBUG
8587  "Second object is NULL, first is not");
8588 #endif
8589  return false;
8590  }
8591  else
8592  {
8594  return false;
8595 
8596  for (int i=0; i<this->numberOfNonlinearExpressions; i++)
8597  if (!this->nl[i]->IsEqual(that->nl[i]))
8598  return false;
8599 
8600  return true;
8601  }
8602  }
8603 }//NonlinearExpressions::IsEqual
8604 
8605 
8606 bool Nl::IsEqual(Nl *that)
8607 {
8608 #ifndef NDEBUG
8609  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Nl");
8610 #endif
8611  if (this == NULL)
8612  {
8613  if (that == NULL)
8614  return true;
8615  else
8616  {
8617 #ifndef NDEBUG
8619  "First object is NULL, second is not");
8620 #endif
8621  return false;
8622  }
8623  }
8624  else
8625  {
8626  if (that == NULL)
8627  {
8628 #ifndef NDEBUG
8630  "Second object is NULL, first is not");
8631 #endif
8632  return false;
8633  }
8634  else
8635  {
8636  if (this->idx != that->idx)
8637  return false;
8638  if (!this->osExpressionTree->IsEqual(that->osExpressionTree))
8639  return false;
8640 
8641  return true;
8642  }
8643  }
8644 }//Nl::IsEqual
8645 
8647 {
8648 #ifndef NDEBUG
8649  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Matrices");
8650 #endif
8651  if (this == NULL)
8652  {
8653  if (that == NULL)
8654  return true;
8655  else
8656  {
8657 #ifndef NDEBUG
8659  "First object is NULL, second is not");
8660 #endif
8661  return false;
8662  }
8663  }
8664  else
8665  {
8666  if (that == NULL)
8667  {
8668 #ifndef NDEBUG
8670  "Second object is NULL, first is not");
8671 #endif
8672  return false;
8673  }
8674  else
8675  {
8676  if (this->numberOfMatrices != that->numberOfMatrices)
8677  return false;
8678  for (int i=0; i<this->numberOfMatrices; i++)
8679  if (!this->matrix[i]->IsEqual(that->matrix[i]))
8680  return false;
8681 
8682  return true;
8683  }
8684  }
8685 }//Matrices::IsEqual
8686 
8688 {
8689 #ifndef NDEBUG
8690  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Cones");
8691 #endif
8692  if (this == NULL)
8693  {
8694  if (that == NULL)
8695  return true;
8696  else
8697  {
8698 #ifndef NDEBUG
8700  "First object is NULL, second is not");
8701 #endif
8702  return false;
8703  }
8704  }
8705  else
8706  {
8707  if (that == NULL)
8708  {
8709 #ifndef NDEBUG
8711  "Second object is NULL, first is not");
8712 #endif
8713  return false;
8714  }
8715  else
8716  {
8717  if (this->numberOfCones != that->numberOfCones)
8718  return false;
8719  for (int i=0; i<this->numberOfCones; i++)
8720  if (!this->cone[i]->IsEqual(that->cone[i]))
8721  return false;
8722 
8723  return true;
8724  }
8725  }
8726 }//Cones::IsEqual
8727 
8728 bool Cone::IsEqual(Cone *that)
8729 {
8730 #ifndef NDEBUG
8731  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Cone");
8732 #endif
8733  if (this == NULL)
8734  {
8735  if (that == NULL)
8736  return true;
8737  else
8738  {
8739 #ifndef NDEBUG
8741  "First object is NULL, second is not");
8742 #endif
8743  return false;
8744  }
8745  }
8746  else
8747  {
8748  if (that == NULL)
8749  {
8750 #ifndef NDEBUG
8752  "Second object is NULL, first is not");
8753 #endif
8754  return false;
8755  }
8756  else
8757  {
8758  if (this->coneType != that->coneType)
8759  return false;
8760  if (this->numberOfColumns != that->numberOfColumns)
8761  return false;
8762  if (this->numberOfRows != that->numberOfRows)
8763  return false;
8764  if (this->numberOfOtherIndexes != that->numberOfOtherIndexes)
8765  return false;
8766  for (int i=0; i<this->numberOfOtherIndexes; i++)
8767  if (this->otherIndexes[i] != that->otherIndexes[i])
8768  return false;
8769  }
8770  }
8771  return true;
8772 }//Cone::IsEqual
8773 
8775 {
8776 #ifndef NDEBUG
8777  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in PolyhedralCone");
8778 #endif
8779  if (this == NULL)
8780  {
8781  if (that == NULL)
8782  return true;
8783  else
8784  {
8785 #ifndef NDEBUG
8787  "First object is NULL, second is not");
8788 #endif
8789  return false;
8790  }
8791  }
8792  else
8793  {
8794  if (that == NULL)
8795  {
8796 #ifndef NDEBUG
8798  "Second object is NULL, first is not");
8799 #endif
8800  return false;
8801  }
8802  else
8803  {
8804  if (this->referenceMatrixIdx != that->referenceMatrixIdx)
8805  return false;
8806 
8807  return this->Cone::IsEqual(that);
8808  }
8809  }
8810 }//PolyhedralCone::IsEqual
8811 
8812 
8814 {
8815 #ifndef NDEBUG
8816  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in QuadraticCone");
8817 #endif
8818  if (this == NULL)
8819  {
8820  if (that == NULL)
8821  return true;
8822  else
8823  {
8824 #ifndef NDEBUG
8826  "First object is NULL, second is not");
8827 #endif
8828  return false;
8829  }
8830  }
8831  else
8832  {
8833  if (that == NULL)
8834  {
8835 #ifndef NDEBUG
8837  "Second object is NULL, first is not");
8838 #endif
8839  return false;
8840  }
8841  else
8842  {
8843  if (this->normScaleFactor != that->normScaleFactor)
8844  return false;
8845  if (this->distortionMatrixIdx != that->distortionMatrixIdx)
8846  return false;
8847  if (this->axisDirection != that->axisDirection)
8848  return false;
8849 
8850  return this->Cone::IsEqual(that);
8851  }
8852  }
8853 }//QuadraticCone::IsEqual
8854 
8855 
8856 
8858 {
8859 #ifndef NDEBUG
8860  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in RotatedQuadraticCone");
8861 #endif
8862  if (this == NULL)
8863  {
8864  if (that == NULL)
8865  return true;
8866  else
8867  {
8868 #ifndef NDEBUG
8870  "First object is NULL, second is not");
8871 #endif
8872  return false;
8873  }
8874  }
8875  else
8876  {
8877  if (that == NULL)
8878  {
8879 #ifndef NDEBUG
8881  "Second object is NULL, first is not");
8882 #endif
8883  return false;
8884  }
8885  else
8886  {
8887  if (this->normScaleFactor != that->normScaleFactor)
8888  return false;
8889  if (this->distortionMatrixIdx != that->distortionMatrixIdx)
8890  return false;
8891  if (this->firstAxisDirection != that->firstAxisDirection)
8892  return false;
8893  if (this->secondAxisDirection != that->secondAxisDirection)
8894  return false;
8895 
8896  return this->Cone::IsEqual(that);
8897  }
8898  }
8899 }//RotatedQuadraticCone::IsEqual
8900 
8902 {
8903 #ifndef NDEBUG
8904  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in SemidefiniteCone");
8905 #endif
8906  if (this == NULL)
8907  {
8908  if (that == NULL)
8909  return true;
8910  else
8911  {
8912 #ifndef NDEBUG
8914  "First object is NULL, second is not");
8915 #endif
8916  return false;
8917  }
8918  }
8919  else
8920  {
8921  if (that == NULL)
8922  {
8923 #ifndef NDEBUG
8925  "Second object is NULL, first is not");
8926 #endif
8927  return false;
8928  }
8929  else
8930  {
8931  if (this->semidefiniteness != that->semidefiniteness)
8932  return false;
8933  return this->Cone::IsEqual(that);
8934  }
8935  }
8936  return true;
8937 }//SemidefiniteCone::IsEqual
8938 
8940 {
8941 #ifndef NDEBUG
8942  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in ProductCone");
8943 #endif
8944  if (this == NULL)
8945  {
8946  if (that == NULL)
8947  return true;
8948  else
8949  {
8950 #ifndef NDEBUG
8952  "First object is NULL, second is not");
8953 #endif
8954  return false;
8955  }
8956  }
8957  else
8958  {
8959  if (that == NULL)
8960  {
8961 #ifndef NDEBUG
8963  "Second object is NULL, first is not");
8964 #endif
8965  return false;
8966  }
8967  else
8968  {
8969  if (!this->factors->IsEqual(that->factors))
8970  return false;
8971  return this->Cone::IsEqual(that);
8972  }
8973  }
8974  return true;
8975 }//ProductCone::IsEqual
8976 
8978 {
8979 #ifndef NDEBUG
8980  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in IntersectionCone");
8981 #endif
8982  if (this == NULL)
8983  {
8984  if (that == NULL)
8985  return true;
8986  else
8987  {
8988 #ifndef NDEBUG
8990  "First object is NULL, second is not");
8991 #endif
8992  return false;
8993  }
8994  }
8995  else
8996  {
8997  if (that == NULL)
8998  {
8999 #ifndef NDEBUG
9001  "Second object is NULL, first is not");
9002 #endif
9003  return false;
9004  }
9005  else
9006  {
9007  if (!this->components->IsEqual(that->components))
9008  return false;
9009  return this->Cone::IsEqual(that);
9010  }
9011  }
9012  return true;
9013 }//IntersectionCone::IsEqual
9014 
9016 {
9017 #ifndef NDEBUG
9018  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in DualCone");
9019 #endif
9020  if (this == NULL)
9021  {
9022  if (that == NULL)
9023  return true;
9024  else
9025  {
9026 #ifndef NDEBUG
9028  "First object is NULL, second is not");
9029 #endif
9030  return false;
9031  }
9032  }
9033  else
9034  {
9035  if (that == NULL)
9036  {
9037 #ifndef NDEBUG
9039  "Second object is NULL, first is not");
9040 #endif
9041  return false;
9042  }
9043  else
9044  {
9045  if (this->referenceConeIdx != that->referenceConeIdx)
9046  return false;
9047 
9048  return this->Cone::IsEqual(that);
9049  }
9050  }
9051 }//DualCone::IsEqual
9052 
9053 
9055 {
9056 #ifndef NDEBUG
9057  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in PolarCone");
9058 #endif
9059  if (this == NULL)
9060  {
9061  if (that == NULL)
9062  return true;
9063  else
9064 
9065  {
9066 #ifndef NDEBUG
9068  "First object is NULL, second is not");
9069 #endif
9070  return false;
9071  }
9072  }
9073  else
9074  {
9075  if (that == NULL)
9076  {
9077 #ifndef NDEBUG
9079  "Second object is NULL, first is not");
9080 #endif
9081  return false;
9082  }
9083  else
9084  {
9085  if (this->referenceConeIdx != that->referenceConeIdx)
9086  return false;
9087 
9088  return this->Cone::IsEqual(that);
9089  }
9090  }
9091 }//PolarCone::IsEqual
9092 
9093 
9095 {
9096 #ifndef NDEBUG
9097  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixProgramming");
9098 #endif
9099 
9100  if (this == NULL)
9101  {
9102  if (that == NULL)
9103  return true;
9104  else
9105  {
9106 #ifndef NDEBUG
9108  "First object is NULL, second is not");
9109 #endif
9110  return false;
9111  }
9112  }
9113  else
9114  {
9115  if (that == NULL)
9116  {
9117 #ifndef NDEBUG
9119  "Second object is NULL, first is not");
9120 #endif
9121  return false;
9122  }
9123  else
9124  {
9125  if (this->matrixVariables != NULL)
9126  {
9127  if (!(this->matrixVariables->IsEqual(that->matrixVariables)))
9128  return false;
9129  }
9130  else
9131  {
9132  if (that->matrixVariables != NULL) return false;
9133  }
9134 
9135  if (this->matrixObjectives != NULL)
9136  {
9137  if (!(this->matrixObjectives->IsEqual(that->matrixObjectives)))
9138  return false;
9139  }
9140  else
9141  {
9142  if (that->matrixObjectives != NULL) return false;
9143  }
9144 
9145  if (this->matrixConstraints != NULL)
9146  {
9147  if (!(this->matrixConstraints->IsEqual(that->matrixConstraints)))
9148  return false;
9149  }
9150  else
9151  {
9152  if (that->matrixConstraints != NULL) return false;
9153  }
9154 
9155  if (this->matrixExpressions != NULL)
9156  {
9157  if (!(this->matrixExpressions->IsEqual(that->matrixExpressions)))
9158  return false;
9159  }
9160  else
9161  {
9162  if (that->matrixExpressions != NULL) return false;
9163  }
9164 
9165  return true;
9166  }
9167 
9168  }
9169 }//MatrixProgramming::IsEqual
9170 
9171 
9173 {
9174 #ifndef NDEBUG
9175  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixVariables");
9176 #endif
9177 
9178  if (this == NULL)
9179  {
9180  if (that == NULL)
9181  return true;
9182  else
9183  {
9184 #ifndef NDEBUG
9186  "First object is NULL, second is not");
9187 #endif
9188  return false;
9189  }
9190  }
9191  else
9192  {
9193  if (that == NULL)
9194  {
9195 #ifndef NDEBUG
9197  "Second object is NULL, first is not");
9198 #endif
9199  return false;
9200  }
9201  else
9202  {
9203  if (this->numberOfMatrixVar != that->numberOfMatrixVar) return false;
9204 
9205  for (int i=0; i<numberOfMatrixVar; i++)
9206  {
9207  if (this->matrixVar[i] != NULL)
9208  {
9209  if (!(this->matrixVar[i]->IsEqual(that->matrixVar[i]))) return false;
9210  }
9211  else
9212  if (that->matrixVar[i] != NULL) return false;
9213  }
9214 
9215  return true;
9216  }
9217  }
9218 }//MatrixVariables::IsEqual
9219 
9221 {
9222 #ifndef NDEBUG
9223  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixVar");
9224 #endif
9225 
9226  if (this == NULL)
9227  {
9228  if (that == NULL)
9229  return true;
9230  else
9231  {
9232 #ifndef NDEBUG
9234  "First object is NULL, second is not");
9235 #endif
9236  return false;
9237  }
9238  }
9239  else
9240  {
9241  if (that == NULL)
9242  {
9243 #ifndef NDEBUG
9245  "Second object is NULL, first is not");
9246 #endif
9247  return false;
9248  }
9249  else
9250  {
9251  if (this->numberOfRows != that->numberOfRows)
9252  return false;
9253  if (this->numberOfColumns != that->numberOfColumns)
9254  return false;
9255  if (this->templateMatrixIdx != that->templateMatrixIdx)
9256  return false;
9257  if (this->varReferenceMatrixIdx != that->varReferenceMatrixIdx)
9258  return false;
9259  if (this->lbMatrixIdx != that->lbMatrixIdx)
9260  return false;
9261  if (this->lbConeIdx != that->lbConeIdx)
9262  return false;
9263  if (this->ubMatrixIdx != that->ubMatrixIdx)
9264  return false;
9265  if (this->ubConeIdx != that->ubConeIdx)
9266  return false;
9267  if (this->name != that->name)
9268  return false;
9269  if (this->varType != that->varType)
9270  return false;
9271 
9272  return true;
9273  }
9274  }
9275 }//MatrixVar::IsEqual
9276 
9278 {
9279 #ifndef NDEBUG
9280  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixProgramming");
9281 #endif
9282 
9283  if (this == NULL)
9284  {
9285  if (that == NULL)
9286  return true;
9287  else
9288  {
9289 #ifndef NDEBUG
9291  "First object is NULL, second is not");
9292 #endif
9293  return false;
9294  }
9295  }
9296  else
9297  {
9298  if (that == NULL)
9299  {
9300 #ifndef NDEBUG
9302  "Second object is NULL, first is not");
9303 #endif
9304  return false;
9305  }
9306  else
9307  {
9308  if (this->numberOfMatrixObj != that->numberOfMatrixObj) return false;
9309 
9310  for (int i=0; i<numberOfMatrixObj; i++)
9311  {
9312  if (this->matrixObj[i] != NULL)
9313  {
9314  if (!(this->matrixObj[i]->IsEqual(that->matrixObj[i]))) return false;
9315  }
9316  else
9317  if (that->matrixObj[i] != NULL) return false;
9318  }
9319 
9320  return true;
9321 
9322  }
9323  }
9324 }//MatrixObjectives::IsEqual
9325 
9327 {
9328 #ifndef NDEBUG
9329  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixObj");
9330 #endif
9331 
9332  if (this == NULL)
9333  {
9334  if (that == NULL)
9335  return true;
9336  else
9337  {
9338 #ifndef NDEBUG
9340  "First object is NULL, second is not");
9341 
9342 #endif
9343  return false;
9344  }
9345  }
9346  else
9347  {
9348  if (that == NULL)
9349  {
9350 #ifndef NDEBUG
9352  "Second object is NULL, first is not");
9353 #endif
9354  return false;
9355  }
9356  else
9357  {
9358  if (this->numberOfRows != that->numberOfRows)
9359  return false;
9360  if (this->numberOfColumns != that->numberOfColumns)
9361  return false;
9362  if (this->templateMatrixIdx != that->templateMatrixIdx)
9363  return false;
9364  if (this->objReferenceMatrixIdx != that->objReferenceMatrixIdx)
9365  return false;
9366  if (this->orderConeIdx != that->orderConeIdx)
9367  return false;
9368  if (this->constantMatrixIdx != that->constantMatrixIdx)
9369  return false;
9370  if (this->name != that->name)
9371  return false;
9372 
9373  return true;
9374  }
9375  }
9376 }//MatrixObj::IsEqual
9377 
9379 {
9380 #ifndef NDEBUG
9381  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixConstraints");
9382 #endif
9383 
9384  if (this == NULL)
9385  {
9386  if (that == NULL)
9387  return true;
9388  else
9389  {
9390 #ifndef NDEBUG
9392  "First object is NULL, second is not");
9393 #endif
9394  return false;
9395  }
9396  }
9397  else
9398  {
9399  if (that == NULL)
9400  {
9401 #ifndef NDEBUG
9403  "Second object is NULL, first is not");
9404 #endif
9405  return false;
9406  }
9407  else
9408  {
9409  if (this->numberOfMatrixCon != that->numberOfMatrixCon) return false;
9410 
9411  for (int i=0; i<numberOfMatrixCon; i++)
9412  {
9413  if (this->matrixCon[i] != NULL)
9414  {
9415  if (!(this->matrixCon[i]->IsEqual(that->matrixCon[i]))) return false;
9416  }
9417  else
9418  if (that->matrixCon[i] != NULL) return false;
9419  }
9420 
9421  return true;
9422  }
9423  }
9424 }//MatrixConstraints::IsEqual
9425 
9427 {
9428 #ifndef NDEBUG
9429  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixCon");
9430 #endif
9431 
9432  if (this == NULL)
9433  {
9434  if (that == NULL)
9435  return true;
9436  else
9437  {
9438 #ifndef NDEBUG
9440  "First object is NULL, second is not");
9441 #endif
9442  return false;
9443  }
9444  }
9445  else
9446  {
9447  if (that == NULL)
9448  {
9449 #ifndef NDEBUG
9451  "Second object is NULL, first is not");
9452 #endif
9453  return false;
9454  }
9455  else
9456  {
9457  if (this->numberOfRows != that->numberOfRows)
9458  return false;
9459  if (this->numberOfColumns != that->numberOfColumns)
9460  return false;
9461  if (this->templateMatrixIdx != that->templateMatrixIdx)
9462  return false;
9463  if (this->conReferenceMatrixIdx != that->conReferenceMatrixIdx)
9464  return false;
9465  if (this->lbMatrixIdx != that->lbMatrixIdx)
9466  return false;
9467  if (this->lbConeIdx != that->lbConeIdx)
9468  return false;
9469  if (this->ubMatrixIdx != that->ubMatrixIdx)
9470  return false;
9471  if (this->ubConeIdx != that->ubConeIdx)
9472  return false;
9473  if (this->name != that->name)
9474  return false;
9475 
9476  return true;
9477  }
9478  }
9479 }//MatrixCon::IsEqual
9480 
9482 {
9483 #ifndef NDEBUG
9484  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixExpressions");
9485 #endif
9486 
9487  if (this == NULL)
9488  {
9489  if (that == NULL)
9490  return true;
9491  else
9492  {
9493 #ifndef NDEBUG
9495  "First object is NULL, second is not");
9496 #endif
9497  return false;
9498  }
9499  }
9500  else
9501  {
9502  if (that == NULL)
9503  {
9504 #ifndef NDEBUG
9506  "Second object is NULL, first is not");
9507 #endif
9508  return false;
9509  }
9510  else
9511  {
9512  if (this->numberOfExpr != that->numberOfExpr) return false;
9513 
9514  for (int i=0; i<numberOfExpr; i++)
9515  {
9516  if (this->expr[i] != NULL)
9517  {
9518  if (!(this->expr[i]->IsEqual(that->expr[i]))) return false;
9519  }
9520  else
9521  if (that->expr[i] != NULL) return false;
9522  }
9523 
9524  return true;
9525  }
9526  }
9527 }//MatrixExpressions::IsEqual
9528 
9530 {
9531 #ifndef NDEBUG
9532  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixExpression");
9533 #endif
9534 
9535  if (this == NULL)
9536  {
9537  if (that == NULL)
9538  return true;
9539  else
9540  {
9541 #ifndef NDEBUG
9543  "First object is NULL, second is not");
9544 #endif
9545  return false;
9546  }
9547  }
9548  else
9549  {
9550  if (that == NULL)
9551  {
9552 #ifndef NDEBUG
9554  "Second object is NULL, first is not");
9555 #endif
9556  return false;
9557  }
9558  else
9559  {
9560  if (this->idx != that->idx ) return false;
9561  if (this->shape != that->shape) return false;
9562 
9563  if (this->matrixExpressionTree != NULL)
9564  {
9565  if (!(this->matrixExpressionTree->IsEqual(that->matrixExpressionTree)))
9566  return false;
9567  }
9568  else
9569  if (that->matrixExpressionTree != NULL) return false;
9570 
9571  return true;
9572  }
9573  }
9574 }//MatrixExpression::IsEqual
9575 
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