00001
00017 #include "OSGeneral.h"
00018 #include "OSInstance.h"
00019 #include "OSMathUtil.h"
00020 #include "OSMatrix.h"
00021 #include "OSErrorClass.h"
00022 #include "OSParameters.h"
00023 #include "OSOutput.h"
00024 #include "OSgLWriter.h"
00025
00026 #include <cstdlib>
00027 #include <stack>
00028 #include <iostream>
00029 #include <sstream>
00030
00031
00032 using namespace std;
00033 using std::ostringstream;
00034
00035
00036 OSInstance::OSInstance():
00037 bVariablesModified(false),
00038 bObjectivesModified(false),
00039 bConstraintsModified(false),
00040 bAMatrixModified(false),
00041 m_sInstanceName(""),
00042 m_sInstanceSource(""),
00043 m_sInstanceDescription(""),
00044 m_sInstanceCreator(""),
00045 m_sInstanceLicence(""),
00046 m_bProcessVariables(false),
00047 m_iVariableNumber(-1),
00048 m_iNumberOfIntegerVariables( 0),
00049 m_iNumberOfBinaryVariables( 0),
00050 m_iNumberOfSemiContinuousVariables( 0),
00051 m_iNumberOfSemiIntegerVariables( 0),
00052 m_iNumberOfStringVariables( 0),
00053 m_msVariableNames(NULL),
00054 m_mcVariableTypes(NULL),
00055 m_mdVariableLowerBounds(NULL),
00056 m_mdVariableUpperBounds(NULL),
00057
00058
00059 m_bProcessObjectives(false),
00060 m_iObjectiveNumber(-1),
00061 m_iObjectiveNumberNonlinear( 0),
00062 m_msObjectiveNames(NULL),
00063 m_msMaxOrMins(NULL),
00064 m_miNumberOfObjCoef(NULL),
00065 m_mdObjectiveConstants(NULL),
00066 m_mdObjectiveWeights(NULL),
00067 m_mObjectiveCoefficients(NULL),
00068 m_bGetDenseObjectives(false),
00069 m_mmdDenseObjectiveCoefficients(NULL),
00070 m_bProcessConstraints(false),
00071 m_iConstraintNumber(-1),
00072 m_iConstraintNumberNonlinear( 0),
00073 m_msConstraintNames(NULL),
00074 m_mdConstraintLowerBounds(NULL),
00075 m_mdConstraintUpperBounds(NULL),
00076 m_mdConstraintConstants( NULL),
00077 m_mcConstraintTypes(NULL),
00078 m_bProcessLinearConstraintCoefficients(false),
00079 m_iLinearConstraintCoefficientNumber(-1),
00080 m_bColumnMajor(true),
00081 m_linearConstraintCoefficientsInColumnMajor(NULL),
00082 m_linearConstraintCoefficientsInRowMajor(NULL),
00083 m_iNumberOfQuadraticRowIndexes( 0),
00084 m_bQuadraticRowIndexesProcessed(false),
00085 m_miQuadRowIndexes( NULL),
00086 m_bProcessQuadraticTerms(false),
00087 m_iQuadraticTermNumber(-1),
00088 m_quadraticTerms( NULL),
00089 m_bQTermsAdded( false),
00090 m_iNumberOfNonlinearExpressionTreeIndexes( 0),
00091 m_bNonlinearExpressionTreeIndexesProcessed( false),
00092 m_miNonlinearExpressionTreeIndexes( NULL),
00093 m_iNumberOfNonlinearExpressionTreeModIndexes( 0),
00094 m_bNonlinearExpressionTreeModIndexesProcessed( false),
00095 m_miNonlinearExpressionTreeModIndexes( NULL),
00096 m_binitForAlgDiff( false),
00097 m_iNumberOfNonlinearVariables( 0),
00098 m_bProcessNonlinearExpressions( false),
00099 m_iNonlinearExpressionNumber( -1),
00100 m_miNonlinearExpressionIndexes( NULL),
00101 m_bProcessExpressionTrees( false),
00102 m_bProcessExpressionTreesMod( false),
00103 m_mdConstraintFunctionValues( NULL),
00104 m_mdObjectiveFunctionValues( NULL),
00105 m_iJacValueSize( 0),
00106 m_miJacStart( NULL),
00107 m_miJacIndex( NULL),
00108 m_mdJacValue( NULL),
00109 m_miJacNumConTerms( NULL),
00110 m_sparseJacMatrix( NULL),
00111 m_iHighestTaylorCoeffOrder(-1),
00112 m_LagrangianExpTree(NULL),
00113 m_bLagrangianExpTreeCreated( false),
00114 m_LagrangianSparseHessian( NULL),
00115 m_bLagrangianSparseHessianCreated( false),
00116 m_miNonLinearVarsReverseMap( NULL),
00117 m_bAllNonlinearVariablesIndex( false),
00118 m_bOSADFunIsCreated( false),
00119 m_bCppADTapesBuilt( false),
00120 m_bCppADMustReTape( false),
00121 m_bDuplicateExpressionTreesMap( false),
00122 m_bNonLinearStructuresInitialized( false),
00123 m_bSparseJacobianCalculated( false),
00124 m_iHighestOrderEvaluated( -1),
00125 m_mmdObjGradient( NULL),
00126 m_bProcessMatrices( false),
00127 m_iMatrixNumber (-1),
00128 m_miMatrixSymmetry(NULL),
00129 m_miMatrixType(NULL),
00130 m_miMatrixNumberOfColumns(NULL),
00131 m_miMatrixNumberOfRows(NULL),
00132 m_msMatrixNames(NULL),
00133 m_mMatrix(NULL),
00134
00135
00136
00137
00138
00139
00140 m_iMatrixVarNumber(-1),
00141 m_iMatrixObjNumber(-1),
00142 m_iMatrixConNumber(-1),
00143 m_iMatrixExpressionNumber(-1),
00144
00145 m_bProcessTimeDomain( false),
00146 m_bProcessTimeStages( false),
00147 m_bProcessTimeInterval( false),
00148 m_bFiniteTimeStages( false),
00149 m_iNumberOfTimeStages(-1),
00150 m_sTimeDomainFormat(""),
00151 m_msTimeDomainStageNames(NULL),
00152 m_miTimeDomainStageVariableNumber(NULL),
00153 m_mmiTimeDomainStageVarList(NULL),
00154 m_miTimeDomainStageConstraintNumber(NULL),
00155 m_mmiTimeDomainStageConList(NULL),
00156 m_miTimeDomainStageObjectiveNumber(NULL),
00157 m_mmiTimeDomainStageObjList(NULL),
00158 bUseExpTreeForFunEval( false)
00159 {
00160 #ifndef NDEBUG
00161 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside OSInstance Constructor");
00162 #endif
00163 this->instanceHeader = new GeneralFileHeader();
00164 this->instanceData = new InstanceData();
00165 }
00166
00167 OSInstance::~OSInstance()
00168 {
00169 std::ostringstream outStr;
00170
00171 #ifndef NDEBUG
00172 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "OSInstance Destructor Called");
00173 #endif
00174 std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
00175
00176
00177 if (this->instanceData->variables != NULL &&
00178 this->instanceData->variables->numberOfVariables > 0 &&
00179 m_bProcessVariables == true)
00180 {
00181 if (m_msVariableNames != NULL) delete[] m_msVariableNames;
00182 m_msVariableNames = NULL;
00183 if (m_mcVariableTypes != NULL) delete[] m_mcVariableTypes;
00184 m_mcVariableTypes = NULL;
00185 if (m_mdVariableLowerBounds != NULL) delete[] m_mdVariableLowerBounds;
00186 m_mdVariableLowerBounds = NULL;
00187 if (m_mdVariableUpperBounds != NULL) delete[] m_mdVariableUpperBounds;
00188 m_mdVariableUpperBounds = NULL;
00189 }
00190
00191
00192 if(m_bProcessConstraints == true)
00193 {
00194 if (m_msConstraintNames != NULL) delete[] m_msConstraintNames;
00195 m_msConstraintNames = NULL;
00196 if (m_mcConstraintTypes != NULL) delete[] m_mcConstraintTypes;
00197 m_mcConstraintTypes = NULL;
00198 if (m_mdConstraintConstants != NULL) delete[] m_mdConstraintConstants;
00199 m_mdConstraintConstants = NULL;
00200 if (m_mdConstraintLowerBounds != NULL) delete[] m_mdConstraintLowerBounds;
00201 m_mdConstraintLowerBounds = NULL;
00202 if (m_mdConstraintUpperBounds != NULL) delete[] m_mdConstraintUpperBounds;
00203 m_mdConstraintUpperBounds = NULL;
00204 }
00205
00206
00207 int i;
00208
00209 if(instanceData->objectives != NULL && m_bProcessObjectives == true )
00210 {
00211 for(i = 0; i < instanceData->objectives->numberOfObjectives; i++)
00212 {
00213 #ifndef NDEBUG
00214 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, "Delete m_mObjectiveCoefficients[i]");
00215 #endif
00216 if (m_mObjectiveCoefficients[i] != NULL) delete m_mObjectiveCoefficients[i];
00217 m_mObjectiveCoefficients[i] = NULL;
00218 }
00219 #ifndef NDEBUG
00220 outStr.str("");
00221 outStr.clear();
00222 outStr << "Delete m_msObjectiveNames" << std::endl;
00223 outStr << "Delete m_msMaxOrMins" << std::endl;
00224 outStr << "Delete m_miNumberOfObjCoef" << std::endl;
00225 outStr << "Delete m_mdObjectiveConstants" << std::endl;
00226 outStr << "Delete m_mdObjectiveWeights" << std::endl;
00227 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
00228 #endif
00229 if (m_msObjectiveNames != NULL) delete[] m_msObjectiveNames;
00230 m_msObjectiveNames = NULL;
00231 if (m_msMaxOrMins != NULL) delete[] m_msMaxOrMins;
00232 m_msMaxOrMins = NULL;
00233 if (m_miNumberOfObjCoef != NULL) delete[] m_miNumberOfObjCoef;
00234 m_miNumberOfObjCoef = NULL;
00235 if (m_mdObjectiveConstants != NULL) delete[] m_mdObjectiveConstants;
00236 m_mdObjectiveConstants = NULL;
00237 if (m_mdObjectiveWeights != NULL) delete[] m_mdObjectiveWeights;
00238 m_mdObjectiveWeights = NULL;
00239 if (m_mObjectiveCoefficients != NULL) delete[] m_mObjectiveCoefficients;
00240 m_mObjectiveCoefficients = NULL;
00241 }
00242
00243 if(instanceData->objectives != NULL && m_bGetDenseObjectives == true)
00244 {
00245 for(i = 0; i < instanceData->objectives->numberOfObjectives; i++)
00246 {
00247
00248 #ifndef NDEBUG
00249 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, "delete m_mmdDenseObjectiveCoefficients[i]");
00250 #endif
00251 if (m_mmdDenseObjectiveCoefficients[i] != NULL)
00252 delete[] m_mmdDenseObjectiveCoefficients[i];
00253 m_mmdDenseObjectiveCoefficients[i] = NULL;
00254 }
00255 if (m_mmdDenseObjectiveCoefficients != NULL)
00256 delete[] m_mmdDenseObjectiveCoefficients;
00257 m_mmdDenseObjectiveCoefficients = NULL;
00258 }
00259
00260 if( m_linearConstraintCoefficientsInColumnMajor != NULL)
00261 delete m_linearConstraintCoefficientsInColumnMajor;
00262 if (m_linearConstraintCoefficientsInRowMajor != NULL )
00263 delete m_linearConstraintCoefficientsInRowMajor;
00264
00265 if( (m_binitForAlgDiff == true) )
00266 {
00267 if (m_miNonLinearVarsReverseMap != NULL) delete[] m_miNonLinearVarsReverseMap;
00268 m_miNonLinearVarsReverseMap = NULL;
00269
00270 if (instanceData->objectives != NULL &&
00271 instanceData->objectives->numberOfObjectives > 0 &&
00272 m_mmdObjGradient != NULL)
00273 {
00274 #ifndef NDEBUG
00275 outStr.str("");
00276 outStr.clear();
00277 outStr << "The number of objectives = " << instanceData->objectives->numberOfObjectives << std::endl;
00278 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
00279 #endif
00280 for(i = 0; i < instanceData->objectives->numberOfObjectives; i++)
00281 {
00282 #ifndef NDEBUG
00283 outStr.str("");
00284 outStr.clear();
00285 outStr << "deleting Objective function gradient " << i << std::endl;
00286 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
00287 #endif
00288 if (m_mmdObjGradient[i] != NULL) delete[] m_mmdObjGradient[i];
00289 m_mmdObjGradient[i] = NULL;
00290 }
00291 if (m_mmdObjGradient != NULL) delete[] m_mmdObjGradient;
00292 m_mmdObjGradient = NULL;
00293 }
00294 }
00295
00296
00297 #ifndef NDEBUG
00298 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
00299 "Do garbage collection for the nonlinear API");
00300 #endif
00301 if(m_bNonLinearStructuresInitialized == true )
00302 {
00303 if (m_mdObjectiveFunctionValues != NULL) delete[] m_mdObjectiveFunctionValues;
00304 m_mdObjectiveFunctionValues = NULL;
00305 if (m_mdConstraintFunctionValues != NULL) delete[] m_mdConstraintFunctionValues;
00306 m_mdConstraintFunctionValues = NULL;
00307 }
00308 if(m_bSparseJacobianCalculated == true)
00309 {
00310 if (m_miJacStart != NULL) delete[] m_miJacStart;
00311 m_miJacStart = NULL;
00312 if (m_miJacIndex != NULL) delete[] m_miJacIndex;
00313 m_miJacIndex = NULL;
00314 if (m_mdJacValue != NULL) delete[] m_mdJacValue;
00315 m_mdJacValue = NULL;
00316 if (m_miJacNumConTerms != NULL) delete[] m_miJacNumConTerms;
00317 m_miJacNumConTerms = NULL;
00318 }
00319 if( m_bLagrangianExpTreeCreated == true)
00320 {
00321 if (m_LagrangianExpTree != NULL) delete m_LagrangianExpTree;
00322 m_LagrangianExpTree = NULL;
00323 }
00324 if( m_bLagrangianSparseHessianCreated == true)
00325 {
00326 if (m_LagrangianSparseHessian != NULL) delete m_LagrangianSparseHessian;
00327 m_LagrangianSparseHessian = NULL;
00328 }
00329 if( m_bSparseJacobianCalculated == true)
00330 {
00331 if (m_sparseJacMatrix != NULL) delete m_sparseJacMatrix;
00332 m_sparseJacMatrix = NULL;
00333 }
00334 if( (instanceData->quadraticCoefficients != NULL) && (instanceData->quadraticCoefficients->qTerm != NULL) )
00335 {
00336 if( (m_bProcessQuadraticTerms == true) )
00337 {
00338 if (m_quadraticTerms != NULL) delete m_quadraticTerms;
00339 m_quadraticTerms = NULL;
00340 }
00341 if( (m_bQuadraticRowIndexesProcessed == true) )
00342 {
00343 if (m_miQuadRowIndexes != NULL) delete[] m_miQuadRowIndexes;
00344 m_miQuadRowIndexes = NULL;
00345 }
00346 }
00347
00348
00349
00350 if( (m_bProcessExpressionTrees == true) && (m_bDuplicateExpressionTreesMap == false) )
00351 {
00352 for(posMapExpTree = m_mapExpressionTrees.begin(); posMapExpTree != m_mapExpressionTrees.end(); ++posMapExpTree)
00353 {
00354 #ifndef NDEBUG
00355 outStr.str("");
00356 outStr.clear();
00357 outStr << "Deleting an expression tree from the map for row " << posMapExpTree->first << std::endl;
00358 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
00359 #endif
00360 delete m_mapExpressionTrees[ posMapExpTree->first ];
00361 }
00362 }
00363 if( m_bDuplicateExpressionTreesMap == true)
00364 {
00365 for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
00366 {
00367 #ifndef NDEBUG
00368 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Deleting an expression tree from m_mapExpressionTreesMod");
00369 #endif
00370 delete m_mapExpressionTreesMod[ posMapExpTree->first ];
00371 }
00372 }
00373
00375 if( (m_bNonlinearExpressionTreeIndexesProcessed == true) && (m_mapExpressionTrees.size() > 0) )
00376 {
00377 #ifndef NDEBUG
00378 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, "Deleting m_miNonlinearExpressionTreeIndexes");
00379 #endif
00380 delete[] m_miNonlinearExpressionTreeIndexes;
00381 #ifndef NDEBUG
00382 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, "Done Deleting m_miNonlinearExpressionTreeIndexes");
00383 #endif
00384 m_miNonlinearExpressionTreeIndexes = NULL;
00385 }
00386 if( (m_bNonlinearExpressionTreeModIndexesProcessed == true) && (m_mapExpressionTreesMod.size() > 0) )
00387 {
00388 #ifndef NDEBUG
00389 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, "Deleting m_miNonlinearExpressionTreeModIndexes");
00390 #endif
00391 delete[] m_miNonlinearExpressionTreeModIndexes;
00392 #ifndef NDEBUG
00393 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, "Done Deleting m_miNonlinearExpressionTreeModIndexes");
00394 #endif
00395 m_miNonlinearExpressionTreeModIndexes = NULL;
00396 }
00397 if(m_bOSADFunIsCreated == true)
00398 {
00399 try
00400 {
00401 #ifdef COIN_HAS_CPPAD
00402 delete Fad;
00403 Fad = NULL;
00404 #else
00405 throw ErrorClass( "Error: An Algorithmic Differentiation Package Not Available");
00406 #endif
00407 }
00408 catch(const ErrorClass& eclass)
00409 {
00410 throw ErrorClass( eclass.errormsg);
00411 }
00412 }
00413
00414 if (this->instanceData->matrices != NULL &&
00415 this->instanceData->matrices->numberOfMatrices > 0 &&
00416 m_bProcessMatrices == true)
00417 {
00418 if (m_miMatrixSymmetry != NULL) delete[] m_miMatrixSymmetry;
00419 m_miMatrixSymmetry = NULL;
00420 if (m_miMatrixType != NULL) delete[] m_miMatrixType;
00421 m_miMatrixType = NULL;
00422 if (m_miMatrixNumberOfColumns != NULL) delete[] m_miMatrixNumberOfColumns;
00423 m_miMatrixNumberOfColumns = NULL;
00424 if (m_miMatrixNumberOfRows != NULL) delete[] m_miMatrixNumberOfRows;
00425 m_miMatrixNumberOfRows = NULL;
00426 if (m_msMatrixNames != NULL) delete[] m_msMatrixNames;
00427 m_msMatrixNames = NULL;
00428
00429 if (m_mMatrix != NULL)
00430 {
00431 for (int i=0; i < instanceData->matrices->numberOfMatrices; i++)
00432 {
00433 if (m_mMatrix[i] != NULL)
00434 delete m_mMatrix[i];
00435 m_mMatrix[i] = NULL;
00436 }
00437 delete[] m_mMatrix;
00438 m_mMatrix = NULL;
00439 }
00440
00441 #if 0
00442 if (m_mExpandedMatricesInColumnMajor != NULL)
00443 {
00444 for (int i=0; i < instanceData->matrices->numberOfMatrices; i++)
00445 {
00446 if (m_mExpandedMatricesInColumnMajor[i] != NULL)
00447 delete m_mExpandedMatricesInColumnMajor[i];
00448 m_mExpandedMatricesInColumnMajor[i] = NULL;
00449 }
00450 delete[] m_mExpandedMatricesInColumnMajor;
00451 m_mExpandedMatricesInColumnMajor = NULL;
00452 }
00453
00454 if (m_mExpandedMatricesInRowMajor != NULL)
00455 {
00456 for (int i=0; i < instanceData->matrices->numberOfMatrices; i++)
00457 {
00458 if (m_mExpandedMatricesInRowMajor[i] != NULL)
00459 delete m_mExpandedMatricesInRowMajor[i];
00460 m_mExpandedMatricesInRowMajor[i] = NULL;
00461 }
00462 delete[] m_mExpandedMatricesInRowMajor;
00463 m_mExpandedMatricesInRowMajor = NULL;
00464 }
00465
00466 if (m_mMatrixBlocksInColumnMajor != NULL)
00467 {
00468 for (int i=0; i < instanceData->matrices->numberOfMatrices; i++)
00469 {
00470 if (m_mMatrixBlocksInColumnMajor[i] != NULL)
00471 delete m_mMatrixBlocksInColumnMajor[i];
00472 m_mMatrixBlocksInColumnMajor[i] = NULL;
00473 }
00474 delete[] m_mMatrixBlocksInColumnMajor;
00475 m_mMatrixBlocksInColumnMajor = NULL;
00476 }
00477 }
00478
00479 if (m_mMatrixTransformation != NULL)
00480 {
00481 for (int i=0; i < instanceData->matrices->numberOfMatrices; i++)
00482 {
00483 if (m_mMatrixTransformation[i] != NULL)
00484 delete m_mMatrixTransformation[i];
00485 m_mMatrixTransformation[i] = NULL;
00486 }
00487 delete[] m_mMatrixTransformation;
00488 m_mMatrixTransformation = NULL;
00489 }
00490 }
00491 #endif
00492
00493
00494
00495
00496
00497 }
00498
00499 if (m_msTimeDomainStageNames != NULL)
00500 {
00501 delete[] m_msTimeDomainStageNames;
00502 m_msTimeDomainStageNames = NULL;
00503 }
00504
00505 if (m_miTimeDomainStageVariableNumber != NULL)
00506 {
00507 delete[] m_miTimeDomainStageVariableNumber;
00508 m_miTimeDomainStageVariableNumber = NULL;
00509 }
00510
00511 if (m_mmiTimeDomainStageVarList != NULL)
00512 {
00513 for (int i = 0; i < m_iNumberOfTimeStages; i ++)
00514 delete[] m_mmiTimeDomainStageVarList[i];
00515 delete[] m_mmiTimeDomainStageVarList;
00516 m_mmiTimeDomainStageVarList = NULL;
00517 }
00518
00519 if (m_miTimeDomainStageConstraintNumber != NULL)
00520 {
00521 delete[] m_miTimeDomainStageConstraintNumber;
00522 m_miTimeDomainStageConstraintNumber = NULL;
00523 }
00524
00525 if (m_mmiTimeDomainStageConList != NULL)
00526 {
00527 for (int i = 0; i < m_iNumberOfTimeStages; i ++)
00528 delete[] m_mmiTimeDomainStageConList[i];
00529 delete[] m_mmiTimeDomainStageConList;
00530 m_mmiTimeDomainStageConList = NULL;
00531 }
00532
00533 if (m_miTimeDomainStageObjectiveNumber != NULL)
00534 {
00535 delete[] m_miTimeDomainStageObjectiveNumber;
00536 m_miTimeDomainStageObjectiveNumber = NULL;
00537 }
00538
00539 if (m_mmiTimeDomainStageObjList != NULL)
00540 {
00541 for (int i = 0; i < m_iNumberOfTimeStages; i ++)
00542 delete[] m_mmiTimeDomainStageObjList[i];
00543 delete[] m_mmiTimeDomainStageObjList;
00544 m_mmiTimeDomainStageObjList = NULL;
00545 }
00546
00547
00548
00549 delete instanceHeader;
00550 instanceHeader = NULL;
00551
00552 delete instanceData;
00553 instanceData = NULL;
00554 }
00555
00556
00557 Variable::Variable():
00558 lb(0.0),
00559 ub(OSDBL_MAX),
00560
00561 type('C'),
00562 name("")
00563
00564 {
00565 #ifndef NDEBUG
00566 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Variable Constructor");
00567 #endif
00568 }
00569
00570 Variable::~Variable()
00571 {
00572 #ifndef NDEBUG
00573 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Variable Destructor");
00574 #endif
00575 }
00576
00577 Variables::Variables()
00578 {
00579 #ifndef NDEBUG
00580 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Variables Constructor");
00581 #endif
00582 numberOfVariables = 0;
00583 var = NULL;
00584 }
00585
00586 Variables::~Variables()
00587 {
00588 #ifndef NDEBUG
00589 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Variables Destructor");
00590 #endif
00591 int i;
00592 if(numberOfVariables > 0 && var != NULL)
00593 {
00594 for(i = 0; i < numberOfVariables; i++)
00595 {
00596 #ifndef NDEBUG
00597 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, "Deleting var[ i]");
00598 #endif
00599 delete var[i];
00600 var[i] = NULL;
00601 }
00602 }
00603 if (var != NULL)
00604 delete[] var;
00605 var = NULL;
00606 }
00607
00608 ObjCoef::ObjCoef():
00609 idx(-1),
00610 value(0.0)
00611 {
00612 #ifndef NDEBUG
00613 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ObjCoef Constructor");
00614 #endif
00615 }
00616
00617 ObjCoef::~ObjCoef()
00618 {
00619 #ifndef NDEBUG
00620 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ObjCoef Destructor");
00621 #endif
00622 }
00623
00624 Objective::Objective():
00625 name("") ,
00626 maxOrMin("min"),
00627 constant(0.0),
00628 weight(OSNaN()),
00629 numberOfObjCoef(0),
00630 coef(NULL)
00631 {
00632
00633 #ifndef NDEBUG
00634 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Objective Constructor");
00635 #endif
00636 }
00637
00638 Objective::~Objective()
00639 {
00640 #ifndef NDEBUG
00641 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Objective Destructor");
00642 #endif
00643 int i;
00644 if(numberOfObjCoef > 0 && coef != NULL)
00645 {
00646 for(i = 0; i < numberOfObjCoef; i++)
00647 {
00648 delete coef[i];
00649 coef[i] = NULL;
00650 }
00651 }
00652 if (coef != NULL)
00653 delete[] coef;
00654 coef = NULL;
00655 }
00656
00657 Objectives::Objectives()
00658 {
00659 #ifndef NDEBUG
00660 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Objectives Constructor");
00661 #endif
00662 numberOfObjectives = 0;
00663 obj = NULL;
00664 }
00665
00666 Objectives::~Objectives()
00667 {
00668 #ifndef NDEBUG
00669 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Objectives Destructor");
00670 #endif
00671 int i;
00672 if(numberOfObjectives > 0 && obj != NULL)
00673 {
00674 for(i = 0; i < numberOfObjectives; i++)
00675 {
00676 delete obj[i];
00677 obj[i] = NULL;
00678 }
00679 }
00680 if (obj != NULL)
00681 delete[] obj;
00682 obj = NULL;
00683 }
00684
00685 Constraint::Constraint():
00686 name(""),
00687 constant(0.0),
00688 lb(-OSDBL_MAX),
00689 ub(OSDBL_MAX)
00690
00691 {
00692 #ifndef NDEBUG
00693 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Constraint Constructor");
00694 #endif
00695 }
00696
00697 Constraint::~Constraint()
00698 {
00699 #ifndef NDEBUG
00700 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Constraint Destructor");
00701 #endif
00702 }
00703
00704 Constraints::Constraints():
00705 numberOfConstraints(0),
00706 con(NULL)
00707 {
00708 #ifndef NDEBUG
00709 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Constraints Constructor");
00710 #endif
00711 }
00712
00713 Constraints::~Constraints()
00714 {
00715 #ifndef NDEBUG
00716 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Constraints Destructor");
00717 #endif
00718 int i;
00719 if(numberOfConstraints > 0 && con != NULL)
00720 {
00721 for( i = 0; i < numberOfConstraints; i++)
00722 {
00723 delete con[i];
00724 con[i] = NULL;
00725 }
00726 }
00727 if (con != NULL)
00728 delete[] con;
00729 con = NULL;
00730 }
00731
00732
00733
00734 LinearConstraintCoefficients::LinearConstraintCoefficients():
00735 numberOfValues(0) ,
00736 iNumberOfStartElements( 0)
00737 {
00738 #ifndef NDEBUG
00739 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the LinearConstraintCoefficients Constructor");
00740 #endif
00741 start = new IntVector();
00742 rowIdx = new IntVector();
00743 colIdx = new IntVector();
00744 value = new DoubleVector();
00745 }
00746
00747
00748 LinearConstraintCoefficients::~LinearConstraintCoefficients()
00749 {
00750 #ifndef NDEBUG
00751 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the LinearConstraintCoefficients Destructor");
00752 #endif
00753 delete start;
00754 start = NULL;
00755 delete rowIdx;
00756 rowIdx = NULL;
00757 delete colIdx;
00758 colIdx = NULL;
00759 delete value;
00760 value = NULL;
00761 }
00762
00763 QuadraticTerm::QuadraticTerm():
00764
00765 idx(0),
00766 idxOne(-1),
00767 idxTwo(-1),
00768 coef(0.0)
00769
00770 {
00771 #ifndef NDEBUG
00772 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the QuadraticTerm Constructor");
00773 #endif
00774 }
00775
00776
00777 QuadraticTerm::~QuadraticTerm()
00778 {
00779 #ifndef NDEBUG
00780 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the QuadraticTerm Destructor");
00781 #endif
00782 }
00783
00784
00785
00786 QuadraticCoefficients::QuadraticCoefficients():
00787 numberOfQuadraticTerms(0),
00788 qTerm(NULL)
00789 {
00790 #ifndef NDEBUG
00791 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the QuadraticCoefficients Constructor");
00792 #endif
00793 }
00794
00795
00796 QuadraticCoefficients::~QuadraticCoefficients()
00797 {
00798 #ifndef NDEBUG
00799 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the QuadraticCoefficients Destructor");
00800 #endif
00801 int i;
00802 if(numberOfQuadraticTerms > 0 && qTerm != NULL)
00803 {
00804 for( i = 0; i < numberOfQuadraticTerms; i++)
00805 {
00806 delete qTerm[i];
00807 qTerm[i] = NULL;
00808 }
00809 }
00810 if (qTerm != NULL)
00811 delete[] qTerm;
00812 qTerm = NULL;
00813 }
00814
00815
00816 Nl::Nl()
00817 {
00818 #ifndef NDEBUG
00819 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Nl Constructor");
00820 #endif
00821 idx = 0;
00822 shape = ENUM_NL_EXPR_SHAPE_general;
00823 osExpressionTree = NULL;
00824 m_bDeleteExpressionTree = true;
00825 }
00826
00827
00828 Nl::~Nl()
00829 {
00830 #ifndef NDEBUG
00831 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Nl Destructor");
00832 #endif
00833
00834
00835 if( m_bDeleteExpressionTree == true)
00836 {
00837 if (osExpressionTree != NULL) delete osExpressionTree;
00838 osExpressionTree = NULL;
00839 }
00840 }
00841
00842
00843
00844 NonlinearExpressions::NonlinearExpressions():
00845 numberOfNonlinearExpressions(0) ,
00846 nl(NULL)
00847 {
00848 #ifndef NDEBUG
00849 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the NonlinearExpressions Constructor");
00850 #endif
00851 }
00852
00853 NonlinearExpressions::~NonlinearExpressions()
00854 {
00855 std::ostringstream outStr;
00856
00857 #ifndef NDEBUG
00858 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the NonlinearExpressions Destructor");
00859 outStr.str("");
00860 outStr.clear();
00861 outStr << "NUMBER OF NONLINEAR EXPRESSIONS = " << numberOfNonlinearExpressions << endl;
00862 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
00863 #endif
00864 int i;
00865 if(numberOfNonlinearExpressions > 0 && nl != NULL)
00866 {
00867 for( i = 0; i < numberOfNonlinearExpressions; i++)
00868 {
00869 #ifndef NDEBUG
00870 outStr.str("");
00871 outStr.clear();
00872 outStr << "DESTROYING EXPRESSION " << i << "(row " << nl[ i]->idx << ")" << endl;
00873 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
00874 #endif
00875 if(nl != NULL)
00876 {
00877 if(nl[i] != NULL)
00878 {
00879 delete nl[i];
00880 nl[i] = NULL;
00881 }
00882 }
00883 }
00884 }
00885 if(nl != NULL)
00886 {
00887 delete[] nl;
00888 }
00889 nl = NULL;
00890 }
00891
00892
00893 Matrices::Matrices():
00894 numberOfMatrices(0) ,
00895 matrix(NULL)
00896 {
00897 #ifndef NDEBUG
00898 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Matrices Constructor");
00899 #endif
00900 }
00901
00902 Matrices::~Matrices()
00903 {
00904 std::ostringstream outStr;
00905
00906 #ifndef NDEBUG
00907 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Matrices Destructor");
00908 outStr.str("");
00909 outStr.clear();
00910 outStr << "NUMBER OF MATRICES = " << numberOfMatrices << endl;
00911 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
00912 #endif
00913 int i;
00914 if(numberOfMatrices > 0 && matrix != NULL)
00915 {
00916 for (i = 0; i < numberOfMatrices; i++)
00917 {
00918 #ifndef NDEBUG
00919 outStr.str("");
00920 outStr.clear();
00921 outStr << "DESTROYING MATRIX " << i << endl;
00922 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
00923 #endif
00924 if(matrix[i] != NULL)
00925 {
00926 delete matrix[i];
00927 matrix[i] = NULL;
00928 }
00929 }
00930 }
00931 if(matrix != NULL)
00932 {
00933 delete[] matrix;
00934 matrix = NULL;
00935 }
00936 }
00937
00938
00939 Cones::Cones():
00940 numberOfCones(0) ,
00941 cone(NULL)
00942 {
00943 #ifndef NDEBUG
00944 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Cones Constructor");
00945 #endif
00946 }
00947
00948 Cones::~Cones()
00949 {
00950 std::ostringstream outStr;
00951
00952 #ifndef NDEBUG
00953 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Cones Destructor");
00954 outStr.str("");
00955 outStr.clear();
00956 outStr << "NUMBER OF CONES = " << numberOfCones << endl;
00957 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
00958 #endif
00959 int i;
00960 if(numberOfCones > 0 && cone != NULL)
00961 {
00962 for( i = 0; i < numberOfCones; i++)
00963 {
00964 #ifndef NDEBUG
00965 outStr.str("");
00966 outStr.clear();
00967 outStr << "DESTROYING CONE " << i << endl;
00968 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
00969 #endif
00970 if(cone != NULL)
00971 {
00972 if(cone[i] != NULL)
00973 {
00974 delete cone[i];
00975 cone[i] = NULL;
00976 }
00977 }
00978 }
00979 }
00980 if(cone != NULL)
00981 {
00982 delete [] cone;
00983 cone = NULL;
00984 }
00985 }
00986
00987 Cone::Cone():
00988 numberOfRows(0),
00989 numberOfColumns(0),
00990 numberOfOtherIndexes(0),
00991 otherIndexes(NULL),
00992 coneType(ENUM_CONE_TYPE_unknown),
00993 idx(-1)
00994 {
00995 #ifndef NDEBUG
00996 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Cone Constructor");
00997 #endif
00998 }
00999
01000 Cone::~Cone()
01001 {
01002 #ifndef NDEBUG
01003 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the Cone Destructor");
01004 #endif
01005 if(otherIndexes != NULL)
01006 {
01007 delete[] otherIndexes;
01008 otherIndexes = NULL;
01009 }
01010 }
01011
01012 std::string Cone::getConeName()
01013 {
01014 return "genericCone";
01015 }
01016
01017 NonnegativeCone::NonnegativeCone()
01018 {
01019 #ifndef NDEBUG
01020 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the NonnegativeCone Constructor");
01021 #endif
01022 }
01023
01024 NonnegativeCone::~NonnegativeCone()
01025 {
01026 #ifndef NDEBUG
01027 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the NonnegativeCone Destructor");
01028 #endif
01029 }
01030
01031 std::string NonnegativeCone::getConeName()
01032 {
01033 return "nonnegativeCone";
01034 }
01035
01036 NonpositiveCone::NonpositiveCone()
01037 {
01038 #ifndef NDEBUG
01039 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the NonpositiveCone Constructor");
01040 #endif
01041 }
01042
01043 NonpositiveCone::~NonpositiveCone()
01044 {
01045 #ifndef NDEBUG
01046 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the NonpositiveCone Destructor");
01047 #endif
01048 }
01049
01050 std::string NonpositiveCone::getConeName()
01051 {
01052 return "nonpositiveCone";
01053 }
01054
01055 OrthantCone::OrthantCone():
01056 ub(NULL),
01057 lb(NULL)
01058 {
01059 #ifndef NDEBUG
01060 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OrthantCone Constructor");
01061 #endif
01062 }
01063
01064 OrthantCone::~OrthantCone()
01065 {
01066 #ifndef NDEBUG
01067 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OrthantCone Destructor");
01068 #endif
01069 if(ub != NULL)
01070 {
01071 delete[] ub;
01072 ub = NULL;
01073 }
01074 if(lb != NULL)
01075 {
01076 delete[] lb;
01077 lb = NULL;
01078 }
01079 }
01080
01081 std::string OrthantCone::getConeName()
01082 {
01083 return "orthantCone";
01084 }
01085
01086 PolyhedralCone::PolyhedralCone():
01087 referenceMatrixIdx(0)
01088 {
01089 #ifndef NDEBUG
01090 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the PolyhedralCone Constructor");
01091 #endif
01092 }
01093
01094 PolyhedralCone::~PolyhedralCone()
01095 {
01096 #ifndef NDEBUG
01097 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the PolyhedralCone Destructor");
01098 #endif
01099 }
01100
01101 std::string PolyhedralCone::getConeName()
01102 {
01103 return "polyhedralCone";
01104 }
01105
01106
01107 QuadraticCone::QuadraticCone():
01108 normScaleFactor(1.0),
01109 distortionMatrixIdx(-1),
01110 axisDirection(0)
01111 {
01112 #ifndef NDEBUG
01113 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the QuadraticCone Constructor");
01114 #endif
01115 }
01116
01117 QuadraticCone::~QuadraticCone()
01118 {
01119 #ifndef NDEBUG
01120 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the QuadraticCone Destructor");
01121 #endif
01122 }
01123
01124 std::string QuadraticCone::getConeName()
01125 {
01126 return "quadraticCone";
01127 }
01128
01129
01130 RotatedQuadraticCone::RotatedQuadraticCone():
01131 normScaleFactor(1.0),
01132 distortionMatrixIdx(-1),
01133 firstAxisDirection(0),
01134 secondAxisDirection(1)
01135 {
01136 #ifndef NDEBUG
01137 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the RotatedQuadraticCone Constructor");
01138 #endif
01139 }
01140
01141 RotatedQuadraticCone::~RotatedQuadraticCone()
01142 {
01143 #ifndef NDEBUG
01144 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the RotatedQuadraticCone Destructor");
01145 #endif
01146 }
01147
01148 std::string RotatedQuadraticCone::getConeName()
01149 {
01150 return "rotatedQuadraticCone";
01151 }
01152
01153
01154
01155
01156 SemidefiniteCone::SemidefiniteCone():
01157 semidefiniteness("positive"),
01158 isPositiveSemiDefinite(true)
01159 {
01160 #ifndef NDEBUG
01161 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the SemidefiniteCone Constructor");
01162 #endif
01163 }
01164
01165 SemidefiniteCone::~SemidefiniteCone()
01166 {
01167 #ifndef NDEBUG
01168 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the SemidefiniteCone Destructor");
01169 #endif
01170 }
01171
01172 std::string SemidefiniteCone::getConeName()
01173 {
01174 return "semidefiniteCone";
01175 }
01176
01177 CopositiveMatricesCone::CopositiveMatricesCone()
01178 {
01179 #ifndef NDEBUG
01180 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the CopositiveMatricesCone Constructor");
01181 #endif
01182 }
01183
01184 CopositiveMatricesCone::~CopositiveMatricesCone()
01185 {
01186 #ifndef NDEBUG
01187 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the CopositiveMatricesCone Destructor");
01188 #endif
01189 }
01190
01191 std::string CopositiveMatricesCone::getConeName()
01192 {
01193 return "copositiveMatricesCone";
01194 }
01195
01196
01197 CompletelyPositiveMatricesCone::CompletelyPositiveMatricesCone()
01198 {
01199 #ifndef NDEBUG
01200 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the CompletelyPositiveMatricesCone Constructor");
01201 #endif
01202 }
01203
01204 CompletelyPositiveMatricesCone::~CompletelyPositiveMatricesCone()
01205 {
01206 #ifndef NDEBUG
01207 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the CompletelyPositiveMatricesCone Destructor");
01208 #endif
01209 }
01210
01211 std::string CompletelyPositiveMatricesCone::getConeName()
01212 {
01213 return "completelyPositiveMatricesCone";
01214 }
01215
01216 ProductCone::ProductCone():
01217 factors(NULL)
01218 {
01219 #ifndef NDEBUG
01220 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ProductCone Constructor");
01221 #endif
01222 }
01223
01224 ProductCone::~ProductCone()
01225 {
01226 #ifndef NDEBUG
01227 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ProductCone Destructor");
01228 #endif
01229 if (factors != NULL)
01230 delete factors;
01231 factors = NULL;
01232 }
01233
01234 std::string ProductCone::getConeName()
01235 {
01236 return "productCone";
01237 }
01238
01239
01240 IntersectionCone::IntersectionCone():
01241 components(NULL)
01242 {
01243 #ifndef NDEBUG
01244 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the IntersectionCone Constructor");
01245 #endif
01246 }
01247
01248 IntersectionCone::~IntersectionCone()
01249 {
01250 #ifndef NDEBUG
01251 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the IntersectionCone Destructor");
01252 #endif
01253 if (components != NULL)
01254 delete components;
01255 components = NULL;
01256 }
01257
01258 std::string IntersectionCone::getConeName()
01259 {
01260 return "intersectionCone";
01261 }
01262
01263
01264 DualCone::DualCone():
01265 referenceConeIdx(0)
01266 {
01267 #ifndef NDEBUG
01268 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the DualCone Constructor");
01269 #endif
01270 }
01271
01272 DualCone::~DualCone()
01273 {
01274 #ifndef NDEBUG
01275 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the DualCone Destructor");
01276 #endif
01277 }
01278
01279 std::string DualCone::getConeName()
01280 {
01281 return "dualCone";
01282 }
01283
01284
01285 PolarCone::PolarCone():
01286 referenceConeIdx(0)
01287 {
01288 #ifndef NDEBUG
01289 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the PolarCone Constructor");
01290 #endif
01291 }
01292
01293 PolarCone::~PolarCone()
01294 {
01295 #ifndef NDEBUG
01296 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the PolarCone Destructor");
01297 #endif
01298 }
01299
01300 std::string PolarCone::getConeName()
01301 {
01302 return "polarCone";
01303 }
01304
01305 MatrixProgramming::MatrixProgramming():
01306 matrixVariables(NULL),
01307 matrixObjectives(NULL),
01308 matrixConstraints(NULL),
01309 matrixExpressions(NULL)
01310 {
01311 #ifndef NDEBUG
01312 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixProgramming Constructor");
01313 #endif
01314 }
01315
01316 MatrixProgramming::~MatrixProgramming()
01317 {
01318 #ifndef NDEBUG
01319 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixProgramming Destructor");
01320 #endif
01321 if (matrixVariables != NULL)
01322 delete matrixVariables;
01323 matrixVariables = NULL;
01324 if (matrixObjectives != NULL)
01325 delete matrixObjectives;
01326 matrixObjectives = NULL;
01327 if (matrixConstraints != NULL)
01328 delete matrixConstraints;
01329 matrixConstraints = NULL;
01330 if (matrixExpressions != NULL)
01331 delete matrixExpressions;
01332 matrixExpressions = NULL;
01333 }
01334
01335
01336 MatrixVariables::MatrixVariables():
01337 numberOfMatrixVar(0),
01338 matrixVar(NULL)
01339 {
01340 #ifndef NDEBUG
01341 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixVariables Constructor");
01342 #endif
01343 }
01344
01345 MatrixVariables::~MatrixVariables()
01346 {
01347 std::ostringstream outStr;
01348
01349 #ifndef NDEBUG
01350 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixVariables Destructor");
01351 outStr.str("");
01352 outStr.clear();
01353 outStr << "NUMBER OF MATRIXVAR = " << numberOfMatrixVar << endl;
01354 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
01355 #endif
01356
01357 if (numberOfMatrixVar > 0 && matrixVar != NULL)
01358 {
01359 for(int i = 0; i < numberOfMatrixVar; i++)
01360 {
01361 #ifndef NDEBUG
01362 outStr.str("");
01363 outStr.clear();
01364 outStr << "DESTROYING MATRIXVAR " << i << endl;
01365 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
01366 #endif
01367 if(matrixVar != NULL)
01368 {
01369 if(matrixVar[i] != NULL)
01370 {
01371 delete matrixVar[i];
01372 matrixVar[i] = NULL;
01373 }
01374 }
01375 }
01376 }
01377 if(matrixVar != NULL)
01378 {
01379 delete [] matrixVar;
01380 matrixVar = NULL;
01381 }
01382 }
01383
01384 MatrixObjectives::MatrixObjectives():
01385 numberOfMatrixObj(0),
01386 matrixObj(NULL)
01387 {
01388 #ifndef NDEBUG
01389 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixObjectives Constructor");
01390 #endif
01391 }
01392
01393 MatrixObjectives::~MatrixObjectives()
01394 {
01395 std::ostringstream outStr;
01396
01397 #ifndef NDEBUG
01398 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixObjectives Destructor");
01399 outStr.str("");
01400 outStr.clear();
01401 outStr << "NUMBER OF MATRIXOBJ = " << numberOfMatrixObj << endl;
01402 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
01403 #endif
01404
01405 if (numberOfMatrixObj > 0 && matrixObj != NULL)
01406 {
01407 for(int i = 0; i < numberOfMatrixObj; i++)
01408 {
01409 #ifndef NDEBUG
01410 outStr.str("");
01411 outStr.clear();
01412 outStr << "DESTROYING MATRIXOBJ " << i << endl;
01413 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
01414 #endif
01415 if(matrixObj != NULL)
01416 {
01417 if(matrixObj[i] != NULL)
01418 {
01419 delete matrixObj[i];
01420 matrixObj[i] = NULL;
01421 }
01422 }
01423 }
01424 }
01425 if(matrixObj != NULL)
01426 {
01427 delete [] matrixObj;
01428 matrixObj = NULL;
01429 }
01430 }
01431
01432 MatrixConstraints::MatrixConstraints():
01433 numberOfMatrixCon(0),
01434 matrixCon(NULL)
01435 {
01436 #ifndef NDEBUG
01437 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixConstraints Constructor");
01438 #endif
01439 }
01440
01441 MatrixConstraints::~MatrixConstraints()
01442 {
01443 std::ostringstream outStr;
01444
01445 #ifndef NDEBUG
01446 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixConstraints Destructor");
01447 outStr.str("");
01448 outStr.clear();
01449 outStr << "NUMBER OF MATRIXCON = " << numberOfMatrixCon << endl;
01450 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
01451 #endif
01452
01453 if (numberOfMatrixCon > 0 && matrixCon != NULL)
01454 {
01455 for(int i = 0; i < numberOfMatrixCon; i++)
01456 {
01457 #ifndef NDEBUG
01458 outStr.str("");
01459 outStr.clear();
01460 outStr << "DESTROYING MATRIXCON " << i << endl;
01461 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
01462 #endif
01463 if(matrixCon != NULL)
01464 {
01465 if(matrixCon[i] != NULL)
01466 {
01467 delete matrixCon[i];
01468 matrixCon[i] = NULL;
01469 }
01470 }
01471 }
01472 }
01473 if(matrixCon != NULL)
01474 {
01475 delete [] matrixCon;
01476 matrixCon = NULL;
01477 }
01478 }
01479
01480 MatrixExpressions::MatrixExpressions():
01481 numberOfExpr(0),
01482 expr(NULL)
01483 {
01484 #ifndef NDEBUG
01485 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixExpressions Constructor");
01486 #endif
01487 }
01488
01489 MatrixExpressions::~MatrixExpressions()
01490 {
01491 std::ostringstream outStr;
01492
01493 #ifndef NDEBUG
01494 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixExpressions Destructor");
01495 outStr.str("");
01496 outStr.clear();
01497 outStr << "NUMBER OF EXPR = " << numberOfExpr << endl;
01498 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
01499 #endif
01500
01501 if (numberOfExpr > 0 && expr != NULL)
01502 {
01503 for(int i = 0; i < numberOfExpr; i++)
01504 {
01505 #ifndef NDEBUG
01506 outStr.str("");
01507 outStr.clear();
01508 outStr << "DESTROYING EXPR " << i << "(\"row\" " << expr[i]->idx << ")" << endl;
01509 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
01510 #endif
01511 if(expr != NULL)
01512 {
01513 if(expr[i] != NULL)
01514 {
01515 delete expr[i];
01516 expr[i] = NULL;
01517 }
01518 }
01519 }
01520 }
01521 if(expr != NULL)
01522 {
01523 delete [] expr;
01524 expr = NULL;
01525 }
01526 }
01527
01528
01529 MatrixVar::MatrixVar():
01530 numberOfRows(0),
01531 numberOfColumns(0),
01532 templateMatrixIdx(-1),
01533 varReferenceMatrixIdx(-1),
01534 lbMatrixIdx(-1),
01535 lbConeIdx(-1),
01536 ubMatrixIdx(-1),
01537 ubConeIdx(-1),
01538 name(""),
01539 varType('C')
01540 {
01541 #ifndef NDEBUG
01542 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixVar Constructor");
01543 #endif
01544 }
01545
01546 MatrixVar::~MatrixVar()
01547 {
01548 #ifndef NDEBUG
01549 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixVar Destructor");
01550 #endif
01551 }
01552
01553
01554 MatrixObj::MatrixObj():
01555 numberOfRows(0),
01556 numberOfColumns(0),
01557 templateMatrixIdx(-1),
01558 objReferenceMatrixIdx(-1),
01559 orderConeIdx(-1),
01560 constantMatrixIdx(-1),
01561 name("")
01562 {
01563 #ifndef NDEBUG
01564 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixObj Constructor");
01565 #endif
01566 }
01567
01568 MatrixObj::~MatrixObj()
01569 {
01570 #ifndef NDEBUG
01571 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixObj Destructor");
01572 #endif
01573 }
01574
01575
01576 MatrixCon::MatrixCon():
01577 numberOfRows(0),
01578 numberOfColumns(0),
01579 templateMatrixIdx(-1),
01580 conReferenceMatrixIdx(-1),
01581 lbMatrixIdx(-1),
01582 lbConeIdx(-1),
01583 ubMatrixIdx(-1),
01584 ubConeIdx(-1),
01585 name("")
01586 {
01587 #ifndef NDEBUG
01588 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixCon Constructor");
01589 #endif
01590 }
01591
01592 MatrixCon::~MatrixCon()
01593 {
01594 #ifndef NDEBUG
01595 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixCon Destructor");
01596 #endif
01597 }
01598
01599 MatrixExpression::MatrixExpression()
01600 {
01601 #ifndef NDEBUG
01602 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixExpression Constructor");
01603 #endif
01604 idx = 0;
01605 shape = ENUM_NL_EXPR_SHAPE_general;
01606 matrixExpressionTree = NULL;
01607 m_bDeleteExpressionTree = true;
01608 }
01609
01610 MatrixExpression::~MatrixExpression()
01611 {
01612 #ifndef NDEBUG
01613 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixExpression Destructor");
01614 #endif
01615 if( m_bDeleteExpressionTree == true)
01616 {
01617 delete matrixExpressionTree;
01618 matrixExpressionTree = NULL;
01619 }
01620 }
01621
01622
01623 TimeDomainStageVar::TimeDomainStageVar():
01624 idx(0)
01625 {
01626 #ifndef NDEBUG
01627 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageVar Constructor");
01628 #endif
01629 }
01630
01631
01632 TimeDomainStageVar::~TimeDomainStageVar()
01633 {
01634 #ifndef NDEBUG
01635 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageVar Destructor");
01636 #endif
01637 }
01638
01639
01640 TimeDomainStageVariables::TimeDomainStageVariables():
01641 numberOfVariables(0),
01642 startIdx(-1)
01643 {
01644 #ifndef NDEBUG
01645 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageVariables Constructor");
01646 #endif
01647 var = NULL;
01648 }
01649
01650 TimeDomainStageVariables::~TimeDomainStageVariables()
01651 {
01652 #ifndef NDEBUG
01653 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageVariables Destructor");
01654 #endif
01655 if (numberOfVariables > 0 && var != NULL)
01656 {
01657 for (int i = 0; i < numberOfVariables; i++)
01658 {
01659 delete var[i];
01660 var[i] = NULL;
01661 }
01662 }
01663 if (var != NULL)
01664 delete [] var;
01665 var = NULL;
01666 }
01667
01668 TimeDomainStageCon::TimeDomainStageCon():
01669 idx(0)
01670 {
01671 #ifndef NDEBUG
01672 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageCon Constructor");
01673 #endif
01674 }
01675
01676
01677 TimeDomainStageCon::~TimeDomainStageCon()
01678 {
01679 #ifndef NDEBUG
01680 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageCon Destructor");
01681 #endif
01682 }
01683
01684
01685 TimeDomainStageConstraints::TimeDomainStageConstraints():
01686 numberOfConstraints(0),
01687 startIdx(-1)
01688 {
01689 #ifndef NDEBUG
01690 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageConstraints Constructor");
01691 #endif
01692 con = NULL;
01693 }
01694
01695 TimeDomainStageConstraints::~TimeDomainStageConstraints()
01696 {
01697 #ifndef NDEBUG
01698 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageConstraints Destructor");
01699 #endif
01700 if (numberOfConstraints > 0 && con != NULL)
01701 {
01702 for (int i = 0; i < numberOfConstraints; i++)
01703 {
01704 delete con[i];
01705 con[i] = NULL;
01706 }
01707 }
01708 if (con != NULL)
01709 delete [] con;
01710 con = NULL;
01711 }
01712
01713 TimeDomainStageObj::TimeDomainStageObj():
01714 idx(0)
01715 {
01716 #ifndef NDEBUG
01717 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageObj Constructor");
01718 #endif
01719 }
01720
01721
01722 TimeDomainStageObj::~TimeDomainStageObj()
01723 {
01724 #ifndef NDEBUG
01725 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageObj Destructor");
01726 #endif
01727 }
01728
01729
01730 TimeDomainStageObjectives::TimeDomainStageObjectives():
01731 numberOfObjectives(0),
01732 startIdx(-1)
01733 {
01734 #ifndef NDEBUG
01735 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageObjectives Constructor");
01736 #endif
01737 obj = NULL;
01738 }
01739
01740 TimeDomainStageObjectives::~TimeDomainStageObjectives()
01741 {
01742 #ifndef NDEBUG
01743 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStageObjectives Destructor");
01744 #endif
01745 if (numberOfObjectives > 0 && obj != NULL)
01746 {
01747 for (int i = 0; i < numberOfObjectives; i++)
01748 {
01749 delete obj[i];
01750 obj[i] = NULL;
01751 }
01752 }
01753 if (obj != NULL)
01754 delete [] obj;
01755 obj = NULL;
01756 }
01757
01758 TimeDomainStage::TimeDomainStage():
01759 name("")
01760 {
01761 #ifndef NDEBUG
01762 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStage Constructor");
01763 #endif
01764 variables = NULL;
01765 constraints = NULL;
01766 objectives = NULL;
01767 }
01768
01769
01770 TimeDomainStage::~TimeDomainStage()
01771 {
01772 #ifndef NDEBUG
01773 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStage Destructor");
01774 #endif
01775 if (variables != NULL)
01776 {
01777 delete variables;
01778 variables = NULL;
01779 }
01780 if (constraints != NULL)
01781 {
01782 delete constraints;
01783 constraints = NULL;
01784 }
01785 if (objectives != NULL)
01786 {
01787 delete objectives;
01788 objectives = NULL;
01789 }
01790 }
01791
01792
01793 TimeDomainStages::TimeDomainStages():
01794 numberOfStages(0),
01795 stage(NULL)
01796 {
01797 #ifndef NDEBUG
01798 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStages Constructor");
01799 #endif
01800 }
01801
01802
01803 TimeDomainStages::~TimeDomainStages()
01804 {
01805 #ifndef NDEBUG
01806 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainStages Destructor");
01807 #endif
01808 int i;
01809 if(numberOfStages > 0 && stage != NULL)
01810 {
01811 for( i = 0; i < numberOfStages; i++)
01812 {
01813 delete stage[i];
01814 stage[i] = NULL;
01815 }
01816 }
01817 if (stage != NULL)
01818 delete[] stage;
01819 stage = NULL;
01820 }
01821
01822 TimeDomainInterval::TimeDomainInterval():
01823 start(0.0),
01824 horizon(0.0)
01825 {
01826 #ifndef NDEBUG
01827 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainInterval Constructor");
01828 #endif
01829 }
01830
01831
01832 TimeDomainInterval::~TimeDomainInterval()
01833 {
01834 #ifndef NDEBUG
01835 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomainInterval Constructor");
01836 #endif
01837 }
01838
01839 TimeDomain::TimeDomain()
01840 {
01841 #ifndef NDEBUG
01842 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomain Constructor");
01843 #endif
01844 stages = NULL;
01845 interval = NULL;
01846 }
01847
01848 TimeDomain::~TimeDomain()
01849 {
01850 #ifndef NDEBUG
01851 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the TimeDomain Constructor");
01852 #endif
01853 if (stages != NULL)
01854 {
01855 delete stages;
01856 stages = NULL;
01857 }
01858 if (interval != NULL)
01859 {
01860 delete interval;
01861 interval = NULL;
01862 }
01863 }
01864
01865
01866 InstanceData::InstanceData():
01867 variables(NULL),
01868 objectives(NULL),
01869 constraints(NULL),
01870 linearConstraintCoefficients(NULL),
01871 quadraticCoefficients(NULL),
01872 nonlinearExpressions(NULL),
01873 matrices(NULL),
01874 cones(NULL),
01875 matrixProgramming(NULL),
01876 timeDomain(NULL)
01877 {
01878 #ifndef NDEBUG
01879 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the InstanceData Constructor");
01880 #endif
01881
01882
01883
01884
01885
01886
01887
01888
01889
01890
01891 }
01892
01893 InstanceData::~InstanceData()
01894 {
01895 #ifndef NDEBUG
01896 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the InstanceData Destructor");
01897 #endif
01898 if (variables != NULL)
01899 {
01900 delete variables;
01901 variables = NULL;
01902 }
01903
01904 if (objectives != NULL)
01905 {
01906 delete objectives;
01907 objectives = NULL;
01908 }
01909
01910 if (constraints != NULL)
01911 {
01912 delete constraints;
01913 constraints = NULL;
01914 }
01915
01916 if (linearConstraintCoefficients != NULL)
01917 {
01918 delete linearConstraintCoefficients;
01919 linearConstraintCoefficients = NULL;
01920 }
01921
01922 if (quadraticCoefficients != NULL)
01923 {
01924 delete quadraticCoefficients;
01925 quadraticCoefficients = NULL;
01926 }
01927
01928 if (nonlinearExpressions != NULL)
01929 {
01930 delete nonlinearExpressions;
01931 nonlinearExpressions = NULL;
01932 }
01933
01934 if (matrices != NULL)
01935 {
01936 delete matrices;
01937 matrices = NULL;
01938 }
01939
01940 if (cones != NULL)
01941 {
01942 delete cones;
01943 cones = NULL;
01944 }
01945
01946 if (matrixProgramming != NULL)
01947 {
01948 delete matrixProgramming;
01949 matrixProgramming = NULL;
01950 }
01951
01952 if (timeDomain != NULL)
01953 {
01954 delete timeDomain;
01955 timeDomain = NULL;
01956 }
01957 }
01958
01959
01963 string OSInstance::getInstanceName()
01964 {
01965 if (m_sInstanceName.length() <= 0)
01966 {
01967 if (instanceHeader == NULL)
01968 throw ErrorClass("instanceHeader object undefined in method getInstanceName()");
01969 m_sInstanceName = instanceHeader->name;
01970 }
01971 return m_sInstanceName;
01972 }
01973
01974 string OSInstance::getInstanceSource()
01975 {
01976 if (m_sInstanceSource.length() <= 0)
01977 {
01978 if (instanceHeader == NULL)
01979 throw ErrorClass("instanceHeader object undefined in method getInstanceSource()");
01980 m_sInstanceSource = instanceHeader->source;
01981 }
01982 return m_sInstanceSource;
01983 }
01984
01985 string OSInstance::getInstanceDescription()
01986 {
01987 if (m_sInstanceDescription.length() <= 0)
01988 {
01989 if (instanceHeader == NULL)
01990 throw ErrorClass("instanceHeader object undefined in method getInstanceDescription()");
01991 m_sInstanceDescription = instanceHeader->description;
01992 }
01993 return m_sInstanceDescription;
01994 }
01995
01996 string OSInstance::getInstanceCreator()
01997 {
01998 if (m_sInstanceCreator.length() <= 0)
01999 {
02000 if (instanceHeader == NULL)
02001 throw ErrorClass("instanceHeader object undefined in method getInstanceCreator()");
02002 m_sInstanceCreator = instanceHeader->fileCreator;
02003 }
02004 return m_sInstanceCreator;
02005 }
02006
02007 string OSInstance::getInstanceLicence()
02008 {
02009 if (m_sInstanceLicence.length() <= 0)
02010 {
02011 if (instanceHeader == NULL)
02012 throw ErrorClass("instanceHeader object undefined in method getInstanceLicence()");
02013 m_sInstanceLicence = instanceHeader->licence;
02014 }
02015 return m_sInstanceLicence;
02016 }
02017
02018 int OSInstance::getVariableNumber()
02019 {
02020 if (m_iVariableNumber == -1)
02021 {
02022 if (instanceData == NULL)
02023 throw ErrorClass("data object undefined in method getVariableNumber()");
02024 if (instanceData->variables == NULL)
02025 m_iVariableNumber = 0;
02026 else
02027 m_iVariableNumber = instanceData->variables->numberOfVariables;
02028 }
02029 return m_iVariableNumber;
02030 }
02031
02032 bool OSInstance::processVariables()
02033 {
02034 if(m_bProcessVariables == true && bVariablesModified == false) return true;
02035
02036 int i = 0;
02037 int varType;
02038 int n = getVariableNumber();
02039 try
02040 {
02041 m_iNumberOfBinaryVariables = 0;
02042 m_iNumberOfIntegerVariables = 0;
02043 m_iNumberOfStringVariables = 0;
02044 if(n > 0)
02045 {
02046 if(m_bProcessVariables != true )
02047 {
02048 m_mcVariableTypes = new char[n];
02049 m_mdVariableLowerBounds = new double[n];
02050 m_mdVariableUpperBounds = new double[n];
02051 m_msVariableNames = new string[n];
02052 m_bProcessVariables = true;
02053 }
02054
02055 for(i = 0; i < n; i++)
02056 {
02057 if(instanceData->variables->var[i] == NULL) throw ErrorClass("processVariables(): var element was never defined");
02058 varType = returnVarType(instanceData->variables->var[i]->type);
02059 switch (varType)
02060 {
02061 case 0:
02062 {
02063 throw ErrorClass("unknown variable type");
02064 break;
02065 }
02066 case ENUM_VARTYPE_continuous:
02067 {
02068 break;
02069 }
02070 case ENUM_VARTYPE_binary:
02071 {
02072 m_iNumberOfBinaryVariables++;
02073 break;
02074 }
02075 case ENUM_VARTYPE_integer:
02076 {
02077 m_iNumberOfIntegerVariables++;
02078 break;
02079 }
02080 case ENUM_VARTYPE_string:
02081 {
02082
02083 m_iNumberOfStringVariables++;
02084 break;
02085 }
02086 case ENUM_VARTYPE_semicontinuous:
02087 {
02088 m_iNumberOfSemiContinuousVariables++;
02089 break;
02090 }
02091 case ENUM_VARTYPE_semiinteger:
02092 {
02093 m_iNumberOfSemiIntegerVariables++;
02094 break;
02095 }
02096 default:
02097 {
02098 throw ErrorClass("variable type not yet implemented");
02099 break;
02100 }
02101 }
02102 m_mcVariableTypes[i] = instanceData->variables->var[i]->type;
02103 m_mdVariableLowerBounds[i] = instanceData->variables->var[i]->lb;
02104 m_mdVariableUpperBounds[i] = instanceData->variables->var[i]->ub;
02105 if(instanceData->variables->var[i]->name.length() > 0)
02106 m_msVariableNames[i] = instanceData->variables->var[i]->name;
02107 else
02108 m_msVariableNames[i] = "";
02109 }
02110 }
02111 return true;
02112 }
02113 catch(const ErrorClass& eclass)
02114 {
02115 throw ErrorClass( eclass.errormsg);
02116 }
02117 }
02118
02119 string* OSInstance::getVariableNames()
02120 {
02121 processVariables();
02122 return m_msVariableNames;
02123 }
02124
02125 char* OSInstance::getVariableTypes()
02126 {
02127 processVariables();
02128 return m_mcVariableTypes;
02129 }
02130
02131 int OSInstance::getNumberOfBinaryVariables()
02132 {
02133 processVariables();
02134 return m_iNumberOfBinaryVariables;
02135 }
02136
02137 int OSInstance::getNumberOfIntegerVariables()
02138 {
02139 processVariables();
02140 return m_iNumberOfIntegerVariables;
02141 }
02142
02143 int OSInstance::getNumberOfSemiContinuousVariables()
02144 {
02145 processVariables();
02146 return m_iNumberOfSemiContinuousVariables;
02147 }
02148
02149 int OSInstance::getNumberOfSemiIntegerVariables()
02150 {
02151 processVariables();
02152 return m_iNumberOfSemiIntegerVariables;
02153 }
02154
02155 int OSInstance::getNumberOfStringVariables()
02156 {
02157 processVariables();
02158 return m_iNumberOfStringVariables;
02159 }
02160
02161 double* OSInstance::getVariableLowerBounds()
02162 {
02163 processVariables();
02164 return m_mdVariableLowerBounds;
02165 }
02166
02167 double* OSInstance::getVariableUpperBounds()
02168 {
02169 processVariables();
02170 return m_mdVariableUpperBounds;
02171 }
02172
02173
02174 int OSInstance::getObjectiveNumber()
02175 {
02176 if (m_iObjectiveNumber == -1)
02177 {
02178 if (instanceData == NULL)
02179 throw ErrorClass("data object undefined in method getVariableNumber()");
02180 if (instanceData->objectives == NULL)
02181 m_iObjectiveNumber = 0;
02182 else
02183 m_iObjectiveNumber = instanceData->objectives->numberOfObjectives;
02184 }
02185 return m_iObjectiveNumber;
02186
02187 }
02188
02189 bool OSInstance::processObjectives()
02190 {
02191 if(m_bProcessObjectives == true && bObjectivesModified == false) return true;
02192
02193 int i = 0;
02194 int j = 0;
02195 int n = getObjectiveNumber();
02196 if (n == 0 || instanceData->objectives->obj == NULL) return true;
02197 try
02198 {
02199 if (n > 0)
02200 {
02201 if(m_bProcessObjectives != true)
02202 {
02203 m_msMaxOrMins = new string[n];
02204 m_miNumberOfObjCoef = new int[n];
02205 m_mdObjectiveConstants = new double[n];
02206 m_mdObjectiveWeights = new double[n];
02207 m_mObjectiveCoefficients = new SparseVector*[n];
02208 m_msObjectiveNames = new string[n];
02209 for(i = 0; i < n; i++)
02210 {
02211 if(instanceData->objectives->obj[i] == NULL) throw ErrorClass("processObjectives(): obj element was never defined");
02212 m_mObjectiveCoefficients[i] = new SparseVector(instanceData->objectives->obj[i]->numberOfObjCoef);
02213
02214 }
02215 m_bProcessObjectives = true;
02216 }
02217
02218 for(i = 0; i < n; i++)
02219 {
02220 if(instanceData->objectives->obj[i] == NULL) throw ErrorClass("processObjectives(): obj element was never defined");
02221 if((instanceData->objectives->obj[i]->maxOrMin.compare("max") != 0) && (instanceData->objectives->obj[i]->maxOrMin.compare("min") != 0 )) throw ErrorClass("wrong objective maxOrMin");
02222 m_msMaxOrMins[i] = instanceData->objectives->obj[i]->maxOrMin;
02223 m_miNumberOfObjCoef[i] = instanceData->objectives->obj[i]->numberOfObjCoef;
02224 m_mdObjectiveConstants[i] = instanceData->objectives->obj[i]->constant;
02225 m_mdObjectiveWeights[i] = instanceData->objectives->obj[i]->weight;
02226 if(instanceData->objectives->obj[i]->coef == NULL && m_miNumberOfObjCoef[i] != 0)
02227 {
02228 throw ErrorClass("objective coefficient number inconsistent with objective coefficient array");
02229 }
02230 if(instanceData->objectives->obj[i]->coef != NULL)
02231 {
02232 for(j = 0; j < m_mObjectiveCoefficients[i]->number; j++)
02233 {
02234 m_mObjectiveCoefficients[i]->indexes[j] = instanceData->objectives->obj[i]->coef[j]->idx;
02235 m_mObjectiveCoefficients[i]->values[j] = instanceData->objectives->obj[i]->coef[j]->value;
02236 }
02237 }
02238 if(instanceData->objectives->obj[i]->name.length() > 0)
02239 m_msObjectiveNames[i] = instanceData->objectives->obj[i]->name;
02240 else
02241 m_msObjectiveNames[i] = "";
02242 }
02243 }
02244 return true;
02245 }
02246 catch(const ErrorClass& eclass)
02247 {
02248 throw ErrorClass( eclass.errormsg);
02249 }
02250 }
02251
02252 string* OSInstance::getObjectiveNames()
02253 {
02254 processObjectives();
02255 return m_msObjectiveNames;
02256 }
02257
02258 string* OSInstance::getObjectiveMaxOrMins()
02259 {
02260 processObjectives();
02261 return m_msMaxOrMins;
02262 }
02263
02264 int* OSInstance::getObjectiveCoefficientNumbers()
02265 {
02266 processObjectives();
02267 return m_miNumberOfObjCoef;
02268 }
02269
02270 double* OSInstance::getObjectiveConstants()
02271 {
02272 processObjectives();
02273 return m_mdObjectiveConstants;
02274 }
02275
02276 double* OSInstance::getObjectiveWeights()
02277 {
02278 processObjectives();
02279 return m_mdObjectiveWeights;
02280
02281 }
02282
02283 SparseVector** OSInstance::getObjectiveCoefficients()
02284 {
02285 processObjectives();
02286 return m_mObjectiveCoefficients;
02287 }
02288
02289
02290 double** OSInstance::getDenseObjectiveCoefficients()
02291 {
02292 if(m_bGetDenseObjectives == true && bObjectivesModified == false) return m_mmdDenseObjectiveCoefficients;
02293 int i, j, numobjcoef;
02294 SparseVector *sparsevec;
02295 int m = getObjectiveNumber();
02296 int n = getVariableNumber();
02297 if (m == 0 || instanceData->objectives->obj == NULL) return NULL;
02298 if (m_bGetDenseObjectives != true)
02299 {
02300 m_mmdDenseObjectiveCoefficients = new double*[m];
02301 for(i = 0; i < m; i++)
02302 {
02303 m_mmdDenseObjectiveCoefficients[ i] = new double[n];
02304 }
02305 m_bGetDenseObjectives = true;
02306 }
02307
02308 for(i = 0; i < m; i++)
02309 {
02310 sparsevec = this->getObjectiveCoefficients()[i];
02311 for(j = 0; j < n; j++)
02312 {
02313 m_mmdDenseObjectiveCoefficients[ i][j] = 0.0;
02314 }
02315 sparsevec = this->getObjectiveCoefficients()[i];
02316 numobjcoef = sparsevec->number;
02317 for(j = 0; j < numobjcoef; j++)
02318 {
02319 m_mmdDenseObjectiveCoefficients[i][ sparsevec->indexes[ j]]
02320 += sparsevec->values[ j];
02321 }
02322 }
02323 return m_mmdDenseObjectiveCoefficients;
02324 }
02325
02326
02327 int OSInstance::getConstraintNumber()
02328 {
02329 if (m_iConstraintNumber == -1)
02330 {
02331 if (instanceData == NULL)
02332 throw ErrorClass("data object undefined in method getConstraintNumber()");
02333 if (instanceData->constraints == NULL)
02334 m_iConstraintNumber = 0;
02335 else
02336 m_iConstraintNumber = instanceData->constraints->numberOfConstraints;
02337 }
02338 return m_iConstraintNumber;
02339 }
02340
02341 bool OSInstance::processConstraints()
02342 {
02343 if(m_bProcessConstraints == true && bConstraintsModified == false) return true;
02344
02345 int i = 0;
02346 ostringstream outStr;
02347 int n = getConstraintNumber();
02348 if (n == 0 || instanceData->constraints->con == NULL) return true;
02349 try
02350 {
02351 if(n > 0)
02352 {
02353 if(m_bProcessConstraints != true)
02354 {
02355 m_mdConstraintLowerBounds = new double[n];
02356 m_mdConstraintUpperBounds = new double[n];
02357 m_mdConstraintConstants = new double[n];
02358 m_mcConstraintTypes = new char[n];
02359 m_msConstraintNames = new string[n];
02360 m_bProcessConstraints = true;
02361 }
02362 for(i = 0; i < n; i++)
02363 {
02364 if(instanceData->constraints->con[i] == NULL) throw ErrorClass("processConstraints(): con element was never defined");
02365 m_mdConstraintLowerBounds[i] = instanceData->constraints->con[i]->lb;
02366 m_mdConstraintUpperBounds[i] = instanceData->constraints->con[i]->ub;
02367 m_mdConstraintConstants[i] = instanceData->constraints->con[i]->constant;
02368 if(m_mdConstraintLowerBounds[i] == OSDBL_MAX || m_mdConstraintUpperBounds[i] == -OSDBL_MAX)
02369 {
02370 outStr << "Constraint " ;
02371 outStr << i;
02372 outStr << " is infeasible";
02373 throw ErrorClass( outStr.str() );
02374 }
02375 else if(m_mdConstraintLowerBounds[i] > m_mdConstraintUpperBounds[i])
02376 {
02377 outStr << "Constraint " ;
02378 outStr << i;
02379 outStr << " is infeasible";
02380 throw ErrorClass( outStr.str());
02381 }
02382 else if(m_mdConstraintLowerBounds[i] == -OSDBL_MAX && m_mdConstraintUpperBounds[i] == OSDBL_MAX)
02383 m_mcConstraintTypes[i] = 'U';
02384 else if(m_mdConstraintLowerBounds[i] == m_mdConstraintUpperBounds[i])
02385 m_mcConstraintTypes[i] = 'E';
02386 else if(m_mdConstraintLowerBounds[i] == -OSDBL_MAX)
02387 m_mcConstraintTypes[i] = 'L';
02388 else if(m_mdConstraintUpperBounds[i] == OSDBL_MAX)
02389 m_mcConstraintTypes[i] = 'G';
02390 else m_mcConstraintTypes[i] = 'R';
02391 if(instanceData->constraints->con[i]->name.length() > 0)
02392 m_msConstraintNames[i] = instanceData->constraints->con[i]->name;
02393 else
02394 m_msConstraintNames[i] = "";
02395 }
02396 }
02397 return true;
02398 }
02399 catch(const ErrorClass& eclass)
02400 {
02401 throw ErrorClass( eclass.errormsg);
02402 }
02403 }
02404
02405
02406 string* OSInstance::getConstraintNames()
02407 {
02408 processConstraints();
02409 return m_msConstraintNames;
02410 }
02411
02412
02413 char* OSInstance::getConstraintTypes()
02414 {
02415 processConstraints();
02416 return m_mcConstraintTypes;
02417 }
02418
02419 double* OSInstance::getConstraintLowerBounds()
02420 {
02421 processConstraints();
02422 return m_mdConstraintLowerBounds;
02423 }
02424
02425 double* OSInstance::getConstraintUpperBounds()
02426 {
02427 processConstraints();
02428 return m_mdConstraintUpperBounds;
02429 }
02430
02431 double* OSInstance::getConstraintConstants()
02432 {
02433 processConstraints();
02434 return m_mdConstraintConstants;
02435 }
02436
02437
02438 int OSInstance::getLinearConstraintCoefficientNumber()
02439 {
02440 if(this->getVariableNumber() <= 0 || this->getConstraintNumber() <= 0) return 0;
02441 if(m_iLinearConstraintCoefficientNumber == -1)
02442 {
02443 if (instanceData == NULL)
02444 throw ErrorClass("data object undefined in method getLinearConstraintCoefficientNumber()");
02445 if (instanceData->linearConstraintCoefficients == NULL)
02446 m_iLinearConstraintCoefficientNumber = 0;
02447 else
02448 m_iLinearConstraintCoefficientNumber
02449 = instanceData->linearConstraintCoefficients->numberOfValues;
02450 }
02451 return m_iLinearConstraintCoefficientNumber;
02452 }
02453
02454 bool OSInstance::processLinearConstraintCoefficients()
02455 {
02456 if(m_bProcessLinearConstraintCoefficients == true && bAMatrixModified == false) return true;
02457
02458 try
02459 {
02460 int n = getLinearConstraintCoefficientNumber();
02461 if((instanceData->linearConstraintCoefficients == NULL ) || (n == 0) ) return true;
02462
02463 if((instanceData->linearConstraintCoefficients->value == NULL ) || (n == 0) ) return true;
02464
02465 if((instanceData->linearConstraintCoefficients->colIdx != NULL && instanceData->linearConstraintCoefficients->colIdx->el != NULL)
02466 && (instanceData->linearConstraintCoefficients->rowIdx != NULL && instanceData->linearConstraintCoefficients->rowIdx->el != NULL))
02467 throw ErrorClass("ambiguous linear constraint coefficient major");
02468 else if(instanceData->linearConstraintCoefficients->value->el == NULL) return true;
02469 else
02470 {
02471 if(instanceData->linearConstraintCoefficients->rowIdx->el != NULL)
02472 {
02473 m_bColumnMajor = true;
02474 if(m_bProcessLinearConstraintCoefficients != true)
02475 {
02476 m_linearConstraintCoefficientsInColumnMajor = new SparseMatrix();
02477 m_linearConstraintCoefficientsInColumnMajor->bDeleteArrays = false;
02478 m_bProcessLinearConstraintCoefficients = true;
02479 }
02480 m_linearConstraintCoefficientsInColumnMajor->isColumnMajor = true;
02481 m_linearConstraintCoefficientsInColumnMajor->valueSize = n;
02482 m_linearConstraintCoefficientsInColumnMajor->startSize = instanceData->variables->numberOfVariables + 1;
02483 }
02484 else
02485 {
02486 m_bColumnMajor = false;
02487 if(m_bProcessLinearConstraintCoefficients != true)
02488 {
02489 m_linearConstraintCoefficientsInRowMajor = new SparseMatrix();
02490 m_linearConstraintCoefficientsInRowMajor->bDeleteArrays = false;
02491 m_bProcessLinearConstraintCoefficients = true;
02492 }
02493 m_linearConstraintCoefficientsInRowMajor->isColumnMajor = false;
02494 m_linearConstraintCoefficientsInRowMajor->valueSize = n;
02495 m_linearConstraintCoefficientsInRowMajor->startSize = instanceData->constraints->numberOfConstraints + 1;
02496 }
02497 }
02498 if(m_bColumnMajor == true)
02499 {
02500 m_linearConstraintCoefficientsInColumnMajor->values = instanceData->linearConstraintCoefficients->value->el;
02501 m_linearConstraintCoefficientsInColumnMajor->indexes = instanceData->linearConstraintCoefficients->rowIdx->el;
02502 m_linearConstraintCoefficientsInColumnMajor->starts = instanceData->linearConstraintCoefficients->start->el;
02503 }
02504 else
02505 {
02506 m_linearConstraintCoefficientsInRowMajor->values = instanceData->linearConstraintCoefficients->value->el;
02507 m_linearConstraintCoefficientsInRowMajor->indexes = instanceData->linearConstraintCoefficients->colIdx->el;
02508 m_linearConstraintCoefficientsInRowMajor->starts = instanceData->linearConstraintCoefficients->start->el;
02509 }
02510 return true;
02511 }
02512 catch(const ErrorClass& eclass)
02513 {
02514 throw ErrorClass( eclass.errormsg);
02515 }
02516 }
02517
02518 bool OSInstance::getLinearConstraintCoefficientMajor()
02519 {
02520 processLinearConstraintCoefficients();
02521 return m_bColumnMajor;
02522 }
02523
02524 SparseMatrix* OSInstance::getLinearConstraintCoefficientsInColumnMajor()
02525 {
02526 processLinearConstraintCoefficients();
02527 if(getVariableNumber() == 0) return NULL;
02528 if(m_linearConstraintCoefficientsInColumnMajor != NULL) return m_linearConstraintCoefficientsInColumnMajor;
02529 if(!m_bColumnMajor)
02530 {
02531 if(m_linearConstraintCoefficientsInRowMajor == NULL) return NULL;
02532 m_linearConstraintCoefficientsInColumnMajor =
02533 MathUtil::convertLinearConstraintCoefficientMatrixToTheOtherMajor(false,
02534 m_linearConstraintCoefficientsInRowMajor->startSize,
02535 m_linearConstraintCoefficientsInRowMajor->valueSize,
02536 m_linearConstraintCoefficientsInRowMajor->starts,
02537 m_linearConstraintCoefficientsInRowMajor->indexes,
02538 m_linearConstraintCoefficientsInRowMajor->values,
02539 getVariableNumber());
02540 }
02541 return m_linearConstraintCoefficientsInColumnMajor;
02542 }
02543
02544 SparseMatrix* OSInstance::getLinearConstraintCoefficientsInRowMajor()
02545 {
02546 processLinearConstraintCoefficients();
02547 if(m_linearConstraintCoefficientsInRowMajor != NULL) return m_linearConstraintCoefficientsInRowMajor;
02548 if(m_bColumnMajor)
02549 {
02550 if(m_linearConstraintCoefficientsInColumnMajor == NULL) return NULL;
02551 m_linearConstraintCoefficientsInRowMajor =
02552
02553 MathUtil::convertLinearConstraintCoefficientMatrixToTheOtherMajor(true,
02554 m_linearConstraintCoefficientsInColumnMajor->startSize,
02555 m_linearConstraintCoefficientsInColumnMajor->valueSize,
02556 m_linearConstraintCoefficientsInColumnMajor->starts,
02557 m_linearConstraintCoefficientsInColumnMajor->indexes,
02558 m_linearConstraintCoefficientsInColumnMajor->values,
02559 getConstraintNumber());
02560 }
02561 return m_linearConstraintCoefficientsInRowMajor;
02562 }
02563
02564
02565 int OSInstance::getNumberOfQuadraticTerms()
02566 {
02567 if(m_iQuadraticTermNumber == -1)
02568 {
02569 if (instanceData == NULL)
02570 throw ErrorClass("data object undefined in method getNumberOfQuadraticTerms()");
02571 if (instanceData->quadraticCoefficients == NULL)
02572 m_iQuadraticTermNumber = 0;
02573 else
02574 m_iQuadraticTermNumber = instanceData->quadraticCoefficients->numberOfQuadraticTerms;
02575 }
02576 return m_iQuadraticTermNumber;
02577 }
02578
02579 QuadraticTerms* OSInstance::getQuadraticTerms()
02580 {
02581 if(m_bProcessQuadraticTerms) return m_quadraticTerms;
02582 m_bProcessQuadraticTerms = true;
02583 int n = getNumberOfQuadraticTerms();
02584 if(instanceData->quadraticCoefficients->qTerm == NULL) return NULL;
02585 try
02586 {
02587 int i = 0;
02588 QuadraticCoefficients* quadraticCoefs = instanceData->quadraticCoefficients;
02589 if(!quadraticCoefs->qTerm && n != 0)
02590 throw ErrorClass("quadratic term number inconsistent with quadratic term array");
02591 m_quadraticTerms = new QuadraticTerms();
02592 if(n > 0)
02593 {
02594 m_quadraticTerms->rowIndexes = new int[n];
02595 m_quadraticTerms->varOneIndexes = new int[n];
02596 m_quadraticTerms->varTwoIndexes = new int[n];
02597 m_quadraticTerms->coefficients = new double[n];
02598 }
02599 for(i = 0; i < n; i++)
02600 {
02601 m_quadraticTerms->rowIndexes[i] = quadraticCoefs->qTerm[i]->idx;
02602 m_quadraticTerms->varOneIndexes[i] = quadraticCoefs->qTerm[i]->idxOne;
02603 m_quadraticTerms->varTwoIndexes[i] = quadraticCoefs->qTerm[i]->idxTwo;
02604 m_quadraticTerms->coefficients[i] = quadraticCoefs->qTerm[i]->coef;
02605 }
02606 return m_quadraticTerms;
02607 }
02608 catch(const ErrorClass& eclass)
02609 {
02610 throw ErrorClass( eclass.errormsg);
02611 }
02612 }
02613
02614 int OSInstance::getNumberOfQuadraticRowIndexes()
02615 {
02616 if(m_bQuadraticRowIndexesProcessed == false) getQuadraticRowIndexes();
02617 return m_iNumberOfQuadraticRowIndexes;
02618 }
02619
02620 int* OSInstance::getQuadraticRowIndexes()
02621 {
02622 if(m_bQuadraticRowIndexesProcessed == true) return m_miQuadRowIndexes;
02623 m_bQuadraticRowIndexesProcessed = true;
02624 int n = getNumberOfQuadraticTerms();
02625 if(n <= 0) return NULL;
02626 QuadraticTerms *qTerms = NULL;
02627 qTerms = getQuadraticTerms();
02628 std::map<int, int> foundIdx;
02629 std::map<int, int>::iterator pos;
02630 int i;
02631 try
02632 {
02633 for(i = 0; i < n; i++)
02634 {
02635
02636 foundIdx[ qTerms->rowIndexes[ i] ];
02637 }
02638
02639 m_iNumberOfQuadraticRowIndexes = foundIdx.size();
02640 m_miQuadRowIndexes = new int[ m_iNumberOfQuadraticRowIndexes ];
02641 i = 0;
02642 for(pos = foundIdx.begin(); pos != foundIdx.end(); ++pos)
02643 {
02644 m_miQuadRowIndexes[ i++] = pos->first;
02645 }
02646 foundIdx.clear();
02647 return m_miQuadRowIndexes;
02648 }
02649 catch(const ErrorClass& eclass)
02650 {
02651 throw ErrorClass( eclass.errormsg);
02652 }
02653 }
02654
02655
02656 int OSInstance::getNumberOfNonlinearExpressions()
02657 {
02658 if(m_iNonlinearExpressionNumber == -1)
02659 {
02660 if (instanceData == NULL)
02661 throw ErrorClass("data object undefined in method getNumberOfNonlinearExpressions()");
02662 if (instanceData->nonlinearExpressions == NULL)
02663 m_iNonlinearExpressionNumber = 0;
02664 else
02665 m_iNonlinearExpressionNumber = instanceData->nonlinearExpressions->numberOfNonlinearExpressions;
02666 }
02667 return m_iNonlinearExpressionNumber;
02668 }
02669
02670 Nl** OSInstance::getNonlinearExpressions()
02671 {
02672 Nl** root = new Nl*[getNumberOfNonlinearExpressions()];
02673 for (int i=0; i < getNumberOfNonlinearExpressions(); i++)
02674 {
02675 root[i] = instanceData->nonlinearExpressions->nl[i];
02676 }
02677 return root;
02678 }
02679
02680
02681 int OSInstance::getNumberOfNonlinearExpressionTreeIndexes()
02682 {
02683 if(m_bNonlinearExpressionTreeIndexesProcessed == false) getNonlinearExpressionTreeIndexes();
02684 return m_iNumberOfNonlinearExpressionTreeIndexes;
02685 }
02686
02687 int* OSInstance::getNonlinearExpressionTreeIndexes()
02688 {
02689 if(m_bNonlinearExpressionTreeIndexesProcessed == true) return m_miNonlinearExpressionTreeIndexes;
02690 m_bNonlinearExpressionTreeIndexesProcessed = true;
02691 std::map<int, ScalarExpressionTree*> expTrees;
02692 expTrees = getAllNonlinearExpressionTrees();
02693
02694 std::map<int, ScalarExpressionTree*>::iterator pos;
02695 try
02696 {
02697
02698 m_iNumberOfNonlinearExpressionTreeIndexes = expTrees.size();
02699 m_miNonlinearExpressionTreeIndexes = new int[ m_iNumberOfNonlinearExpressionTreeIndexes ] ;
02700 int i = 0;
02701 for(pos = expTrees.begin(); pos != expTrees.end(); ++pos)
02702 {
02703 m_miNonlinearExpressionTreeIndexes[ i++] = pos->first;
02704 }
02705 expTrees.clear();
02706 return m_miNonlinearExpressionTreeIndexes;
02707 }
02708 catch(const ErrorClass& eclass)
02709 {
02710 throw ErrorClass( eclass.errormsg);
02711 }
02712 }
02713
02714 int OSInstance::getNumberOfNonlinearExpressionTreeModIndexes()
02715 {
02716 if(m_bNonlinearExpressionTreeModIndexesProcessed == false) getNonlinearExpressionTreeModIndexes();
02717 return m_iNumberOfNonlinearExpressionTreeModIndexes;
02718 }
02719
02720 int* OSInstance::getNonlinearExpressionTreeModIndexes()
02721 {
02722 if(m_bNonlinearExpressionTreeModIndexesProcessed == true) return m_miNonlinearExpressionTreeModIndexes;
02723 m_bNonlinearExpressionTreeModIndexesProcessed = true;
02724 std::map<int, ScalarExpressionTree*> expTrees;
02725 expTrees = getAllNonlinearExpressionTreesMod();
02726 std::map<int, ScalarExpressionTree*>::iterator pos;
02727 try
02728 {
02729
02730 m_iNumberOfNonlinearExpressionTreeModIndexes = expTrees.size();
02731 m_miNonlinearExpressionTreeModIndexes = new int[ m_iNumberOfNonlinearExpressionTreeModIndexes ] ;
02732 int i = 0;
02733 for(pos = expTrees.begin(); pos != expTrees.end(); ++pos)
02734 {
02735 m_miNonlinearExpressionTreeModIndexes[ i++] = pos->first;
02736 }
02737 expTrees.clear();
02738 return m_miNonlinearExpressionTreeModIndexes;
02739 }
02740 catch(const ErrorClass& eclass)
02741 {
02742 throw ErrorClass( eclass.errormsg);
02743 }
02744 }
02745
02746 int OSInstance::getNumberOfNonlinearConstraints()
02747 {
02748 if( m_bProcessExpressionTrees == false )
02749 getAllNonlinearExpressionTrees();
02750 return m_iConstraintNumberNonlinear;
02751 }
02752
02753 int OSInstance::getNumberOfNonlinearObjectives()
02754 {
02755 if( m_bProcessExpressionTrees == false )
02756 getAllNonlinearExpressionTrees();
02757
02758 return m_iObjectiveNumberNonlinear;
02759 }
02760
02761 ScalarExpressionTree* OSInstance::getNonlinearExpressionTree(int rowIdx)
02762 {
02763
02764 if( m_bProcessExpressionTrees == false )
02765 {
02766 getAllNonlinearExpressionTrees();
02767 }
02768 if( m_mapExpressionTrees.find( rowIdx) != m_mapExpressionTrees.end())
02769 return m_mapExpressionTrees[ rowIdx];
02770 else return NULL ;
02771 }
02772
02773 ScalarExpressionTree* OSInstance::getNonlinearExpressionTreeMod(int rowIdx)
02774 {
02775
02776 if( m_bProcessExpressionTreesMod == false )
02777 {
02778 getAllNonlinearExpressionTreesMod();
02779 }
02780 if( m_mapExpressionTreesMod.find( rowIdx) != m_mapExpressionTreesMod.end())
02781 return m_mapExpressionTreesMod[ rowIdx];
02782 else return NULL ;
02783 }
02784
02785 std::vector<ExprNode*> OSInstance::getNonlinearExpressionTreeInPostfix( int rowIdx)
02786 {
02787
02788 if( m_bProcessExpressionTrees == false ) getAllNonlinearExpressionTrees();
02789 std::vector<ExprNode*> postfixVec;
02790 try
02791 {
02792 if( m_mapExpressionTrees.find( rowIdx) != m_mapExpressionTrees.end())
02793 {
02794 ScalarExpressionTree* expTree = getNonlinearExpressionTree( rowIdx);
02795 postfixVec = expTree->m_treeRoot->getPostfixFromExpressionTree();
02796 }
02797 else
02798 {
02799 throw ErrorClass("Error in getNonlinearExpressionTreeInPostfix, rowIdx not valid");
02800 }
02801 return postfixVec;
02802 }
02803 catch(const ErrorClass& eclass)
02804 {
02805 throw ErrorClass( eclass.errormsg);
02806 }
02807 }
02808
02809 std::string OSInstance::getNonlinearExpressionTreeInInfix( int rowIdx_)
02810 {
02811 if( m_binitForAlgDiff == false) this->initForAlgDiff();
02812
02813 if( m_bProcessExpressionTrees == false ) getAllNonlinearExpressionTrees();
02814 std::string resultString;
02815 resultString = "";
02816 unsigned int i;
02817 unsigned int j;
02818 unsigned int n;
02819 ostringstream outStr;
02820 std::vector<ExprNode*> postfixVec;
02821
02822 int rowIdx = rowIdx_;
02823 ExprNode *nlnode = NULL;
02824 OSnLNodeNumber *nlnodeNum = NULL;
02825 OSnLNodeVariable *nlnodeVar = NULL;
02826 OSnLNodeSum *nlnodeSum = NULL;
02827 OSnLNodeProduct *nlnodeProduct = NULL;
02828 OSnLNodeMin *nlnodeMin = NULL;
02829 OSnLNodeMax *nlnodeMax = NULL;
02830 std::string tmp1 = "";
02831 std::string tmp2 = "";
02832 std::string tmp3 = "";
02833 std::stack<ExprNode*> opStack;
02834 std::stack<std::string> tmpStack;
02835 std::stack<std::string> sumStack;
02836 std::stack<std::string> productStack;
02837 std::stack<std::string> minStack;
02838 std::stack<std::string> maxStack;
02839
02840 try
02841 {
02842 if( m_mapExpressionTrees.find( rowIdx) != m_mapExpressionTrees.end())
02843 {
02844
02845
02846
02847 ScalarExpressionTree* exptree = this->getNonlinearExpressionTree( rowIdx);
02848 if(exptree != NULL)
02849 {
02850 postfixVec = this->getNonlinearExpressionTreeInPostfix( rowIdx);
02851 n = postfixVec.size();
02852
02853 for (i = 0 ; i < n; i++)
02854 {
02855 nlnode = postfixVec[ n - 1 - i];
02856 opStack.push( nlnode);
02857 }
02858
02859 n = opStack.size();
02860 for(i = 0; i < n; i++)
02861 {
02862 nlnode = opStack.top();
02863 switch (nlnode->inodeInt)
02864 {
02865 case OS_NUMBER:
02866 nlnodeNum = (OSnLNodeNumber*)nlnode;
02867 tmpStack.push( os_dtoa_format(nlnodeNum->value) );
02868 break;
02869
02870 case OS_PI:
02871 tmpStack.push( "PI" );
02872 break;
02873
02874 case OS_E:
02875 tmpStack.push( "E" );
02876 break;
02877
02878 case OS_VARIABLE:
02879 outStr.str("");
02880
02881 nlnodeVar = (OSnLNodeVariable*)nlnode;
02882
02883 if( (nlnodeVar->coef > 1.0) || (nlnodeVar->coef < 1.0) )
02884 {
02885 outStr << "(";
02886 outStr << os_dtoa_format(nlnodeVar->coef);
02887 outStr << "*x_";
02888 outStr << nlnodeVar->idx;
02889 outStr << ")";
02890 tmpStack.push(outStr.str() );
02891 }
02892 else
02893 {
02894 outStr << "x_";
02895 outStr << nlnodeVar->idx;
02896 tmpStack.push(outStr.str() );
02897 }
02898 break;
02899
02900 case OS_PLUS :
02901 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing plus operator");
02902 tmp1 = tmpStack.top();
02903 tmpStack.pop();
02904 tmp2 = tmpStack.top();
02905 tmpStack.pop();
02906 tmpStack.push("(" + tmp2 + " + " + tmp1 + ")");
02907 break;
02908
02909 case OS_SUM :
02910 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing sum operator");
02911
02912 nlnodeSum = (OSnLNodeSum*)nlnode;
02913 outStr.str("");
02914 for(j = 0; j < nlnodeSum->inumberOfChildren; j++)
02915 {
02916 sumStack.push( tmpStack.top() );
02917 tmpStack.pop();
02918 }
02919 outStr << "(";
02920 for(j = 0; j < nlnodeSum->inumberOfChildren; j++)
02921 {
02922 outStr << sumStack.top();
02923 if (j < nlnodeSum->inumberOfChildren - 1) outStr << " + ";
02924 sumStack.pop();
02925 }
02926 outStr << ")";
02927 tmpStack.push( outStr.str() );
02928
02929 break;
02930
02931 case OS_MINUS :
02932 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing minus operator");
02933 tmp1 = tmpStack.top();
02934 tmpStack.pop();
02935 tmp2 = tmpStack.top();
02936 tmpStack.pop();
02937 tmpStack.push("(" + tmp2 + " - " + tmp1 + ")");
02938 break;
02939
02940 case OS_NEGATE :
02941 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- -- Problem writing negate operator");
02942 tmp1 = tmpStack.top();
02943 tmpStack.pop();
02944 tmpStack.push( "-"+ tmp1 );
02945
02946
02947 break;
02948
02949 case OS_TIMES :
02950 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing times operator");
02951 tmp1 = tmpStack.top();
02952 tmpStack.pop();
02953 tmp2 = tmpStack.top();
02954 tmpStack.pop();
02955 tmpStack.push("(" + tmp2 + "*" + tmp1 + ")");
02956 break;
02957
02958 case OS_DIVIDE :
02959 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing divide operator");
02960 tmp1 = tmpStack.top();
02961 tmpStack.pop();
02962 tmp2 = tmpStack.top();
02963 tmpStack.pop();
02964 tmpStack.push("(" + tmp2 + " / " + tmp1 + ")");
02965 break;
02966
02967 case OS_POWER :
02968 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing power operator");
02969 tmp1 = tmpStack.top();
02970 tmpStack.pop();
02971 tmp2 = tmpStack.top();
02972 tmpStack.pop();
02973 tmpStack.push("(" + tmp2 + " ^ " + tmp1 + ")");
02974 break;
02975
02976
02977 case OS_ABS :
02978 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing abs operator");
02979 tmp1 = tmpStack.top();
02980 tmpStack.pop();
02981 tmpStack.push( "abs( "+ tmp1 + ")");
02982 break;
02983
02984 case OS_ERF :
02985 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing erf operator");
02986 tmp1 = tmpStack.top();
02987 tmpStack.pop();
02988 tmpStack.push( "erf( "+ tmp1 + ")");
02989 break;
02990
02991
02992 case OS_SQUARE :
02993 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing square operator ");
02994 tmp1 = tmpStack.top();
02995 tmpStack.pop();
02996 tmpStack.push( "("+ tmp1 + ")^2");
02997 break;
02998
02999 case OS_LN :
03000 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing ln operator");
03001 tmp1 = tmpStack.top();
03002 tmpStack.pop();
03003 tmpStack.push( "ln( "+ tmp1 + ")");
03004 break;
03005
03006 case OS_EXP :
03007 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing exp operator");
03008 tmp1 = tmpStack.top();
03009 tmpStack.pop();
03010 tmpStack.push( "exp( "+ tmp1 + ")");
03011 break;
03012
03013 case OS_SIN :
03014 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing sin operator");
03015 tmp1 = tmpStack.top();
03016 tmpStack.pop();
03017 tmpStack.push( "sin( "+ tmp1 + ")");
03018 break;
03019
03020 case OS_COS :
03021 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing cos operator ");
03022 tmp1 = tmpStack.top();
03023 tmpStack.pop();
03024 tmpStack.push( "cos( "+ tmp1 + ")");
03025 break;
03026
03027 case OS_SQRT :
03028 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing sqrt operator ");
03029 tmp1 = tmpStack.top();
03030 tmpStack.pop();
03031 tmpStack.push( "sqrt( "+ tmp1 + ")");
03032 break;
03033
03034 case OS_MIN :
03035 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing min operator");
03036
03037 nlnodeMin = (OSnLNodeMin*)nlnode;
03038 outStr.str("");
03039 for(j = 0; j < nlnodeMin->inumberOfChildren; j++)
03040 {
03041 minStack.push( tmpStack.top() );
03042 tmpStack.pop();
03043 }
03044 outStr << "min(";
03045 for(j = 0; j < nlnodeMin->inumberOfChildren; j++)
03046 {
03047 outStr << minStack.top();
03048 if (j < nlnodeMin->inumberOfChildren - 1) outStr << " , ";
03049 minStack.pop();
03050 }
03051 outStr << ")";
03052 tmpStack.push( outStr.str() );
03053 break;
03054
03055
03056 case OS_MAX :
03057 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing max operator");
03058
03059 nlnodeMax = (OSnLNodeMax*)nlnode;
03060 outStr.str("");
03061 for(j = 0; j < nlnodeMax->inumberOfChildren; j++)
03062 {
03063 maxStack.push( tmpStack.top() );
03064 tmpStack.pop();
03065 }
03066 outStr << "max(";
03067 for(j = 0; j < nlnodeMax->inumberOfChildren; j++)
03068 {
03069 outStr << maxStack.top();
03070 if (j < nlnodeMax->inumberOfChildren - 1) outStr << " , ";
03071 maxStack.pop();
03072 }
03073 outStr << ")";
03074 tmpStack.push( outStr.str() );
03075 break;
03076
03077 case OS_IF :
03078
03079 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing if operator ");
03080 if(nlnode->inumberOfChildren != 3)throw ErrorClass("The if node must have three children");
03081 tmp1 = tmpStack.top();
03082 tmpStack.pop();
03083 tmp2 = tmpStack.top();
03084 tmpStack.pop();
03085 tmp3 = tmpStack.top();
03086 tmpStack.pop();
03087 tmpStack.push( "if(" + tmp3 + "," + tmp2 + "," + tmp1 +")" );
03088 break;
03089
03090
03091 case OS_PRODUCT :
03092 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing product operator");
03093
03094 nlnodeProduct = (OSnLNodeProduct*)nlnode;
03095 outStr.str("");
03096 for(j = 0; j < nlnodeProduct->inumberOfChildren; j++)
03097 {
03098 productStack.push( tmpStack.top() );
03099 tmpStack.pop();
03100 }
03101 outStr << "(";
03102 for(j = 0; j < nlnodeProduct->inumberOfChildren; j++)
03103 {
03104 outStr << productStack.top();
03105 if (j < nlnodeProduct->inumberOfChildren - 1) outStr << " * ";
03106 productStack.pop();
03107 }
03108 outStr << ")";
03109 tmpStack.push( outStr.str() );
03110
03111 break;
03112
03113 default:
03114 throw ErrorClass("operator " + nlnode->getTokenName() + " not supported");
03115 break;
03116 }
03117 opStack.pop();
03118 }
03119 postfixVec.clear();
03120 if(tmpStack.size() != 1) throw ErrorClass( "There is an error in the OSExpression Tree -- stack size should be 1 at end");
03121 resultString = tmpStack.top();
03122
03123 tmpStack.pop();
03124
03125 return resultString;
03126 }
03127 else
03128 {
03129
03130 return "";
03131 }
03132 }
03133 else
03134 {
03135 throw ErrorClass("Error in getNonlinearExpressionTreeInInfix, rowIdx not valid");
03136 }
03137 return resultString;
03138 }
03139 catch(const ErrorClass& eclass)
03140 {
03141 throw ErrorClass( eclass.errormsg);
03142 }
03143 }
03144
03145
03146 std::vector<ExprNode*> OSInstance::getNonlinearExpressionTreeModInPostfix( int rowIdx)
03147 {
03148
03149 if( m_bProcessExpressionTreesMod == false ) getAllNonlinearExpressionTreesMod();
03150 std::vector<ExprNode*> postfixVec;
03151 try
03152 {
03153 if( m_mapExpressionTreesMod.find( rowIdx) != m_mapExpressionTreesMod.end())
03154 {
03155 ScalarExpressionTree* expTree = getNonlinearExpressionTreeMod( rowIdx);
03156 postfixVec = expTree->m_treeRoot->getPostfixFromExpressionTree();
03157
03158 }
03159 else
03160 {
03161 throw ErrorClass("Error in getNonlinearExpressionTreeModInPostfix, rowIdx not valid");
03162 }
03163 return postfixVec;
03164 }
03165 catch(const ErrorClass& eclass)
03166 {
03167 throw ErrorClass( eclass.errormsg);
03168 }
03169 }
03170
03171
03172 std::vector<ExprNode*> OSInstance::getNonlinearExpressionTreeInPrefix( int rowIdx)
03173 {
03174
03175 if( m_bProcessExpressionTrees == false ) getAllNonlinearExpressionTrees();
03176 std::vector<ExprNode*> prefixVec;
03177 try
03178 {
03179 if( m_mapExpressionTrees.find( rowIdx) != m_mapExpressionTrees.end())
03180 {
03181 ScalarExpressionTree* expTree = getNonlinearExpressionTree( rowIdx);
03182 prefixVec = expTree->m_treeRoot->getPrefixFromExpressionTree();
03183 }
03184 else
03185 {
03186 throw ErrorClass("Error in getNonlinearExpressionTreeInPrefix, rowIdx not valid");
03187 }
03188 return prefixVec;
03189 }
03190 catch(const ErrorClass& eclass)
03191 {
03192 throw ErrorClass( eclass.errormsg);
03193 }
03194 }
03195
03196 std::vector<ExprNode*> OSInstance::getNonlinearExpressionTreeModInPrefix( int rowIdx)
03197 {
03198
03199
03200 if( m_bProcessExpressionTreesMod == false ) getAllNonlinearExpressionTreesMod();
03201 std::vector<ExprNode*> prefixVec;
03202 try
03203 {
03204 if( m_mapExpressionTreesMod.find( rowIdx) != m_mapExpressionTreesMod.end())
03205 {
03206 ScalarExpressionTree* expTree = getNonlinearExpressionTreeMod( rowIdx);
03207 prefixVec = expTree->m_treeRoot->getPrefixFromExpressionTree();
03208 }
03209 else
03210 {
03211 throw ErrorClass("Error in getNonlinearExpressionTreeInPrefix, rowIdx not valid");
03212 }
03213 return prefixVec;
03214 }
03215 catch(const ErrorClass& eclass)
03216 {
03217 throw ErrorClass( eclass.errormsg);
03218 }
03219 }
03220
03221 std::map<int, ScalarExpressionTree*> OSInstance::getAllNonlinearExpressionTrees()
03222 {
03223
03224 if(m_bProcessExpressionTrees == true) return m_mapExpressionTrees;
03225 std::map<int, int> foundIdx;
03226 std::map<int, int>::iterator pos;
03227 OSnLNodePlus *nlNodePlus;
03228 ScalarExpressionTree *expTree;
03229 m_iObjectiveNumberNonlinear = 0;
03230 m_iConstraintNumberNonlinear = 0;
03231 int i;
03232
03233 if (instanceData->nonlinearExpressions != NULL)
03234 {
03235 if (instanceData->nonlinearExpressions->numberOfNonlinearExpressions > 0 &&
03236 instanceData->nonlinearExpressions->nl != NULL)
03237 {
03238 for( i = 0; i < instanceData->nonlinearExpressions->numberOfNonlinearExpressions; i++)
03239 {
03240 instanceData->nonlinearExpressions->nl[i]->m_bDeleteExpressionTree = false;
03241 }
03242 }
03243 int index;
03244
03245 for(i = 0; i < instanceData->nonlinearExpressions->numberOfNonlinearExpressions; i++)
03246 {
03247 index = instanceData->nonlinearExpressions->nl[ i]->idx;
03248 if(foundIdx.find( index) != foundIdx.end() )
03249 {
03250 nlNodePlus = new OSnLNodePlus();
03251
03252 expTree = instanceData->nonlinearExpressions->nl[ i]->osExpressionTree;
03253
03254 nlNodePlus->m_mChildren[ 0] = m_mapExpressionTrees[ index]->m_treeRoot;
03255 nlNodePlus->m_mChildren[ 1] = instanceData->nonlinearExpressions->nl[ i]->osExpressionTree->m_treeRoot;
03256
03257 instanceData->nonlinearExpressions->nl[ foundIdx[ index] ]->m_bDeleteExpressionTree = true;
03258 instanceData->nonlinearExpressions->nl[ foundIdx[ index] ]->osExpressionTree->bDestroyNlNodes = false;
03259
03260 m_mapExpressionTrees[ index] = expTree;
03261 m_mapExpressionTrees[ index]->m_treeRoot = nlNodePlus;
03262 foundIdx[ index] = i;
03263 }
03264 else
03265 {
03266
03267 m_mapExpressionTrees[ index] = instanceData->nonlinearExpressions->nl[ i]->osExpressionTree;
03268 m_mapExpressionTrees[ index]->m_treeRoot = instanceData->nonlinearExpressions->nl[ i]->osExpressionTree->m_treeRoot;
03269 foundIdx[ index] = i;
03270 }
03271
03272 }
03273 }
03274
03275 for(pos = foundIdx.begin(); pos != foundIdx.end(); ++pos)
03276 {
03277 if(pos->first < 0)
03278 {
03279 m_iObjectiveNumberNonlinear++;
03280 }
03281 else
03282 {
03283 m_iConstraintNumberNonlinear++;
03284 }
03285 }
03286 m_bProcessExpressionTrees = true;
03287 return m_mapExpressionTrees;
03288 }
03289
03290 std::map<int, ScalarExpressionTree*> OSInstance::getAllNonlinearExpressionTreesMod()
03291 {
03292 if( m_bProcessExpressionTreesMod == true ) return m_mapExpressionTreesMod;
03293 m_bProcessExpressionTreesMod = true;
03294
03295 if( m_bNonLinearStructuresInitialized == false) initializeNonLinearStructures( );
03296 return m_mapExpressionTreesMod;
03297 }
03298
03299
03300
03301 int OSInstance::getMatrixNumber()
03302 {
03303 if(m_iMatrixNumber == -1)
03304 {
03305 if (instanceData == NULL)
03306 throw ErrorClass("data object undefined in method getMatrixNumber()");
03307 if (instanceData->matrices == NULL)
03308 m_iMatrixNumber = 0;
03309 else
03310 m_iMatrixNumber = instanceData->matrices->numberOfMatrices;
03311 }
03312 return m_iMatrixNumber;
03313 }
03314
03315 bool OSInstance::processMatrices()
03316 {
03317 if (m_bProcessMatrices == true) return true;
03318
03319 int n = getMatrixNumber();
03320 if((instanceData->matrices == NULL ) || (n == 0) ) return true;
03321
03322 try
03323 {
03324
03325
03326
03327
03328
03329 if (n > 0)
03330 {
03331 if(m_bProcessMatrices != true)
03332 {
03333
03334 m_miMatrixType = new ENUM_MATRIX_TYPE[n];
03335 m_miMatrixSymmetry = new ENUM_MATRIX_SYMMETRY[n];
03336 m_miMatrixNumberOfColumns = new int[n];
03337 m_miMatrixNumberOfRows = new int[n];
03338 m_msMatrixNames = new std::string[n];
03339 m_mMatrix = new OSMatrix*[n];
03340
03341
03342
03343
03344 m_bProcessMatrices = true;
03345 }
03346
03347
03348 for (int i=0; i < n; i++)
03349 {
03350 int nCh = ((OSMatrix*)instanceData->matrices->matrix[i])->inumberOfChildren;
03351
03352 for (int j=0; j < nCh; j++)
03353 {
03354 m_miMatrixSymmetry[i] = instanceData->matrices->matrix[i]->symmetry;
03355 m_miMatrixType[i] = mergeMatrixType(ENUM_MATRIX_TYPE_unknown,
03356 instanceData->matrices->matrix[i]->getMatrixType());
03357 m_miMatrixNumberOfColumns[i] = instanceData->matrices->matrix[i]->numberOfColumns;
03358 m_miMatrixNumberOfRows[i] = instanceData->matrices->matrix[i]->numberOfRows;
03359 m_msMatrixNames[i] = instanceData->matrices->matrix[i]->name;
03360 m_mMatrix[i] = (OSMatrix*)instanceData->matrices->matrix[i];
03361
03362 #if 0
03363
03364
03365
03366
03367
03368
03369
03370
03371
03372
03373
03374
03375
03376
03377
03378
03379
03380
03381
03382
03383
03384 if (nCh == 0)
03385 {
03386 m_miMatrixNumberOfValues[i] = 0;
03387 m_miMatrixNumberOfBlocks[i] = 0;
03388 break;
03389 }
03390
03391 if (instanceData->matrices->matrix[i]->m_mChildren[j]->nType
03392 == ENUM_MATRIX_CONSTRUCTOR_TYPE_baseMatrix)
03393 {
03394 int bm;
03395 bm = (BaseMatrix*)instanceData->matrices->matrix[i]->m_mChildren[j])->baseMatrixIdx;
03396 if (bm >= i)
03397 throw ErrorClass("Illegal reference to baseMatrix while processing matrices");
03398 else
03399 {
03400 if (m_mExpandedMatricesInColumnMajor[bm] != NULL)
03401 haveElements = true;
03402 if (m_mExpandedMatricesInRowMajor[bm] != NULL)
03403 {
03404 rowMajor = true;
03405 haveElements = true;
03406 }
03407 if (m_mMatrixBlocksInColumnMajor != NULL)
03408 haveBlocks = true;
03409 if (m_mMatrixTransformation != NULL)
03410 haveTransformation = true;
03411 }
03412 }
03413 else if (instanceData->matrices->matrix[i]->m_mChildren[j]->nType
03414 == ENUM_MATRIX_CONSTRUCTOR_TYPE_elements)
03415 {
03416 haveElements = true;
03417 }
03418 else if (instanceData->matrices->matrix[i]->m_mChildren[j]->nType
03419 == ENUM_MATRIX_CONSTRUCTOR_TYPE_transformation)
03420 haveTransformation = true;
03421 else if (instanceData->matrices->matrix[i]->m_mChildren[j]->nType
03422 == ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks)
03423 haveBlocks = true;
03424 }
03425 m_miMatrixNumberOfValues[i] = new int[n];
03426 m_miMatrixNumberOfBlocks[i] = new int[n];
03427 #endif
03428
03429 }
03430
03431 }
03432 }
03433 return true;
03434 }
03435 catch(const ErrorClass& eclass)
03436 {
03437 throw ErrorClass( eclass.errormsg);
03438 }
03439 }
03440
03441
03442 bool OSInstance::matrixHasBase(int n)
03443 {
03444 int nMatrices = getMatrixNumber();
03445 if ( (instanceData->matrices == NULL) || (nMatrices == 0) ) return false;
03446 if ( (n < 0) || (n >= nMatrices) ) return false;
03447 return instanceData->matrices->matrix[n]->matrixHasBase();
03448 }
03449
03450 bool OSInstance::matrixHasElements(int n)
03451 {
03452 int nMatrices = getMatrixNumber();
03453 if ( (instanceData->matrices == NULL) || (nMatrices == 0) ) return false;
03454 if ( (n < 0) || (n >= nMatrices) ) return false;
03455 return instanceData->matrices->matrix[n]->matrixHasElements();
03456 }
03457
03458 bool OSInstance::matrixHasTransformations(int n)
03459 {
03460 int nMatrices = getMatrixNumber();
03461 if ( (instanceData->matrices == NULL) || (nMatrices == 0) ) return false;
03462 if ( (n < 0) || (n >= nMatrices) ) return false;
03463 return instanceData->matrices->matrix[n]->matrixHasTransformations();
03464 }
03465
03466 bool OSInstance::matrixHasBlocks(int n)
03467 {
03468 int nMatrices = getMatrixNumber();
03469 if ( (instanceData->matrices == NULL) || (nMatrices == 0) ) return false;
03470 if ( (n < 0) || (n >= nMatrices) ) return false;
03471 return instanceData->matrices->matrix[n]->matrixHasBlocks();
03472 }
03473
03474 int OSInstance::getNumberOfElementConstructors(int n)
03475 {
03476 int nMatrices = getMatrixNumber();
03477 if ( (instanceData->matrices == NULL) || (nMatrices == 0) ) return 0;
03478 if ( (n < 0) || (n >= nMatrices) ) return false;
03479 return instanceData->matrices->matrix[n]->getNumberOfElementConstructors();
03480 }
03481
03482 int OSInstance::getNumberOfTransformationConstructors(int n)
03483 {
03484 int nMatrices = getMatrixNumber();
03485 if ( (instanceData->matrices == NULL) || (nMatrices == 0) ) return 0;
03486 if ( (n < 0) || (n >= nMatrices) ) return false;
03487 return instanceData->matrices->matrix[n]->getNumberOfTransformationConstructors();
03488 }
03489
03490 int OSInstance::getNumberOfBlocksConstructors(int n)
03491 {
03492 int nMatrices = getMatrixNumber();
03493 if ( (instanceData->matrices == NULL) || (nMatrices == 0) ) return 0;
03494 if ( (n < 0) || (n >= nMatrices) ) return false;
03495 return instanceData->matrices->matrix[n]->getNumberOfBlocksConstructors();
03496 }
03497
03498
03499 GeneralSparseMatrix* OSInstance::getMatrixCoefficientsInColumnMajor(int n)
03500 {
03501 try
03502 {
03503 int nMatrices = getMatrixNumber();
03504 if ( (instanceData->matrices == NULL) || (nMatrices == 0) )
03505 throw ErrorClass("no matrices defined in method getMatrixCoefficientsInColumnMajor()");
03506 if ( (n < 0) || (n >= nMatrices) )
03507 throw ErrorClass("invalid matrix index in method getMatrixCoefficientsInColumnMajor()");
03508 return instanceData->matrices->matrix[n]->getMatrixCoefficientsInColumnMajor();
03509 }
03510 catch(const ErrorClass& eclass)
03511 {
03512 throw ErrorClass( eclass.errormsg);
03513 }
03514 }
03515
03516
03517 GeneralSparseMatrix* OSInstance::getMatrixCoefficientsInRowMajor(int n)
03518 {
03519 try
03520 {
03521 int nMatrices = getMatrixNumber();
03522 if ( (instanceData->matrices == NULL) || (nMatrices == 0) )
03523 throw ErrorClass("no matrices defined in method getMatrixCoefficientsInRowMajor()");
03524 if ( (n < 0) || (n >= nMatrices) )
03525 throw ErrorClass("invalid matrix index in method getMatrixCoefficientsInRowMajor()");
03526 return instanceData->matrices->matrix[n]->getMatrixCoefficientsInRowMajor();
03527 }
03528 catch(const ErrorClass& eclass)
03529 {
03530 throw ErrorClass( eclass.errormsg);
03531 }
03532 }
03533
03534
03535
03536 int OSInstance::getNumberOfMatrixVariables()
03537 {
03538 if(m_iMatrixVarNumber == -1)
03539 {
03540 if (instanceData == NULL)
03541 throw ErrorClass("data object undefined in method getNumberOfMatrixVariables()");
03542 if (instanceData->matrixProgramming == NULL ||
03543 instanceData->matrixProgramming->matrixVariables == NULL)
03544 m_iMatrixVarNumber = 0;
03545 else
03546 m_iMatrixVarNumber = instanceData->matrixProgramming->matrixVariables->numberOfMatrixVar;
03547 }
03548 return m_iMatrixVarNumber;
03549 }
03550
03551 int OSInstance::getNumberOfMatrixObjectives()
03552 {
03553 if(m_iMatrixObjNumber == -1)
03554 {
03555 if (instanceData == NULL)
03556 throw ErrorClass("data object undefined in method getNumberOfMatrixObjectives()");
03557 if (instanceData->matrixProgramming == NULL ||
03558 instanceData->matrixProgramming->matrixObjectives == NULL)
03559 m_iMatrixObjNumber = 0;
03560 else
03561 m_iMatrixObjNumber = instanceData->matrixProgramming->matrixObjectives->numberOfMatrixObj;
03562 }
03563 return m_iMatrixObjNumber;
03564 }
03565
03566 int OSInstance::getNumberOfMatrixConstraints()
03567 {
03568 if(m_iMatrixObjNumber == -1)
03569 {
03570 if (instanceData == NULL)
03571 throw ErrorClass("data object undefined in method getNumberOfMatrixConstraints()");
03572 if (instanceData->matrixProgramming == NULL ||
03573 instanceData->matrixProgramming->matrixConstraints == NULL)
03574 m_iMatrixConNumber = 0;
03575 else
03576 m_iMatrixConNumber = instanceData->matrixProgramming->matrixConstraints->numberOfMatrixCon;
03577 }
03578 return m_iMatrixConNumber;
03579 }
03580
03581 int OSInstance::getNumberOfMatrixExpressions()
03582 {
03583 if(m_iMatrixExpressionNumber == -1)
03584 {
03585 if (instanceData == NULL)
03586 throw ErrorClass("data object undefined in method getNumberOfMatrixExpressions()");
03587 if (instanceData->matrixProgramming == NULL||
03588 instanceData->matrixProgramming->matrixExpressions == NULL)
03589 m_iMatrixExpressionNumber = 0;
03590 else
03591 m_iMatrixExpressionNumber = instanceData->matrixProgramming->matrixExpressions->numberOfExpr;
03592 }
03593 return m_iMatrixExpressionNumber;
03594 }
03595
03596
03597
03598 #if 0
03599 int OSInstance::getNumberOfMatrixExpressions()
03600 {
03601 if(m_iMatrixExpressionNumber == -1)
03602 {
03603 if (instanceData == NULL || instanceData->matrixProgramming == NULL
03604 || instanceData->matrixProgramming->matrixExpressions == NULL)
03605 throw ErrorClass("data object undefined in method getNumberOfMatrixExpressions()");
03606 m_iMatrixExpressionNumber = instanceData->matrixProgramming->matrixExpressions->numberOfExpr;
03607 }
03608 return m_iMatrixExpressionNumber;
03609 }
03610
03611 MatrixExpressions** OSInstance::getMatrixExpressions()
03612 {
03613 MatrixExpressions** root = new MatrixExpressions*[getNumberOfMatrixExpressions()];
03614 for (int i=0; i < getNumberOfMatrixExpressions(); i++)
03615 {
03616 root[i] = instanceData->matrixProgramming->matrixExpressions->expr[i];
03617 }
03618 return root;
03619 }
03620
03621
03622 int OSInstance::getNumberOfMatrixExpressionTreeIndexes()
03623 {
03624 if(m_bMatrixExpressionTreeIndexesProcessed == false) getMatrixExpressionTreeIndexes();
03625 return m_iNumberOfMatrixExpressionTreeIndexes;
03626 }
03627
03628 int* OSInstance::getMatrixExpressionTreeIndexes()
03629 {
03630 if(m_bMatrixExpressionTreeIndexesProcessed == true) return m_miMatrixExpressionTreeIndexes;
03631 m_bMatrixExpressionTreeIndexesProcessed = true;
03632 std::map<int, MatrixExpressionTree*> expTrees;
03633 expTrees = getAllMatrixExpressionTrees();
03634 std::map<int, MatrixExpressionTree*>::iterator pos;
03635 try
03636 {
03637
03638 m_iNumberOfMatrixExpressionTreeIndexes = expTrees.size();
03639 m_miMatrixExpressionTreeIndexes = new int[ m_iNumberOfMatrixExpressionTreeIndexes ] ;
03640 int i = 0;
03641 for(pos = expTrees.begin(); pos != expTrees.end(); ++pos)
03642 {
03643 m_miMatrixExpressionTreeIndexes[ i++] = pos->first;
03644 }
03645 expTrees.clear();
03646 return m_miMatrixExpressionTreeIndexes;
03647 }
03648 catch(const ErrorClass& eclass)
03649 {
03650 throw ErrorClass( eclass.errormsg);
03651 }
03652 }
03653
03654 MatrixExpressionTree* OSInstance::getMatrixExpressionTree(int rowIdx)
03655 {
03656
03657 if( m_bProcessMatrixExpressionTrees == false )
03658 {
03659 getAllMatrixExpressionTrees();
03660 }
03661 if( m_mapMatrixExpressionTrees.find( rowIdx) != m_mapMatrixExpressionTrees.end())
03662 return m_mapMatrixExpressionTrees[ rowIdx];
03663 else return NULL ;
03664 }
03665
03666 MatrixExpressionTree* OSInstance::getMatrixExpressionTreeMod(int rowIdx)
03667 {
03668
03669 if( m_bProcessMatrixExpressionTreesMod == false )
03670 {
03671 getAllMatrixExpressionTreesMod();
03672 }
03673 if( m_mapMatrixExpressionTreesMod.find( rowIdx) != m_mapMatrixExpressionTreesMod.end())
03674 return m_mapMatrixExpressionTreesMod[ rowIdx];
03675 else return NULL ;
03676 }
03677
03678 std::vector<ExprNode*> OSInstance::getMatrixExpressionTreeInPostfix( int rowIdx)
03679 {
03680
03681 if( m_bProcessMatrixExpressionTrees == false ) getAllMatrixExpressionTrees();
03682 std::vector<ExprNode*> postfixVec;
03683 try
03684 {
03685 if( m_mapMatrixExpressionTrees.find( rowIdx) != m_mapMatrixExpressionTrees.end())
03686 {
03687 MatrixExpressionTree* expTree = getMatrixExpressionTree( rowIdx);
03688 postfixVec = expTree->m_treeRoot->getPostfixFromExpressionTree();
03689 }
03690 else
03691 {
03692 throw ErrorClass("Error in getMatrixExpressionTreeInPostfix, rowIdx not valid");
03693 }
03694 return postfixVec;
03695 }
03696 catch(const ErrorClass& eclass)
03697 {
03698 throw ErrorClass( eclass.errormsg);
03699 }
03700 }
03701
03702 std::string OSInstance::getMatrixExpressionTreeInInfix( int rowIdx_)
03703 {
03704 if( m_binitForAlgDiff == false) this->initForAlgDiff();
03705 if( m_bProcessExpressionTrees == false ) getAllMatrixExpressionTrees();
03706 std::string resultString;
03707 resultString = "";
03708 unsigned int i;
03709 unsigned int j;
03710 unsigned int n;
03711 ostringstream outStr;
03712 std::vector<ExprNode*> postfixVec;
03713 int rowIdx = rowIdx_;
03714 OSnLNode *nlnode = NULL ;
03715 OSnLNodeNumber *nlnodeNum = NULL;
03716 OSnLNodeVariable *nlnodeVar = NULL;
03717 OSnLNodeSum *nlnodeSum = NULL;
03718 OSnLNodeProduct *nlnodeProduct = NULL;
03719 OSnLNodeMin *nlnodeMin = NULL;
03720 OSnLNodeMax *nlnodeMax = NULL;
03721 std::string tmp1 = "";
03722 std::string tmp2 = "";
03723 std::string tmp3 = "";
03724 std::stack<OSnLNode*> opStack;
03725 std::stack<std::string> tmpStack;
03726 std::stack<std::string> sumStack;
03727 std::stack<std::string> productStack;
03728 std::stack<std::string> minStack;
03729 std::stack<std::string> maxStack;
03730
03731 try
03732 {
03733 if( m_mapMatrixExpressionTrees.find( rowIdx) != m_mapMatrixExpressionTrees.end())
03734 {
03735
03736
03737
03738 MatrixExpressionTree* exptree = this->getMatrixExpressionTree( rowIdx);
03739 if(exptree != NULL)
03740 {
03741 postfixVec = this->getMatrixExpressionTreeInPostfix( rowIdx);
03742 n = postfixVec.size();
03743
03744 for (i = 0 ; i < n; i++)
03745 {
03746 nlnode = postfixVec[ n - 1 - i];
03747 opStack.push( nlnode);
03748
03749
03750 }
03751
03752 n = opStack.size();
03753 for(i = 0; i < n; i++)
03754 {
03755
03756 nlnode = opStack.top();
03757
03758 switch (nlnode->inodeInt)
03759 {
03760 case OS_NUMBER:
03761 nlnodeNum = (OSnLNodeNumber*)nlnode;
03762 tmpStack.push( os_dtoa_format(nlnodeNum->value) );
03763 break;
03764
03765 case OS_PI:
03766 tmpStack.push( "PI" );
03767 break;
03768
03769 case OS_E:
03770 tmpStack.push( "E" );
03771 break;
03772
03773 case OS_VARIABLE:
03774 outStr.str("");
03775
03776 nlnodeVar = (OSnLNodeVariable*)nlnode;
03777
03778 if( (nlnodeVar->coef > 1.0) || (nlnodeVar->coef < 1.0) )
03779 {
03780 outStr << "(";
03781 outStr << os_dtoa_format(nlnodeVar->coef);
03782 outStr << "*x_";
03783 outStr << nlnodeVar->idx;
03784 outStr << ")";
03785 tmpStack.push(outStr.str() );
03786
03787 }
03788 else
03789 {
03790 outStr << "x_";
03791 outStr << nlnodeVar->idx;
03792 tmpStack.push(outStr.str() );
03793
03794 }
03795 break;
03796
03797 case OS_PLUS :
03798 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing plus operator");
03799 tmp1 = tmpStack.top();
03800 tmpStack.pop();
03801 tmp2 = tmpStack.top();
03802 tmpStack.pop();
03803 tmpStack.push("(" + tmp2 + " + " + tmp1 + ")");
03804 break;
03805
03806 case OS_SUM :
03807 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing sum operator");
03808
03809 nlnodeSum = (OSnLNodeSum*)nlnode;
03810 outStr.str("");
03811 for(j = 0; j < nlnodeSum->inumberOfChildren; j++)
03812 {
03813 sumStack.push( tmpStack.top() );
03814 tmpStack.pop();
03815 }
03816 outStr << "(";
03817 for(j = 0; j < nlnodeSum->inumberOfChildren; j++)
03818 {
03819 outStr << sumStack.top();
03820 if (j < nlnodeSum->inumberOfChildren - 1) outStr << " + ";
03821 sumStack.pop();
03822 }
03823 outStr << ")";
03824 tmpStack.push( outStr.str() );
03825
03826 break;
03827
03828 case OS_MINUS :
03829 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing minus operator");
03830 tmp1 = tmpStack.top();
03831 tmpStack.pop();
03832 tmp2 = tmpStack.top();
03833 tmpStack.pop();
03834 tmpStack.push("(" + tmp2 + " - " + tmp1 + ")");
03835 break;
03836
03837 case OS_NEGATE :
03838 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- -- Problem writing negate operator");
03839 tmp1 = tmpStack.top();
03840 tmpStack.pop();
03841 tmpStack.push( "-"+ tmp1 );
03842
03843
03844 break;
03845
03846 case OS_TIMES :
03847 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing times operator");
03848 tmp1 = tmpStack.top();
03849 tmpStack.pop();
03850 tmp2 = tmpStack.top();
03851 tmpStack.pop();
03852 tmpStack.push("(" + tmp2 + "*" + tmp1 + ")");
03853 break;
03854
03855 case OS_DIVIDE :
03856 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing divide operator");
03857 tmp1 = tmpStack.top();
03858 tmpStack.pop();
03859 tmp2 = tmpStack.top();
03860 tmpStack.pop();
03861 tmpStack.push("(" + tmp2 + " / " + tmp1 + ")");
03862 break;
03863
03864 case OS_POWER :
03865 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing power operator");
03866 tmp1 = tmpStack.top();
03867 tmpStack.pop();
03868 tmp2 = tmpStack.top();
03869 tmpStack.pop();
03870 tmpStack.push("(" + tmp2 + " ^ " + tmp1 + ")");
03871 break;
03872
03873
03874 case OS_ABS :
03875 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing abs operator");
03876 tmp1 = tmpStack.top();
03877 tmpStack.pop();
03878 tmpStack.push( "abs( "+ tmp1 + ")");
03879 break;
03880
03881 case OS_ERF :
03882 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing erf operator");
03883 tmp1 = tmpStack.top();
03884 tmpStack.pop();
03885 tmpStack.push( "erf( "+ tmp1 + ")");
03886 break;
03887
03888
03889 case OS_SQUARE :
03890 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing square operator ");
03891 tmp1 = tmpStack.top();
03892 tmpStack.pop();
03893 tmpStack.push( "("+ tmp1 + ")^2");
03894 break;
03895
03896 case OS_LN :
03897 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing ln operator");
03898 tmp1 = tmpStack.top();
03899 tmpStack.pop();
03900 tmpStack.push( "ln( "+ tmp1 + ")");
03901 break;
03902
03903 case OS_EXP :
03904
03905 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing exp operator");
03906 tmp1 = tmpStack.top();
03907 tmpStack.pop();
03908 tmpStack.push( "exp( "+ tmp1 + ")");
03909 break;
03910
03911 case OS_SIN :
03912 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing sin operator");
03913 tmp1 = tmpStack.top();
03914 tmpStack.pop();
03915 tmpStack.push( "sin( "+ tmp1 + ")");
03916 break;
03917
03918 case OS_COS :
03919 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing cos operator ");
03920 tmp1 = tmpStack.top();
03921 tmpStack.pop();
03922 tmpStack.push( "cos( "+ tmp1 + ")");
03923 break;
03924
03925 case OS_SQRT :
03926 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing sqrt operator ");
03927 tmp1 = tmpStack.top();
03928 tmpStack.pop();
03929 tmpStack.push( "sqrt( "+ tmp1 + ")");
03930 break;
03931
03932 case OS_MIN :
03933 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing min operator");
03934
03935 nlnodeMin = (OSnLNodeMin*)nlnode;
03936 outStr.str("");
03937 for(j = 0; j < nlnodeMin->inumberOfChildren; j++)
03938 {
03939 minStack.push( tmpStack.top() );
03940 tmpStack.pop();
03941 }
03942 outStr << "min(";
03943 for(j = 0; j < nlnodeMin->inumberOfChildren; j++)
03944 {
03945 outStr << minStack.top();
03946 if (j < nlnodeMin->inumberOfChildren - 1) outStr << " , ";
03947 minStack.pop();
03948 }
03949 outStr << ")";
03950 tmpStack.push( outStr.str() );
03951 break;
03952
03953 case OS_MAX :
03954 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing max operator");
03955
03956 nlnodeMax = (OSnLNodeMax*)nlnode;
03957 outStr.str("");
03958 for(j = 0; j < nlnodeMax->inumberOfChildren; j++)
03959 {
03960 maxStack.push( tmpStack.top() );
03961 tmpStack.pop();
03962 }
03963 outStr << "max(";
03964 for(j = 0; j < nlnodeMax->inumberOfChildren; j++)
03965 {
03966 outStr << maxStack.top();
03967 if (j < nlnodeMax->inumberOfChildren - 1) outStr << " , ";
03968 maxStack.pop();
03969 }
03970 outStr << ")";
03971 tmpStack.push( outStr.str() );
03972 break;
03973
03974 case OS_IF :
03975
03976 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing if operator ");
03977 if(nlnode->inumberOfChildren != 3)throw ErrorClass("The if node must have three children");
03978 tmp1 = tmpStack.top();
03979 tmpStack.pop();
03980 tmp2 = tmpStack.top();
03981 tmpStack.pop();
03982 tmp3 = tmpStack.top();
03983 tmpStack.pop();
03984 tmpStack.push( "if(" + tmp3 + "," + tmp2 + "," + tmp1 +")" );
03985 break;
03986
03987 case OS_PRODUCT :
03988 if( tmpStack.size() < nlnode->inumberOfChildren) throw ErrorClass("There is an error in the OSExpression Tree -- Problem writing product operator");
03989
03990 nlnodeProduct = (OSnLNodeProduct*)nlnode;
03991 outStr.str("");
03992 for(j = 0; j < nlnodeProduct->inumberOfChildren; j++)
03993 {
03994 productStack.push( tmpStack.top() );
03995 tmpStack.pop();
03996 }
03997 outStr << "(";
03998 for(j = 0; j < nlnodeProduct->inumberOfChildren; j++)
03999 {
04000 outStr << productStack.top();
04001 if (j < nlnodeProduct->inumberOfChildren - 1) outStr << " * ";
04002 productStack.pop();
04003 }
04004 outStr << ")";
04005 tmpStack.push( outStr.str() );
04006
04007 break;
04008
04009 default:
04010 throw ErrorClass("operator " + nlnode->getTokenName() + " not supported");
04011 break;
04012 }
04013 opStack.pop();
04014 }
04015 postfixVec.clear();
04016 if(tmpStack.size() != 1) throw ErrorClass( "There is an error in the OSExpression Tree -- stack size should be 1 at end");
04017 resultString = tmpStack.top();
04018
04019 tmpStack.pop();
04020
04021 return resultString;
04022 }
04023 else
04024 {
04025
04026 return "";
04027 }
04028 }
04029 else
04030 {
04031 throw ErrorClass("Error in getNonlinearExpressionTreeInInfix, rowIdx not valid");
04032 }
04033 return resultString;
04034 }
04035 catch(const ErrorClass& eclass)
04036 {
04037 throw ErrorClass( eclass.errormsg);
04038 }
04039 }
04040
04041
04042 std::vector<ExprNode*> OSInstance::getMatrixExpressionTreeModInPostfix( int rowIdx)
04043 {
04044
04045 if( m_bProcessMatrixExpressionTreesMod == false ) getAllMatrixExpressionTreesMod();
04046 std::vector<ExprNode*> postfixVec;
04047 try
04048 {
04049 if( m_mapMatrixExpressionTreesMod.find( rowIdx) != m_mapMatrixExpressionTreesMod.end())
04050 {
04051 MatrixExpressionTree* expTree = getMatrixExpressionTreeMod( rowIdx);
04052 postfixVec = expTree->m_treeRoot->getPostfixFromExpressionTree();
04053
04054 }
04055 else
04056 {
04057 throw ErrorClass("Error in getMatrixExpressionTreeModInPostfix, rowIdx not valid");
04058 }
04059 return postfixVec;
04060 }
04061 catch(const ErrorClass& eclass)
04062 {
04063 throw ErrorClass( eclass.errormsg);
04064 }
04065 }
04066
04067
04068 std::vector<ExprNode*> OSInstance::getMatrixExpressionTreeInPrefix( int rowIdx)
04069 {
04070
04071 if( m_bProcessMatrixExpressionTrees == false ) getAllMatrixExpressionTrees();
04072 std::vector<ExprNode*> prefixVec;
04073 try
04074 {
04075 if( m_mapMatrixExpressionTrees.find( rowIdx) != m_mapMatrixExpressionTrees.end())
04076 {
04077 MatrixExpressionTree* expTree = getMatrixExpressionTree( rowIdx);
04078 prefixVec = expTree->m_treeRoot->getPrefixFromExpressionTree();
04079 }
04080 else
04081 {
04082 throw ErrorClass("Error in getMatrixExpressionTreeInPrefix, rowIdx not valid");
04083 }
04084 return prefixVec;
04085 }
04086 catch(const ErrorClass& eclass)
04087 {
04088 throw ErrorClass( eclass.errormsg);
04089 }
04090 }
04091
04092 std::vector<ExprNode*> OSInstance::getMatrixExpressionTreeModInPrefix( int rowIdx)
04093 {
04094
04095
04096 if( m_bProcessMatrixExpressionTreesMod == false ) getAllMatrixExpressionTreesMod();
04097 std::vector<ExprNode*> prefixVec;
04098 try
04099 {
04100 if( m_mapMatrixExpressionTreesMod.find( rowIdx) != m_mapMatrixExpressionTreesMod.end())
04101 {
04102 MatrixExpressionTree* expTree = getMatrixExpressionTreeMod( rowIdx);
04103 prefixVec = expTree->m_treeRoot->getPrefixFromExpressionTree();
04104 }
04105 else
04106 {
04107 throw ErrorClass("Error in getMatrixExpressionTreeInPrefix, rowIdx not valid");
04108 }
04109 return prefixVec;
04110 }
04111 catch(const ErrorClass& eclass)
04112 {
04113 throw ErrorClass( eclass.errormsg);
04114 }
04115 }
04116
04117 std::map<int, MatrixExpressionTree*> OSInstance::getAllMatrixExpressionTrees()
04118 {
04119
04120 if(m_bProcessMatrixExpressionTrees == true) return m_mapMatrixExpressionTrees;
04121 std::map<int, int> foundIdx;
04122 std::map<int, int>::iterator pos;
04123 OSnLNodePlus *nlNodePlus;
04124 MatrixExpressionTree *expTree;
04125
04126
04127 m_iObjectiveNumberNonlinear = 0;
04128 m_iConstraintNumberNonlinear = 0;
04129 int i;
04130
04131 if( instanceData->nonlinearExpressions->numberOfNonlinearExpressions > 0 && instanceData->nonlinearExpressions->nl != NULL)
04132 {
04133 for( i = 0; i < instanceData->nonlinearExpressions->numberOfNonlinearExpressions; i++)
04134 {
04135 instanceData->nonlinearExpressions->nl[i]->m_bDeleteExpressionTree = false;
04136
04137
04138
04139
04140 }
04141 }
04142 int index;
04143
04144 for(i = 0; i < instanceData->nonlinearExpressions->numberOfNonlinearExpressions; i++)
04145 {
04146 index = instanceData->nonlinearExpressions->nl[ i]->idx;
04147 if(foundIdx.find( index) != foundIdx.end() )
04148 {
04149
04150
04151
04152
04153
04154
04155
04156 nlNodePlus = new OSnLNodePlus();
04157
04158 expTree = instanceData->nonlinearExpressions->nl[ i]->osExpressionTree;
04159
04160 nlNodePlus->m_mChildren[ 0] = m_mapExpressionTrees[ index]->m_treeRoot;
04161 nlNodePlus->m_mChildren[ 1] = instanceData->nonlinearExpressions->nl[ i]->osExpressionTree->m_treeRoot;
04162
04163 instanceData->nonlinearExpressions->nl[ foundIdx[ index] ]->m_bDeleteExpressionTree = true;
04164 instanceData->nonlinearExpressions->nl[ foundIdx[ index] ]->osExpressionTree->bDestroyNlNodes = false;
04165
04166 m_mapExpressionTrees[ index] = expTree;
04167 m_mapExpressionTrees[ index]->m_treeRoot = nlNodePlus;
04168 foundIdx[ index] = i;
04169 }
04170 else
04171 {
04172
04173 m_mapExpressionTrees[ index] = instanceData->nonlinearExpressions->nl[ i]->osExpressionTree;
04174 m_mapExpressionTrees[ index]->m_treeRoot = instanceData->nonlinearExpressions->nl[ i]->osExpressionTree->m_treeRoot;
04175 foundIdx[ index] = i;
04176 }
04177
04178 }
04179
04180 for(pos = foundIdx.begin(); pos != foundIdx.end(); ++pos)
04181 {
04182 if(pos->first < 0)
04183 {
04184 m_iMatrixObjectiveNumberNonlinear++;
04185 }
04186 else
04187 {
04188 m_iMatrixConstraintNumberNonlinear++;
04189 }
04190 }
04191 m_bProcessMatrixExpressionTrees = true;
04192 return m_mapMatrixExpressionTrees;
04193 }
04194 #endif
04195
04196
04197 std::string OSInstance::getTimeDomainFormat()
04198 {
04199 if (instanceData->timeDomain == NULL)
04200 return "";
04201 if (instanceData->timeDomain->interval != NULL)
04202 return "interval";
04203 if (instanceData->timeDomain->stages != NULL)
04204 return "stages";
04205 return "";
04206 }
04207
04208 int OSInstance::getTimeDomainStageNumber()
04209 {
04210 try
04211 {
04212 if (instanceData->timeDomain == NULL)
04213 return 1;
04214 if (instanceData->timeDomain->interval != NULL)
04215 throw ErrorClass("getTimeDomainStageNumber: Continuous time not implemented yet");
04216 if (instanceData->timeDomain->stages == NULL)
04217 return 1;
04218 return instanceData->timeDomain->stages->numberOfStages;
04219 }
04220 catch(const ErrorClass& eclass)
04221 {
04222 throw ErrorClass( eclass.errormsg);
04223 }
04224 }
04225
04226 std::string* OSInstance::getTimeDomainStageNames()
04227 {
04228 if (instanceData->timeDomain == NULL)
04229 return NULL;
04230 if (instanceData->timeDomain->interval != NULL)
04231 return NULL;
04232 if (instanceData->timeDomain->stages == NULL)
04233 return NULL;
04234 if (m_msTimeDomainStageNames != NULL)
04235 delete [] m_msTimeDomainStageNames;
04236 if (instanceData->timeDomain->stages->numberOfStages == 0)
04237 return NULL;
04238 m_msTimeDomainStageNames = new std::string[instanceData->timeDomain->stages->numberOfStages];
04239 for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
04240 m_msTimeDomainStageNames[i] = instanceData->timeDomain->stages->stage[i]->name;
04241 return m_msTimeDomainStageNames;
04242 }
04243
04244
04245 int* OSInstance::getTimeDomainStageNumberOfVariables()
04246 {
04247 if (instanceData->timeDomain == NULL)
04248 return NULL;
04249 if (instanceData->timeDomain->interval != NULL)
04250 return NULL;
04251 if (instanceData->timeDomain->stages == NULL)
04252 return NULL;
04253 if (m_miTimeDomainStageVariableNumber != NULL)
04254 delete [] m_miTimeDomainStageVariableNumber;
04255 if (instanceData->timeDomain->stages->numberOfStages == 0)
04256 return NULL;
04257 m_miTimeDomainStageVariableNumber = new int[instanceData->timeDomain->stages->numberOfStages];
04258 for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
04259 m_miTimeDomainStageVariableNumber[i] = instanceData->timeDomain->stages->stage[i]->variables->numberOfVariables;
04260 return m_miTimeDomainStageVariableNumber;
04261 }
04262
04263 int* OSInstance::getTimeDomainStageNumberOfConstraints()
04264 {
04265 if (instanceData->timeDomain == NULL)
04266 return NULL;
04267 if (instanceData->timeDomain->interval != NULL)
04268 return NULL;
04269 if (instanceData->timeDomain->stages == NULL)
04270 return NULL;
04271 if (m_miTimeDomainStageConstraintNumber != NULL)
04272 delete [] m_miTimeDomainStageConstraintNumber;
04273 if (instanceData->timeDomain->stages->numberOfStages == 0)
04274 return NULL;
04275 m_miTimeDomainStageConstraintNumber = new int[instanceData->timeDomain->stages->numberOfStages];
04276 for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
04277 m_miTimeDomainStageConstraintNumber[i] = instanceData->timeDomain->stages->stage[i]->constraints->numberOfConstraints;
04278 return m_miTimeDomainStageConstraintNumber;
04279 }
04280
04281 int* OSInstance::getTimeDomainStageNumberOfObjectives()
04282 {
04283 if (instanceData->timeDomain == NULL)
04284 return NULL;
04285 if (instanceData->timeDomain->interval != NULL)
04286 return NULL;
04287 if (instanceData->timeDomain->stages == NULL)
04288 return NULL;
04289 if (m_miTimeDomainStageObjectiveNumber != NULL)
04290 delete [] m_miTimeDomainStageObjectiveNumber;
04291 if (instanceData->timeDomain->stages->numberOfStages == 0)
04292 return NULL;
04293 m_miTimeDomainStageObjectiveNumber = new int[instanceData->timeDomain->stages->numberOfStages];
04294 for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
04295 m_miTimeDomainStageObjectiveNumber[i] = instanceData->timeDomain->stages->stage[i]->objectives->numberOfObjectives;
04296 return m_miTimeDomainStageObjectiveNumber;
04297 }
04298
04299 int** OSInstance::getTimeDomainStageVarList()
04300 {
04301 if (instanceData->timeDomain == NULL)
04302 return NULL;
04303 if (instanceData->timeDomain->interval != NULL)
04304 return NULL;
04305 if (instanceData->timeDomain->stages == NULL)
04306 return NULL;
04307 if (m_miTimeDomainStageVariableNumber == NULL)
04308 return NULL;
04309 if (m_mmiTimeDomainStageVarList != NULL)
04310 {
04311 for (int i = 0; i < m_iNumberOfTimeStages; i ++)
04312 delete[] m_mmiTimeDomainStageVarList[i];
04313 delete[] m_mmiTimeDomainStageVarList;
04314 m_mmiTimeDomainStageVarList = NULL;
04315 }
04316
04317
04318 if (instanceData->timeDomain->stages->numberOfStages == 0)
04319 return NULL;
04320 m_iNumberOfTimeStages = instanceData->timeDomain->stages->numberOfStages;
04321 m_mmiTimeDomainStageVarList = new int*[instanceData->timeDomain->stages->numberOfStages];
04322 int timeDomainStageNumberVar;
04323 for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
04324 {
04325 timeDomainStageNumberVar = m_miTimeDomainStageVariableNumber[i];
04326 m_mmiTimeDomainStageVarList[i] = new int[ timeDomainStageNumberVar ];
04327 if (instanceData->timeDomain->stages->stage[i]->variables->startIdx == -1)
04328 for (int j = 0; j < m_miTimeDomainStageVariableNumber[i]; j++)
04329 m_mmiTimeDomainStageVarList[i][j] = instanceData->timeDomain->stages->stage[i]->variables->var[j]->idx;
04330 else
04331 for (int j = 0; j < m_miTimeDomainStageVariableNumber[i]; j++)
04332 m_mmiTimeDomainStageVarList[i][j] = instanceData->timeDomain->stages->stage[i]->variables->startIdx + j;
04333 }
04334 return m_mmiTimeDomainStageVarList;
04335 }
04336
04337 int** OSInstance::getTimeDomainStageConList()
04338 {
04339 if (instanceData->timeDomain == NULL)
04340 return NULL;
04341 if (instanceData->timeDomain->interval != NULL)
04342 return NULL;
04343 if (instanceData->timeDomain->stages == NULL)
04344 return NULL;
04345 if (m_miTimeDomainStageConstraintNumber == NULL)
04346 return NULL;
04347 if (m_mmiTimeDomainStageConList != NULL)
04348 {
04349
04350 for (int i = 0; i < m_iNumberOfTimeStages; i ++)
04351 delete[] m_mmiTimeDomainStageConList[i];
04352 delete[] m_mmiTimeDomainStageConList;
04353 m_mmiTimeDomainStageConList = NULL;
04354 }
04355
04356 if (instanceData->timeDomain->stages->numberOfStages == 0)
04357 return NULL;
04358 m_iNumberOfTimeStages = instanceData->timeDomain->stages->numberOfStages;
04359 m_mmiTimeDomainStageConList = new int*[instanceData->timeDomain->stages->numberOfStages];
04360 int numTimeDomainStageCon;
04361 for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
04362 {
04363 numTimeDomainStageCon = m_miTimeDomainStageConstraintNumber[i];
04364 m_mmiTimeDomainStageConList[i] = new int[ numTimeDomainStageCon];
04365 if (instanceData->timeDomain->stages->stage[i]->constraints->startIdx == -1)
04366 for (int j = 0; j < m_miTimeDomainStageConstraintNumber[i]; j++)
04367 m_mmiTimeDomainStageConList[i][j] = instanceData->timeDomain->stages->stage[i]->constraints->con[j]->idx;
04368 else
04369 for (int j = 0; j < m_miTimeDomainStageConstraintNumber[i]; j++)
04370 m_mmiTimeDomainStageConList[i][j] = instanceData->timeDomain->stages->stage[i]->constraints->startIdx + j;
04371 }
04372 return m_mmiTimeDomainStageConList;
04373 }
04374
04375 int** OSInstance::getTimeDomainStageObjList()
04376 {
04377 if (instanceData->timeDomain == NULL)
04378 return NULL;
04379 if (instanceData->timeDomain->interval != NULL)
04380 return NULL;
04381 if (instanceData->timeDomain->stages == NULL)
04382 return NULL;
04383 if (m_miTimeDomainStageObjectiveNumber == NULL)
04384 return NULL;
04385 if (m_mmiTimeDomainStageObjList != NULL)
04386 {
04387 for (int i = 0; i < m_iNumberOfTimeStages; i ++)
04388 delete[] m_mmiTimeDomainStageObjList[i];
04389 delete[] m_mmiTimeDomainStageObjList;
04390 m_mmiTimeDomainStageObjList = NULL;
04391 }
04392 if (instanceData->timeDomain->stages->numberOfStages == 0)
04393 return NULL;
04394 m_iNumberOfTimeStages = instanceData->timeDomain->stages->numberOfStages;
04395 m_mmiTimeDomainStageObjList = new int*[instanceData->timeDomain->stages->numberOfStages];
04396 int numTimeDomainStageObjNum;
04397 for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
04398 {
04399 numTimeDomainStageObjNum = m_miTimeDomainStageObjectiveNumber[i];
04400 m_mmiTimeDomainStageObjList[i] = new int[ numTimeDomainStageObjNum];
04401 if (instanceData->timeDomain->stages->stage[i]->objectives->startIdx == 0)
04402 for (int j = 0; j < m_miTimeDomainStageObjectiveNumber[i]; j++)
04403 m_mmiTimeDomainStageObjList[i][j] = instanceData->timeDomain->stages->stage[i]->objectives->obj[j]->idx;
04404 else
04405 for (int j = 0; j < m_miTimeDomainStageObjectiveNumber[i]; j++)
04406 m_mmiTimeDomainStageObjList[i][j] = instanceData->timeDomain->stages->stage[i]->objectives->startIdx - j;
04407 }
04408 return m_mmiTimeDomainStageObjList;
04409 }
04410
04411 double OSInstance::getTimeDomainIntervalStart()
04412 {
04413 if (instanceData->timeDomain == NULL)
04414 return 0.0;
04415 if (instanceData->timeDomain->stages != NULL)
04416 return 0.0;
04417 if (instanceData->timeDomain->interval == NULL)
04418 return 0.0;
04419 return instanceData->timeDomain->interval->start;
04420 }
04421
04422 double OSInstance::getTimeDomainIntervalHorizon()
04423 {
04424 if (instanceData->timeDomain == NULL)
04425 return 0.0;
04426 if (instanceData->timeDomain->stages != NULL)
04427 return 0.0;
04428 if (instanceData->timeDomain->interval == NULL)
04429 return 0.0;
04430 return instanceData->timeDomain->interval->horizon;
04431 }
04432
04433
04434
04435
04436
04437
04438 bool OSInstance::setInstanceName(string name)
04439 {
04440 instanceHeader->name = name;
04441 return true;
04442 }
04443
04444 bool OSInstance::setInstanceSource(string source)
04445 {
04446 instanceHeader->source = source;
04447 return true;
04448 }
04449
04450 bool OSInstance::setInstanceDescription(string description)
04451 {
04452 instanceHeader->description = description;
04453 return true;
04454 }
04455
04456 bool OSInstance::setInstanceCreator(string fileCreator)
04457 {
04458 instanceHeader->fileCreator = fileCreator;
04459 return true;
04460 }
04461
04462 bool OSInstance::setInstanceLicence(string licence)
04463 {
04464 instanceHeader->licence = licence;
04465 return true;
04466 }
04467
04468
04469 bool OSInstance::setVariableNumber(int number)
04470 {
04471
04472 if(number < 0) return false;
04473
04474
04475
04476
04477 if(instanceData->variables == NULL) instanceData->variables = new Variables();
04478 instanceData->variables->numberOfVariables = number;
04479 if(instanceData->variables->var == NULL && number > 0)
04480 {
04481 instanceData->variables->var = new Variable*[number];
04482 }
04483 return true;
04484 }
04485
04486
04487 bool OSInstance::addVariable(int index, string name, double lowerBound, double upperBound, char type)
04488 {
04489 if (verifyVarType(type) == false) type = 'C';
04490 instanceData->variables->var[index] = new Variable();
04491 if(index < 0 || instanceData->variables->numberOfVariables <= 0 || index >= instanceData->variables->numberOfVariables) return false;
04492 instanceData->variables->var[index]->name = name;
04493 instanceData->variables->var[index]->lb = lowerBound;
04494 instanceData->variables->var[index]->ub = upperBound;
04495 instanceData->variables->var[index]->type = type;
04496
04497
04498 return true;
04499 }
04500
04501
04502 bool OSInstance::setVariables(int number, string *names, double *lowerBounds,
04503 double *upperBounds, char *types)
04504 {
04505 if(number <= 0) return false;
04506 try
04507 {
04508 if(instanceData->variables == NULL)
04509 {
04510 throw ErrorClass("There is no variables object");
04511 }
04512 if(instanceData->variables->numberOfVariables != number)
04513 {
04514 throw ErrorClass("input number of variables not equal to number in class");
04515 }
04516
04517 int i;
04518 for(i = 0; i < number; i++)
04519 {
04520 instanceData->variables->var[ i] = new Variable();
04521 }
04522 if(names != NULL)
04523 {
04524 for(i = 0; i < number; i++) instanceData->variables->var[i]->name = names[i];
04525 }
04526 if(lowerBounds != NULL)
04527 {
04528 for(i = 0; i < number; i++)
04529 {
04530 instanceData->variables->var[i]->lb = lowerBounds[i];
04531 }
04532 }
04533 if(upperBounds != NULL)
04534 {
04535 for(i = 0; i < number; i++)
04536 {
04537 instanceData->variables->var[i]->ub = upperBounds[i];
04538 }
04539 }
04540 if(types != NULL)
04541 {
04542 for(i = 0; i < number; i++)
04543 {
04544 if(verifyVarType(types[i]) == false) types[i] = 'C';
04545 instanceData->variables->var[i]->type = types[i];
04546 }
04547 }
04548 return true;
04549 }
04550 catch(const ErrorClass& eclass)
04551 {
04552 throw ErrorClass( eclass.errormsg);
04553 }
04554 }
04555
04556
04557
04558 bool OSInstance::setObjectiveNumber(int number)
04559 {
04560 if(number < 0) return false;
04561 if(instanceData->objectives == NULL) instanceData->objectives = new Objectives();
04562 if(number == 0)
04563 {
04564 instanceData->objectives->numberOfObjectives = 0;
04565 instanceData->objectives->obj = 0;
04566 return true;
04567 }
04568 instanceData->objectives->numberOfObjectives = number;
04569 instanceData->objectives->obj = new Objective*[number];
04570 return true;
04571 }
04572
04573 bool OSInstance::addObjective(int index, string name, string maxOrMin, double constant, double weight, SparseVector *objectiveCoefficients)
04574 {
04575 if(index >= 0 || instanceData->objectives->numberOfObjectives <= 0 || abs(index) > instanceData->objectives->numberOfObjectives) return false;
04576 int arrayIndex = abs(index) -1;
04577 if(instanceData->objectives->obj == NULL) return false;
04578 instanceData->objectives->obj[arrayIndex] = new Objective();
04579 instanceData->objectives->obj[arrayIndex]->name = name;
04580 if( (maxOrMin != "max") && (maxOrMin != "min") ) return false;
04581 else instanceData->objectives->obj[arrayIndex]->maxOrMin = maxOrMin;
04582 instanceData->objectives->obj[arrayIndex]->constant = constant;
04583 instanceData->objectives->obj[arrayIndex]->weight = weight;
04584 int n = objectiveCoefficients->number;
04585 instanceData->objectives->obj[arrayIndex]->numberOfObjCoef = n;
04586 if(n == 0)
04587 {
04588 instanceData->objectives->obj[arrayIndex]->coef = 0;
04589 }
04590 else
04591 {
04592 int i = 0;
04593 instanceData->objectives->obj[arrayIndex]->coef = new ObjCoef*[n];
04594 for(i = 0; i < n; i++) instanceData->objectives->obj[arrayIndex]->coef[i] = new ObjCoef();
04595 for(i = 0; i < n; i++)
04596 {
04597 instanceData->objectives->obj[arrayIndex]->coef[i]->idx = objectiveCoefficients->indexes[i];
04598 instanceData->objectives->obj[arrayIndex]->coef[i]->value = objectiveCoefficients->values[i];
04599 }
04600 }
04601 return true;
04602 }
04603
04604 bool OSInstance::setObjectives(int number, string *names, string *maxOrMins, double *constants, double *weights, SparseVector **objectiveCoefficients)
04605 {
04606 if(number < 0) return false;
04607 try
04608 {
04609 if(instanceData->objectives == NULL)
04610 {
04611 throw ErrorClass("there is no objectives object");
04612 }
04613 if(instanceData->objectives->numberOfObjectives != number)
04614 {
04615 throw ErrorClass("input number of objective not equal to number in class");
04616 }
04617 if(number == 0) return true;
04618 int i = 0;
04619 for(i = 0; i < number; i++)instanceData->objectives->obj[i] = new Objective();
04620 int j = 0;
04621 if(names != NULL)
04622 {
04623 for(i = 0; i < number; i++) instanceData->objectives->obj[i]->name = names[i];
04624 }
04625 if(maxOrMins != NULL)
04626 {
04627 for(i = 0; i < number; i++)
04628 {
04629 if(maxOrMins[i] == "" || (maxOrMins[i].compare("max") != 0 && maxOrMins[i].compare("min") !=0)) return false;
04630 instanceData->objectives->obj[i]->maxOrMin = maxOrMins[i];
04631 }
04632 }
04633 if(constants != NULL)
04634 {
04635 for(i = 0; i < number; i++) instanceData->objectives->obj[i]->constant = constants[i];
04636 }
04637 if(weights != NULL)
04638 {
04639 for(i = 0; i < number; i++) instanceData->objectives->obj[i]->weight = weights[i];
04640 }
04641 if(objectiveCoefficients != NULL)
04642 {
04643 for(i = 0; i < number; i++)
04644 {
04645 int n = (&objectiveCoefficients[i] == NULL || objectiveCoefficients[i]->indexes == NULL)?0:objectiveCoefficients[i]->number;
04646 instanceData->objectives->obj[i]->numberOfObjCoef = n;
04647 if(n == 0)
04648 {
04649 instanceData->objectives->obj[i]->coef = NULL;
04650 }
04651 else
04652 {
04653 instanceData->objectives->obj[i]->coef = new ObjCoef*[n];
04654 for(j = 0; j < n; j++)
04655 {
04656 instanceData->objectives->obj[i]->coef[j] = new ObjCoef();
04657 instanceData->objectives->obj[i]->coef[j]->idx = objectiveCoefficients[i]->indexes[j];
04658 instanceData->objectives->obj[i]->coef[j]->value = objectiveCoefficients[i]->values[j];
04659 }
04660 }
04661 }
04662 }
04663 return true;
04664 }
04665 catch(const ErrorClass& eclass)
04666 {
04667 throw ErrorClass( eclass.errormsg);
04668 }
04669 }
04670
04671
04672 bool OSInstance::setConstraintNumber(int number)
04673 {
04674 if(number < 0) return false;
04675 if(instanceData->constraints == NULL) instanceData->constraints = new Constraints();
04676 if(number == 0)
04677 {
04678 instanceData->constraints->numberOfConstraints = 0;
04679 instanceData->constraints->con = 0;
04680 return true;
04681 }
04682 instanceData->constraints->numberOfConstraints = number;
04683 if(instanceData->constraints->con == 0 )
04684 {
04685 instanceData->constraints->con = new Constraint*[number];
04686 }
04687 return true;
04688 }
04689
04690 bool OSInstance::addConstraint(int index, string name, double lowerBound, double upperBound, double constant)
04691 {
04692 instanceData->constraints->con[ index] = new Constraint();
04693 if(index < 0 || instanceData->constraints->numberOfConstraints <= 0 || index >= instanceData->constraints->numberOfConstraints) return false;
04694 instanceData->constraints->con[ index]->name = name;
04695 if(lowerBound != -OSDBL_MAX && lowerBound != -OSDBL_MAX) instanceData->constraints->con[ index]->lb = lowerBound;
04696 if(upperBound != OSDBL_MAX && upperBound != OSDBL_MAX)instanceData->constraints->con[ index]->ub = upperBound;
04697 instanceData->constraints->con[ index]->constant = constant;
04698 return true;
04699 }
04700
04701
04702 bool OSInstance::setConstraints(int number, string* names, double* lowerBounds, double* upperBounds, double* constants)
04703 {
04704 if(number < 0) return false;
04705 if(number == 0)
04706 {
04707 return true;
04708 }
04709 try
04710 {
04711
04712 if(instanceData->constraints == NULL)
04713 {
04714 throw ErrorClass("there is no constraints object");
04715 }
04716 if(instanceData->constraints->numberOfConstraints != number)
04717 {
04718 throw ErrorClass("input number of constraints not equal to number in class");
04719 }
04720 int i = 0;
04721 for(i = 0; i < number; i++)
04722 {
04723 instanceData->constraints->con[i] = new Constraint();
04724 }
04725 if(names != NULL)
04726 {
04727 for(i = 0; i < number; i++) instanceData->constraints->con[i]->name = names[i];
04728 }
04729 if(lowerBounds != NULL)
04730 {
04731 for(i = 0; i < number; i++)
04732 {
04733 if(lowerBounds[i] != -OSDBL_MAX && lowerBounds[i] != -OSDBL_MAX)instanceData->constraints->con[i]->lb = lowerBounds[i];
04734 }
04735 }
04736 if(upperBounds != NULL)
04737 {
04738 for(i = 0; i < number; i++)
04739 {
04740 if(upperBounds[i] != OSDBL_MAX && upperBounds[i] != OSDBL_MAX)instanceData->constraints->con[i]->ub = upperBounds[i];
04741 }
04742 }
04743 if(constants != NULL)
04744 {
04745 for(i = 0; i < number; i++) instanceData->constraints->con[i]->constant = constants[i];
04746 }
04747 return true;
04748 }
04749 catch(const ErrorClass& eclass)
04750 {
04751 throw ErrorClass( eclass.errormsg);
04752 }
04753 }
04754
04755 bool OSInstance::setLinearConstraintCoefficients(int numberOfValues, bool isColumnMajor,
04756 double* values, int valuesBegin, int valuesEnd,
04757 int* indexes, int indexesBegin, int indexesEnd,
04758 int* starts, int startsBegin, int startsEnd)
04759 {
04760 if(numberOfValues < 0) return false;
04761 if(instanceData->linearConstraintCoefficients == NULL)
04762 instanceData->linearConstraintCoefficients = new LinearConstraintCoefficients() ;
04763 if(numberOfValues == 0) return true;
04764 if((values == 0 ) ||
04765 (valuesBegin < 0 || (valuesEnd - valuesBegin + 1) != numberOfValues) ||
04766 (indexes == 0) ||
04767 (indexesBegin < 0 || (indexesEnd - indexesBegin + 1) != numberOfValues) ||
04768 (starts == 0 ) ||
04769 (startsBegin < 0 || startsBegin >= startsEnd)) return false;
04770 instanceData->linearConstraintCoefficients->numberOfValues = numberOfValues;
04771
04772
04773 if (instanceData->linearConstraintCoefficients->start == NULL)
04774 instanceData->linearConstraintCoefficients->start = new IntVector();
04775 else
04776 if (instanceData->linearConstraintCoefficients->start->el != NULL)
04777 delete [] instanceData->linearConstraintCoefficients->start->el;
04778
04779 instanceData->linearConstraintCoefficients->start->el = (starts+startsBegin);
04780 instanceData->linearConstraintCoefficients->start->numberOfEl = startsEnd - startsBegin + 1;
04781 instanceData->linearConstraintCoefficients->iNumberOfStartElements = startsEnd - startsBegin + 1;
04782
04783
04784 if (instanceData->linearConstraintCoefficients->value == NULL)
04785 instanceData->linearConstraintCoefficients->value = new DoubleVector();
04786 else
04787 if (instanceData->linearConstraintCoefficients->value->el != NULL)
04788 delete[] instanceData->linearConstraintCoefficients->value->el;
04789
04790 instanceData->linearConstraintCoefficients->value->el = (values+valuesBegin);
04791 instanceData->linearConstraintCoefficients->value->numberOfEl = numberOfValues;
04792
04793
04794 if(isColumnMajor)
04795 {
04796 if (instanceData->linearConstraintCoefficients->rowIdx == NULL)
04797 instanceData->linearConstraintCoefficients->rowIdx = new IntVector();
04798 else
04799 if (instanceData->linearConstraintCoefficients->rowIdx->el != NULL)
04800 delete[] instanceData->linearConstraintCoefficients->rowIdx->el;
04801
04802 instanceData->linearConstraintCoefficients->rowIdx->el = (indexes+indexesBegin);
04803 instanceData->linearConstraintCoefficients->rowIdx->numberOfEl = numberOfValues;
04804 }
04805 else
04806 {
04807 if (instanceData->linearConstraintCoefficients->colIdx == NULL)
04808 instanceData->linearConstraintCoefficients->colIdx = new IntVector();
04809 else
04810 if (instanceData->linearConstraintCoefficients->colIdx->el != NULL)
04811 delete[] instanceData->linearConstraintCoefficients->colIdx->el;
04812
04813 instanceData->linearConstraintCoefficients->colIdx->el = (indexes+indexesBegin);
04814 instanceData->linearConstraintCoefficients->colIdx->numberOfEl = numberOfValues;
04815 }
04816 return true;
04817 }
04818
04819
04820 bool OSInstance::copyLinearConstraintCoefficients(int numberOfValues, bool isColumnMajor,
04821 double* values, int valuesBegin, int valuesEnd,
04822 int* indexes, int indexesBegin, int indexesEnd,
04823 int* starts, int startsBegin, int startsEnd)
04824 {
04825 if (numberOfValues < 0) return false;
04826 if (instanceData->linearConstraintCoefficients == NULL)
04827 instanceData->linearConstraintCoefficients = new LinearConstraintCoefficients() ;
04828 if (numberOfValues == 0) return true;
04829 if ((values == 0 ) ||
04830 (valuesBegin < 0 || (valuesEnd - valuesBegin + 1) != numberOfValues) ||
04831 (indexes == 0) ||
04832 (indexesBegin < 0 || (indexesEnd - indexesBegin + 1) != numberOfValues) ||
04833 (starts == 0 ) ||
04834 (startsBegin < 0 || startsBegin >= startsEnd)) return false;
04835 instanceData->linearConstraintCoefficients->numberOfValues = numberOfValues;
04836 int i = 0;
04837 int k;
04838
04839
04840 if (instanceData->linearConstraintCoefficients->start == NULL)
04841 instanceData->linearConstraintCoefficients->start = new IntVector();
04842 else
04843 delete [] instanceData->linearConstraintCoefficients->start->el;
04844
04845 instanceData->linearConstraintCoefficients->start->el = new int[startsEnd - startsBegin + 1];
04846 k = 0;
04847 for(i = startsBegin; i <= startsEnd; i++)
04848 {
04849 instanceData->linearConstraintCoefficients->start->el[k] = starts[i];
04850 k++;
04851 }
04852
04853 instanceData->linearConstraintCoefficients->start->numberOfEl = startsEnd - startsBegin + 1;
04854
04855
04856 if (instanceData->linearConstraintCoefficients->value == NULL)
04857 instanceData->linearConstraintCoefficients->value = new DoubleVector();
04858 else
04859 delete [] instanceData->linearConstraintCoefficients->value->el;
04860
04861 instanceData->linearConstraintCoefficients->value->el = new double[numberOfValues];
04862 k = 0;
04863 for(i = valuesBegin; i <= valuesEnd; i++)
04864 {
04865 instanceData->linearConstraintCoefficients->value->el[k] = values[i];
04866 k++;
04867 }
04868 instanceData->linearConstraintCoefficients->value->numberOfEl = numberOfValues;
04869
04870
04871 if(isColumnMajor)
04872 {
04873 if (instanceData->linearConstraintCoefficients->rowIdx == NULL)
04874 instanceData->linearConstraintCoefficients->rowIdx = new IntVector();
04875 else
04876 delete [] instanceData->linearConstraintCoefficients->rowIdx->el;
04877
04878 instanceData->linearConstraintCoefficients->rowIdx->el = new int[numberOfValues];
04879 k = 0;
04880 for(i = indexesBegin; i <= indexesEnd; i++)
04881 {
04882 instanceData->linearConstraintCoefficients->rowIdx->el[k] = indexes[i];
04883 k++;
04884 }
04885 instanceData->linearConstraintCoefficients->rowIdx->numberOfEl = k;
04886 }
04887 else
04888 {
04889 if (instanceData->linearConstraintCoefficients->colIdx == NULL)
04890 instanceData->linearConstraintCoefficients->colIdx = new IntVector();
04891 else
04892 delete [] instanceData->linearConstraintCoefficients->colIdx->el;
04893
04894 instanceData->linearConstraintCoefficients->colIdx->el = new int[numberOfValues];
04895 k = 0;
04896 for(i = indexesBegin; i <= indexesEnd; i++)
04897 {
04898 instanceData->linearConstraintCoefficients->colIdx->el[k] = indexes[i];
04899 k++;
04900 }
04901 instanceData->linearConstraintCoefficients->colIdx->numberOfEl = k;
04902 }
04903 return true;
04904 }
04905
04906
04907 bool OSInstance::setNumberOfQuadraticTerms(int nq)
04908 {
04909 if (nq < 0)
04910 throw ErrorClass("number of quadratic terms cannot be negative");
04911 if (instanceData == NULL) instanceData = new InstanceData();
04912 if (instanceData->quadraticCoefficients == NULL)
04913 instanceData->quadraticCoefficients = new QuadraticCoefficients();
04914 m_iQuadraticTermNumber = nq;
04915 instanceData->quadraticCoefficients->numberOfQuadraticTerms = nq;
04916 return true;
04917 }
04918
04919
04920 bool OSInstance::setQuadraticCoefficients(int number,
04921 int* rowIndexes, int* varOneIndexes, int* varTwoIndexes,
04922 double* coefficients, int begin, int end)
04923 {
04924 if(number < 0) return false;
04925 if(number != (end - begin) + 1) return false;
04926 if(number == 0)
04927 {
04928 instanceData->quadraticCoefficients = NULL;
04929 return true;
04930 }
04931 if( (rowIndexes == 0) ||
04932 (varOneIndexes == 0) ||
04933 (varTwoIndexes == 0) ||
04934 (coefficients == 0) ) return false;
04935 if (instanceData->quadraticCoefficients == NULL)
04936 instanceData->quadraticCoefficients = new QuadraticCoefficients();
04937
04938 instanceData->quadraticCoefficients->numberOfQuadraticTerms = number;
04939 int i = 0;
04940
04941 if (instanceData->quadraticCoefficients->qTerm != NULL)
04942 delete [] instanceData->quadraticCoefficients->qTerm;
04943
04944 instanceData->quadraticCoefficients->qTerm = new QuadraticTerm*[number];
04945 for(i = 0; i < number; i++) instanceData->quadraticCoefficients->qTerm[i] = new QuadraticTerm();
04946 int k = 0;
04947 for(i = begin; i <= end; i++)
04948 {
04949 instanceData->quadraticCoefficients->qTerm[k]->idx = rowIndexes[i];
04950 instanceData->quadraticCoefficients->qTerm[k]->idxOne = varOneIndexes[i];
04951 instanceData->quadraticCoefficients->qTerm[k]->idxTwo = varTwoIndexes[i];
04952 instanceData->quadraticCoefficients->qTerm[k]->coef = coefficients[i];
04953 k++;
04954 }
04955 return true;
04956 }
04957
04958 bool OSInstance::setQuadraticTermsInNonlinearExpressions(int numQPTerms, int* rowIndexes, int* varOneIndexes, int* varTwoIndexes, double* coefficients)
04959 {
04960 instanceData->nonlinearExpressions->numberOfNonlinearExpressions = numQPTerms;
04961 instanceData->nonlinearExpressions->nl = new Nl*[ numQPTerms ];
04962
04963 OSnLNode *nlNodePoint;
04964 OSnLNodeVariable *nlNodeVariablePoint;
04965 std::vector<ExprNode*> nlNodeVec;
04966
04967
04968 int i;
04969 for(i = 0; i < numQPTerms; i++)
04970 {
04971 instanceData->nonlinearExpressions->nl[ i] = new Nl();
04972 instanceData->nonlinearExpressions->nl[ i]->idx = rowIndexes[ i];
04973 instanceData->nonlinearExpressions->nl[ i]->osExpressionTree = new ScalarExpressionTree();
04974
04975 nlNodeVariablePoint = new OSnLNodeVariable();
04976 nlNodeVariablePoint->idx = varOneIndexes[ i];
04977
04978 nlNodeVariablePoint->coef = coefficients[ i];
04979 nlNodeVec.push_back( nlNodeVariablePoint);
04980
04981 nlNodeVariablePoint = new OSnLNodeVariable();
04982 nlNodeVariablePoint->idx = varTwoIndexes[ i];
04983 nlNodeVec.push_back( nlNodeVariablePoint);
04984
04985 nlNodePoint = new OSnLNodeTimes();
04986 nlNodeVec.push_back( (OSnLNode*)nlNodePoint);
04987
04988
04989 instanceData->nonlinearExpressions->nl[ i]->osExpressionTree->m_treeRoot =
04990 ((OSnLNode*)nlNodeVec[ 0])->createExpressionTreeFromPostfix( nlNodeVec);
04991 nlNodeVec.clear();
04992 }
04993 return true;
04994 }
04995
04996 bool OSInstance::setNonlinearExpressions(int nexpr, Nl** root)
04997 {
04998 if(nexpr < 0) return false;
04999
05000 if(nexpr == 0)
05001 {
05002 instanceData->nonlinearExpressions = 0;
05003 return true;
05004 }
05005
05006 if (instanceData->nonlinearExpressions == NULL)
05007 instanceData->nonlinearExpressions = new NonlinearExpressions();
05008 instanceData->nonlinearExpressions->numberOfNonlinearExpressions = nexpr;
05009 instanceData->nonlinearExpressions->nl = new Nl*[nexpr];
05010
05011 for (int i=0; i < nexpr; i++)
05012 {
05013 instanceData->nonlinearExpressions->nl[i] = new Nl();
05014 instanceData->nonlinearExpressions->nl[i]->idx = root[i]->idx;
05015 instanceData->nonlinearExpressions->nl[i]->osExpressionTree = new ScalarExpressionTree();
05016 instanceData->nonlinearExpressions->nl[i]->osExpressionTree->m_treeRoot
05017 = (OSnLNode*)root[i]->osExpressionTree->m_treeRoot->copyNodeAndDescendants();
05018 }
05019 return true;
05020 }
05021
05022 bool OSInstance::initializeNonLinearStructures( )
05023 {
05024 std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
05025 if( m_bNonLinearStructuresInitialized == true) return true;
05026 if( m_bProcessVariables == false) processVariables();
05027 if( m_bProcessObjectives == false) processObjectives();
05028 if( m_bProcessConstraints == false) processConstraints();
05029 m_iVariableNumber = getVariableNumber();
05030 m_iObjectiveNumber = getObjectiveNumber();
05031 m_iConstraintNumber = getConstraintNumber();
05032
05033 if( m_bProcessExpressionTrees == false) getAllNonlinearExpressionTrees();
05034
05035 if( m_bDuplicateExpressionTreesMap == false) duplicateExpressionTreesMap();
05036
05037 for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
05038 {
05039 (posMapExpTree->second)->getVariableIndicesMap() ;
05040 }
05041
05042 if(getNumberOfQuadraticTerms() > 0) addQTermsToExpressionTree();
05043
05044 getAllNonlinearVariablesIndexMap( );
05045 getDenseObjectiveCoefficients();
05046 m_mdConstraintFunctionValues = new double[ this->getConstraintNumber()];
05047 m_mdObjectiveFunctionValues = new double[ this->getObjectiveNumber()];
05048
05049 m_bNonLinearStructuresInitialized = true;
05050 m_bProcessVariables = true;
05051 m_bProcessObjectives = true;
05052 m_bProcessConstraints = true;
05053 m_bProcessExpressionTrees = true;
05054 m_bDuplicateExpressionTreesMap = true;
05055 return true;
05056 }
05057
05058 SparseJacobianMatrix *OSInstance::getJacobianSparsityPattern( )
05059 {
05060
05061
05062
05063
05064 #ifndef NDEBUG
05065 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
05066 "in getJacobianSparsityPattern");
05067 #endif
05068 if( m_bSparseJacobianCalculated == true) return m_sparseJacMatrix;
05069
05070 getLinearConstraintCoefficientMajor();
05071
05072 if( m_bNonLinearStructuresInitialized == false) initializeNonLinearStructures( );
05073 try
05074 {
05075 if( m_bColumnMajor == true)
05076 {
05077 if( getSparseJacobianFromColumnMajor( ) == false) throw ErrorClass("An error occurred in getSpareJacobianFromColumnMajor");
05078 }
05079 else
05080 {
05081 if( getSparseJacobianFromRowMajor( ) == false) throw ErrorClass("An error occurred in getSpareJacobianFromRowMajor");
05082 }
05083 }
05084 catch(const ErrorClass& eclass)
05085 {
05086 throw ErrorClass( eclass.errormsg);
05087 }
05088
05089 m_sparseJacMatrix = new SparseJacobianMatrix();
05090
05091
05092 m_sparseJacMatrix->bDeleteArrays = false;
05093 m_sparseJacMatrix->valueSize = m_iJacValueSize;
05094 m_sparseJacMatrix->starts = m_miJacStart;
05095 m_sparseJacMatrix->conVals = m_miJacNumConTerms;
05096 m_sparseJacMatrix->indexes = m_miJacIndex;
05097 m_sparseJacMatrix->values = m_mdJacValue;
05098 m_bSparseJacobianCalculated = true;
05099 return m_sparseJacMatrix;
05100 }
05101
05102 bool OSInstance::addQTermsToExressionTree()
05103 {
05104 return addQTermsToExpressionTree();
05105 }
05106
05107 bool OSInstance::addQTermsToExpressionTree()
05108 {
05109 std::ostringstream outStr;
05110 int i, k, idx;
05111
05112 int numQTerms = instanceData->quadraticCoefficients->numberOfQuadraticTerms;
05113 if(numQTerms <= 0 || m_bQTermsAdded == true) return true;
05114 OSnLNodeVariable* nlNodeVariableOne;
05115 OSnLNodeVariable* nlNodeVariableTwo;
05116 OSnLNodeTimes* nlNodeTimes;
05117 OSnLNodePlus* nlNodePlus;
05118 ScalarExpressionTree* expTree;
05119 getQuadraticTerms();
05120 #ifndef NDEBUG
05121
05122 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "PROCESSING QUADRATIC TERMS");
05123 #endif
05124 for(i = 0; i < numQTerms; i++)
05125 {
05126 idx = m_quadraticTerms->rowIndexes[ i];
05127
05128 #ifndef NDEBUG
05129 outStr.str("");
05130 outStr.clear();
05131 outStr << "PROCESSING QTERM " << i << std::endl;
05132 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
05133 #endif
05134
05135 if( m_mapExpressionTreesMod.find( idx) != m_mapExpressionTreesMod.end() )
05136 {
05137
05138
05139
05140 nlNodeVariableOne = new OSnLNodeVariable();
05141 nlNodeVariableOne->idx = m_quadraticTerms->varOneIndexes[ i];
05142
05143
05144 expTree = m_mapExpressionTreesMod[ idx];
05145 if( expTree->m_bIndexMapGenerated == false) expTree->getVariableIndicesMap();
05146 if( (*expTree->mapVarIdx).find( nlNodeVariableOne->idx) == (*expTree->mapVarIdx).end() )
05147 {
05148
05149 (*expTree->mapVarIdx)[ nlNodeVariableOne->idx] = 1;
05150 #ifndef NDEBUG
05151 outStr.str("");
05152 outStr.clear();
05153 outStr << "ADDED THE FOLLOWING VARIABLE TO THE MAP: " << nlNodeVariableOne->idx << std::endl;
05154 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
05155 #endif
05156 }
05157 nlNodeVariableOne->coef = m_quadraticTerms->coefficients[ i];
05158 nlNodeVariableTwo = new OSnLNodeVariable();
05159 nlNodeVariableTwo->idx = m_quadraticTerms->varTwoIndexes[ i];
05160
05161
05162 if( (*expTree->mapVarIdx).find( nlNodeVariableTwo->idx) == (*expTree->mapVarIdx).end() )
05163 {
05164
05165 k = (*expTree->mapVarIdx).size();
05166 (*expTree->mapVarIdx)[ nlNodeVariableTwo->idx] = k + 1;
05167 #ifndef NDEBUG
05168 outStr.str("");
05169 outStr.clear();
05170 outStr << "ADDED THE FOLLOWING VARIABLE TO THE MAP" << nlNodeVariableTwo->idx << std::endl;
05171 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
05172 #endif
05173 }
05174 nlNodeVariableTwo->coef = 1.;
05175
05176 nlNodeTimes = new OSnLNodeTimes();
05177 nlNodeTimes->m_mChildren[ 0] = nlNodeVariableOne;
05178 nlNodeTimes->m_mChildren[ 1] = nlNodeVariableTwo;
05179
05180 nlNodePlus = new OSnLNodePlus();
05181 nlNodePlus->m_mChildren[ 0] = (OSnLNode*)expTree->m_treeRoot;
05182 nlNodePlus->m_mChildren[ 1] = nlNodeTimes;
05183
05184 expTree->m_treeRoot = nlNodePlus ;
05185
05186 if(expTree->m_bIndexMapGenerated == true)
05187 {
05188 delete expTree->mapVarIdx;
05189 expTree->mapVarIdx = NULL;
05190 expTree->m_bIndexMapGenerated = false;
05191 }
05192
05193
05194
05195 }
05196 else
05197 {
05198
05199 nlNodeVariableOne = new OSnLNodeVariable();
05200 nlNodeVariableOne->idx = m_quadraticTerms->varOneIndexes[ i];
05201 nlNodeVariableOne->coef = m_quadraticTerms->coefficients[ i];
05202 nlNodeVariableTwo = new OSnLNodeVariable();
05203 nlNodeVariableTwo->idx = m_quadraticTerms->varTwoIndexes[ i];
05204 nlNodeVariableTwo->coef = 1.;
05205
05206 nlNodeTimes = new OSnLNodeTimes();
05207 nlNodeTimes->m_mChildren[ 0] = nlNodeVariableOne;
05208 nlNodeTimes->m_mChildren[ 1] = nlNodeVariableTwo;
05209
05210 expTree = new ScalarExpressionTree();
05211 expTree->m_treeRoot = nlNodeTimes ;
05212 expTree->mapVarIdx = expTree->getVariableIndicesMap();
05213 m_mapExpressionTreesMod[ idx ] = expTree;
05214 if(idx < 0)
05215 {
05216 m_iObjectiveNumberNonlinear++;
05217 m_bProcessExpressionTrees = true;
05218 }
05219 else
05220 {
05221 m_iConstraintNumberNonlinear++;
05222 m_bProcessExpressionTrees = true;
05223 }
05224 #ifndef NDEBUG
05225 outStr.str("");
05226 outStr.clear();
05227 outStr << "NUMBER OF EXPRESSION TREES = " << m_mapExpressionTreesMod.size() <<std::endl;
05228 outStr << "NUMBER OF NONLINEAR OBJECTIVES = " << getNumberOfNonlinearObjectives() <<std::endl;
05229 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
05230 #endif
05231 }
05232
05233 if(m_iNonlinearExpressionNumber <= 0) m_mapExpressionTrees = m_mapExpressionTreesMod;
05234 m_bQTermsAdded =true;
05235 }
05236 return true;
05237 }
05238
05239
05240 bool OSInstance::setMatrixNumber(int number)
05241 {
05242 if(number < 0) return false;
05243 if(instanceData->matrices == NULL) instanceData->matrices = new Matrices();
05244 if(number == 0)
05245 {
05246 instanceData->matrices->numberOfMatrices = 0;
05247 instanceData->matrices->matrix = NULL;
05248 return true;
05249 }
05250 instanceData->matrices->numberOfMatrices = number;
05251 instanceData->matrices->matrix = new OSMatrix*[number];
05252 return true;
05253 }
05254
05255 bool OSInstance::addMatrix(int arrayIndex, std::string name, int numberOfRows, int numberOfColumns,
05256 ENUM_MATRIX_SYMMETRY symmetry, ENUM_MATRIX_TYPE matrixType,
05257 unsigned int inumberOfChildren, MatrixNode **m_mChildren)
05258 {
05259 if (instanceData->matrices->numberOfMatrices <= 0) return false;
05260 if (arrayIndex < 0 || arrayIndex > instanceData->matrices->numberOfMatrices) return false;
05261 if (instanceData->matrices->matrix == NULL) return false;
05262 instanceData->matrices->matrix[arrayIndex] = new OSMatrix();
05263 return instanceData->matrices->matrix[arrayIndex]->setMatrix(name,numberOfRows,numberOfColumns,symmetry,
05264 matrixType,inumberOfChildren,m_mChildren);
05265 }
05266
05267 bool OSInstance::setConeNumber(int number)
05268 {
05269 if (number < 0) return false;
05270 if (instanceData->cones == NULL) instanceData->cones = new Cones();
05271 instanceData->cones->numberOfCones = number;
05272
05273 if (number == 0)
05274 instanceData->cones->cone = NULL;
05275 else
05276 instanceData->cones->cone = new Cone*[number];
05277 return true;
05278 }
05279
05280 bool OSInstance::addCone(int arrayIndex, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType,
05281 std::string name, int numberOfOtherIndexes, int* otherIndexes)
05282 {
05283 if (instanceData->cones->numberOfCones <= 0) return false;
05284 if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
05285 if (instanceData->cones->cone == NULL) return false;
05286
05287 switch (coneType)
05288 {
05289
05290 case ENUM_CONE_TYPE_nonnegative:
05291 instanceData->cones->cone[arrayIndex] = new NonnegativeCone();
05292 ((NonnegativeCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
05293 ((NonnegativeCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
05294 ((NonnegativeCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
05295 ((NonnegativeCone*)instanceData->cones->cone[arrayIndex])->name = name;
05296 ((NonnegativeCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
05297 ((NonnegativeCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
05298 break;
05299 case ENUM_CONE_TYPE_nonpositive:
05300 instanceData->cones->cone[arrayIndex] = new NonpositiveCone();
05301 ((NonpositiveCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
05302 ((NonpositiveCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
05303 ((NonpositiveCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
05304 ((NonpositiveCone*)instanceData->cones->cone[arrayIndex])->name = name;
05305 ((NonpositiveCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
05306 ((NonpositiveCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
05307 break;
05308 case ENUM_CONE_TYPE_copositiveMatrices:
05309 instanceData->cones->cone[arrayIndex] = new CopositiveMatricesCone();
05310 ((CopositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
05311 ((CopositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
05312 ((CopositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
05313 ((CopositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->name = name;
05314 ((CopositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
05315 ((CopositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
05316 break;
05317 case ENUM_CONE_TYPE_completelyPositiveMatrices:
05318 instanceData->cones->cone[arrayIndex] = new CompletelyPositiveMatricesCone();
05319 ((CompletelyPositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
05320 ((CompletelyPositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
05321 ((CompletelyPositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
05322 ((CompletelyPositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->name = name;
05323 ((CompletelyPositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes
05324 = numberOfOtherIndexes;
05325 ((CompletelyPositiveMatricesCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
05326 break;
05327 default:
05328 return false;
05329 }
05330 return true;
05331 }
05332
05333 bool OSInstance::addCone(int arrayIndex, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType,
05334 std::string name, int numberOfComponents, int* components,
05335 int numberOfOtherIndexes, int* otherIndexes)
05336 {
05337 if (instanceData->cones->numberOfCones <= 0) return false;
05338 if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
05339 if (instanceData->cones->cone == NULL) return false;
05340
05341 switch (coneType)
05342 {
05343 case ENUM_CONE_TYPE_product:
05344 instanceData->cones->cone[arrayIndex] = new ProductCone();
05345 ((ProductCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
05346 ((ProductCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
05347 ((ProductCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
05348 ((ProductCone*)instanceData->cones->cone[arrayIndex])->name = name;
05349 ((ProductCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
05350 ((ProductCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
05351
05352 ((ProductCone*)instanceData->cones->cone[arrayIndex])->factors = new IntVector();
05353 ((ProductCone*)instanceData->cones->cone[arrayIndex])->factors->numberOfEl = numberOfComponents;
05354 ((ProductCone*)instanceData->cones->cone[arrayIndex])->factors->el = components;
05355 break;
05356 case ENUM_CONE_TYPE_intersection:
05357 instanceData->cones->cone[arrayIndex] = new IntersectionCone();
05358 ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
05359 ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
05360 ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
05361 ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->name = name;
05362 ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
05363 ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
05364
05365 ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->components = new IntVector();
05366 ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->components->numberOfEl = numberOfComponents;
05367 ((IntersectionCone*)instanceData->cones->cone[arrayIndex])->components->el = components;
05368 break;
05369 default:
05370 return false;
05371 }
05372 return true;
05373 }
05374
05375 bool OSInstance::addCone(int arrayIndex, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType,
05376 std::string name, int referenceIdx, int numberOfOtherIndexes, int* otherIndexes)
05377 {
05378 if (instanceData->cones->numberOfCones <= 0) return false;
05379 if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
05380 if (instanceData->cones->cone == NULL) return false;
05381
05382 switch (coneType)
05383
05384 {
05385
05386
05387
05388
05389
05390
05391
05392
05393
05394
05395
05396
05397
05398
05399
05400
05401
05402
05403
05404
05405
05406
05407 case ENUM_CONE_TYPE_polyhedral:
05408 instanceData->cones->cone[arrayIndex] = new PolyhedralCone();
05409 ((PolyhedralCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
05410 ((PolyhedralCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
05411 ((PolyhedralCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
05412 ((PolyhedralCone*)instanceData->cones->cone[arrayIndex])->name = name;
05413 ((PolyhedralCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
05414 ((PolyhedralCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
05415 ((PolyhedralCone*)instanceData->cones->cone[arrayIndex])->referenceMatrixIdx = referenceIdx;
05416 break;
05417 default:
05418 return false;
05419 }
05420
05421 return true;
05422 }
05423
05424 bool OSInstance::addCone(int arrayIndex, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType,
05425 std::string name, std::string semidefiniteness, int numberOfOtherIndexes, int* otherIndexes)
05426 {
05427 if (instanceData->cones->numberOfCones <= 0) return false;
05428 if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
05429 if (instanceData->cones->cone == NULL) return false;
05430
05431 if (coneType == ENUM_CONE_TYPE_semidefinite)
05432 {
05433 instanceData->cones->cone[arrayIndex] = new SemidefiniteCone();
05434 ((SemidefiniteCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
05435 ((SemidefiniteCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
05436 ((SemidefiniteCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
05437 ((SemidefiniteCone*)instanceData->cones->cone[arrayIndex])->name = name;
05438 ((SemidefiniteCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
05439 ((SemidefiniteCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
05440 ((SemidefiniteCone*)instanceData->cones->cone[arrayIndex])->semidefiniteness = semidefiniteness;
05441 return true;
05442 }
05443 else
05444 return false;
05445 }
05446
05447 bool OSInstance::addCone(int arrayIndex, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType,
05448 std::string name, int distortionMatrixIdx, double normFactor, int axisDirection,
05449 int numberOfOtherIndexes, int* otherIndexes)
05450 {
05451 if (instanceData->cones->numberOfCones <= 0) return false;
05452 if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
05453 if (instanceData->cones->cone == NULL) return false;
05454
05455 if (coneType == ENUM_CONE_TYPE_quadratic)
05456 {
05457 instanceData->cones->cone[arrayIndex] = new QuadraticCone();
05458 ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
05459 ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
05460 ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
05461 ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->name = name;
05462 ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
05463 ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
05464 ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->distortionMatrixIdx = distortionMatrixIdx;
05465 ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->normScaleFactor = normFactor;
05466 ((QuadraticCone*)instanceData->cones->cone[arrayIndex])->axisDirection = axisDirection;
05467 return true;
05468 }
05469 else
05470 return false;
05471 }
05472
05473 bool OSInstance::addCone(int arrayIndex, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType,
05474 std::string name, int distortionMatrixIdx, double normFactor, int firstAxisDirection,
05475 int secondAxisDirection, int numberOfOtherIndexes, int* otherIndexes)
05476 {
05477 if (instanceData->cones->numberOfCones <= 0) return false;
05478 if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
05479 if (instanceData->cones->cone == NULL) return false;
05480
05481 if (instanceData->cones->numberOfCones <= 0) return false;
05482 if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
05483 if (instanceData->cones->cone == NULL) return false;
05484
05485 if (coneType == ENUM_CONE_TYPE_rotatedQuadratic)
05486 {
05487 instanceData->cones->cone[arrayIndex] = new RotatedQuadraticCone();
05488 ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->numberOfRows = numberOfRows;
05489 ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->numberOfColumns = numberOfColumns;
05490 ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->coneType = coneType;
05491 ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->name = name;
05492 ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->numberOfOtherIndexes = numberOfOtherIndexes;
05493 ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->otherIndexes = otherIndexes;
05494 ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->distortionMatrixIdx = distortionMatrixIdx;
05495 ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->normScaleFactor = normFactor;
05496 ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->firstAxisDirection = firstAxisDirection;
05497 ((RotatedQuadraticCone*)instanceData->cones->cone[arrayIndex])->secondAxisDirection = secondAxisDirection;
05498 return true;
05499 }
05500 else
05501 return false;
05502 }
05503
05504 bool OSInstance::addCone(int arrayIndex, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType,
05505 std::string name, int distortionMatrixIdx, double normFactor, int axisDirection, double pNorm,
05506 int numberOfOtherIndexes, int* otherIndexes)
05507 {
05508 if (instanceData->cones->numberOfCones <= 0) return false;
05509 if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
05510 if (instanceData->cones->cone == NULL) return false;
05511
05512
05513
05514
05515
05516
05517
05518
05519
05520
05521
05522
05523
05524
05525
05526
05527
05528
05529
05530 return false;
05531 }
05532
05533 bool OSInstance::addCone(int arrayIndex, int numberOfRows, int numberOfColumns, ENUM_CONE_TYPE coneType,
05534 std::string name, int maxDegree, int numberOfUB, double* ub, int numberOfLB, double* lb,
05535 int numberOfOtherIndexes, int* otherIndexes)
05536 {
05537 if (instanceData->cones->numberOfCones <= 0) return false;
05538 if (arrayIndex < 0 || arrayIndex > instanceData->cones->numberOfCones) return false;
05539 if (instanceData->cones->cone == NULL) return false;
05540
05541 switch (coneType)
05542 {
05543
05544
05545
05546
05547
05548
05549
05550
05551
05552
05553
05554
05555
05556
05557
05558
05559
05560
05561
05562
05563
05564
05565
05566
05567
05568
05569
05570
05571
05572
05573
05574
05575
05576
05577
05578
05579 default:
05580 return false;
05581 }
05582 return true;
05583 }
05584
05585 std::string OSInstance::printModel( )
05586 {
05587 std::string resultString = "";
05588 ostringstream outStr;
05589 outStr << "";
05590 int numCon;
05591 int numObj;
05592 int numVar;
05593 int i;
05594 numCon = this->getConstraintNumber();
05595 numObj = this->getObjectiveNumber();
05596 numVar = this->getVariableNumber();
05597 this->initForAlgDiff( );
05598 outStr << std::endl;
05599 std::string *objMaxOrMin = getObjectiveMaxOrMins();
05600 outStr << "Objectives:" << std::endl;
05601 for(i = 0; i < numObj; i++)
05602 {
05603 outStr << objMaxOrMin[i] << ' ';
05604 outStr << this->printModel(-i-1);
05605 }
05606 outStr << std::endl;
05607 outStr << "Constraints:" << std::endl;
05608 for(i = 0; i < numCon; i++)
05609 {
05610 outStr << this->printModel( i);
05611 }
05612
05613 outStr << std::endl;
05614 outStr << "Variables:" << std::endl;
05615 if(m_bProcessVariables != true || bVariablesModified == true ) this->processVariables();
05616 for(i = 0; i < numVar; i++)
05617 {
05618 if(this->instanceData->variables->numberOfVariables > 0 && this->instanceData->variables->var[ i ]->name.size() > 0)
05619 {
05620 outStr << this->instanceData->variables->var[ i ]->name << ": ";
05621 }
05622
05623 {
05624 outStr << "x_";
05625 outStr << i;
05626 }
05627
05628
05629
05630
05631 outStr << " Type = " ;
05632 outStr << m_mcVariableTypes[i];
05633 outStr << " Lower Bound = ";
05634 outStr << os_dtoa_format( m_mdVariableLowerBounds[i]) ;
05635 outStr << " Upper Bound = ";
05636 outStr << os_dtoa_format( m_mdVariableUpperBounds[i]) ;
05637 outStr << std::endl;
05638 }
05639
05640
05641
05642
05643
05644
05645
05646
05647
05648 return outStr.str() ;
05649 }
05650
05651
05652 std::string OSInstance::printModel(int rowIdx )
05653 {
05654 std::string resultString = "";
05655
05656
05657 ostringstream outStr;
05658 outStr << "";
05659
05660 int j;
05661 int row_nonz = 0;
05662 int obj_nonz = 0;
05663 int varIdx = 0;
05664 bool addedLinearTerm = false;
05665
05666
05667 this->initForAlgDiff( );
05668
05669 if( rowIdx >= 0)
05670 {
05671 if (rowIdx < this->getConstraintNumber())
05672 {
05673 outStr << this->getConstraintNames()[ rowIdx] ;
05674 outStr << " ";
05675 if( m_bProcessConstraints != true || bConstraintsModified == true) this->processConstraints() ;
05676 if( m_mdConstraintLowerBounds[ rowIdx] > -OSDBL_MAX)
05677 {
05678 if(m_mdConstraintLowerBounds[ rowIdx] < m_mdConstraintUpperBounds[ rowIdx])
05679 {
05680 outStr << os_dtoa_format( m_mdConstraintLowerBounds[ rowIdx] );
05681 outStr << " <= ";
05682 }
05683 }
05684
05685 if(this->instanceData->linearConstraintCoefficients != NULL && this->instanceData->linearConstraintCoefficients->numberOfValues > 0)
05686 {
05687 if(m_linearConstraintCoefficientsInRowMajor == NULL)
05688 m_linearConstraintCoefficientsInRowMajor = this->getLinearConstraintCoefficientsInRowMajor();
05689 row_nonz = m_linearConstraintCoefficientsInRowMajor->starts[ rowIdx + 1] - m_linearConstraintCoefficientsInRowMajor->starts[ rowIdx];
05690
05691 for(j = 0; j < row_nonz; j++)
05692 {
05693 varIdx = m_linearConstraintCoefficientsInRowMajor->indexes[ m_linearConstraintCoefficientsInRowMajor->starts[ rowIdx] + j];
05694
05695 if(m_bSparseJacobianCalculated == false || (m_mapExpressionTreesMod.find( rowIdx) == m_mapExpressionTreesMod.end() ) ||
05696 ( (*m_mapExpressionTreesMod[ rowIdx]->mapVarIdx).find( varIdx) == (*m_mapExpressionTreesMod[ rowIdx]->mapVarIdx).end()) )
05697 {
05698 outStr << os_dtoa_format( m_linearConstraintCoefficientsInRowMajor->values[ m_linearConstraintCoefficientsInRowMajor->starts[ rowIdx] + j] );
05699 outStr << "*";
05700
05701
05702
05703
05704
05705
05706 {
05707 outStr << "x_";
05708 outStr << varIdx;
05709 }
05710
05711
05712 if( j < row_nonz - 1) outStr << " + ";
05713 addedLinearTerm = true;
05714 }
05715 }
05716 }
05717 }
05718 else
05719 return "row index not found; print command ignored\n";
05720 }
05721 else
05722 {
05723 if(m_bProcessObjectives != true || bObjectivesModified == true) this->processObjectives() ;
05724 int obj_idx = -rowIdx - 1;
05725 if (obj_idx < this->getObjectiveNumber())
05726 {
05727 obj_nonz = m_miNumberOfObjCoef[ obj_idx];
05728 for(j = 0; j < obj_nonz; j++)
05729 {
05730 outStr << os_dtoa_format( m_mObjectiveCoefficients[obj_idx]->values[j] );
05731 outStr << "*";
05732 outStr << "x_";
05733 outStr << m_mObjectiveCoefficients[obj_idx]->indexes[j] ;
05734 if( j < obj_nonz - 1) outStr << " + ";
05735 }
05736 }
05737 else
05738 return "row index not found; print command ignored\n";
05739 }
05740 if( this->getNonlinearExpressionTree( rowIdx) != NULL)
05741 {
05742 if( (addedLinearTerm == true) || (obj_nonz > 0) ) outStr << " + " ;
05743 outStr << getNonlinearExpressionTreeInInfix( rowIdx);
05744
05745 }
05746
05747 if( rowIdx >= 0)
05748 {
05749 if( m_bProcessConstraints != true ) this->processConstraints() ;
05750 if( m_mdConstraintUpperBounds[ rowIdx] < OSDBL_MAX)
05751 {
05752 if(m_mdConstraintLowerBounds[ rowIdx] < m_mdConstraintUpperBounds[ rowIdx])
05753 {
05754 outStr << " <= ";
05755 }
05756 else
05757 {
05758 outStr << " = ";
05759 }
05760 outStr << os_dtoa_format( m_mdConstraintUpperBounds[ rowIdx] );
05761 }
05762 }
05763 outStr << std::endl;
05764 resultString = outStr.str();
05765 return resultString;
05766 }
05767
05768
05769 double OSInstance::calculateFunctionValue(int idx, double *x, bool new_x)
05770 {
05771 try
05772 {
05773 int i, j;
05774 double dvalue = 0;
05775 if( m_binitForAlgDiff == false) initForAlgDiff();
05776 if( m_bSparseJacobianCalculated == false) getJacobianSparsityPattern();
05777 if(idx >= 0)
05778 {
05779
05780 if( getConstraintNumber() <= idx ) throw
05781 ErrorClass("constraint index not valid in OSInstance::calculateFunctionValue");
05782 if( new_x == false) return *(m_mdConstraintFunctionValues + idx);
05783
05784 if( m_mapExpressionTreesMod.find( idx) != m_mapExpressionTreesMod.end() )
05785 {
05786 dvalue = m_mapExpressionTreesMod[ idx]->calculateFunction( x, new_x);
05787 }
05788
05789
05790 i = m_sparseJacMatrix->starts[ idx];
05791 j = m_sparseJacMatrix->starts[ idx + 1 ];
05792 while ( (i - m_sparseJacMatrix->starts[ idx]) < m_sparseJacMatrix->conVals[ idx] )
05793 {
05794 dvalue += m_sparseJacMatrix->values[ i]*x[ m_sparseJacMatrix->indexes[ i] ];
05795 i++;
05796 }
05797
05798 dvalue += m_mdConstraintConstants[ idx ];
05799 return dvalue;
05800 }
05801 else
05802 {
05803
05804 if( getObjectiveNumber() <= ( abs( idx) - 1) ) throw
05805 ErrorClass("objective function index not valid in OSInstance::calculateFunctionValue");
05806 if( new_x == false) return *(m_mdObjectiveFunctionValues + ( abs( idx) - 1));
05807
05808 if( m_mapExpressionTreesMod.find( idx) != m_mapExpressionTreesMod.end() )
05809 {
05810 dvalue = m_mapExpressionTreesMod[ idx]->calculateFunction( x, new_x);
05811 }
05812
05813 SparseVector **objCoef = getObjectiveCoefficients();
05814 SparseVector *obj = objCoef[ abs( idx) - 1];
05815 for(i = 0; i < obj->number; i++)
05816 {
05817 dvalue += x[ obj->indexes[i]]*(obj->values[ i]);
05818 }
05819
05820 dvalue += m_mdObjectiveConstants[ abs( idx) - 1 ];
05821
05822 *(m_mdObjectiveFunctionValues + ( abs( idx) - 1)) = dvalue;
05823 return *(m_mdObjectiveFunctionValues + ( abs( idx) - 1));
05824 }
05825 }
05826
05827 catch(const ErrorClass& eclass)
05828 {
05829 throw ErrorClass( eclass.errormsg);
05830 }
05831 }
05832
05833
05834 double *OSInstance::calculateAllConstraintFunctionValues( double* x, double *objLambda, double *conLambda,
05835 bool new_x, int highestOrder)
05836 {
05837 try
05838 {
05839 if( new_x == true || (highestOrder > m_iHighestOrderEvaluated) )
05840 getIterateResults(x, objLambda, conLambda, new_x, highestOrder);
05841 }
05842 catch(const ErrorClass& eclass)
05843 {
05844 throw ErrorClass( eclass.errormsg);
05845 }
05846 return m_mdConstraintFunctionValues;
05847 }
05848
05849
05850 double *OSInstance::calculateAllConstraintFunctionValues(double* x, bool new_x)
05851 {
05852 try
05853 {
05854 m_iHighestOrderEvaluated = -1;
05855 if( new_x == false) return m_mdConstraintFunctionValues;
05856 int idx, numConstraints;
05857 numConstraints = getConstraintNumber();
05858
05859 for(idx = 0; idx < numConstraints; idx++)
05860 {
05861 m_mdConstraintFunctionValues[ idx] = calculateFunctionValue(idx, x, new_x);
05862 }
05863
05864 }
05865 catch(const ErrorClass& eclass)
05866 {
05867 throw ErrorClass( eclass.errormsg);
05868 }
05869 return m_mdConstraintFunctionValues;
05870 }
05871
05872
05873 double *OSInstance::calculateAllObjectiveFunctionValues( double* x, double *objLambda, double *conLambda,
05874 bool new_x, int highestOrder)
05875 {
05876 try
05877 {
05878 if( new_x == true || (highestOrder > m_iHighestOrderEvaluated) )
05879 getIterateResults(x, objLambda, conLambda, new_x, highestOrder);
05880 }
05881 catch(const ErrorClass& eclass)
05882 {
05883 throw ErrorClass( eclass.errormsg);
05884 }
05885 return m_mdObjectiveFunctionValues;
05886 }
05887
05888
05889 double *OSInstance::calculateAllObjectiveFunctionValues( double* x, bool new_x)
05890 {
05891 try
05892 {
05893 m_iHighestOrderEvaluated = -1;
05894
05895 if( new_x == false) return m_mdObjectiveFunctionValues;
05896 int idx, numObjectives;
05897 numObjectives = getObjectiveNumber();
05898
05899 for(idx = 0; idx < numObjectives; idx++)
05900 {
05901 m_mdObjectiveFunctionValues[ idx] = calculateFunctionValue(-idx -1, x, new_x);
05902 }
05903 }
05904 catch(const ErrorClass& eclass)
05905 {
05906 throw ErrorClass( eclass.errormsg);
05907 }
05908 return m_mdObjectiveFunctionValues;
05909 }
05910
05911
05912 SparseJacobianMatrix *OSInstance::calculateAllConstraintFunctionGradients(double* x, double *objLambda, double *conLambda,
05913 bool new_x, int highestOrder)
05914 {
05915 try
05916
05917 {
05918 if(highestOrder < 1 ) throw ErrorClass("When calling calculateAllConstraintFunctionGradients highestOrder should be 1 or 2");
05919
05920 if( new_x == true || (highestOrder > m_iHighestOrderEvaluated) )
05921 getIterateResults(x, objLambda, conLambda, new_x, highestOrder);
05922 }
05923 catch(const ErrorClass& eclass)
05924 {
05925 throw ErrorClass( eclass.errormsg);
05926 }
05927 return m_sparseJacMatrix;
05928 }
05929
05930
05931 SparseVector *OSInstance::calculateConstraintFunctionGradient(double* x, double *objLambda, double *conLambda,
05932 int idx, bool new_x, int highestOrder)
05933 {
05934 try
05935 {
05936 if(highestOrder < 1 ) throw ErrorClass("When calling calculateConstraintFunctionGradient highestOrder should be 1 or 2");
05937 if(idx < 0 || idx >= instanceData->constraints->numberOfConstraints )
05938 throw ErrorClass("invalid index passed to calculateConstraintFunctionGrad");
05939 SparseVector *sp;
05940 sp = new SparseVector();
05941 sp->bDeleteArrays = true;
05942 int i;
05943 if( new_x == true || (highestOrder > m_iHighestOrderEvaluated) )
05944 getIterateResults(x, objLambda, conLambda, new_x, highestOrder);
05945 sp->number = m_miJacStart[ idx + 1] - m_miJacStart[ idx];
05946 sp->values = new double[ sp->number];
05947 sp->indexes = new int[ sp->number];
05948 for(i = 0; i < sp->number; i++)
05949 {
05950 sp->values[ i] = m_mdJacValue[ m_miJacStart[ idx] + i];
05951 sp->indexes[ i] = m_miJacIndex[ m_miJacStart[ idx] + i];
05952 }
05953 return sp;
05954 }
05955 catch(const ErrorClass& eclass)
05956 {
05957 throw ErrorClass( eclass.errormsg);
05958 }
05959 }
05960
05961
05962 SparseVector *OSInstance::calculateConstraintFunctionGradient(double* x, int idx, bool new_x)
05963 {
05964 try
05965 {
05966 if(idx < 0 || idx >= instanceData->constraints->numberOfConstraints )
05967 throw ErrorClass("invalid index passed to calculateConstraintFunctionGrad");
05968 SparseVector *sp;
05969 sp = new SparseVector();
05970 sp->bDeleteArrays = true;
05971 int i;
05972 if( new_x == true || (1 > m_iHighestOrderEvaluated) )
05973 getIterateResults(x, NULL, NULL, new_x, 1);
05974 sp->number = m_miJacStart[ idx + 1] - m_miJacStart[ idx];
05975 sp->values = new double[ sp->number];
05976 sp->indexes = new int[ sp->number];
05977 for(i = 0; i < sp->number; i++)
05978 {
05979 sp->values[ i] = m_mdJacValue[ m_miJacStart[ idx] + i];
05980 sp->indexes[i] = m_miJacIndex[ m_miJacStart[ idx] + i];
05981 }
05982 return sp;
05983 }
05984 catch(const ErrorClass& eclass)
05985 {
05986 throw ErrorClass( eclass.errormsg);
05987 }
05988 }
05989
05990
05991 double **OSInstance::calculateAllObjectiveFunctionGradients(double* x, double *objLambda, double *conLambda,
05992 bool new_x, int highestOrder)
05993 {
05994 try
05995 {
05996 if(highestOrder < 1 ) throw ErrorClass("When calling calculateAllObjectiveFunctionGradients highestOrder should be 1 or 2");
05997 if( new_x == true || (highestOrder > m_iHighestOrderEvaluated) )
05998 {
05999 std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
06000 for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
06001 {
06002 if(posMapExpTree->first < 0)
06003 {
06004 m_mmdObjGradient[ abs( posMapExpTree->first) - 1 ] = calculateObjectiveFunctionGradient(x, objLambda, conLambda,
06005 posMapExpTree->first, new_x, highestOrder);
06006 }
06007 }
06008 }
06009 }
06010 catch(const ErrorClass& eclass)
06011 {
06012 throw ErrorClass( eclass.errormsg);
06013 }
06014 return m_mmdObjGradient;
06015 }
06016
06017 double *OSInstance::calculateObjectiveFunctionGradient(double* x, double *objLambda, double *conLambda,
06018 int objIdx, bool new_x, int highestOrder)
06019 {
06020
06021
06022
06023 try
06024 {
06025 if(highestOrder < 1 ) throw ErrorClass("When calling calculateObjectiveFunctionGradient highestOrder should be 1 or 2");
06026 if( new_x == true || (highestOrder > m_iHighestOrderEvaluated) )
06027 {
06028 int domainIdx = 0;
06029 std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
06030 std::map<int, int>::iterator posVarIndexMap;
06031 int iHighestOrderEvaluatedStore;
06032 unsigned int i;
06033 iHighestOrderEvaluatedStore = m_iHighestOrderEvaluated;
06034 for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
06035 {
06036
06037 if(posMapExpTree->first == objIdx)
06038 {
06039 if( new_x == true )
06040 {
06041 if( m_vdX.size() > 0) m_vdX.clear();
06042 for(posVarIndexMap = m_mapAllNonlinearVariablesIndex.begin(); posVarIndexMap != m_mapAllNonlinearVariablesIndex.end(); ++posVarIndexMap)
06043 {
06044 m_vdX.push_back( x[ posVarIndexMap->first]) ;
06045 }
06046 if( (m_bOSADFunIsCreated == false || m_bCppADMustReTape == true ) && (m_mapExpressionTreesMod.size() > 0) )
06047 {
06048 createOSADFun( m_vdX);
06049 }
06050 }
06051
06052 if(( new_x == true ) || (m_iHighestOrderEvaluated < 0) )this->forwardAD(0, m_vdX);
06053
06054 if(( new_x == true ) || (m_iHighestOrderEvaluated < 1) )
06055 {
06056 m_vdRangeUnitVec[ domainIdx] = 1.;
06057 m_vdYjacval = this->reverseAD(1, m_vdRangeUnitVec);
06058 for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
06059 {
06060 m_mmdObjGradient[ abs( objIdx) - 1 ][ m_miNonLinearVarsReverseMap[ i]] = m_vdYjacval[ i] +
06061 m_mmdDenseObjectiveCoefficients[ abs( objIdx) - 1][ m_miNonLinearVarsReverseMap[ i]];
06062 }
06063 }
06064 m_iHighestOrderEvaluated = iHighestOrderEvaluatedStore;
06065 m_vdRangeUnitVec[ domainIdx] = 0.;
06066
06067 break;
06068 }
06069 domainIdx++;
06070 }
06071 }
06072 }
06073 catch(const ErrorClass& eclass)
06074 {
06075 throw ErrorClass( eclass.errormsg);
06076 }
06077 return m_mmdObjGradient[abs( objIdx) - 1];
06078 }
06079
06080
06081 double *OSInstance::calculateObjectiveFunctionGradient(double* x, int objIdx, bool new_x)
06082 {
06083 try
06084 {
06085 int domainIdx = 0;
06086 std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
06087 std::map<int, int>::iterator posVarIndexMap;
06088 unsigned int i;
06089 int iHighestOrderEvaluatedStore;
06090 iHighestOrderEvaluatedStore = m_iHighestOrderEvaluated;
06091 for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
06092 {
06093 if(posMapExpTree->first == objIdx)
06094 {
06095 if( new_x == true )
06096 {
06097 if( m_vdX.size() > 0) m_vdX.clear();
06098 for(posVarIndexMap = m_mapAllNonlinearVariablesIndex.begin(); posVarIndexMap != m_mapAllNonlinearVariablesIndex.end(); ++posVarIndexMap)
06099 {
06100 m_vdX.push_back( x[ posVarIndexMap->first]) ;
06101 }
06102 if( (m_bOSADFunIsCreated == false || m_bCppADMustReTape == true ) && (m_mapExpressionTreesMod.size() > 0) )
06103 {
06104 createOSADFun( m_vdX);
06105 }
06106 }
06107
06108 if(( new_x == true ) || (m_iHighestOrderEvaluated < 0) ) this->forwardAD(0, m_vdX);
06109
06110 if(( new_x == true ) || (m_iHighestOrderEvaluated < 1) )
06111 {
06112 m_vdRangeUnitVec[ domainIdx] = 1.;
06113 m_vdYjacval = this->reverseAD(1, m_vdRangeUnitVec);
06114 for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
06115 {
06116 m_mmdObjGradient[ abs( objIdx) - 1 ][ m_miNonLinearVarsReverseMap[ i]] = m_vdYjacval[ i] +
06117 m_mmdDenseObjectiveCoefficients[ abs( objIdx) - 1][ m_miNonLinearVarsReverseMap[ i]];
06118 }
06119 }
06120 m_iHighestOrderEvaluated = iHighestOrderEvaluatedStore;
06121 m_vdRangeUnitVec[ domainIdx] = 0.;
06122
06123 break;
06124 }
06125 domainIdx++;
06126 }
06127 }
06128 catch(const ErrorClass& eclass)
06129 {
06130 throw ErrorClass( eclass.errormsg);
06131 }
06132 return m_mmdObjGradient[abs( objIdx) - 1];
06133 }
06134
06135 SparseHessianMatrix *OSInstance::calculateLagrangianHessian( double* x, double *objLambda, double *conLambda,
06136 bool new_x, int highestOrder)
06137 {
06138 try
06139 {
06140 if(highestOrder != 2 ) throw ErrorClass("When calling calculateLagrangianHessian highestOrder should be 2");
06141 if( new_x == true || (highestOrder > m_iHighestOrderEvaluated) )
06142 {
06143 getIterateResults(x, objLambda, conLambda, new_x, highestOrder);
06144 }
06145 }
06146 catch(const ErrorClass& eclass)
06147 {
06148 throw ErrorClass( eclass.errormsg);
06149 }
06150 return m_LagrangianSparseHessian;
06151 }
06152
06153 SparseHessianMatrix *OSInstance::calculateHessian(double* x, int idx, bool new_x)
06154 {
06155 try
06156 {
06157 if(idx < -instanceData->objectives->numberOfObjectives || idx >= instanceData->constraints->numberOfConstraints )
06158 throw ErrorClass("invalid index passed to calculateHessian");
06159 double *objLambda = new double[ getObjectiveNumber() ];
06160 double *conLambda = new double[ getConstraintNumber() ];
06161 int i;
06162
06163 for(i = 0; i < getObjectiveNumber(); i++)
06164 {
06165 objLambda[ i] = 0.0;
06166 }
06167 for(i = 0; i < getConstraintNumber(); i++)
06168 {
06169 conLambda[ i] = 0.0;
06170 }
06171
06172
06173 if(idx < 0)
06174 {
06175 objLambda[ abs(idx) - 1] = 1.0;
06176 }
06177 else
06178 {
06179 conLambda[ idx] = 1.0;
06180 }
06181
06182 if( new_x == true || (2 > m_iHighestOrderEvaluated) )
06183 {
06184 getIterateResults(x, objLambda, conLambda, new_x, 2);
06185 }
06186 delete[] objLambda;
06187 delete[] conLambda;
06188 }
06189 catch(const ErrorClass& eclass)
06190 {
06191 throw ErrorClass( eclass.errormsg);
06192 }
06193 return m_LagrangianSparseHessian;
06194 }
06195
06196
06197 bool OSInstance::getSparseJacobianFromColumnMajor( )
06198 {
06199 std::ostringstream outStr;
06200
06201
06202 if( m_bColumnMajor == false) return false;
06203 int iNumRowStarts = getConstraintNumber() + 1;
06204 int i,j, iTemp;
06205 int iNumVariableStarts = getVariableNumber();
06206 int *start = NULL;
06207 int *index = NULL;
06208 double *value = NULL;
06209
06210 if(this->instanceData->linearConstraintCoefficients != NULL)
06211 {
06212 start = this->instanceData->linearConstraintCoefficients->start->el;
06213 index = this->instanceData->linearConstraintCoefficients->rowIdx->el;
06214 value = this->instanceData->linearConstraintCoefficients->value->el;
06215 }
06216 m_miJacStart = new int[ iNumRowStarts];
06217 m_miJacNumConTerms = new int[ getConstraintNumber()];
06218 OSnLNodePlus *nlNodePlus;
06219 OSnLNodeVariable *nlNodeVariable;
06220 ScalarExpressionTree *expTree = NULL;
06221
06222 for ( i = 0; i < iNumRowStarts; i++)
06223 {
06224 m_miJacStart [ i ] = 0;
06225
06226 if( m_mapExpressionTreesMod.find( i) != m_mapExpressionTreesMod.end() )
06227 {
06228
06229 m_mapExpressionTreesMod[ i]->getVariableIndicesMap();
06230
06231 }
06232 }
06233
06234 if (this->instanceData->linearConstraintCoefficients != NULL &&
06235 this->instanceData->linearConstraintCoefficients->numberOfValues > 0)
06236 {
06237
06238 for (i = 0; i < iNumVariableStarts; i++)
06239 {
06240 for (j = start[i]; j < start[ i + 1 ]; j++)
06241 {
06242
06243
06244
06245
06246
06247
06248 if( (m_mapExpressionTreesMod.find( index[ j]) != m_mapExpressionTreesMod.end() ) &&
06249 ( (*m_mapExpressionTreesMod[ index[ j]]->mapVarIdx).find( i) != (*m_mapExpressionTreesMod[ index[ j]]->mapVarIdx).end()) )
06250 {
06251
06252
06253
06254
06255 if( value[j] > 0 || value[j] < 0)
06256 {
06257 expTree = m_mapExpressionTreesMod[ index[j] ];
06258 nlNodeVariable = new OSnLNodeVariable();
06259 nlNodeVariable->coef = value[ j];
06260 nlNodeVariable->idx = i;
06261 nlNodePlus = new OSnLNodePlus();
06262 nlNodePlus->m_mChildren[ 0] = m_mapExpressionTreesMod[ index[ j] ]->m_treeRoot;
06263 nlNodePlus->m_mChildren[ 1] = nlNodeVariable;
06264 expTree->m_treeRoot = nlNodePlus ;
06265 }
06266 }
06267 else
06268 {
06269 m_miJacStart[ index[j] + 1] ++;
06270 }
06271 }
06272 }
06273 }
06274
06275
06276
06277
06278 m_miJacStart[0] = 0;
06279 for (i = 1; i < iNumRowStarts; i++ )
06280 {
06281 m_miJacNumConTerms[ i - 1] = m_miJacStart[i];
06282 if( m_mapExpressionTreesMod.find( i - 1) != m_mapExpressionTreesMod.end() )
06283 {
06284 m_miJacStart[i] += (m_miJacStart[i - 1] + (*m_mapExpressionTreesMod[ i - 1]->mapVarIdx).size() );
06285 }
06286 else
06287 {
06288 m_miJacStart[i] += m_miJacStart[i - 1];
06289 }
06290 }
06291
06292 m_iJacValueSize = m_miJacStart[ iNumRowStarts - 1];
06293 m_miJacIndex = new int[ m_iJacValueSize];
06294 m_mdJacValue = new double[ m_iJacValueSize ];
06295
06296 if (this->instanceData->linearConstraintCoefficients != NULL &&
06297 this->instanceData->linearConstraintCoefficients->numberOfValues > 0)
06298
06299 {
06300
06301 for (i = 0; i < iNumVariableStarts; i++)
06302 {
06303
06304
06305 for (j = start[i]; j < start[ i + 1 ]; j++)
06306 {
06307
06308
06309 if( (m_mapExpressionTreesMod.find( index[ j]) == m_mapExpressionTreesMod.end() ) ||
06310 ( (*m_mapExpressionTreesMod[ index[ j]]->mapVarIdx).find( i) == (*m_mapExpressionTreesMod[ index[ j]]->mapVarIdx).end()) )
06311 {
06312 iTemp = m_miJacStart[ index[j]];
06313 m_miJacIndex[ iTemp] = i;
06314 m_mdJacValue[ iTemp] = value[j];
06315 m_miJacStart[ index[j]]++;
06316 }
06317 }
06318 }
06319 }
06320
06321 std::map<int, int>::iterator posVarIdx;
06322
06323 for (i = 0; i < iNumRowStarts - 1; i++ )
06324 {
06325 m_miJacStart[ i] = m_miJacStart [ i] - m_miJacNumConTerms[ i] ;
06326 iTemp = m_miJacStart[ i] + m_miJacNumConTerms[ i];
06327
06328 if( m_mapExpressionTreesMod.find( i) != m_mapExpressionTreesMod.end() )
06329 {
06330 for(posVarIdx = (*m_mapExpressionTreesMod[ i]->mapVarIdx).begin(); posVarIdx
06331 != (*m_mapExpressionTreesMod[ i]->mapVarIdx).end(); ++posVarIdx)
06332 {
06333 m_miJacIndex[ iTemp] = posVarIdx->first;
06334 m_mdJacValue[ iTemp] = 0;
06335 iTemp++;
06336 }
06337 }
06338 }
06339 #ifndef NDEBUG
06340 outStr.str("");
06341 outStr.clear();
06342 outStr << "HERE ARE ROW STARTS:" << std::endl;
06343 for (i = 0; i < iNumRowStarts; i++ )
06344 {
06345 outStr << m_miJacStart[ i] << " ";
06346 }
06347 outStr << std::endl << std::endl;
06348 outStr << "HERE ARE VARIABLE INDICES:" << std::endl;
06349 for (i = 0; i < m_miJacStart[ iNumRowStarts - 1]; i++ )
06350 {
06351 outStr << m_miJacIndex[ i] << " ";
06352 }
06353 outStr << std::endl << std::endl;
06354 outStr << "HERE ARE VALUES:" << std::endl;
06355 for (i = 0; i < m_miJacStart[ iNumRowStarts - 1]; i++ )
06356 {
06357 outStr << m_mdJacValue[ i] << " ";
06358 }
06359 outStr << std::endl << std::endl;
06360
06361 outStr << "HERE ARE NUMBER OF CONSTANT TERMS:" << std::endl;
06362 for (i = 0; i < iNumRowStarts - 1; i++ )
06363
06364 {
06365 outStr << m_miJacNumConTerms[ i ] << " ";
06366 }
06367 outStr << std::endl << std::endl;
06368 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06369 #endif
06370 return true;
06371 }
06372
06373
06374 bool OSInstance::getSparseJacobianFromRowMajor( )
06375 {
06376 std::ostringstream outStr;
06377
06378
06379 if( m_bColumnMajor == true) return false;
06380 int iNumJacRowStarts = getConstraintNumber() + 1;
06381 std::map<int, int>::iterator posVarIdx;
06382 int i,j, k;
06383 int *start = NULL;
06384 int *index = NULL;
06385 double *value = NULL;
06386
06387 if (this->instanceData->linearConstraintCoefficients != NULL &&
06388 this->instanceData->linearConstraintCoefficients->numberOfValues > 0)
06389 {
06390 start = this->instanceData->linearConstraintCoefficients->start->el;
06391 index = this->instanceData->linearConstraintCoefficients->colIdx->el;
06392 value = this->instanceData->linearConstraintCoefficients->value->el;
06393 }
06394
06395 m_miJacStart = new int[ iNumJacRowStarts];
06396 m_miJacNumConTerms = new int[ getConstraintNumber()];
06397 OSnLNodePlus *nlNodePlus;
06398 OSnLNodeVariable *nlNodeVariable;
06399
06400 for ( i = 0; i < iNumJacRowStarts; i++)
06401 {
06402 m_miJacStart [ i ] = 0;
06403
06404 if( m_mapExpressionTreesMod.find( i) != m_mapExpressionTreesMod.end() )
06405 {
06406
06407 m_mapExpressionTreesMod[ i]->getVariableIndicesMap();
06408
06409 }
06410 }
06411 int loopLimit = getConstraintNumber();
06412
06413
06414 if (this->instanceData->linearConstraintCoefficients != NULL &&
06415 this->instanceData->linearConstraintCoefficients->numberOfValues > 0)
06416 {
06417
06418 for (i = 0; i < loopLimit; i++)
06419 {
06420 m_miJacNumConTerms[ i] = 0;
06421 for (j = start[i]; j < start[ i + 1 ]; j++)
06422 {
06423
06424
06425
06426 if( (m_mapExpressionTreesMod.find( i) != m_mapExpressionTreesMod.end() ) &&
06427 ( (*m_mapExpressionTreesMod[ i]->mapVarIdx).find( index[ j]) != (*m_mapExpressionTreesMod[ i]->mapVarIdx).end()) )
06428 {
06429
06430
06431
06432 if(value[ j] > 0 || value[j] < 0)
06433 {
06434 nlNodeVariable = new OSnLNodeVariable();
06435 nlNodeVariable->coef = value[ j];
06436 nlNodeVariable->idx = index[ j];
06437 nlNodePlus = new OSnLNodePlus();
06438 nlNodePlus->m_mChildren[ 0] = m_mapExpressionTreesMod[ i ]->m_treeRoot;
06439 nlNodePlus->m_mChildren[ 1] = nlNodeVariable;
06440 m_mapExpressionTreesMod[ i ]->m_treeRoot = nlNodePlus;
06441 }
06442 }
06443 else
06444 {
06445
06446 m_miJacNumConTerms[ i]++;
06447 }
06448 }
06449 }
06450 }
06451
06452 m_miJacStart[0] = 0;
06453 for (i = 1; i < iNumJacRowStarts; i++ )
06454 {
06455 if( m_mapExpressionTreesMod.find( i - 1) != m_mapExpressionTreesMod.end() )
06456 {
06457 m_miJacStart[i] = m_miJacStart[i - 1] + (m_miJacNumConTerms[ i - 1] + (*m_mapExpressionTreesMod[ i - 1]->mapVarIdx).size() );
06458 }
06459 else
06460 {
06461 m_miJacStart[i] = m_miJacStart[i - 1] + m_miJacNumConTerms[ i - 1];
06462 }
06463 }
06464
06465
06466 m_iJacValueSize = m_miJacStart[ iNumJacRowStarts - 1];
06467 m_miJacIndex = new int[ m_iJacValueSize];
06468 m_mdJacValue = new double[ m_iJacValueSize ];
06469
06470
06471 if (this->instanceData->linearConstraintCoefficients != NULL &&
06472 this->instanceData->linearConstraintCoefficients->numberOfValues > 0)
06473 {
06474 for (i = 0; i < loopLimit; i++)
06475 {
06476 k = 0;
06477 for (j = start[i]; j < start[ i + 1 ]; j++)
06478 {
06479 if( (m_mapExpressionTreesMod.find( i) == m_mapExpressionTreesMod.end() ) ||
06480 ( (*m_mapExpressionTreesMod[ i]->mapVarIdx).find( index[ j]) == (*m_mapExpressionTreesMod[ i]->mapVarIdx).end()) )
06481 {
06482 m_miJacIndex[ m_miJacStart[i] + k ] = index[ j];
06483 m_mdJacValue[ m_miJacStart[i] + k ] = value[ j];
06484 k++;
06485 }
06486 }
06487 }
06488 }
06489
06490 for (i = 0; i < loopLimit; i++ )
06491 {
06492 k = m_miJacStart[i] + m_miJacNumConTerms[ i ];
06493
06494 if( m_mapExpressionTreesMod.find( i) != m_mapExpressionTreesMod.end() )
06495 {
06496 for(posVarIdx = (*m_mapExpressionTreesMod[ i]->mapVarIdx).begin(); posVarIdx
06497 != (*m_mapExpressionTreesMod[ i]->mapVarIdx).end(); ++posVarIdx)
06498 {
06499 m_miJacIndex[ k] = posVarIdx->first;
06500 m_mdJacValue[ k] = 0;
06501 k++;
06502 }
06503 }
06504 }
06505 #ifndef NDEBUG
06506 outStr.str("");
06507 outStr.clear();
06508 outStr << "HERE ARE ROW STARTS:" << std::endl;
06509 for (i = 0; i < iNumJacRowStarts; i++ )
06510 {
06511 outStr << m_miJacStart[ i] << " ";
06512 }
06513 outStr << std::endl << std::endl;
06514 outStr << "HERE ARE VARIABLE INDICES:" << std::endl;
06515 for (i = 0; i < m_miJacStart[ iNumJacRowStarts - 1]; i++ )
06516 {
06517 outStr << m_miJacIndex[ i] << " ";
06518 }
06519 outStr << std::endl << std::endl;
06520 outStr << "HERE ARE VALUES:" << std::endl;
06521 for (i = 0; i < m_miJacStart[ iNumJacRowStarts - 1]; i++ )
06522 {
06523 outStr << m_mdJacValue[ i] << " ";
06524 }
06525 outStr << std::endl << std::endl;
06526
06527 outStr << "HERE ARE NUMBER OF CONSTANT TERMS:" << std::endl;
06528 for (i = 0; i < iNumJacRowStarts - 1; i++ )
06529 {
06530 outStr << m_miJacNumConTerms[ i ] << " ";
06531 }
06532 outStr << std::endl << std::endl;
06533 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06534 #endif
06535 return true;
06536 }
06537
06538 ScalarExpressionTree* OSInstance::getLagrangianExpTree( )
06539 {
06540 if( m_bLagrangianExpTreeCreated == true) return m_LagrangianExpTree;
06541
06542
06543
06544 if(m_bSparseJacobianCalculated == false) getJacobianSparsityPattern( );
06545 std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
06546 OSnLNodeTimes* nlNodeTimes = NULL;
06547 OSnLNodeVariable* nlNodeVariable = NULL;
06548 OSnLNodeSum* nlNodeSum = NULL;
06549 int numChildren = 0;
06550 int rowIdx;
06551
06552 nlNodeSum = new OSnLNodeSum();
06553 nlNodeSum->inumberOfChildren = m_mapExpressionTreesMod.size();
06554 nlNodeSum->m_mChildren = new OSnLNode*[ nlNodeSum->inumberOfChildren];
06555
06556 m_LagrangianExpTree = new ScalarExpressionTree();
06557 m_LagrangianExpTree->m_treeRoot = nlNodeSum;
06558
06559 for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
06560 {
06561
06562 nlNodeVariable = new OSnLNodeVariable();
06563 nlNodeVariable->coef = 1.;
06564
06565
06566 rowIdx = posMapExpTree->first;
06567 if(rowIdx >= 0)
06568 {
06569 nlNodeVariable->idx = instanceData->variables->numberOfVariables + rowIdx;
06570 }
06571 else
06572 {
06573 nlNodeVariable->idx = instanceData->variables->numberOfVariables +
06574 instanceData->constraints->numberOfConstraints + (abs(rowIdx) - 1);
06575 }
06576
06577
06578 nlNodeTimes = new OSnLNodeTimes();
06579 nlNodeTimes->m_mChildren[ 0] = nlNodeVariable;
06580 nlNodeTimes->m_mChildren[ 1] = m_mapExpressionTreesMod[ posMapExpTree->first ]->m_treeRoot;
06581
06582 nlNodeSum->m_mChildren[ numChildren] = nlNodeTimes;
06583 numChildren++;
06584 }
06585
06586 m_LagrangianExpTree->getVariableIndicesMap();
06587 m_bLagrangianExpTreeCreated = true;
06588 return m_LagrangianExpTree;
06589 }
06590
06591 std::map<int, int> OSInstance::getAllNonlinearVariablesIndexMap( )
06592 {
06593 std::ostringstream outStr;
06594
06595 if(m_bAllNonlinearVariablesIndex == true) return m_mapAllNonlinearVariablesIndex;
06596
06597
06598 std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
06599 std::map<int, int>::iterator posVarIdx;
06600 ScalarExpressionTree *expTree;
06601 for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
06602 {
06603
06604
06605 expTree = posMapExpTree->second;
06606 if(expTree->m_bIndexMapGenerated == false)expTree->getVariableIndicesMap();
06607 for(posVarIdx = (*expTree->mapVarIdx).begin(); posVarIdx != (*expTree->mapVarIdx).end(); ++posVarIdx)
06608 {
06609 if( m_mapAllNonlinearVariablesIndex.find( posVarIdx->first) == m_mapAllNonlinearVariablesIndex.end() )
06610 {
06611
06612 m_mapAllNonlinearVariablesIndex[ posVarIdx->first] = 1;
06613 }
06614 }
06615 }
06616 m_miNonLinearVarsReverseMap = new int[m_mapAllNonlinearVariablesIndex.size()];
06617
06618 int kount = 0;
06619 for(posVarIdx = m_mapAllNonlinearVariablesIndex.begin(); posVarIdx !=m_mapAllNonlinearVariablesIndex.end(); ++posVarIdx)
06620 {
06621 posVarIdx->second = kount;
06622 m_miNonLinearVarsReverseMap[ kount] = posVarIdx->first;
06623 kount++;
06624 #ifndef NDEBUG
06625 outStr.str("");
06626 outStr.clear();
06627 outStr << "POSITION FIRST = " << posVarIdx->first ;
06628 outStr << " POSITION SECOND = " << posVarIdx->second << std::endl;
06629 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06630 #endif
06631 }
06632 m_iNumberOfNonlinearVariables = kount;
06633 m_bAllNonlinearVariablesIndex = true;
06634 return m_mapAllNonlinearVariablesIndex;
06635 }
06636
06637 SparseHessianMatrix* OSInstance::getLagrangianHessianSparsityPattern( )
06638 {
06639 std::ostringstream outStr;
06640
06641
06642 if( m_bLagrangianSparseHessianCreated == true) return m_LagrangianSparseHessian;
06643 if( m_iNumberOfNonlinearVariables == 0) return NULL;
06644 if( m_binitForAlgDiff == false ) initForAlgDiff();
06645 unsigned int i = 0;
06646 unsigned int j;
06647 int numNonz = 0;
06648
06649
06650 std::vector<double> vx;
06651 std::map<int, int>::iterator posMap1, posMap2;
06652 if( (m_bOSADFunIsCreated == false || m_bCppADMustReTape == true ) && (m_mapExpressionTreesMod.size() > 0) )
06653 {
06654 for(posMap1 = m_mapAllNonlinearVariablesIndex.begin(); posMap1 != m_mapAllNonlinearVariablesIndex.end(); ++posMap1)
06655 {
06656 vx.push_back( 1.0) ;
06657 }
06658 createOSADFun( vx);
06659 }
06660
06661
06662 numNonz = getADSparsityHessian();
06663
06664 i = 0;
06665
06666 m_LagrangianSparseHessian = new SparseHessianMatrix();
06667 m_LagrangianSparseHessian->bDeleteArrays = true;
06668 m_LagrangianSparseHessian->hessDimension = numNonz;
06669 m_LagrangianSparseHessian->hessRowIdx = new int[m_LagrangianSparseHessian->hessDimension];
06670 m_LagrangianSparseHessian->hessColIdx = new int[m_LagrangianSparseHessian->hessDimension];
06671 m_LagrangianSparseHessian->hessValues = new double[m_LagrangianSparseHessian->hessDimension];
06672 numNonz = 0;
06673 for(posMap1 = m_mapAllNonlinearVariablesIndex.begin(); posMap1 != m_mapAllNonlinearVariablesIndex.end(); ++posMap1)
06674 {
06675 j = i;
06676 for(posMap2 = posMap1; posMap2 != m_mapAllNonlinearVariablesIndex.end(); ++posMap2)
06677 {
06678 if(m_vbLagHessNonz[ i*m_iNumberOfNonlinearVariables + j] == true)
06679 {
06680 *(m_LagrangianSparseHessian->hessRowIdx + numNonz) = posMap1->first;
06681 *(m_LagrangianSparseHessian->hessColIdx + numNonz) = posMap2->first;
06682 numNonz++;
06683 }
06684 j++;
06685 }
06686 i++;
06687 }
06688 #ifndef NDEBUG
06689 outStr.str("");
06690 outStr.clear();
06691 outStr << "HESSIAN SPARSITY PATTERN" << std::endl;
06692 int kj;
06693 for(kj = 0; kj < m_LagrangianSparseHessian->hessDimension; kj++)
06694 {
06695 outStr << "Row Index = " << *(m_LagrangianSparseHessian->hessRowIdx + kj) << std::endl;
06696 outStr << "Column Index = " << *(m_LagrangianSparseHessian->hessColIdx + kj) << std::endl;
06697 }
06698 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06699 #endif
06700
06701 m_bLagrangianSparseHessianCreated = true;
06702 return m_LagrangianSparseHessian;
06703 }
06704
06705
06706 void OSInstance::duplicateExpressionTreesMap()
06707 {
06708
06709 if(m_bDuplicateExpressionTreesMap == false)
06710 {
06711
06712 if( m_bProcessExpressionTrees == false) getAllNonlinearExpressionTrees();
06713 m_mapExpressionTreesMod = m_mapExpressionTrees;
06714 m_bDuplicateExpressionTreesMap = true;
06715 return;
06716 }
06717 else
06718 {
06719 return;
06720 }
06721 }
06722
06723
06724 bool OSInstance::getIterateResults( double *x, double *objLambda, double* conMultipliers,
06725 bool new_x, int highestOrder)
06726 {
06727 try
06728 {
06729 if( m_binitForAlgDiff == false) initForAlgDiff();
06730 std::map<int, int>::iterator posVarIndexMap;
06731
06732 if(new_x == true)
06733 {
06734 if( m_vdX.size() > 0) m_vdX.clear();
06735 for(posVarIndexMap = m_mapAllNonlinearVariablesIndex.begin(); posVarIndexMap != m_mapAllNonlinearVariablesIndex.end(); ++posVarIndexMap)
06736 {
06737 m_vdX.push_back( x[ posVarIndexMap->first]) ;
06738 }
06739 if( (m_bOSADFunIsCreated == false || m_bCppADMustReTape == true ) && (m_mapExpressionTreesMod.size() > 0) )
06740 {
06741 createOSADFun( m_vdX);
06742 }
06743 }
06744 else
06745
06746 {
06747 if( m_vdX.size() == 0)
06748 {
06749 for(posVarIndexMap = m_mapAllNonlinearVariablesIndex.begin(); posVarIndexMap != m_mapAllNonlinearVariablesIndex.end(); ++posVarIndexMap)
06750 {
06751 m_vdX.push_back( x[ posVarIndexMap->first]) ;
06752 }
06753 if( (m_bOSADFunIsCreated == false || m_bCppADMustReTape == true ) && (m_mapExpressionTreesMod.size() > 0) )
06754 {
06755 createOSADFun( m_vdX);
06756 }
06757 }
06758 }
06759 switch( highestOrder)
06760 {
06761 case 0:
06762 if(new_x == true || m_iHighestOrderEvaluated < 0)
06763 {
06764 if(bUseExpTreeForFunEval == true)
06765 {
06766 calculateAllConstraintFunctionValues( x, new_x);
06767 calculateAllObjectiveFunctionValues( x, new_x);
06768 }
06769 else
06770 {
06771 getZeroOrderResults(x, objLambda, conMultipliers);
06772 }
06773
06774 }
06775 break;
06776 case 1:
06777 if(new_x == true || m_iHighestOrderEvaluated < 0)
06778 getZeroOrderResults(x, objLambda, conMultipliers);
06779 if(new_x == true || m_iHighestOrderEvaluated < 1)
06780 getFirstOrderResults(x, objLambda, conMultipliers);
06781 break;
06782 case 2:
06783 if(new_x == true || m_iHighestOrderEvaluated < 0)
06784 getZeroOrderResults(x, objLambda, conMultipliers);
06785 if(new_x == true || m_iHighestOrderEvaluated < 2)
06786 getSecondOrderResults(x, objLambda, conMultipliers);
06787 break;
06788 default:
06789 throw ErrorClass("Derivative should be order 0, 1, or 2");
06790 }
06791 return true;
06792 }
06793 catch(const ErrorClass& eclass)
06794 {
06795 throw ErrorClass( eclass.errormsg);
06796 }
06797 }
06798
06799
06800 bool OSInstance::getZeroOrderResults(double *x, double *objLambda, double *conMultipliers)
06801 {
06802 std::ostringstream outStr;
06803
06804 try
06805 {
06806
06807 int i, j, rowNum, objNum;
06808 if( m_mapExpressionTreesMod.size() > 0)
06809 {
06810 m_vdYval = this->forwardAD(0, m_vdX);
06811 }
06812
06813 for(rowNum = 0; rowNum < m_iConstraintNumber; rowNum++)
06814 {
06815 m_mdConstraintFunctionValues[ rowNum] = 0.0;
06816 if( m_mapExpressionTreesMod.find( rowNum) != m_mapExpressionTreesMod.end() )
06817 {
06818 m_mdConstraintFunctionValues[ rowNum] = m_vdYval[ m_mapOSADFunRangeIndex[ rowNum]];
06819 }
06820
06821
06822 i = m_sparseJacMatrix->starts[ rowNum];
06823 j = m_sparseJacMatrix->starts[ rowNum + 1 ];
06824 while ( (i - m_sparseJacMatrix->starts[ rowNum]) < m_sparseJacMatrix->conVals[ rowNum] )
06825 {
06826 m_mdConstraintFunctionValues[ rowNum] += m_sparseJacMatrix->values[ i]*x[ m_sparseJacMatrix->indexes[ i] ];
06827 i++;
06828 }
06829
06830 m_mdConstraintFunctionValues[ rowNum] += m_mdConstraintConstants[ rowNum ];
06831 #ifndef NDEBUG
06832 outStr.str("");
06833 outStr.clear();
06834 outStr << "Constraint " << rowNum << " function value = " << m_mdConstraintFunctionValues[ rowNum ] << std::endl;
06835 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06836 #endif
06837 }
06838
06839 for(objNum = 0; objNum < m_iObjectiveNumber; objNum++)
06840 {
06841 m_mdObjectiveFunctionValues[ objNum] = 0.0;
06842 if( m_mapExpressionTreesMod.find( -objNum -1) != m_mapExpressionTreesMod.end() )
06843 {
06844 m_mdObjectiveFunctionValues[ objNum] = m_vdYval[ objNum];
06845 }
06846 for(i = 0; i < m_iVariableNumber; i++)
06847 {
06848 m_mdObjectiveFunctionValues[ objNum] += m_mmdDenseObjectiveCoefficients[ objNum][i]*x[ i];
06849 }
06850 #ifndef NDEBUG
06851 outStr.str("");
06852 outStr.clear();
06853 outStr << "Objective " << objNum << " function value = " << m_mdObjectiveFunctionValues[ objNum] << std::endl;
06854 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06855 #endif
06856 }
06857 return true;
06858 }
06859 catch(const ErrorClass& eclass)
06860 {
06861 throw ErrorClass( eclass.errormsg);
06862 }
06863 }
06864
06865
06866 bool OSInstance::getFirstOrderResults(double *x, double *objLambda, double *conMultipliers)
06867 {
06868 std::ostringstream outStr;
06869
06870 try
06871 {
06872
06873 unsigned int i, j;
06874 int rowNum, jacIndex;
06875 unsigned int jstart, jend;
06876 int idx;
06877 ScalarExpressionTree *expTree = NULL;
06878 int domainIdx = 0;
06879 std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
06880 std::map<int, int>::iterator posVarIdx;
06881
06887 if(m_iNumberOfNonlinearVariables >= m_mapExpressionTreesMod.size() )
06888 {
06889
06890
06891 for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
06892 {
06893 idx = posMapExpTree->first;
06894
06895 if(idx >= 0)
06896 {
06897 m_vdRangeUnitVec[ domainIdx] = 1.;
06898 m_mapExpressionTreesMod[ idx]->getVariableIndicesMap();
06899 m_vdYjacval = this->reverseAD(1, m_vdRangeUnitVec);
06900
06901 jstart = m_miJacStart[ idx] + m_miJacNumConTerms[ idx];
06902 jend = m_miJacStart[ idx + 1 ];
06903 if( (*m_mapExpressionTreesMod[ idx]->mapVarIdx).size() != (jend - jstart)) throw
06904 ErrorClass("number of partials not consistent");
06905 j = 0;
06906 jacIndex = 0;
06907 for(posVarIdx = m_mapAllNonlinearVariablesIndex.begin(); posVarIdx
06908 != m_mapAllNonlinearVariablesIndex.end(); ++posVarIdx)
06909 {
06910
06911
06912 if( (*m_mapExpressionTreesMod[ idx]->mapVarIdx).find( posVarIdx->first) != (*m_mapExpressionTreesMod[ idx]->mapVarIdx).end())
06913 {
06914 m_mdJacValue[ jstart] = m_vdYjacval[ jacIndex];
06915 jstart++;
06916 j++;
06917 }
06918 jacIndex++;
06919 }
06920
06921 m_vdRangeUnitVec[ domainIdx] = 0.;
06922 domainIdx++;
06923 }
06924 else
06925 {
06926 domainIdx++;
06927 }
06928 }
06929 }
06930 else
06931 {
06932
06933 for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
06934 {
06935 m_vdDomainUnitVec[i] = 1.;
06936 rowNum = 0;
06937 if( m_mapExpressionTreesMod.size() > 0)
06938 {
06939 m_vdYjacval = this->forwardAD(1, m_vdDomainUnitVec);
06940 }
06941
06942
06943 for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
06944 {
06945 idx = posMapExpTree->first;
06946
06947 if(idx >= 0)
06948 {
06949
06950
06951
06952 expTree = m_mapExpressionTreesMod[ idx];
06953 if( (*expTree->mapVarIdx).find( m_miNonLinearVarsReverseMap[ i]) != (*expTree->mapVarIdx).end() )
06954 {
06955 jacIndex = (*m_mapExpressionTreesMod[ idx]->mapVarIdx)[ m_miNonLinearVarsReverseMap[ i]];
06956 jstart = m_miJacStart[ idx] + m_miJacNumConTerms[ idx];
06957
06958 m_mdJacValue[ jstart + jacIndex] = m_vdYjacval[m_iObjectiveNumberNonlinear + rowNum];
06959 }
06960 rowNum++;
06961 }
06962 }
06963
06964 m_vdDomainUnitVec[i] = 0.;
06965 }
06966 }
06967 #ifndef NDEBUG
06968 outStr.str("");
06969 outStr.clear();
06970 int k;
06971 outStr << "JACOBIAN DATA " << std::endl;
06972 for(idx = 0; idx < m_iConstraintNumber; idx++)
06973 {
06974 for(k = *(m_sparseJacMatrix->starts + idx); k < *(m_sparseJacMatrix->starts + idx + 1); k++)
06975 {
06976 outStr << "row idx = " << idx << " col idx = "<< *(m_sparseJacMatrix->indexes + k)
06977 << " value = " << *(m_sparseJacMatrix->values + k) << std::endl;
06978 }
06979 }
06980 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06981 #endif
06982 return true;
06983 }
06984 catch(const ErrorClass& eclass)
06985 {
06986 throw ErrorClass( eclass.errormsg);
06987 }
06988 }
06989
06990
06991 bool OSInstance::getSecondOrderResults(double *x, double *objLambda, double *conMultipliers)
06992 {
06993 std::ostringstream outStr;
06994
06995 try
06996 {
06997
06998 unsigned int i, j;
06999 int rowNum, jacIndex;
07000 int jstart, idx;
07001 ScalarExpressionTree *expTree = NULL;
07002 int hessValuesIdx = 0;
07003 if( m_bLagrangianSparseHessianCreated == false) getLagrangianHessianSparsityPattern( );
07004 std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
07005 std::map<int, int>::iterator posVarIndexMap;
07006 if( objLambda == NULL) throw ErrorClass("must have a multiplier for the objective function even if zero when calling getSecondOrderResults");
07007
07008 if( conMultipliers == NULL) throw ErrorClass("cannot have a null vector of lagrange multipliers when calling getSecondOrderResults -- okay if zero");
07009 if( m_vdLambda.size() > 0) m_vdLambda.clear();
07010 for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
07011 {
07012 if( posMapExpTree->first >= 0)
07013 {
07014 m_vdLambda.push_back( conMultipliers[ posMapExpTree->first]);
07015 }
07016 else
07017 {
07018
07019 m_vdLambda.push_back( objLambda[ abs(posMapExpTree->first) - 1] );
07020 }
07021 }
07022 for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
07023 {
07024 m_vdDomainUnitVec[i] = 1.;
07025 rowNum = 0;
07026 if( m_mapExpressionTreesMod.size() > 0)
07027 {
07028 m_vdYjacval = this->forwardAD(1, m_vdDomainUnitVec);
07029 }
07030
07031
07032 for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
07033 {
07034 idx = posMapExpTree->first;
07035
07036 if(idx >= 0)
07037 {
07038
07039
07040
07041
07042 expTree = m_mapExpressionTreesMod[ idx];
07043 if( (*expTree->mapVarIdx).find( m_miNonLinearVarsReverseMap[ i]) != (*expTree->mapVarIdx).end() )
07044 {
07045 jacIndex = (*m_mapExpressionTreesMod[ idx]->mapVarIdx)[ m_miNonLinearVarsReverseMap[ i]];
07046 jstart = m_miJacStart[ idx] + m_miJacNumConTerms[ idx];
07047 m_mdJacValue[ jstart + jacIndex] = m_vdYjacval[m_iObjectiveNumberNonlinear + rowNum];
07048 }
07049 rowNum++;
07050 }
07051 else
07052 {
07053
07054
07055 m_mmdObjGradient[ (abs( idx) - 1)][ m_miNonLinearVarsReverseMap[ i]] = m_vdYjacval[ (abs( idx) - 1)] +
07056 m_mmdDenseObjectiveCoefficients[ (abs( idx) - 1)][ m_miNonLinearVarsReverseMap[ i]];
07057 }
07058 }
07059
07060 if( m_mapExpressionTreesMod.size() > 0)
07061 {
07062 m_vdw = reverseAD(2, m_vdLambda);
07063 }
07064 for(j = i; j < m_iNumberOfNonlinearVariables; j++)
07065 {
07066 if( m_vbLagHessNonz[i*m_iNumberOfNonlinearVariables + j] == true)
07067 {
07068 m_LagrangianSparseHessian->hessValues[ hessValuesIdx] = m_vdw[ j*2 + 1];
07069 #ifndef NDEBUG
07070 outStr.str("");
07071 outStr.clear();
07072 outStr << "reverse 2 " << m_LagrangianSparseHessian->hessValues[ hessValuesIdx] << std::endl;
07073 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
07074 #endif
07075 hessValuesIdx++;
07076 }
07077 }
07078
07079
07080 m_vdDomainUnitVec[i] = 0.;
07081 }
07082 #ifndef NDEBUG
07083 outStr.str("");
07084 outStr.clear();
07085 int k;
07086 outStr << "JACOBIAN DATA " << std::endl;
07087 for(idx = 0; idx < m_iConstraintNumber; idx++)
07088 {
07089 for(k = *(m_sparseJacMatrix->starts + idx); k < *(m_sparseJacMatrix->starts + idx + 1); k++)
07090 {
07091 outStr << "row idx = " << idx << " col idx = "<< *(m_sparseJacMatrix->indexes + k)
07092 << " value = " << *(m_sparseJacMatrix->values + k) << std::endl;
07093 }
07094 }
07095 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
07096 #endif
07097 return true;
07098 }
07099 catch(const ErrorClass& eclass)
07100 {
07101 throw ErrorClass( eclass.errormsg);
07102 }
07103 }
07104
07105 bool OSInstance::initForAlgDiff()
07106 {
07107 std::ostringstream outStr;
07108
07109 if( m_binitForAlgDiff == true ) return true;
07110 initializeNonLinearStructures( );
07111 initObjGradients();
07112 getAllNonlinearVariablesIndexMap( );
07113
07114
07115
07116 std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
07117 for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
07118 {
07119 if(posMapExpTree->second->bADMustReTape == true) m_bCppADMustReTape = true;
07120 }
07121
07122 #ifndef NDEBUG
07123 outStr << "RETAPE == " << m_bCppADMustReTape << std::endl;
07124 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
07125 #endif
07126 unsigned int i;
07127 for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
07128 {
07129 m_vdDomainUnitVec.push_back( 0.0 );
07130 }
07131 for(i = 0; i < m_mapExpressionTreesMod.size(); i++)
07132 {
07133 m_vdRangeUnitVec.push_back( 0.0 );
07134 }
07135 m_binitForAlgDiff = true;
07136
07137
07138 return true;
07139 }
07140
07141 bool OSInstance::initObjGradients()
07142 {
07143 std::ostringstream outStr;
07144
07145 int i, j;
07146 int m, n;
07147 m = getObjectiveNumber();
07148 n = getVariableNumber();
07149 getDenseObjectiveCoefficients();
07150 if(m <= 0)
07151 {
07152 m_mmdObjGradient = NULL;
07153 return true;
07154 }
07155 m_mmdObjGradient = new double*[m];
07156 for(i = 0; i < m; i++)
07157 {
07158 m_mmdObjGradient[i] = new double[n];
07159 for(j = 0; j < n; j++)
07160 {
07161 m_mmdObjGradient[i][j] = m_mmdDenseObjectiveCoefficients[ i][j];
07162 #ifndef NDEBUG
07163 outStr << "m_mmdObjGradient[i][j] = " << m_mmdObjGradient[i][j] << std::endl;
07164 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
07165 #endif
07166 }
07167 }
07168 return true;
07169 }
07185 bool OSInstance::setTimeDomain(std::string format)
07186 {
07187 if ((format != "stages") && (format != "interval") && (format != "none"))
07188 return false;
07189 if (instanceData->timeDomain == NULL)
07190 {
07191 instanceData->timeDomain = new TimeDomain();
07192 }
07193 if (format == "stages")
07194 {
07195 if (instanceData->timeDomain->interval != NULL)
07196 {
07197 delete instanceData->timeDomain->interval;
07198 instanceData->timeDomain->interval = NULL;
07199 }
07200 if (instanceData->timeDomain->stages == NULL)
07201 instanceData->timeDomain->stages = new TimeDomainStages();
07202 m_sTimeDomainFormat = format;
07203 }
07204 if (format == "interval")
07205 {
07206 if (instanceData->timeDomain->stages != NULL)
07207 {
07208 delete instanceData->timeDomain->stages;
07209 instanceData->timeDomain->stages = NULL;
07210 }
07211 if (instanceData->timeDomain->interval == NULL)
07212 instanceData->timeDomain->interval = new TimeDomainInterval();
07213 m_sTimeDomainFormat = format;
07214 }
07215 if (format == "none")
07216 {
07217 if (instanceData->timeDomain->stages != NULL)
07218 {
07219 delete instanceData->timeDomain->stages;
07220 instanceData->timeDomain->stages = NULL;
07221 }
07222 if (instanceData->timeDomain->interval != NULL)
07223 {
07224 delete instanceData->timeDomain->interval;
07225 instanceData->timeDomain->interval = NULL;
07226 }
07227 m_sTimeDomainFormat = "";
07228 }
07229 return true;
07230 }
07231
07235 bool OSInstance::setTimeDomainStages(int number, std::string *names)
07236 {
07237 if (instanceData->timeDomain == NULL)
07238 instanceData->timeDomain = new TimeDomain();
07239 if (instanceData->timeDomain->interval != NULL)
07240 return false;
07241 if (instanceData->timeDomain->stages == NULL)
07242 {
07243 instanceData->timeDomain->stages = new TimeDomainStages;
07244 }
07245 else
07246 {
07247 if (instanceData->timeDomain->stages->numberOfStages != number)
07248 {
07249 for (int i = 0; i < instanceData->timeDomain->stages->numberOfStages; i++)
07250 {
07251 if (instanceData->timeDomain->stages->stage[i]->variables != NULL)
07252 {
07253 delete instanceData->timeDomain->stages->stage[i]->variables;
07254 instanceData->timeDomain->stages->stage[i]->variables = NULL;
07255 }
07256 if (instanceData->timeDomain->stages->stage[i]->constraints != NULL)
07257 {
07258 delete instanceData->timeDomain->stages->stage[i]->constraints;
07259 instanceData->timeDomain->stages->stage[i]->constraints = NULL;
07260
07261 }
07262 if (instanceData->timeDomain->stages->stage[i]->objectives != NULL)
07263 {
07264 delete instanceData->timeDomain->stages->stage[i]->objectives;
07265 instanceData->timeDomain->stages->stage[i]->objectives = NULL;
07266 }
07267 delete instanceData->timeDomain->stages->stage[i];
07268 instanceData->timeDomain->stages->stage[i] = NULL;
07269 }
07270 delete []instanceData->timeDomain->stages->stage;
07271 instanceData->timeDomain->stages->stage = NULL;
07272 }
07273 }
07274 if (number != 0 )
07275 {
07276 if (instanceData->timeDomain->stages->stage == NULL)
07277 instanceData->timeDomain->stages->stage = new TimeDomainStage*[number];
07278 for (int i = 0; i < number; i++)
07279 {
07280 instanceData->timeDomain->stages->stage[i] = new TimeDomainStage();
07281 }
07282 instanceData->timeDomain->stages->numberOfStages = number;
07283 }
07284 for (int i = 0; i < number; i++)
07285
07286 {
07287 if (instanceData->timeDomain->stages->stage[i]->variables != NULL)
07288 {
07289 delete instanceData->timeDomain->stages->stage[i]->variables;
07290 instanceData->timeDomain->stages->stage[i]->variables = NULL;
07291 }
07292 instanceData->timeDomain->stages->stage[i]->variables = new TimeDomainStageVariables();
07293 if (instanceData->timeDomain->stages->stage[i]->constraints != NULL)
07294 {
07295 delete instanceData->timeDomain->stages->stage[i]->constraints;
07296 instanceData->timeDomain->stages->stage[i]->constraints = NULL;
07297 }
07298 instanceData->timeDomain->stages->stage[i]->constraints = new TimeDomainStageConstraints();
07299 if (instanceData->timeDomain->stages->stage[i]->objectives != NULL)
07300 {
07301 delete instanceData->timeDomain->stages->stage[i]->objectives;
07302 instanceData->timeDomain->stages->stage[i]->objectives = NULL;
07303 }
07304 instanceData->timeDomain->stages->stage[i]->objectives = new TimeDomainStageObjectives();
07305 instanceData->timeDomain->stages->stage[i]->objectives->numberOfObjectives = instanceData->objectives->numberOfObjectives;
07306 instanceData->timeDomain->stages->stage[i]->objectives->obj = new TimeDomainStageObj*[instanceData->objectives->numberOfObjectives];
07307 for (int j = 0; j < instanceData->objectives->numberOfObjectives; j++)
07308 {
07309 instanceData->timeDomain->stages->stage[i]->objectives->obj[j] = new TimeDomainStageObj();
07310 instanceData->timeDomain->stages->stage[i]->objectives->obj[j]->idx = -(j+1);
07311 }
07312 if (names != NULL)
07313 instanceData->timeDomain->stages->stage[i]->name = names[i];
07314 }
07315 return true;
07316 }
07317
07321 bool OSInstance::setTimeDomainStageVariablesOrdered(int numberOfStages, int *numberOfVariables, int *startIdx)
07322 {
07323 if (instanceData->timeDomain == NULL)
07324 instanceData->timeDomain = new TimeDomain();
07325 if (instanceData->timeDomain->interval != NULL)
07326 return false;
07327 if (instanceData->timeDomain->stages == NULL)
07328 instanceData->timeDomain->stages = new TimeDomainStages();
07329 if (instanceData->timeDomain->stages != NULL)
07330 {
07331 if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
07332 (instanceData->timeDomain->stages->numberOfStages != 0))
07333 return false;
07334 }
07335 if (instanceData->timeDomain->stages->numberOfStages == 0)
07336 {
07337 instanceData->timeDomain->stages->numberOfStages = numberOfStages;
07338 if (instanceData->timeDomain->stages->stage == NULL)
07339 instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
07340 for (int i = 0; i < numberOfStages; i++)
07341 instanceData->timeDomain->stages->stage[i] = new TimeDomainStage();
07342 }
07343 int checksum = 0;
07344 for (int i = 0; i < numberOfStages; i++)
07345
07346 {
07347 if (instanceData->timeDomain->stages->stage[i]->variables != NULL)
07348 {
07349 delete instanceData->timeDomain->stages->stage[i]->variables;
07350 instanceData->timeDomain->stages->stage[i]->variables = NULL;
07351 }
07352 instanceData->timeDomain->stages->stage[i]->variables = new TimeDomainStageVariables();
07353 instanceData->timeDomain->stages->stage[i]->variables->startIdx = startIdx[i];
07354 instanceData->timeDomain->stages->stage[i]->variables->numberOfVariables = numberOfVariables[i];
07355 checksum += numberOfVariables[i];
07356 }
07357 return (checksum == instanceData->variables->numberOfVariables);
07358 }
07359
07363 bool OSInstance::setTimeDomainStageVariablesUnordered(int numberOfStages, int *numberOfVariables, int **varIndex)
07364 {
07365 if (instanceData->timeDomain == NULL)
07366 instanceData->timeDomain = new TimeDomain();
07367 if (instanceData->timeDomain->interval != NULL)
07368 return false;
07369 if (instanceData->timeDomain->stages == NULL)
07370 instanceData->timeDomain->stages = new TimeDomainStages();
07371 if (instanceData->timeDomain->stages != NULL)
07372 {
07373 if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
07374 (instanceData->timeDomain->stages->numberOfStages != 0))
07375 return false;
07376 }
07377 if (instanceData->timeDomain->stages->numberOfStages == 0 )
07378 {
07379 instanceData->timeDomain->stages->numberOfStages = numberOfStages;
07380 if (instanceData->timeDomain->stages->stage == NULL)
07381 instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
07382 for (int i = 0; i < numberOfStages; i++)
07383 instanceData->timeDomain->stages->stage[i] = new TimeDomainStage();
07384 }
07385 int checksum = 0;
07386 for (int i = 0; i < numberOfStages; i++)
07387
07388 {
07389 if (instanceData->timeDomain->stages->stage[i]->variables != NULL)
07390 {
07391 delete instanceData->timeDomain->stages->stage[i]->variables;
07392 instanceData->timeDomain->stages->stage[i]->variables = NULL;
07393 }
07394 instanceData->timeDomain->stages->stage[i]->variables = new TimeDomainStageVariables();
07395 instanceData->timeDomain->stages->stage[i]->variables->numberOfVariables = numberOfVariables[i];
07396 instanceData->timeDomain->stages->stage[i]->variables->var = new TimeDomainStageVar*[numberOfVariables[i]];
07397 for (int j = 0; j < numberOfVariables[i]; j++)
07398 {
07399 instanceData->timeDomain->stages->stage[i]->variables->var[j] = new TimeDomainStageVar();
07400 instanceData->timeDomain->stages->stage[i]->variables->var[j]->idx = varIndex[i][j];
07401 }
07402 checksum += numberOfVariables[i];
07403 }
07404 if (checksum != instanceData->variables->numberOfVariables) return false;
07405 int *checkvar = new int[instanceData->variables->numberOfVariables];
07406 for (int j = 0; j < instanceData->variables->numberOfVariables; j++)
07407 checkvar[j] = -1;
07408 int k;
07409 for (int i = 0; i < numberOfStages; i++)
07410 for (int j = 0; j < instanceData->timeDomain->stages->stage[i]->variables->numberOfVariables; j++)
07411 {
07412 k = instanceData->timeDomain->stages->stage[i]->variables->var[j]->idx;
07413 if (checkvar[k] != -1)
07414 {
07415 delete [] checkvar;
07416 checkvar = NULL;
07417 return false;
07418 }
07419 checkvar[k] = instanceData->timeDomain->stages->stage[i]->variables->var[j]->idx;
07420 }
07421 delete [] checkvar;
07422 checkvar = NULL;
07423 return true;
07424 }
07425
07429 bool OSInstance::setTimeDomainStageConstraintsOrdered(int numberOfStages, int *numberOfConstraints, int *startIdx)
07430 {
07431 if (instanceData->timeDomain == NULL)
07432 instanceData->timeDomain = new TimeDomain();
07433 if (instanceData->timeDomain->interval != NULL)
07434 return false;
07435 if (instanceData->timeDomain->stages == NULL)
07436 instanceData->timeDomain->stages = new TimeDomainStages();
07437 if (instanceData->timeDomain->stages != NULL)
07438 {
07439 if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
07440 (instanceData->timeDomain->stages->numberOfStages != 0))
07441 return false;
07442 }
07443 if (instanceData->timeDomain->stages->numberOfStages == 0 )
07444 {
07445 instanceData->timeDomain->stages->numberOfStages = numberOfStages;
07446 if (instanceData->timeDomain->stages->stage == NULL)
07447 instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
07448 for (int i = 0; i < numberOfStages; i++)
07449 instanceData->timeDomain->stages->stage[i] = new TimeDomainStage();
07450 }
07451 int checksum = 0;
07452 for (int i = 0; i < numberOfStages; i++)
07453
07454 {
07455 if (instanceData->timeDomain->stages->stage[i]->constraints != NULL)
07456 {
07457 delete instanceData->timeDomain->stages->stage[i]->constraints;
07458 instanceData->timeDomain->stages->stage[i]->constraints = NULL;
07459 }
07460 instanceData->timeDomain->stages->stage[i]->constraints = new TimeDomainStageConstraints();
07461 instanceData->timeDomain->stages->stage[i]->constraints->startIdx = startIdx[i];
07462 instanceData->timeDomain->stages->stage[i]->constraints->numberOfConstraints = numberOfConstraints[i];
07463 checksum += numberOfConstraints[i];
07464 }
07465 return (checksum == instanceData->constraints->numberOfConstraints);
07466 }
07467
07471 bool OSInstance::setTimeDomainStageConstraintsUnordered(int numberOfStages, int *numberOfConstraints, int **conIndex)
07472 {
07473 if (instanceData->timeDomain == NULL)
07474 instanceData->timeDomain = new TimeDomain();
07475 if (instanceData->timeDomain->interval != NULL)
07476 return false;
07477 if (instanceData->timeDomain->stages == NULL)
07478 instanceData->timeDomain->stages = new TimeDomainStages();
07479 if (instanceData->timeDomain->stages != NULL)
07480 {
07481 if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
07482 (instanceData->timeDomain->stages->numberOfStages != 0))
07483 return false;
07484 }
07485 if ( instanceData->timeDomain->stages->numberOfStages == 0 )
07486 {
07487 instanceData->timeDomain->stages->numberOfStages = numberOfStages;
07488 if (instanceData->timeDomain->stages->stage == NULL)
07489 instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
07490 for (int i = 0; i < numberOfStages; i++)
07491 instanceData->timeDomain->stages->stage[i] = new TimeDomainStage();
07492 }
07493 int checksum = 0;
07494 for (int i = 0; i < numberOfStages; i++)
07495
07496 {
07497 if (instanceData->timeDomain->stages->stage[i]->constraints != NULL)
07498 {
07499 delete instanceData->timeDomain->stages->stage[i]->constraints;
07500 instanceData->timeDomain->stages->stage[i]->constraints = NULL;
07501 }
07502 instanceData->timeDomain->stages->stage[i]->constraints = new TimeDomainStageConstraints();
07503 instanceData->timeDomain->stages->stage[i]->constraints->numberOfConstraints = numberOfConstraints[i];
07504 instanceData->timeDomain->stages->stage[i]->constraints->con = new TimeDomainStageCon*[numberOfConstraints[i]];
07505 for (int j = 0; j < numberOfConstraints[i]; j++)
07506 {
07507 instanceData->timeDomain->stages->stage[i]->constraints->con[j] = new TimeDomainStageCon();
07508 instanceData->timeDomain->stages->stage[i]->constraints->con[j]->idx = conIndex[i][j];
07509 }
07510 checksum += numberOfConstraints[i];
07511 }
07512 if (checksum != instanceData->constraints->numberOfConstraints) return false;
07513 int *checkvar = new int[instanceData->constraints->numberOfConstraints];
07514 for (int j = 0; j < instanceData->constraints->numberOfConstraints; j++)
07515 checkvar[j] = -1;
07516 int k;
07517 for (int i = 0; i < numberOfStages; i++)
07518 for (int j = 0; j < instanceData->timeDomain->stages->stage[i]->constraints->numberOfConstraints; j++)
07519 {
07520 k = instanceData->timeDomain->stages->stage[i]->constraints->con[j]->idx;
07521 if (checkvar[k] != -1)
07522 {
07523 delete [] checkvar;
07524 checkvar = NULL;
07525 return false;
07526 }
07527 checkvar[k] = instanceData->timeDomain->stages->stage[i]->constraints->con[j]->idx;
07528 }
07529 delete [] checkvar;
07530 checkvar = NULL;
07531 return true;
07532 }
07533
07537 bool OSInstance::setTimeDomainStageObjectivesOrdered(int numberOfStages, int *numberOfObjectives, int *startIdx)
07538 {
07539 if (instanceData->timeDomain == NULL)
07540 instanceData->timeDomain = new TimeDomain();
07541 if (instanceData->timeDomain->interval != NULL)
07542 return false;
07543 if (instanceData->timeDomain->stages == NULL)
07544
07545 instanceData->timeDomain->stages = new TimeDomainStages();
07546 if (instanceData->timeDomain->stages != NULL)
07547 {
07548 if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
07549 (instanceData->timeDomain->stages->numberOfStages != 0))
07550 return false;
07551 }
07552 if (instanceData->timeDomain->stages->numberOfStages == 0)
07553
07554 {
07555 instanceData->timeDomain->stages->numberOfStages = numberOfStages;
07556 if (instanceData->timeDomain->stages->stage == NULL)
07557 instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
07558 for (int i = 0; i < numberOfStages; i++)
07559 instanceData->timeDomain->stages->stage[i] = new TimeDomainStage();
07560 }
07561 for (int i = 0; i < numberOfStages; i++)
07562
07563 {
07564
07565 if (instanceData->timeDomain->stages->stage[i]->objectives != NULL)
07566 {
07567 delete instanceData->timeDomain->stages->stage[i]->objectives;
07568 instanceData->timeDomain->stages->stage[i]->objectives = NULL;
07569 }
07570 instanceData->timeDomain->stages->stage[i]->objectives = new TimeDomainStageObjectives();
07571 instanceData->timeDomain->stages->stage[i]->objectives->startIdx = startIdx[i];
07572 instanceData->timeDomain->stages->stage[i]->objectives->numberOfObjectives = numberOfObjectives[i];
07573 }
07574 return true;
07575 }
07576
07580 bool OSInstance::setTimeDomainStageObjectivesUnordered(int numberOfStages, int *numberOfObjectives, int **objIndex)
07581 {
07582 if (instanceData->timeDomain == NULL)
07583 instanceData->timeDomain = new TimeDomain();
07584 if (instanceData->timeDomain->interval != NULL)
07585 return false;
07586 if (instanceData->timeDomain->stages == NULL)
07587 instanceData->timeDomain->stages = new TimeDomainStages();
07588 if (instanceData->timeDomain->stages != NULL)
07589 {
07590 if ((instanceData->timeDomain->stages->numberOfStages != numberOfStages) &&
07591 (instanceData->timeDomain->stages->numberOfStages != 0))
07592 return false;
07593 }
07594 if (instanceData->timeDomain->stages->numberOfStages == 0)
07595 {
07596 instanceData->timeDomain->stages->numberOfStages = numberOfStages;
07597 if (instanceData->timeDomain->stages->stage == NULL)
07598 instanceData->timeDomain->stages->stage = new TimeDomainStage*[numberOfStages];
07599 for (int i = 0; i < numberOfStages; i++)
07600 instanceData->timeDomain->stages->stage[i] = new TimeDomainStage();
07601 }
07602 for (int i = 0; i < numberOfStages; i++)
07603
07604 {
07605 if (instanceData->timeDomain->stages->stage[i]->objectives != NULL)
07606 {
07607 delete instanceData->timeDomain->stages->stage[i]->objectives;
07608 instanceData->timeDomain->stages->stage[i]->objectives = NULL;
07609 }
07610 instanceData->timeDomain->stages->stage[i]->objectives = new TimeDomainStageObjectives();
07611 instanceData->timeDomain->stages->stage[i]->objectives->numberOfObjectives = numberOfObjectives[i];
07612 instanceData->timeDomain->stages->stage[i]->objectives->obj = new TimeDomainStageObj*[numberOfObjectives[i]];
07613 for (int j = 0; j < numberOfObjectives[i]; j++)
07614 {
07615 instanceData->timeDomain->stages->stage[i]->objectives->obj[j] = new TimeDomainStageObj();
07616 instanceData->timeDomain->stages->stage[i]->objectives->obj[j]->idx = objIndex[i][j];
07617 }
07618 }
07619 int *checkvar = new int[instanceData->objectives->numberOfObjectives];
07620 for (int j = 0; j < instanceData->objectives->numberOfObjectives; j++)
07621 checkvar[j] = 0;
07622 int k;
07623 for (int i = 0; i < numberOfStages; i++)
07624 for (int j = 0; j < instanceData->timeDomain->stages->stage[i]->objectives->numberOfObjectives; j++)
07625 {
07626 k = -instanceData->timeDomain->stages->stage[i]->objectives->obj[j]->idx-1;
07627 checkvar[k] = instanceData->timeDomain->stages->stage[i]->objectives->obj[j]->idx;
07628 }
07629 for (int i = 0; i < instanceData->objectives->numberOfObjectives; i++)
07630 if (checkvar[i] == 0)
07631 {
07632 delete [] checkvar;
07633 checkvar = NULL;
07634 return false;
07635 }
07636 delete [] checkvar;
07637 checkvar = NULL;
07638 return true;
07639 }
07640
07644 bool OSInstance::setTimeDomainInterval(double start, double horizon)
07645 {
07646 if (instanceData->timeDomain == NULL)
07647 instanceData->timeDomain = new TimeDomain();
07648 if (instanceData->timeDomain->stages != NULL)
07649 return false;
07650 if (instanceData->timeDomain->interval == NULL)
07651 instanceData->timeDomain->interval = new TimeDomainInterval();
07652 instanceData->timeDomain->interval->start = start;
07653 instanceData->timeDomain->interval->horizon = horizon;
07654 return true;
07655 }
07656
07657
07658 bool OSInstance::createOSADFun(std::vector<double> vdX)
07659 {
07660 try
07661 {
07662 if(m_bOSADFunIsCreated == true) return true;
07663
07664 if(m_binitForAlgDiff == false) initForAlgDiff();
07665
07666
07667 std::map<int, ScalarExpressionTree*>::iterator posMapExpTree;
07668 unsigned int i;
07669 size_t n = vdX.size();
07670 #ifdef COIN_HAS_CPPAD
07671
07672 CppAD::vector< CppAD::AD<double> > vdaX( n );
07673 for(i = 0; i < n; i++)
07674 {
07675 vdaX[ i] = vdX[ i];
07676 }
07677
07678 CppAD::Independent( vdaX);
07684 CppAD::vector< CppAD::AD<double> > m_vFG;
07685 int kount = 0;
07686 for(posMapExpTree = m_mapExpressionTreesMod.begin(); posMapExpTree != m_mapExpressionTreesMod.end(); ++posMapExpTree)
07687 {
07688 m_vFG.push_back( (posMapExpTree->second)->m_treeRoot->constructADTape(&m_mapAllNonlinearVariablesIndex, &vdaX) );
07689 if( m_mapOSADFunRangeIndex.find( posMapExpTree->first) == m_mapOSADFunRangeIndex.end() )
07690 {
07691
07692 m_mapOSADFunRangeIndex[ posMapExpTree->first] = kount;
07693 kount++;
07694 }
07695 }
07696
07697
07698 Fad = new CppAD::ADFun<double>(vdaX, m_vFG);
07699
07700 m_iHighestTaylorCoeffOrder = -1;
07701 m_bOSADFunIsCreated = true;
07702 #else
07703 throw ErrorClass( "Error: An Algorithmic Differentiation Package Not Available");
07704 #endif
07705
07706 return true;
07707 }
07708 catch(const ErrorClass& eclass)
07709 {
07710 throw ErrorClass( eclass.errormsg);
07711 }
07712 }
07713
07714
07715 std::vector<double> OSInstance::forwardAD(int p, std::vector<double> vdX)
07716 {
07717 try
07718 {
07719
07720 if(m_bOSADFunIsCreated == false) createOSADFun( vdX);
07721 if(p > (m_iHighestTaylorCoeffOrder + 1) ) throw
07722 ErrorClass( "trying to calculate a p order forward when p-1 Taylor coefficient not available");
07723
07724 m_iHighestTaylorCoeffOrder = p;
07725 m_iHighestOrderEvaluated = p;
07726 #ifdef COIN_HAS_CPPAD
07727 return (*Fad).Forward(p, vdX);
07728 #else
07729 throw ErrorClass( "Error: An Algorithmic Differentiation Package Not Available");
07730 #endif
07731
07732 }
07733 catch(const ErrorClass& eclass)
07734 {
07735 throw ErrorClass( eclass.errormsg);
07736 }
07737 }
07738
07739
07740 std::vector<double> OSInstance::reverseAD(int p, std::vector<double> vdlambda)
07741 {
07742 try
07743 {
07744 #ifndef COIN_HAS_CPPAD
07745 throw ErrorClass( "Error: An Algorithmic Differentiation Package Not Available");
07746 #endif
07747 if(p == 0) throw
07748 ErrorClass( "reverseAD must have p >= 1");
07749 if(p > (m_iHighestTaylorCoeffOrder + 1) ) throw
07750 ErrorClass( "trying to calculate a p order reverse when p-1 Taylor coefficient not available");
07751 m_iHighestOrderEvaluated = p;
07752 #ifdef COIN_HAS_CPPAD
07753 return (*Fad).Reverse(p, vdlambda);
07754 #endif
07755
07756 }
07757 catch(const ErrorClass& eclass)
07758 {
07759 throw ErrorClass( eclass.errormsg);
07760 }
07761 }
07762
07763
07764 int OSInstance::getADSparsityHessian()
07765 {
07766 unsigned int i;
07767 int numNonz;
07768 numNonz = 0;
07769 try
07770 {
07771 std::vector<bool> r(m_iNumberOfNonlinearVariables * m_iNumberOfNonlinearVariables);
07772 unsigned int j;
07773 for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
07774 {
07775 for(j = 0; j < m_iNumberOfNonlinearVariables; j++)
07776 r[ i * m_iNumberOfNonlinearVariables + j ] = false;
07777 r[ i * m_iNumberOfNonlinearVariables + i] = true;
07778 }
07779
07780
07781 #ifdef COIN_HAS_CPPAD
07782 (*Fad).ForSparseJac(m_iNumberOfNonlinearVariables, r);
07783 #else
07784 throw ErrorClass( "Error: An Algorithmic Differentiation Package Not Available");
07785 #endif
07786
07787
07788 unsigned int m = m_mapExpressionTreesMod.size();
07789 std::vector<bool> e( m);
07790
07791 for(i = 0; i < m; i++) e[i] = true;
07792 #ifndef NDEBUG
07793 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Computing Sparse Hessian");
07794 #endif
07795
07796 #ifdef COIN_HAS_CPPAD
07797 m_vbLagHessNonz = (*Fad).RevSparseHes(m_iNumberOfNonlinearVariables, e);
07798 #endif
07799
07800 for(i = 0; i < m_iNumberOfNonlinearVariables; i++)
07801 {
07802 for(j = i; j < m_iNumberOfNonlinearVariables; j++)
07803 {
07804 if(m_vbLagHessNonz[ i*m_iNumberOfNonlinearVariables + j] == true) numNonz++;
07805 }
07806 }
07807 return numNonz;
07808 }
07809 catch(const ErrorClass& eclass)
07810 {
07811 throw ErrorClass( eclass.errormsg);
07812 }
07813 }
07814
07815
07816
07817
07818
07819 std::string Cone::getConeInXML()
07820 {
07821 ostringstream outStr;
07822 outStr << "<cone";
07823 outStr << " numberOfRows=\"" << numberOfRows << "\"";
07824 outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
07825 if (name != "")
07826 outStr << " name=\"" << name << "\"";
07827 outStr << "/>" << std::endl;
07828 return outStr.str();
07829 }
07830
07831 std::string NonnegativeCone::getConeInXML()
07832 {
07833 ostringstream outStr;
07834 outStr << "<nonnegativeCone";
07835 outStr << " numberOfRows=\"" << numberOfRows << "\"";
07836 outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
07837 if (name != "")
07838 outStr << " name=\"" << name << "\"";
07839 outStr << "/>" << std::endl;
07840 return outStr.str();
07841 }
07842
07843 std::string NonpositiveCone::getConeInXML()
07844 {
07845 ostringstream outStr;
07846 outStr << "<nonpositiveCone";
07847 outStr << " numberOfRows=\"" << numberOfRows << "\"";
07848 outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
07849 if (name != "")
07850 outStr << " name=\"" << name << "\"";
07851 outStr << "/>" << std::endl;
07852 return outStr.str();
07853 }
07854
07855 std::string OrthantCone::getConeInXML()
07856 {
07857 ostringstream outStr;
07858 outStr << "<generalOrthantCone";
07859 outStr << " numberOfRows=\"" << numberOfRows << "\"";
07860 outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
07861 if (name != "")
07862 outStr << " name=\"" << name << "\"";
07863 outStr << ">" << std::endl;
07864 int i = 0;
07865 int mult = 1;
07866 double ubt;
07867 double lbt;
07868 while (i < numberOfRows*numberOfColumns)
07869 {
07870 ubt = ub[i];
07871 lbt = lb[i];
07872 if (i+mult < numberOfRows*numberOfColumns && ubt == ub[i+mult] && lbt == lb[i+mult])
07873 {
07874 mult++;
07875 }
07876 else
07877 {
07878 outStr << "<direction";
07879 if (ubt == 0.0)
07880 if (lbt == 0.0)
07881 outStr << " type=\"zero\"";
07882 else
07883 outStr << " type=\"nonpositive\"";
07884 else if(lbt == 0.0)
07885 outStr << " type=\"nonnegative\"";
07886 else
07887 outStr << " type=\"free\"";
07888 if (mult > 1)
07889 outStr <<" mult=\"" << mult << "\"";
07890 outStr << "/>";
07891 i += mult;
07892 mult = 1;
07893 }
07894 }
07895 outStr << "</generalOrthantCone>" << std::endl;
07896 return outStr.str();
07897 }
07898
07899 std::string PolyhedralCone::getConeInXML()
07900 {
07901 ostringstream outStr;
07902 outStr << "<polyhedralCone";
07903 outStr << " numberOfRows=\"" << numberOfRows << "\"";
07904 outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
07905 outStr << " referenceMatrixIdx=\"" << referenceMatrixIdx << "\"";
07906 if (name != "")
07907 outStr << " name=\"" << name << "\"";
07908 outStr << "/>" << std::endl;
07909 return outStr.str();
07910 }
07911
07912 std::string QuadraticCone::getConeInXML()
07913 {
07914 ostringstream outStr;
07915 outStr << "<quadraticCone";
07916 outStr << " numberOfRows=\"" << numberOfRows << "\"";
07917 outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
07918 if (name != "")
07919 outStr << " name=\"" << name << "\"";
07920 if (normScaleFactor != 1.0)
07921 outStr << " normScaleFactor=\"" << normScaleFactor << "\"";
07922 if (distortionMatrixIdx != -1)
07923 outStr << " distortionMatrixIdx=\"" << distortionMatrixIdx << "\"";
07924 if (axisDirection != 0)
07925 outStr << " axisDirection=\"" << axisDirection << "\"";
07926 outStr << "/>" << std::endl;
07927 return outStr.str();
07928 }
07929
07930 std::string RotatedQuadraticCone::getConeInXML()
07931 {
07932 ostringstream outStr;
07933 outStr << "<rotatedQuadraticCone";
07934 outStr << " numberOfRows=\"" << numberOfRows << "\"";
07935 outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
07936 if (name != "")
07937 outStr << " name=\"" << name << "\"";
07938 if (normScaleFactor != 1.0)
07939 outStr << " normScaleFactor=\"" << normScaleFactor << "\"";
07940 if (distortionMatrixIdx != -1)
07941 outStr << " distortionMatrixIdx=\"" << distortionMatrixIdx << "\"";
07942 if (firstAxisDirection != 0)
07943 outStr << " firstAxisDirection=\"" << firstAxisDirection << "\"";
07944 if (secondAxisDirection != 1)
07945 outStr << " secondAxisDirection=\"" << secondAxisDirection << "\"";
07946 outStr << "/>" << std::endl;
07947 return outStr.str();
07948 }
07949
07950 std::string SemidefiniteCone::getConeInXML()
07951 {
07952 ostringstream outStr;
07953 outStr << "<semidefiniteCone";
07954 outStr << " numberOfRows=\"" << numberOfRows << "\"";
07955 outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
07956 if (semidefiniteness != "positive")
07957 outStr << " semidefiniteness=\"" << semidefiniteness << "\"";
07958 outStr << "/>" << std::endl;
07959
07960 return outStr.str();
07961 }
07962
07963 std::string CopositiveMatricesCone::getConeInXML()
07964 {
07965 ostringstream outStr;
07966 outStr << "<nonnegativeCone";
07967 outStr << " numberOfRows=\"" << numberOfRows << "\"";
07968 outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
07969 if (name != "")
07970 outStr << " name=\"" << name << "\"";
07971 outStr << "/>" << std::endl;
07972 return outStr.str();
07973 }
07974
07975 std::string CompletelyPositiveMatricesCone::getConeInXML()
07976 {
07977 ostringstream outStr;
07978 outStr << "<nonnegativeCone";
07979 outStr << " numberOfRows=\"" << numberOfRows << "\"";
07980 outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
07981 if (name != "")
07982 outStr << " name=\"" << name << "\"";
07983 outStr << "/>" << std::endl;
07984 return outStr.str();
07985 }
07986
07987 std::string ProductCone::getConeInXML()
07988 {
07989 ostringstream outStr;
07990 outStr << "<productCone";
07991 outStr << " numberOfRows=\"" << numberOfRows << "\"";
07992 outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
07993 if (name != "")
07994 outStr << " name=\"" << name << "\"";
07995 outStr << ">" << std::endl;
07996
07997 outStr << "<factors numberOfEl=\"" << factors->numberOfEl << "\">" << std::endl;
07998 outStr << writeIntVectorData(factors, true, false);
07999 outStr << "</factors>" << std::endl;
08000
08001 outStr << "</productCone>" << std::endl;
08002 return outStr.str();
08003 }
08004
08005 std::string IntersectionCone::getConeInXML()
08006 {
08007 ostringstream outStr;
08008 outStr << "<intersectionCone";
08009 outStr << " numberOfRows=\"" << numberOfRows << "\"";
08010 outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
08011 if (name != "")
08012 outStr << " name=\"" << name << "\"";
08013 outStr << ">" << std::endl;
08014
08015 outStr << "<components numberOfEl=\"" << components->numberOfEl << "\">";
08016 outStr << writeIntVectorData(components, true, false);
08017 outStr << "</components>" << std::endl;
08018
08019 outStr << "</intersectionCone>" << std::endl;
08020 return outStr.str();
08021 }
08022
08023
08024
08025
08026
08027
08028 bool OSInstance::IsEqual(OSInstance *that)
08029 {
08030 #ifndef NDEBUG
08031 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in OSInstance");
08032 #endif
08033 if (this == NULL)
08034 {
08035 if (that == NULL)
08036 return true;
08037 else
08038 {
08039 #ifndef NDEBUG
08040 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08041 "First object is NULL, second is not");
08042 #endif
08043 return false;
08044 }
08045 }
08046 else
08047 {
08048 if (that == NULL)
08049 {
08050 #ifndef NDEBUG
08051 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08052 "Second object is NULL, first is not");
08053 #endif
08054 return false;
08055 }
08056 else
08057 {
08058 if (!this->instanceHeader->IsEqual(that->instanceHeader))
08059 return false;
08060 if (!this->instanceData->IsEqual(that->instanceData))
08061 return false;
08062
08063 return true;
08064 }
08065 }
08066 }
08067
08068
08069 bool InstanceData::IsEqual(InstanceData *that)
08070 {
08071 #ifndef NDEBUG
08072 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in InstanceData");
08073 #endif
08074 if (this == NULL)
08075 {
08076 if (that == NULL)
08077 return true;
08078 else
08079 {
08080 #ifndef NDEBUG
08081 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08082 "First object is NULL, second is not");
08083 #endif
08084 return false;
08085 }
08086 }
08087 else
08088 {
08089 if (that == NULL)
08090 {
08091 #ifndef NDEBUG
08092 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08093 "Second object is NULL, first is not");
08094 #endif
08095 return false;
08096 }
08097 else
08098 {
08099 if (!this->variables->IsEqual(that->variables))
08100 return false;
08101 if (!this->objectives->IsEqual(that->objectives))
08102 return false;
08103 if (!this->constraints->IsEqual(that->constraints))
08104 return false;
08105 if (!this->linearConstraintCoefficients->IsEqual(that->linearConstraintCoefficients))
08106 return false;
08107 if (!this->quadraticCoefficients->IsEqual(that->quadraticCoefficients))
08108 return false;
08109 if (!this->nonlinearExpressions->IsEqual(that->nonlinearExpressions))
08110 return false;
08111 if (!this->matrices->IsEqual(that->matrices))
08112 return false;
08113 if (!this->cones->IsEqual(that->cones))
08114 return false;
08115 if (!this->matrixProgramming->IsEqual(that->matrixProgramming))
08116 return false;
08117
08118 return true;
08119 }
08120 }
08121 }
08122
08123 bool Variables::IsEqual(Variables *that)
08124 {
08125 #ifndef NDEBUG
08126 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Variables");
08127
08128 #endif
08129 if (this == NULL)
08130 {
08131 if (that == NULL)
08132 return true;
08133 else
08134 {
08135 #ifndef NDEBUG
08136 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08137 "First object is NULL, second is not");
08138 #endif
08139 return false;
08140 }
08141 }
08142 else
08143 {
08144 if (that == NULL)
08145 {
08146 #ifndef NDEBUG
08147 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08148 "Second object is NULL, first is not");
08149 #endif
08150 return false;
08151 }
08152 else
08153 {
08154 if (this->numberOfVariables != that->numberOfVariables)
08155 return false;
08156 for (int i=0; i<this->numberOfVariables; i++)
08157 if (!this->var[i]->IsEqual(that->var[i]))
08158 return false;
08159
08160 return true;
08161 }
08162 }
08163 }
08164
08165 bool Variable::IsEqual(Variable *that)
08166 {
08167 #ifndef NDEBUG
08168 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Variable");
08169 #endif
08170 if (this == NULL)
08171 {
08172 if (that == NULL)
08173 return true;
08174 else
08175 {
08176 #ifndef NDEBUG
08177 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08178 "First object is NULL, second is not");
08179 #endif
08180 return false;
08181 }
08182 }
08183 else
08184 {
08185 if (that == NULL)
08186 {
08187 #ifndef NDEBUG
08188 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08189 "Second object is NULL, first is not");
08190 #endif
08191 return false;
08192 }
08193 else
08194 {
08195 if (this->lb != that->lb)
08196 return false;
08197 if (this->ub != that->ub)
08198 return false;
08199 if (this->type != that->type)
08200 return false;
08201 if (this->name != that->name)
08202 return false;
08203
08204 return true;
08205 }
08206 }
08207 }
08208
08209 bool Objectives::IsEqual(Objectives *that)
08210 {
08211 #ifndef NDEBUG
08212 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Objectives");
08213 #endif
08214 if (this == NULL)
08215 {
08216 if (that == NULL)
08217 return true;
08218 else
08219 {
08220 #ifndef NDEBUG
08221 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08222 "First object is NULL, second is not");
08223 #endif
08224 return false;
08225 }
08226 }
08227 else
08228 {
08229 if (that == NULL)
08230 {
08231 #ifndef NDEBUG
08232 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08233 "Second object is NULL, first is not");
08234 #endif
08235 return false;
08236 }
08237 else
08238 {
08239 if (this->numberOfObjectives != that->numberOfObjectives)
08240 return false;
08241 for (int i=0; i<this->numberOfObjectives; i++)
08242 if (!this->obj[i]->IsEqual(that->obj[i]))
08243 return false;
08244
08245 return true;
08246 }
08247 }
08248 }
08249
08250 bool Objective::IsEqual(Objective *that)
08251 {
08252 #ifndef NDEBUG
08253 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Objective");
08254 #endif
08255 if (this == NULL)
08256 {
08257 if (that == NULL)
08258 return true;
08259 else
08260 {
08261 #ifndef NDEBUG
08262 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08263 "First object is NULL, second is not");
08264 #endif
08265 return false;
08266 }
08267 }
08268 else
08269 {
08270 if (that == NULL)
08271 {
08272 #ifndef NDEBUG
08273 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08274 "Second object is NULL, first is not");
08275 #endif
08276 return false;
08277 }
08278 else
08279 {
08280 if (this->name != that->name)
08281 return false;
08282 if (this->maxOrMin != that->maxOrMin)
08283 return false;
08284 if (this->constant != that->constant)
08285 return false;
08286 if (!OSIsEqual(this->weight, that->weight))
08287 return false;
08288 if (this->numberOfObjCoef != that->numberOfObjCoef)
08289 return false;
08290
08291 for (int i=0; i<this->numberOfObjCoef; i++)
08292 if (!this->coef[i]->IsEqual(that->coef[i]))
08293 return false;
08294
08295 return true;
08296 }
08297 }
08298 }
08299
08300 bool ObjCoef::IsEqual(ObjCoef *that)
08301 {
08302 #ifndef NDEBUG
08303 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in ObjCoef");
08304 #endif
08305 if (this == NULL)
08306 {
08307 if (that == NULL)
08308 return true;
08309 else
08310 {
08311 #ifndef NDEBUG
08312 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08313 "First object is NULL, second is not");
08314 #endif
08315 return false;
08316 }
08317 }
08318 else
08319 {
08320 if (that == NULL)
08321 {
08322 #ifndef NDEBUG
08323 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08324 "Second object is NULL, first is not");
08325 #endif
08326 return false;
08327 }
08328 else
08329 {
08330 if (this->idx != that->idx)
08331 return false;
08332 if (this->value != that->value)
08333 return false;
08334
08335 return true;
08336 }
08337 }
08338 }
08339
08340 bool Constraints::IsEqual(Constraints *that)
08341 {
08342 #ifndef NDEBUG
08343 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Constraints");
08344 #endif
08345 if (this == NULL)
08346 {
08347 if (that == NULL)
08348 return true;
08349 else
08350 {
08351 #ifndef NDEBUG
08352 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08353 "First object is NULL, second is not");
08354 #endif
08355 return false;
08356 }
08357 }
08358 else
08359 {
08360 if (that == NULL)
08361 {
08362 #ifndef NDEBUG
08363 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08364 "Second object is NULL, first is not");
08365 #endif
08366 return false;
08367 }
08368 else
08369 {
08370 if (this->numberOfConstraints != that->numberOfConstraints)
08371 return false;
08372 for (int i=0; i<this->numberOfConstraints; i++)
08373 if (!this->con[i]->IsEqual(that->con[i]))
08374 return false;
08375
08376 return true;
08377 }
08378 }
08379 }
08380
08381 bool Constraint::IsEqual(Constraint *that)
08382 {
08383 #ifndef NDEBUG
08384 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Constraint");
08385 #endif
08386 if (this == NULL)
08387 {
08388 if (that == NULL)
08389 return true;
08390 else
08391 {
08392 #ifndef NDEBUG
08393 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08394 "First object is NULL, second is not");
08395 #endif
08396 return false;
08397 }
08398 }
08399 else
08400 {
08401 if (that == NULL)
08402 {
08403 #ifndef NDEBUG
08404 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08405 "Second object is NULL, first is not");
08406 #endif
08407 return false;
08408 }
08409 else
08410 {
08411 if (this->name != that->name)
08412 return false;
08413 if (this->constant != that->constant)
08414 return false;
08415 if (this->lb != that->lb)
08416 return false;
08417 if (this->ub != that->ub)
08418 return false;
08419
08420 return true;
08421
08422 }
08423 }
08424 }
08425
08426 bool LinearConstraintCoefficients::IsEqual(LinearConstraintCoefficients *that)
08427 {
08428 #ifndef NDEBUG
08429 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in LinearConstraintCoefficients");
08430 #endif
08431 if (this == NULL)
08432 {
08433 if (that == NULL)
08434 return true;
08435 else
08436 {
08437 #ifndef NDEBUG
08438 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08439 "First object is NULL, second is not");
08440 #endif
08441 return false;
08442 }
08443 }
08444 else
08445 {
08446 if (that == NULL)
08447 {
08448 #ifndef NDEBUG
08449 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08450 "Second object is NULL, first is not");
08451 #endif
08452 return false;
08453 }
08454 else
08455 {
08456 if (this->numberOfValues != that->numberOfValues)
08457 return false;
08458
08459 if (!this->start->IsEqual(that->start))
08460 return false;
08461 if (!this->rowIdx->IsEqual(that->rowIdx))
08462 return false;
08463 if (!this->colIdx->IsEqual(that->colIdx))
08464 return false;
08465 if (!this->value->IsEqual(that->value))
08466 return false;
08467
08468 return true;
08469 }
08470 }
08471 }
08472
08473 bool QuadraticCoefficients::IsEqual(QuadraticCoefficients *that)
08474 {
08475 #ifndef NDEBUG
08476 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in QuadraticCoefficients");
08477 #endif
08478 if (this == NULL)
08479 {
08480 if (that == NULL)
08481 return true;
08482 else
08483 {
08484 #ifndef NDEBUG
08485 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08486 "First object is NULL, second is not");
08487
08488 #endif
08489 return false;
08490 }
08491 }
08492 else
08493 {
08494 if (that == NULL)
08495 {
08496 #ifndef NDEBUG
08497 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08498 "Second object is NULL, first is not");
08499 #endif
08500 return false;
08501 }
08502 else
08503
08504 {
08505 if (this->numberOfQuadraticTerms != that->numberOfQuadraticTerms)
08506 return false;
08507 for (int i=0; i<this->numberOfQuadraticTerms; i++)
08508 if (!this->qTerm[i]->IsEqual(that->qTerm[i]))
08509 return false;
08510
08511 return true;
08512 }
08513 }
08514 }
08515
08516
08517 bool QuadraticTerm::IsEqual(QuadraticTerm *that)
08518 {
08519 #ifndef NDEBUG
08520 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in QuadraticTerm");
08521 #endif
08522 if (this == NULL)
08523 {
08524 if (that == NULL)
08525 return true;
08526 else
08527 {
08528 #ifndef NDEBUG
08529 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08530 "First object is NULL, second is not");
08531 #endif
08532 return false;
08533 }
08534 }
08535 else
08536 {
08537 if (that == NULL)
08538 {
08539 #ifndef NDEBUG
08540 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08541 "Second object is NULL, first is not");
08542 #endif
08543 return false;
08544 }
08545 else
08546 {
08547 if (this->idx != that->idx)
08548 return false;
08549 if (this->idxOne != that->idxOne)
08550 return false;
08551 if (this->idxTwo != that->idxTwo)
08552 return false;
08553 if (this->coef != that->coef)
08554 return false;
08555
08556 return true;
08557 }
08558 }
08559 }
08560
08561 bool NonlinearExpressions::IsEqual(NonlinearExpressions *that)
08562 {
08563 #ifndef NDEBUG
08564 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in NonlinearExpressions");
08565 #endif
08566 if (this == NULL)
08567 {
08568 if (that == NULL)
08569 return true;
08570 else
08571 {
08572 #ifndef NDEBUG
08573 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08574 "First object is NULL, second is not");
08575 #endif
08576 return false;
08577 }
08578 }
08579 else
08580 {
08581 if (that == NULL)
08582 {
08583 #ifndef NDEBUG
08584 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08585 "Second object is NULL, first is not");
08586 #endif
08587 return false;
08588 }
08589 else
08590 {
08591 if (this->numberOfNonlinearExpressions != that->numberOfNonlinearExpressions)
08592 return false;
08593
08594 for (int i=0; i<this->numberOfNonlinearExpressions; i++)
08595 if (!this->nl[i]->IsEqual(that->nl[i]))
08596 return false;
08597
08598 return true;
08599 }
08600 }
08601 }
08602
08603
08604 bool Nl::IsEqual(Nl *that)
08605 {
08606 #ifndef NDEBUG
08607 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Nl");
08608 #endif
08609 if (this == NULL)
08610 {
08611 if (that == NULL)
08612 return true;
08613 else
08614 {
08615 #ifndef NDEBUG
08616 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08617 "First object is NULL, second is not");
08618 #endif
08619 return false;
08620 }
08621 }
08622 else
08623 {
08624 if (that == NULL)
08625 {
08626 #ifndef NDEBUG
08627 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08628 "Second object is NULL, first is not");
08629 #endif
08630 return false;
08631 }
08632 else
08633 {
08634 if (this->idx != that->idx)
08635 return false;
08636 if (!this->osExpressionTree->IsEqual(that->osExpressionTree))
08637 return false;
08638
08639 return true;
08640 }
08641 }
08642 }
08643
08644 bool Matrices::IsEqual(Matrices *that)
08645 {
08646 #ifndef NDEBUG
08647 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Matrices");
08648 #endif
08649 if (this == NULL)
08650 {
08651 if (that == NULL)
08652 return true;
08653 else
08654 {
08655 #ifndef NDEBUG
08656 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08657 "First object is NULL, second is not");
08658 #endif
08659 return false;
08660 }
08661 }
08662 else
08663 {
08664 if (that == NULL)
08665 {
08666 #ifndef NDEBUG
08667 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08668 "Second object is NULL, first is not");
08669 #endif
08670 return false;
08671 }
08672 else
08673 {
08674 if (this->numberOfMatrices != that->numberOfMatrices)
08675 return false;
08676 for (int i=0; i<this->numberOfMatrices; i++)
08677 if (!this->matrix[i]->IsEqual(that->matrix[i]))
08678 return false;
08679
08680 return true;
08681 }
08682 }
08683 }
08684
08685 bool Cones::IsEqual(Cones *that)
08686 {
08687 #ifndef NDEBUG
08688 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Cones");
08689 #endif
08690 if (this == NULL)
08691 {
08692 if (that == NULL)
08693 return true;
08694 else
08695 {
08696 #ifndef NDEBUG
08697 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08698 "First object is NULL, second is not");
08699 #endif
08700 return false;
08701 }
08702 }
08703 else
08704 {
08705 if (that == NULL)
08706 {
08707 #ifndef NDEBUG
08708 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08709 "Second object is NULL, first is not");
08710 #endif
08711 return false;
08712 }
08713 else
08714 {
08715 if (this->numberOfCones != that->numberOfCones)
08716 return false;
08717 for (int i=0; i<this->numberOfCones; i++)
08718 if (!this->cone[i]->IsEqual(that->cone[i]))
08719 return false;
08720
08721 return true;
08722 }
08723 }
08724 }
08725
08726 bool Cone::IsEqual(Cone *that)
08727 {
08728 #ifndef NDEBUG
08729 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in Cone");
08730 #endif
08731 if (this == NULL)
08732 {
08733 if (that == NULL)
08734 return true;
08735 else
08736 {
08737 #ifndef NDEBUG
08738 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08739 "First object is NULL, second is not");
08740 #endif
08741 return false;
08742 }
08743 }
08744 else
08745 {
08746 if (that == NULL)
08747 {
08748 #ifndef NDEBUG
08749 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08750 "Second object is NULL, first is not");
08751 #endif
08752 return false;
08753 }
08754 else
08755 {
08756 if (this->coneType != that->coneType)
08757 return false;
08758 if (this->numberOfColumns != that->numberOfColumns)
08759 return false;
08760 if (this->numberOfRows != that->numberOfRows)
08761 return false;
08762 if (this->numberOfOtherIndexes != that->numberOfOtherIndexes)
08763 return false;
08764 for (int i=0; i<this->numberOfOtherIndexes; i++)
08765 if (this->otherIndexes[i] != that->otherIndexes[i])
08766 return false;
08767 }
08768 }
08769 return true;
08770 }
08771
08772 bool PolyhedralCone::IsEqual(PolyhedralCone *that)
08773 {
08774 #ifndef NDEBUG
08775 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in PolyhedralCone");
08776 #endif
08777 if (this == NULL)
08778 {
08779 if (that == NULL)
08780 return true;
08781 else
08782 {
08783 #ifndef NDEBUG
08784 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08785 "First object is NULL, second is not");
08786 #endif
08787 return false;
08788 }
08789 }
08790 else
08791 {
08792 if (that == NULL)
08793 {
08794 #ifndef NDEBUG
08795 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08796 "Second object is NULL, first is not");
08797 #endif
08798 return false;
08799 }
08800 else
08801 {
08802 if (this->referenceMatrixIdx != that->referenceMatrixIdx)
08803 return false;
08804
08805 return this->Cone::IsEqual(that);
08806 }
08807 }
08808 }
08809
08810
08811 bool QuadraticCone::IsEqual(QuadraticCone *that)
08812 {
08813 #ifndef NDEBUG
08814 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in QuadraticCone");
08815 #endif
08816 if (this == NULL)
08817 {
08818 if (that == NULL)
08819 return true;
08820 else
08821 {
08822 #ifndef NDEBUG
08823 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08824 "First object is NULL, second is not");
08825 #endif
08826 return false;
08827 }
08828 }
08829 else
08830 {
08831 if (that == NULL)
08832 {
08833 #ifndef NDEBUG
08834 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08835 "Second object is NULL, first is not");
08836 #endif
08837 return false;
08838 }
08839 else
08840 {
08841 if (this->normScaleFactor != that->normScaleFactor)
08842 return false;
08843 if (this->distortionMatrixIdx != that->distortionMatrixIdx)
08844 return false;
08845 if (this->axisDirection != that->axisDirection)
08846 return false;
08847
08848 return this->Cone::IsEqual(that);
08849 }
08850 }
08851 }
08852
08853
08854
08855 bool RotatedQuadraticCone::IsEqual(RotatedQuadraticCone *that)
08856 {
08857 #ifndef NDEBUG
08858 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in RotatedQuadraticCone");
08859 #endif
08860 if (this == NULL)
08861 {
08862 if (that == NULL)
08863 return true;
08864 else
08865 {
08866 #ifndef NDEBUG
08867 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08868 "First object is NULL, second is not");
08869 #endif
08870 return false;
08871 }
08872 }
08873 else
08874 {
08875 if (that == NULL)
08876 {
08877 #ifndef NDEBUG
08878 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08879 "Second object is NULL, first is not");
08880 #endif
08881 return false;
08882 }
08883 else
08884 {
08885 if (this->normScaleFactor != that->normScaleFactor)
08886 return false;
08887 if (this->distortionMatrixIdx != that->distortionMatrixIdx)
08888 return false;
08889 if (this->firstAxisDirection != that->firstAxisDirection)
08890 return false;
08891 if (this->secondAxisDirection != that->secondAxisDirection)
08892 return false;
08893
08894 return this->Cone::IsEqual(that);
08895 }
08896 }
08897 }
08898
08899 bool SemidefiniteCone::IsEqual(SemidefiniteCone *that)
08900 {
08901 #ifndef NDEBUG
08902 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in SemidefiniteCone");
08903 #endif
08904 if (this == NULL)
08905 {
08906 if (that == NULL)
08907 return true;
08908 else
08909 {
08910 #ifndef NDEBUG
08911 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08912 "First object is NULL, second is not");
08913 #endif
08914 return false;
08915 }
08916 }
08917 else
08918 {
08919 if (that == NULL)
08920 {
08921 #ifndef NDEBUG
08922 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08923 "Second object is NULL, first is not");
08924 #endif
08925 return false;
08926 }
08927 else
08928 {
08929 if (this->semidefiniteness != that->semidefiniteness)
08930 return false;
08931 return this->Cone::IsEqual(that);
08932 }
08933 }
08934 return true;
08935 }
08936
08937 bool ProductCone::IsEqual(ProductCone *that)
08938 {
08939 #ifndef NDEBUG
08940 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in ProductCone");
08941 #endif
08942 if (this == NULL)
08943 {
08944 if (that == NULL)
08945 return true;
08946 else
08947 {
08948 #ifndef NDEBUG
08949 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08950 "First object is NULL, second is not");
08951 #endif
08952 return false;
08953 }
08954 }
08955 else
08956 {
08957 if (that == NULL)
08958 {
08959 #ifndef NDEBUG
08960 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08961 "Second object is NULL, first is not");
08962 #endif
08963 return false;
08964 }
08965 else
08966 {
08967 if (!this->factors->IsEqual(that->factors))
08968 return false;
08969 return this->Cone::IsEqual(that);
08970 }
08971 }
08972 return true;
08973 }
08974
08975 bool IntersectionCone::IsEqual(IntersectionCone *that)
08976 {
08977 #ifndef NDEBUG
08978 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in IntersectionCone");
08979 #endif
08980 if (this == NULL)
08981 {
08982 if (that == NULL)
08983 return true;
08984 else
08985 {
08986 #ifndef NDEBUG
08987 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08988 "First object is NULL, second is not");
08989 #endif
08990 return false;
08991 }
08992 }
08993 else
08994 {
08995 if (that == NULL)
08996 {
08997 #ifndef NDEBUG
08998 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
08999 "Second object is NULL, first is not");
09000 #endif
09001 return false;
09002 }
09003 else
09004 {
09005 if (!this->components->IsEqual(that->components))
09006 return false;
09007 return this->Cone::IsEqual(that);
09008 }
09009 }
09010 return true;
09011 }
09012
09013 bool DualCone::IsEqual(DualCone *that)
09014 {
09015 #ifndef NDEBUG
09016 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in DualCone");
09017 #endif
09018 if (this == NULL)
09019 {
09020 if (that == NULL)
09021 return true;
09022 else
09023 {
09024 #ifndef NDEBUG
09025 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09026 "First object is NULL, second is not");
09027 #endif
09028 return false;
09029 }
09030 }
09031 else
09032 {
09033 if (that == NULL)
09034 {
09035 #ifndef NDEBUG
09036 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09037 "Second object is NULL, first is not");
09038 #endif
09039 return false;
09040 }
09041 else
09042 {
09043 if (this->referenceConeIdx != that->referenceConeIdx)
09044 return false;
09045
09046 return this->Cone::IsEqual(that);
09047 }
09048 }
09049 }
09050
09051
09052 bool PolarCone::IsEqual(PolarCone *that)
09053 {
09054 #ifndef NDEBUG
09055 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in PolarCone");
09056 #endif
09057 if (this == NULL)
09058 {
09059 if (that == NULL)
09060 return true;
09061 else
09062
09063 {
09064 #ifndef NDEBUG
09065 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09066 "First object is NULL, second is not");
09067 #endif
09068 return false;
09069 }
09070 }
09071 else
09072 {
09073 if (that == NULL)
09074 {
09075 #ifndef NDEBUG
09076 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09077 "Second object is NULL, first is not");
09078 #endif
09079 return false;
09080 }
09081 else
09082 {
09083 if (this->referenceConeIdx != that->referenceConeIdx)
09084 return false;
09085
09086 return this->Cone::IsEqual(that);
09087 }
09088 }
09089 }
09090
09091
09092 bool MatrixProgramming::IsEqual(MatrixProgramming *that)
09093 {
09094 #ifndef NDEBUG
09095 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixProgramming");
09096 #endif
09097
09098 if (this == NULL)
09099 {
09100 if (that == NULL)
09101 return true;
09102 else
09103 {
09104 #ifndef NDEBUG
09105 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09106 "First object is NULL, second is not");
09107 #endif
09108 return false;
09109 }
09110 }
09111 else
09112 {
09113 if (that == NULL)
09114 {
09115 #ifndef NDEBUG
09116 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09117 "Second object is NULL, first is not");
09118 #endif
09119 return false;
09120 }
09121 else
09122 {
09123 if (this->matrixVariables != NULL)
09124 {
09125 if (!(this->matrixVariables->IsEqual(that->matrixVariables)))
09126 return false;
09127 }
09128 else
09129 {
09130 if (that->matrixVariables != NULL) return false;
09131 }
09132
09133 if (this->matrixObjectives != NULL)
09134 {
09135 if (!(this->matrixObjectives->IsEqual(that->matrixObjectives)))
09136 return false;
09137 }
09138 else
09139 {
09140 if (that->matrixObjectives != NULL) return false;
09141 }
09142
09143 if (this->matrixConstraints != NULL)
09144 {
09145 if (!(this->matrixConstraints->IsEqual(that->matrixConstraints)))
09146 return false;
09147 }
09148 else
09149 {
09150 if (that->matrixConstraints != NULL) return false;
09151 }
09152
09153 if (this->matrixExpressions != NULL)
09154 {
09155 if (!(this->matrixExpressions->IsEqual(that->matrixExpressions)))
09156 return false;
09157 }
09158 else
09159 {
09160 if (that->matrixExpressions != NULL) return false;
09161 }
09162
09163 return true;
09164 }
09165
09166 }
09167 }
09168
09169
09170 bool MatrixVariables::IsEqual(MatrixVariables *that)
09171 {
09172 #ifndef NDEBUG
09173 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixVariables");
09174 #endif
09175
09176 if (this == NULL)
09177 {
09178 if (that == NULL)
09179 return true;
09180 else
09181 {
09182 #ifndef NDEBUG
09183 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09184 "First object is NULL, second is not");
09185 #endif
09186 return false;
09187 }
09188 }
09189 else
09190 {
09191 if (that == NULL)
09192 {
09193 #ifndef NDEBUG
09194 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09195 "Second object is NULL, first is not");
09196 #endif
09197 return false;
09198 }
09199 else
09200 {
09201 if (this->numberOfMatrixVar != that->numberOfMatrixVar) return false;
09202
09203 for (int i=0; i<numberOfMatrixVar; i++)
09204 {
09205 if (this->matrixVar[i] != NULL)
09206 {
09207 if (!(this->matrixVar[i]->IsEqual(that->matrixVar[i]))) return false;
09208 }
09209 else
09210 if (that->matrixVar[i] != NULL) return false;
09211 }
09212
09213 return true;
09214 }
09215 }
09216 }
09217
09218 bool MatrixVar::IsEqual(MatrixVar *that)
09219 {
09220 #ifndef NDEBUG
09221 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixVar");
09222 #endif
09223
09224 if (this == NULL)
09225 {
09226 if (that == NULL)
09227 return true;
09228 else
09229 {
09230 #ifndef NDEBUG
09231 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09232 "First object is NULL, second is not");
09233 #endif
09234 return false;
09235 }
09236 }
09237 else
09238 {
09239 if (that == NULL)
09240 {
09241 #ifndef NDEBUG
09242 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09243 "Second object is NULL, first is not");
09244 #endif
09245 return false;
09246 }
09247 else
09248 {
09249 if (this->numberOfRows != that->numberOfRows)
09250 return false;
09251 if (this->numberOfColumns != that->numberOfColumns)
09252 return false;
09253 if (this->templateMatrixIdx != that->templateMatrixIdx)
09254 return false;
09255 if (this->varReferenceMatrixIdx != that->varReferenceMatrixIdx)
09256 return false;
09257 if (this->lbMatrixIdx != that->lbMatrixIdx)
09258 return false;
09259 if (this->lbConeIdx != that->lbConeIdx)
09260 return false;
09261 if (this->ubMatrixIdx != that->ubMatrixIdx)
09262 return false;
09263 if (this->ubConeIdx != that->ubConeIdx)
09264 return false;
09265 if (this->name != that->name)
09266 return false;
09267 if (this->varType != that->varType)
09268 return false;
09269
09270 return true;
09271 }
09272 }
09273 }
09274
09275 bool MatrixObjectives::IsEqual(MatrixObjectives *that)
09276 {
09277 #ifndef NDEBUG
09278 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixProgramming");
09279 #endif
09280
09281 if (this == NULL)
09282 {
09283 if (that == NULL)
09284 return true;
09285 else
09286 {
09287 #ifndef NDEBUG
09288 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09289 "First object is NULL, second is not");
09290 #endif
09291 return false;
09292 }
09293 }
09294 else
09295 {
09296 if (that == NULL)
09297 {
09298 #ifndef NDEBUG
09299 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09300 "Second object is NULL, first is not");
09301 #endif
09302 return false;
09303 }
09304 else
09305 {
09306 if (this->numberOfMatrixObj != that->numberOfMatrixObj) return false;
09307
09308 for (int i=0; i<numberOfMatrixObj; i++)
09309 {
09310 if (this->matrixObj[i] != NULL)
09311 {
09312 if (!(this->matrixObj[i]->IsEqual(that->matrixObj[i]))) return false;
09313 }
09314 else
09315 if (that->matrixObj[i] != NULL) return false;
09316 }
09317
09318 return true;
09319
09320 }
09321 }
09322 }
09323
09324 bool MatrixObj::IsEqual(MatrixObj *that)
09325 {
09326 #ifndef NDEBUG
09327 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixObj");
09328 #endif
09329
09330 if (this == NULL)
09331 {
09332 if (that == NULL)
09333 return true;
09334 else
09335 {
09336 #ifndef NDEBUG
09337 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09338 "First object is NULL, second is not");
09339
09340 #endif
09341 return false;
09342 }
09343 }
09344 else
09345 {
09346 if (that == NULL)
09347 {
09348 #ifndef NDEBUG
09349 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09350 "Second object is NULL, first is not");
09351 #endif
09352 return false;
09353 }
09354 else
09355 {
09356 if (this->numberOfRows != that->numberOfRows)
09357 return false;
09358 if (this->numberOfColumns != that->numberOfColumns)
09359 return false;
09360 if (this->templateMatrixIdx != that->templateMatrixIdx)
09361 return false;
09362 if (this->objReferenceMatrixIdx != that->objReferenceMatrixIdx)
09363 return false;
09364 if (this->orderConeIdx != that->orderConeIdx)
09365 return false;
09366 if (this->constantMatrixIdx != that->constantMatrixIdx)
09367 return false;
09368 if (this->name != that->name)
09369 return false;
09370
09371 return true;
09372 }
09373 }
09374 }
09375
09376 bool MatrixConstraints::IsEqual(MatrixConstraints *that)
09377 {
09378 #ifndef NDEBUG
09379 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixConstraints");
09380 #endif
09381
09382 if (this == NULL)
09383 {
09384 if (that == NULL)
09385 return true;
09386 else
09387 {
09388 #ifndef NDEBUG
09389 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09390 "First object is NULL, second is not");
09391 #endif
09392 return false;
09393 }
09394 }
09395 else
09396 {
09397 if (that == NULL)
09398 {
09399 #ifndef NDEBUG
09400 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09401 "Second object is NULL, first is not");
09402 #endif
09403 return false;
09404 }
09405 else
09406 {
09407 if (this->numberOfMatrixCon != that->numberOfMatrixCon) return false;
09408
09409 for (int i=0; i<numberOfMatrixCon; i++)
09410 {
09411 if (this->matrixCon[i] != NULL)
09412 {
09413 if (!(this->matrixCon[i]->IsEqual(that->matrixCon[i]))) return false;
09414 }
09415 else
09416 if (that->matrixCon[i] != NULL) return false;
09417 }
09418
09419 return true;
09420 }
09421 }
09422 }
09423
09424 bool MatrixCon::IsEqual(MatrixCon *that)
09425 {
09426 #ifndef NDEBUG
09427 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixCon");
09428 #endif
09429
09430 if (this == NULL)
09431 {
09432 if (that == NULL)
09433 return true;
09434 else
09435 {
09436 #ifndef NDEBUG
09437 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09438 "First object is NULL, second is not");
09439 #endif
09440 return false;
09441 }
09442 }
09443 else
09444 {
09445 if (that == NULL)
09446 {
09447 #ifndef NDEBUG
09448 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09449 "Second object is NULL, first is not");
09450 #endif
09451 return false;
09452 }
09453 else
09454 {
09455 if (this->numberOfRows != that->numberOfRows)
09456 return false;
09457 if (this->numberOfColumns != that->numberOfColumns)
09458 return false;
09459 if (this->templateMatrixIdx != that->templateMatrixIdx)
09460 return false;
09461 if (this->conReferenceMatrixIdx != that->conReferenceMatrixIdx)
09462 return false;
09463 if (this->lbMatrixIdx != that->lbMatrixIdx)
09464 return false;
09465 if (this->lbConeIdx != that->lbConeIdx)
09466 return false;
09467 if (this->ubMatrixIdx != that->ubMatrixIdx)
09468 return false;
09469 if (this->ubConeIdx != that->ubConeIdx)
09470 return false;
09471 if (this->name != that->name)
09472 return false;
09473
09474 return true;
09475 }
09476 }
09477 }
09478
09479 bool MatrixExpressions::IsEqual(MatrixExpressions *that)
09480 {
09481 #ifndef NDEBUG
09482 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixExpressions");
09483 #endif
09484
09485 if (this == NULL)
09486 {
09487 if (that == NULL)
09488 return true;
09489 else
09490 {
09491 #ifndef NDEBUG
09492 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09493 "First object is NULL, second is not");
09494 #endif
09495 return false;
09496 }
09497 }
09498 else
09499 {
09500 if (that == NULL)
09501 {
09502 #ifndef NDEBUG
09503 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09504 "Second object is NULL, first is not");
09505 #endif
09506 return false;
09507 }
09508 else
09509 {
09510 if (this->numberOfExpr != that->numberOfExpr) return false;
09511
09512 for (int i=0; i<numberOfExpr; i++)
09513 {
09514 if (this->expr[i] != NULL)
09515 {
09516 if (!(this->expr[i]->IsEqual(that->expr[i]))) return false;
09517 }
09518 else
09519 if (that->expr[i] != NULL) return false;
09520 }
09521
09522 return true;
09523 }
09524 }
09525 }
09526
09527 bool MatrixExpression::IsEqual(MatrixExpression *that)
09528 {
09529 #ifndef NDEBUG
09530 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixExpression");
09531 #endif
09532
09533 if (this == NULL)
09534 {
09535 if (that == NULL)
09536 return true;
09537 else
09538 {
09539 #ifndef NDEBUG
09540 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09541 "First object is NULL, second is not");
09542 #endif
09543 return false;
09544 }
09545 }
09546 else
09547 {
09548 if (that == NULL)
09549 {
09550 #ifndef NDEBUG
09551 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
09552 "Second object is NULL, first is not");
09553 #endif
09554 return false;
09555 }
09556 else
09557 {
09558 if (this->idx != that->idx ) return false;
09559 if (this->shape != that->shape) return false;
09560
09561 if (this->matrixExpressionTree != NULL)
09562 {
09563 if (!(this->matrixExpressionTree->IsEqual(that->matrixExpressionTree)))
09564 return false;
09565 }
09566 else
09567 if (that->matrixExpressionTree != NULL) return false;
09568
09569 return true;
09570 }
09571 }
09572 }
09573