00001
00017 #include "OSResult.h"
00018 #include "OSParameters.h"
00019 #include "ErrorClass.h"
00020 #include<iostream>
00021 #include<sstream>
00022
00023 using namespace std;
00024
00025 GeneralStatus::GeneralStatus():
00026 type( ""),
00027 description( "")
00028 {
00029 #ifdef DEBUG
00030 cout << "Inside GeneralStatus Constructor" << endl;
00031 #endif
00032 }
00033
00034 GeneralStatus::~GeneralStatus(){
00035 #ifdef DEBUG
00036 cout << "GeneralStatus Destructor Called" << endl;
00037 #endif
00038 }
00039
00040 OSResult::OSResult():
00041 m_iVariableNumber( -1),
00042 m_iObjectiveNumber( -1),
00043 m_iConstraintNumber( -1),
00044 m_iNumberOfOtherVariableResult( -1),
00045 m_mdPrimalValues( NULL),
00046 m_mdDualValues( NULL)
00047
00048 {
00049 #ifdef DEBUG
00050 cout << "Inside OSResult Constructor" << endl;
00051 #endif
00052 this->resultHeader = new ResultHeader();
00053 this->resultData = new ResultData();
00054 }
00055
00056 OSResult::~OSResult(){
00057 #ifdef DEBUG
00058 cout << "OSResult Destructor Called" << endl;
00059 #endif
00060
00061
00062 delete resultHeader;
00063 resultHeader = NULL;
00064
00065 delete resultData;
00066 resultData = NULL;
00067 delete[] m_mdPrimalValues;
00068 m_mdPrimalValues = 0;
00069 delete[] m_mdDualValues;
00070 m_mdDualValues = 0;
00071 }
00072
00073
00074 ResultHeader::ResultHeader():
00075 serviceURI(""),
00076 serviceName(""),
00077 instanceName(""),
00078 jobID(""),
00079 time(""),
00080 message("")
00081 {
00082 #ifdef DEBUG
00083 cout << "Inside the ResultHeader Constructor" << endl;
00084 #endif
00085 generalStatus = new GeneralStatus();
00086 }
00087
00088
00089 ResultHeader::~ResultHeader(){
00090 #ifdef DEBUG
00091 cout << "Inside the ResultHeader Destructor" << endl;
00092 #endif
00093 delete generalStatus;
00094 generalStatus = NULL;
00095 }
00096
00097
00098 VarValue::VarValue():
00099 idx( -1),
00100 value( 0)
00101 {
00102 #ifdef DEBUG
00103 cout << "Inside the VarValue Constructor" << endl;
00104 #endif
00105 }
00106
00107
00108 VarValue::~VarValue(){
00109 #ifdef DEBUG
00110 cout << "Inside the VarValue Destructor" << endl;
00111 #endif
00112 }
00113
00114
00115 OtherVarResult::OtherVarResult():
00116 idx( -1),
00117 value( "")
00118 {
00119 #ifdef DEBUG
00120 cout << "Inside the OtherVarResult Constructor" << endl;
00121 #endif
00122 }
00123
00124
00125 OtherVarResult::~OtherVarResult(){
00126 #ifdef DEBUG
00127 cout << "Inside the OtherVarResult Destructor" << endl;
00128 #endif
00129 }
00130
00131
00132 OtherObjResult::OtherObjResult():
00133 idx( -1),
00134 value( "")
00135 {
00136 #ifdef DEBUG
00137 cout << "Inside the OtherObjResult Constructor" << endl;
00138 #endif
00139 }
00140
00141
00142 OtherObjResult::~OtherObjResult(){
00143 #ifdef DEBUG
00144 cout << "Inside the OtherObjResult Destructor" << endl;
00145 #endif
00146 }
00147
00148
00149 OtherConResult::OtherConResult():
00150 idx( -1),
00151 value( "")
00152 {
00153 #ifdef DEBUG
00154 cout << "Inside the OtherConResult Constructor" << endl;
00155 #endif
00156 }
00157
00158
00159 OtherConResult::~OtherConResult(){
00160 #ifdef DEBUG
00161 cout << "Inside the OtherConResult Destructor" << endl;
00162 #endif
00163 }
00164
00165
00166 ObjValue::ObjValue():
00167 idx( -1),
00168 value( OSNAN)
00169 {
00170 #ifdef DEBUG
00171 cout << "Inside the ObjValue Constructor" << endl;
00172 #endif
00173 }
00174
00175
00176 ConValue::ConValue():
00177 idx( -1),
00178 value( 0)
00179 {
00180 #ifdef DEBUG
00181 cout << "Inside the ConValue Constructor" << endl;
00182 #endif
00183 }
00184
00185
00186 ConValue::~ConValue(){
00187 #ifdef DEBUG
00188 cout << "Inside the ConValue Destructor" << endl;
00189 #endif
00190 }
00191
00192 ObjValue::~ObjValue(){
00193 #ifdef DEBUG
00194 cout << "Inside the ObjValue Destructor" << endl;
00195 #endif
00196 }
00197
00198 DualVarValue::DualVarValue():
00199 idx( -1),
00200 lbValue( 0),
00201 ubValue( 0),
00202 value( 0)
00203 {
00204 #ifdef DEBUG
00205 cout << "Inside the DualVarValue Constructor" << endl;
00206 #endif
00207 }
00208
00209
00210 DualVarValue::~DualVarValue(){
00211 #ifdef DEBUG
00212 cout << "Inside the DualVarValue Destructor" << endl;
00213 #endif
00214 }
00215
00216
00217
00218 VariableValues::VariableValues() {
00219 #ifdef DEBUG
00220 cout << "Inside the VariableValues Constructor" << endl;
00221 #endif
00222
00223 }
00224
00225
00226 VariableValues::~VariableValues(){
00227 #ifdef DEBUG
00228 cout << "Inside the VariableValues Destructor" << endl;
00229 #endif
00230 int n = var.size();
00231 if(n > 0 ){
00232 for(int i = 0; i < n; i++){
00233 delete var[i];
00234 var[i] = NULL;
00235 }
00236 }
00237 var.clear();
00238
00239 }
00240
00241
00242 OtherVariableResult::OtherVariableResult():
00243 name(""),
00244 description("")
00245 {
00246 #ifdef DEBUG
00247 cout << "Inside the OtherVariableResult Constructor" << endl;
00248 #endif
00249
00250 }
00251
00252
00253 OtherVariableResult::~OtherVariableResult(){
00254 #ifdef DEBUG
00255 cout << "Inside the OtherVariableResult Destructor" << endl;
00256 #endif
00257 int n = var.size();
00258 if(n > 0) {
00259 for(int i = 0; i < n; i++){
00260 delete var[i];
00261 var[i] = NULL;
00262 }
00263 }
00264 var.clear();
00265 }
00266
00267
00268 OtherObjectiveResult::OtherObjectiveResult():
00269 name(""),
00270 description("")
00271 {
00272 #ifdef DEBUG
00273 cout << "Inside the OtherObjectiveResult Constructor" << endl;
00274 #endif
00275 }
00276
00277
00278 OtherObjectiveResult::~OtherObjectiveResult(){
00279 #ifdef DEBUG
00280 cout << "Inside the OtherObjectiveResult Destructor" << endl;
00281 #endif
00282 int n = obj.size();
00283 if(n > 0) {
00284 for(int i = 0; i < n; i++){
00285 delete obj[i];
00286 obj[i] = NULL;
00287 }
00288 }
00289 obj.clear();
00290 }
00291
00292
00293 OtherConstraintResult::OtherConstraintResult():
00294 name(""),
00295 description("")
00296 {
00297 #ifdef DEBUG
00298 cout << "Inside the OtherConstraintResult Constructor" << endl;
00299 #endif
00300 }
00301
00302
00303 OtherConstraintResult::~OtherConstraintResult(){
00304 #ifdef DEBUG
00305 cout << "Inside the OtherConstraintResult Destructor" << endl;
00306 #endif
00307 int n = con.size();
00308 if(n > 0){
00309 for(int i = 0; i < n; i++){
00310 delete con[i];
00311 con[i] = NULL;
00312 }
00313 }
00314 con.clear();
00315 }
00316
00317
00318 ObjectiveValues::ObjectiveValues() {
00319 #ifdef DEBUG
00320 cout << "Inside the ObjectiveValues Constructor" << endl;
00321 #endif
00322
00323 }
00324
00325
00326 ObjectiveValues::~ObjectiveValues(){
00327 #ifdef DEBUG
00328 cout << "Inside the ObjectiveValues Destructor" << endl;
00329 #endif
00330 int n = obj.size();
00331 if(n > 0 ){
00332 for(int i = 0; i < n; i++){
00333 delete obj[i];
00334 obj[i] = NULL;
00335 }
00336 }
00337 obj.clear();
00338
00339 }
00340
00341
00342 ConstraintValues::ConstraintValues(){
00343 #ifdef DEBUG
00344 cout << "Inside the ConstraintValues Constructor" << endl;
00345 #endif
00346 }
00347
00348
00349 ConstraintValues::~ConstraintValues(){
00350 #ifdef DEBUG
00351 cout << "Inside the ConstraintValues Destructor" << endl;
00352 #endif
00353 int n = con.size();
00354 if(n > 0){
00355 for(int i = 0; i < n; i++){
00356 delete con[i];
00357 con[i] = NULL;
00358 }
00359 }
00360 con.clear();
00361 }
00362
00363 DualVariableValues::DualVariableValues() {
00364 #ifdef DEBUG
00365 cout << "Inside the DualVariableValues Constructor" << endl;
00366 #endif
00367
00368 }
00369
00370
00371 DualVariableValues::~DualVariableValues(){
00372 #ifdef DEBUG
00373 cout << "Inside the DualVariableValues Destructor" << endl;
00374 #endif
00375 int n = con.size();
00376 if(n > 0){
00377 for(int i = 0; i < n; i++){
00378 delete con[i];
00379 con[i] = NULL;
00380 }
00381 }
00382 con.clear();
00383 }
00384
00385
00386
00387 VariableSolution::VariableSolution():
00388 numberOfOtherVariableResult( 0),
00389 values( NULL),
00390 other( NULL)
00391
00392 {
00393 #ifdef DEBUG
00394 cout << "Inside the VariableSolution Constructor" << endl;
00395 #endif
00396 }
00397
00398
00399 VariableSolution::~VariableSolution(){
00400 #ifdef DEBUG
00401 cout << "Inside the VariableSolution Destructor" << endl;
00402 #endif
00403 delete values;
00404 values = NULL;
00405 if(numberOfOtherVariableResult > 0 && other != NULL){
00406 for(int i = 0; i < numberOfOtherVariableResult; i++){
00407 delete other[i];
00408 other[i] = NULL;
00409 }
00410 }
00411 delete[] other;
00412 other = NULL;
00413 }
00414
00415 ObjectiveSolution::ObjectiveSolution():
00416 numberOfOtherObjectiveResult( 0),
00417 values( NULL),
00418 other( NULL)
00419
00420 {
00421 #ifdef DEBUG
00422 cout << "Inside the ObjectiveSolution Constructor" << endl;
00423 #endif
00424 }
00425
00426
00427 ObjectiveSolution::~ObjectiveSolution(){
00428 #ifdef DEBUG
00429 cout << "Inside the ObjectieSolution Destructor" << endl;
00430 #endif
00431 delete values;
00432 values = NULL;
00433 if(numberOfOtherObjectiveResult > 0 && other != NULL){
00434 for(int i = 0; i < numberOfOtherObjectiveResult; i++){
00435 delete other[i];
00436 other[i] = NULL;
00437 }
00438 }
00439 delete[] other;
00440 other = NULL;
00441 }
00442
00443
00444
00445 ConstraintSolution::ConstraintSolution():
00446 numberOfOtherConstraintResult( 0),
00447 values( NULL),
00448 dualValues( NULL),
00449 other( NULL)
00450 {
00451 #ifdef DEBUG
00452 cout << "Inside the ConstraintSolution Constructor" << endl;
00453 #endif
00454 }
00455
00456
00457 ConstraintSolution::~ConstraintSolution(){
00458 #ifdef DEBUG
00459 cout << "Inside the ConstraintSolution Destructor" << endl;
00460 #endif
00461 delete values;
00462 values = NULL;
00463 delete dualValues;
00464 dualValues = NULL;
00465 if(numberOfOtherConstraintResult > 0 && other != NULL){
00466 for(int i = 0; i < numberOfOtherConstraintResult; i++){
00467 delete other[i];
00468 other[i] = NULL;
00469 }
00470 }
00471 delete[] other;
00472 other = NULL;
00473 }
00474
00475
00476
00477 OptimizationSolutionStatus::OptimizationSolutionStatus():
00478 type(""),
00479 description("")
00480
00481 {
00482 #ifdef DEBUG
00483 cout << "Inside the OptimizationSolutionStatus Constructor" << endl;
00484 #endif
00485 }
00486
00487
00488 OptimizationSolutionStatus::~OptimizationSolutionStatus(){
00489 #ifdef DEBUG
00490 cout << "Inside the OptimzationSolutionStatus Destructor" << endl;
00491 #endif
00492 }
00493
00494
00495 OptimizationSolution::OptimizationSolution():
00496 objectiveIdx( -1),
00497 message( ""),
00498 variables( NULL),
00499 objectives( NULL),
00500 constraints( NULL)
00501
00502 {
00503 #ifdef DEBUG
00504 cout << "Inside the OptimizationSolution Constructor" << endl;
00505 #endif
00506 status = new OptimizationSolutionStatus();
00507 }
00508
00509
00510 OptimizationSolution::~OptimizationSolution(){
00511 #ifdef DEBUG
00512 cout << "Inside the OptimzationSolution Destructor" << endl;
00513 #endif
00514 delete variables;
00515 variables = NULL;
00516 delete constraints;
00517 constraints = NULL;
00518 delete objectives;
00519 objectives = NULL;
00520 delete status;
00521 status = NULL;
00522 }
00523
00524
00525
00526 OptimizationResult::OptimizationResult():
00527 numberOfVariables( -1),
00528 numberOfObjectives( -1),
00529 numberOfConstraints(-1),
00530 numberOfSolutions( -1),
00531 solution(NULL)
00532 {
00533 #ifdef DEBUG
00534 cout << "Inside the OptimizationResult Constructor" << endl;
00535 #endif
00536 }
00537
00538
00539 OptimizationResult::~OptimizationResult(){
00540 #ifdef DEBUG
00541 cout << "Inside the OptimzationResult Destructor" << endl;
00542 cout << "Number of solutions = " << this->numberOfSolutions << endl;
00543 #endif
00544 if( solution != NULL){
00545 for(int i = 0; i < this->numberOfSolutions; i++){
00546 delete solution[i];
00547 solution[i] = NULL;
00548 #ifdef DEBUG
00549 cout << "Delelting Solution: " << i << endl;
00550 #endif
00551 i++;
00552 }
00553 }
00554 delete[] solution;
00555 solution = NULL;
00556 }
00557
00558
00559
00560
00561 ResultData::ResultData():
00562 optimization(NULL)
00563 {
00564 #ifdef DEBUG
00565 cout << "Inside the ResultData Constructor" << endl;
00566 #endif
00567 }
00568
00569
00570 ResultData::~ResultData(){
00571 #ifdef DEBUG
00572 cout << "Inside the ResulData Destructor" << endl;
00573 #endif
00574 delete optimization;
00575 optimization = NULL;
00576 }
00577
00578
00579
00580
00581
00582 GeneralStatus* OSResult::getGeneralStatus(){
00583 return resultHeader->generalStatus;
00584 }
00585
00586
00587 string OSResult::getGeneralStatusType(){
00588 if(resultHeader->generalStatus == NULL) return "";
00589 return resultHeader->generalStatus->type;
00590 }
00591
00592 string OSResult::getGeneralStatusDescription(){
00593 if(resultHeader->generalStatus == NULL) return NULL;
00594 return resultHeader->generalStatus->description;
00595 }
00596
00597 string OSResult::getServiceName(){
00598 return resultHeader->serviceName;
00599 }
00600
00601 string OSResult::getServiceURI(){
00602 return resultHeader->serviceURI;
00603 }
00604
00605 string OSResult::getInstanceName(){
00606 return resultHeader->instanceName;
00607 }
00608
00609 string OSResult::getJobID(){
00610 return resultHeader->jobID;
00611 }
00612
00613
00614 string OSResult::getGeneralMessage(){
00615 return resultHeader->message;
00616 }
00617
00618 int OSResult::getVariableNumber(){
00619 if(m_iVariableNumber == -1){
00620 if(resultData->optimization == NULL) return -1;
00621 m_iVariableNumber = resultData->optimization->numberOfVariables;
00622 }
00623 return m_iVariableNumber;
00624 }
00625
00626
00627
00628 int OSResult::getObjectiveNumber(){
00629 if(m_iObjectiveNumber == -1){
00630 if(resultData->optimization == NULL) return -1;
00631 m_iObjectiveNumber = resultData->optimization->numberOfObjectives;
00632 }
00633 return m_iObjectiveNumber;
00634 }
00635
00636
00637 int OSResult::getConstraintNumber(){
00638 if(m_iConstraintNumber == -1){
00639 if(resultData->optimization == NULL) return -1;
00640 m_iConstraintNumber = resultData->optimization->numberOfConstraints;
00641 }
00642 return m_iConstraintNumber;
00643 }
00644
00645 int OSResult::getSolutionNumber(){
00646 if(resultData->optimization == NULL) return 0;
00647 if(resultData->optimization->solution == NULL) return 0;
00648 return resultData->optimization->numberOfSolutions;
00649 }
00650
00651
00652 int OSResult::getNumberOfOtherVariableResult(int solIdx){
00653 if(m_iNumberOfOtherVariableResult == -1){
00654 if(resultData->optimization->solution[solIdx]->variables->other == NULL) return -1;
00655 m_iNumberOfOtherVariableResult = resultData->optimization->solution[solIdx]->variables->numberOfOtherVariableResult;
00656 }
00657 return m_iNumberOfOtherVariableResult;
00658 }
00659
00660
00661 OptimizationSolutionStatus* OSResult::getSolutionStatus( int solIdx){
00662 if(resultData->optimization == NULL || resultData->optimization->solution == NULL) return NULL;
00663 if( resultData->optimization->numberOfSolutions <= 0 ||
00664 solIdx < 0 || solIdx >= resultData->optimization->numberOfSolutions) return NULL;
00665 if(resultData->optimization->solution[solIdx] == NULL) return NULL;
00666 return resultData->optimization->solution[solIdx]->status;
00667 }
00668
00669 string OSResult::getSolutionStatusType(int solIdx){
00670 if(resultData->optimization == NULL || resultData->optimization->solution == NULL) return NULL;
00671 if( resultData->optimization->numberOfSolutions <= 0 ||
00672 solIdx < 0 || solIdx >= resultData->optimization->numberOfSolutions) return NULL;
00673 if(resultData->optimization->solution[solIdx] == NULL) return NULL;
00674 if(resultData->optimization->solution[solIdx]->status == NULL) return NULL;
00675 return resultData->optimization->solution[solIdx]->status->type;
00676 }
00677
00678 string OSResult::getSolutionStatusDescription(int solIdx){
00679 if(resultData->optimization == NULL || resultData->optimization->solution == NULL) return NULL;
00680 if( resultData->optimization->numberOfSolutions <= 0 ||
00681 solIdx < 0 || solIdx >= resultData->optimization->numberOfSolutions) return NULL;
00682 if(resultData->optimization->solution[solIdx] == NULL) return NULL;
00683 if(resultData->optimization->solution[solIdx]->status == NULL) return NULL;
00684 return resultData->optimization->solution[solIdx]->status->description;
00685 }
00686
00687 string OSResult::getSolutionMessage(int solIdx){
00688 if(resultData->optimization == NULL) return "there is no solution";
00689 if(resultData->optimization->solution == NULL ||
00690 solIdx < 0 || solIdx >= resultData->optimization->numberOfSolutions) return "there is no solution";
00691 if(resultData->optimization->solution[solIdx] == NULL) return "there is no solution";
00692 return resultData->optimization->solution[solIdx]->message;
00693 }
00694
00695 double* OSResult::getOptimalPrimalVariableValues(int objIdx){
00696 if(resultData->optimization == NULL || resultData->optimization->solution == NULL) return NULL;
00697 int iNumberOfVariables = this->getVariableNumber();
00698 if(iNumberOfVariables <= 0) return NULL;
00699 int iSolutions = this->getSolutionNumber();
00700 for(int i = 0; i < iSolutions; i++){
00701 if(resultData->optimization->solution[i] == NULL) continue;
00702 if(resultData->optimization->solution[i]->objectiveIdx != objIdx) continue;
00703 if(resultData->optimization->solution[i]->variables == NULL) continue;
00704 if(resultData->optimization->solution[i]->variables->values == NULL) continue;
00705 if((resultData->optimization->solution[i]->status->type.find("ptimal") != string::npos && m_mdPrimalValues == NULL) ||
00706 resultData->optimization->solution[i]->status->type.compare("globallyOptimal") == 0){
00707 m_mdPrimalValues = new double[iNumberOfVariables];
00708 for(int j = 0; j < iNumberOfVariables; j++){
00709 m_mdPrimalValues[ j] = resultData->optimization->solution[i]->variables->values->var[j]->value;
00710 }
00711 }
00712 if(resultData->optimization->solution[i]->status->type.compare("globallyOptimal") == 0){
00713 return m_mdPrimalValues;
00714 }
00715 }
00716 return m_mdPrimalValues;
00717 }
00718
00719
00720 double* OSResult::getOptimalDualVariableValues(int objIdx){
00721 if(resultData->optimization == NULL || resultData->optimization->solution == NULL) return NULL;
00722 int iNumberOfConstraints = this->getConstraintNumber();
00723 if(iNumberOfConstraints <= 0) return NULL;
00724 int iSolutions = this->getSolutionNumber();
00725 for(int i = 0; i < iSolutions; i++){
00726 if(resultData->optimization->solution[i] == NULL) continue;
00727 if(resultData->optimization->solution[i]->objectiveIdx != objIdx) continue;
00728 if(resultData->optimization->solution[i]->constraints == NULL) continue;
00729 if(resultData->optimization->solution[i]->constraints->dualValues == NULL) continue;
00730 if((resultData->optimization->solution[i]->status->type.find("ptimal") != string::npos && m_mdDualValues == NULL) ||
00731 resultData->optimization->solution[i]->status->type.compare("globallyOptimal") == 0){
00732 m_mdDualValues = new double[iNumberOfConstraints];
00733 for(int j = 0; j < iNumberOfConstraints; j++){
00734 m_mdDualValues[ j] = resultData->optimization->solution[i]->constraints->dualValues->con[j]->value;
00735 }
00736 }
00737 if(resultData->optimization->solution[i]->status->type.compare("globallyOptimal")){
00738 return m_mdDualValues;
00739 }
00740 }
00741 return m_mdDualValues;
00742 }
00743
00744
00745
00746 bool OSResult::setGeneralStatus(GeneralStatus *status){
00747 resultHeader->generalStatus = status;
00748 return true;
00749 }
00750
00751 bool OSResult::setGeneralStatusType(string type){
00752 if(resultHeader->generalStatus == NULL) resultHeader->generalStatus = new GeneralStatus();
00753 resultHeader->generalStatus->type = type;
00754 return true;
00755 }
00756
00757 bool OSResult::setGeneralStatusDescription(string description){
00758 if(resultHeader->generalStatus == NULL) resultHeader->generalStatus = new GeneralStatus();
00759 resultHeader->generalStatus->description = description;
00760 return true;
00761 }
00762
00763
00764
00765 bool OSResult::setServiceName(string serviceName){
00766 resultHeader->serviceName = serviceName;
00767 return true;
00768 }
00769
00770 bool OSResult::setServiceURI(string serviceURI){
00771 resultHeader->serviceURI = serviceURI;
00772 return true;
00773 }
00774
00775 bool OSResult::setInstanceName(string instanceName){
00776 resultHeader->instanceName = instanceName;
00777 return true;
00778 }
00779
00780 bool OSResult::setJobID(string jobID){
00781 resultHeader->jobID = jobID;
00782 return true;
00783 }
00784
00785 bool OSResult::setGeneralMessage(string message){
00786 resultHeader->message = message;
00787 return true;
00788 }
00789
00790 bool OSResult::setVariableNumber(int variableNumber){
00791 if(variableNumber <= 0){
00792 return false;
00793 }
00794 if(resultData->optimization == NULL) resultData->optimization = new OptimizationResult();
00795 resultData->optimization->numberOfVariables = variableNumber;
00796 return true;
00797 }
00798
00799 bool OSResult::setObjectiveNumber(int objectiveNumber){
00800 if(objectiveNumber < 0){
00801 return false;
00802 }
00803 if(resultData->optimization == NULL) resultData->optimization = new OptimizationResult();
00804 resultData->optimization->numberOfObjectives = objectiveNumber;
00805 return true;
00806 }
00807
00808 bool OSResult::setConstraintNumber(int constraintNumber){
00809 if(constraintNumber < 0){
00810 return false;
00811 }
00812 if(resultData->optimization == NULL) resultData->optimization = new OptimizationResult();
00813 resultData->optimization->numberOfConstraints = constraintNumber;
00814 return true;
00815 }
00816
00817 bool OSResult::setSolutionNumber(int number){
00818
00819
00820
00821 if(number < 0) return false;
00822 if(number == 0) return true;
00823 if(resultData->optimization == NULL) resultData->optimization = new OptimizationResult();
00824 resultData->optimization->numberOfSolutions = number;
00825 resultData->optimization->solution = new OptimizationSolution*[number];
00826 for(int i = 0; i < number; i++){
00827 std::cout << "CREATING A NEW OPTIMIZATION SOLUTION" << std::endl;
00828 resultData->optimization->solution[i] = new OptimizationSolution();
00829 }
00830 return true;
00831 }
00832
00833 bool OSResult::setSolutionStatus(int solIdx, string type, string description){
00834 int nSols = this->getSolutionNumber();
00835 if(resultData->optimization == NULL) return false;
00836 if(nSols <= 0) return false;
00837 if(resultData->optimization->solution == NULL ||
00838 solIdx < 0 || solIdx >= nSols) return false;
00839 if(resultData->optimization->solution[solIdx] == NULL){
00840 resultData->optimization->solution[solIdx] = new OptimizationSolution();
00841 }
00842 if(resultData->optimization->solution[solIdx]->status == NULL){
00843 resultData->optimization->solution[solIdx]->status = new OptimizationSolutionStatus();
00844 }
00845
00846 resultData->optimization->solution[solIdx]->status->type = type;
00847 resultData->optimization->solution[solIdx]->status->description = description;
00848 return true;
00849 }
00850
00851 bool OSResult::setSolutionObjectiveIndex(int solIdx, int objectiveIdx){
00852 int nSols = this->getSolutionNumber();
00853 if(resultData->optimization == NULL) return false;
00854 if(nSols <= 0) return false;
00855 if(resultData->optimization == NULL) return false;
00856 if(resultData->optimization->solution == NULL ||
00857 solIdx < 0 || solIdx >= nSols) return false;
00858 if(resultData->optimization->solution[solIdx] == NULL){
00859 resultData->optimization->solution[solIdx] = new OptimizationSolution();
00860 }
00861 if(objectiveIdx >= 0) return false;
00862 resultData->optimization->solution[solIdx]->objectiveIdx = objectiveIdx;
00863 return true;
00864 }
00865
00866 bool OSResult::setPrimalVariableValues(int solIdx, double *x){
00867 int iNumberOfVariables = this->getVariableNumber();
00868 if(iNumberOfVariables <= 0) return false;
00869 if(x == NULL) return false;
00870 int nSols = this->getSolutionNumber();
00871 if(resultData->optimization == NULL) return false;
00872 if(nSols <= 0) return false;
00873 if(resultData->optimization->solution == NULL ||
00874 solIdx < 0 || solIdx >= nSols) return false;
00875 if(resultData->optimization->solution[solIdx] == NULL){
00876 resultData->optimization->solution[solIdx] = new OptimizationSolution();
00877 }
00878 if(resultData->optimization->solution[solIdx]->variables == NULL){
00879 resultData->optimization->solution[solIdx]->variables = new VariableSolution();
00880 }
00881 if(resultData->optimization->solution[solIdx]->variables->values == NULL){
00882 resultData->optimization->solution[solIdx]->variables->values = new VariableValues();
00883 }
00884 if(x == NULL){
00885
00886 return true;
00887 }
00888 for(int i = 0; i < iNumberOfVariables; i++){
00889 resultData->optimization->solution[solIdx]->variables->values->var.push_back(new VarValue());
00890 resultData->optimization->solution[solIdx]->variables->values->var[i]->idx = i;
00891 resultData->optimization->solution[solIdx]->variables->values->var[i]->value = x[i];
00892 }
00893 return true;
00894 }
00895
00896
00897 bool OSResult::setNumberOfOtherVariableResult(int solIdx, int numberOfOtherVariableResult){
00898 int iNumberOfVariables = this->getVariableNumber();
00899 if(iNumberOfVariables <= 0) return false;
00900 int nSols = this->getSolutionNumber();
00901 if(resultData->optimization == NULL) return false;
00902 if(nSols <= 0) return false;
00903 if(resultData->optimization == NULL) return false;
00904 if(resultData->optimization->solution == NULL ||
00905 solIdx < 0 || solIdx >= nSols) return false;
00906 if(resultData->optimization->solution[solIdx] == NULL){
00907 resultData->optimization->solution[solIdx] = new OptimizationSolution();
00908 }
00909 if(resultData->optimization->solution[solIdx]->variables == NULL){
00910 resultData->optimization->solution[solIdx]->variables = new VariableSolution();
00911 }
00912 resultData->optimization->solution[solIdx]->variables->numberOfOtherVariableResult = numberOfOtherVariableResult;
00913 resultData->optimization->solution[solIdx]->variables->other = new OtherVariableResult*[ numberOfOtherVariableResult];
00914 for(int i = 0; i < numberOfOtherVariableResult; i++){
00915 resultData->optimization->solution[solIdx]->variables->other[ i] = new OtherVariableResult();
00916 }
00917 return true;
00918 }
00919
00920
00921
00922 bool OSResult::setAnOtherVariableResult(int solIdx, int otherIdx, string name, string description, string *s){
00923 int iNumberOfVariables = this->getVariableNumber();
00924 if(iNumberOfVariables <= 0) return false;
00925 int nSols = this->getSolutionNumber();
00926 if(resultData->optimization == NULL) return false;
00927 if(nSols <= 0) return false;
00928 if(resultData->optimization == NULL) return false;
00929 if(resultData->optimization->solution == NULL ||
00930 solIdx < 0 || solIdx >= nSols) return false;
00931 if(resultData->optimization->solution[solIdx] == NULL) return false;
00932 if(resultData->optimization->solution[solIdx]->variables == NULL)return false;
00933 if(resultData->optimization->solution[solIdx]->variables->other == NULL) return false;
00934 if(resultData->optimization->solution[solIdx]->variables->other[ otherIdx] == NULL) return false;
00935 resultData->optimization->solution[solIdx]->variables->other[ otherIdx]->name = name;
00936 resultData->optimization->solution[solIdx]->variables->other[ otherIdx]->description = description;
00937 for(int i = 0; i < iNumberOfVariables; i++){
00938 resultData->optimization->solution[solIdx]->variables->other[ otherIdx]->var.push_back(new OtherVarResult());
00939 resultData->optimization->solution[solIdx]->variables->other[ otherIdx]->var[i]->idx = i;
00940 resultData->optimization->solution[solIdx]->variables->other[ otherIdx]->var[i]->value = s[i];
00941 }
00942 return true;
00943 }
00944
00945
00946
00947 bool OSResult::setObjectiveValues(int solIdx, double *objectiveValues){
00948 int iNumberOfObjectives = this->getObjectiveNumber();
00949 if(iNumberOfObjectives < 0) return false;
00950 if(iNumberOfObjectives == 0) return true;
00951 if(objectiveValues == NULL) return false;
00952 int nSols = this->getSolutionNumber();
00953 if(resultData->optimization == NULL) return false;
00954 if(nSols <= 0) return false;
00955 if(resultData->optimization == NULL) return false;
00956 if(resultData->optimization->solution == NULL ||
00957 solIdx < 0 || solIdx >= nSols) return false;
00958 if(resultData->optimization->solution[solIdx] == NULL){
00959 resultData->optimization->solution[solIdx] = new OptimizationSolution();
00960 }
00961 if(resultData->optimization->solution[solIdx]->objectives == NULL){
00962 resultData->optimization->solution[solIdx]->objectives = new ObjectiveSolution();
00963 }
00964 if(resultData->optimization->solution[solIdx]->objectives->values == NULL){
00965 resultData->optimization->solution[solIdx]->objectives->values = new ObjectiveValues();
00966 }
00967 for(int i = 0; i < iNumberOfObjectives; i++){
00968 resultData->optimization->solution[solIdx]->objectives->values->obj.push_back( new ObjValue());
00969 resultData->optimization->solution[solIdx]->objectives->values->obj[i]->idx = -(i+1);
00970 resultData->optimization->solution[solIdx]->objectives->values->obj[i]->value = objectiveValues[i];
00971 }
00972 return true;
00973 }
00974
00975 bool OSResult::setDualVariableValues(int solIdx, double *lbValues, double *ubValues){
00976 int iNumberOfConstraints = this->getConstraintNumber();
00977 if(iNumberOfConstraints < 0) return false;
00978 if(iNumberOfConstraints == 0) return true;
00979 int nSols = this->getSolutionNumber();
00980 if(resultData->optimization == NULL) return false;
00981 if(nSols <= 0) return false;
00982 if(resultData->optimization == NULL) return false;
00983 if(resultData->optimization->solution == NULL ||
00984 solIdx < 0 || solIdx >= nSols) return false;
00985 if(resultData->optimization->solution[solIdx] == NULL){
00986 resultData->optimization->solution[solIdx] = new OptimizationSolution();
00987 }
00988 if(resultData->optimization->solution[solIdx]->constraints == NULL){
00989 resultData->optimization->solution[solIdx]->constraints = new ConstraintSolution();
00990 }
00991 if(resultData->optimization->solution[solIdx]->constraints->dualValues == NULL){
00992 resultData->optimization->solution[solIdx]->constraints->dualValues = new DualVariableValues();
00993 }
00994 if(lbValues == NULL && ubValues == NULL){
00995
00996 return true;
00997 }
00998 int iCons = 0;
00999 if(lbValues == NULL){
01000 for(int i = 0; i < iNumberOfConstraints; i++){
01001 if(ubValues[i] != 0) iCons++;
01002 }
01003 }
01004 else if(ubValues == NULL){
01005 for(int i = 0; i < iNumberOfConstraints; i++){
01006 if(lbValues[i] != 0) iCons++;
01007 }
01008 }
01009 else{
01010 for(int i = 0; i < iNumberOfConstraints; i++){
01011 if(lbValues[i] != 0 || ubValues[i] != 0) iCons++;
01012 }
01013 }
01014
01015
01016 for(int i = 0; i < iCons; i++) resultData->optimization->solution[solIdx]->constraints->dualValues->con.push_back( new DualVarValue());
01017 int j = 0;
01018 if(lbValues == NULL){
01019 for(int i = 0; i < iNumberOfConstraints; i++){
01020 if(ubValues[i] != 0){
01021 resultData->optimization->solution[solIdx]->constraints->dualValues->con[j]->idx = i;
01022 resultData->optimization->solution[solIdx]->constraints->dualValues->con[j]->ubValue = 0;
01023 resultData->optimization->solution[solIdx]->constraints->dualValues->con[j]->ubValue = ubValues[i];
01024 j++;
01025 }
01026 }
01027 }
01028 else if(ubValues == NULL){
01029 for(int i = 0; i < iNumberOfConstraints; i++){
01030 if(lbValues[i] != 0){
01031 resultData->optimization->solution[solIdx]->constraints->dualValues->con[j]->idx = i;
01032 resultData->optimization->solution[solIdx]->constraints->dualValues->con[j]->lbValue = lbValues[i];
01033 resultData->optimization->solution[solIdx]->constraints->dualValues->con[j]->ubValue = 0;
01034 j++;
01035 }
01036 }
01037 }
01038 else{
01039 for(int i = 0; i < iNumberOfConstraints; i++){
01040 if(lbValues[i] != 0 || ubValues[i] != 0){
01041 resultData->optimization->solution[solIdx]->constraints->dualValues->con[j]->idx = i;
01042 resultData->optimization->solution[solIdx]->constraints->dualValues->con[j]->lbValue = lbValues[i];
01043 resultData->optimization->solution[solIdx]->constraints->dualValues->con[j]->ubValue = ubValues[i];
01044 j++;
01045 }
01046 }
01047 }
01048 return true;
01049 }
01050
01051 bool OSResult::setDualVariableValues(int solIdx, double *y){
01052 int iNumberOfConstraints = this->getConstraintNumber();
01053 if(iNumberOfConstraints < 0) return false;
01054 if(iNumberOfConstraints == 0) return true;
01055 int nSols = this->getSolutionNumber();
01056 if(resultData->optimization == NULL) return false;
01057 if(nSols <= 0) return false;
01058 if(resultData->optimization == NULL) return false;
01059 if(resultData->optimization->solution == NULL ||
01060 solIdx < 0 || solIdx >= nSols) return false;
01061 if(resultData->optimization->solution[solIdx] == NULL){
01062 resultData->optimization->solution[solIdx] = new OptimizationSolution();
01063 }
01064 if(resultData->optimization->solution[solIdx]->constraints == NULL){
01065 resultData->optimization->solution[solIdx]->constraints = new ConstraintSolution();
01066 }
01067 if(resultData->optimization->solution[solIdx]->constraints->dualValues == NULL){
01068 resultData->optimization->solution[solIdx]->constraints->dualValues = new DualVariableValues();
01069 }
01070 if(y == NULL){
01071 resultData->optimization->solution[solIdx]->constraints->dualValues = NULL;
01072 return true;
01073 }
01074 for(int i = 0; i < iNumberOfConstraints; i++){
01075 resultData->optimization->solution[solIdx]->constraints->dualValues->con.push_back( new DualVarValue());
01076 resultData->optimization->solution[solIdx]->constraints->dualValues->con[i]->idx = i;
01077 resultData->optimization->solution[solIdx]->constraints->dualValues->con[i]->value = y[i];
01078 }
01079 return true;
01080 }
01081
01082 bool OSResult::setConstraintValues(int solIdx, double *constraintValues){
01083 int iNumberOfConstraints = this->getConstraintNumber();
01084 if(iNumberOfConstraints <= 0) return false;
01085 int nSols = this->getSolutionNumber();
01086 if(resultData->optimization == NULL) return false;
01087 if(nSols <= 0) return false;
01088 if(resultData->optimization == NULL) return false;
01089 if(resultData->optimization->solution == NULL ||
01090 solIdx < 0 || solIdx >= nSols) return false;
01091 if(resultData->optimization->solution[solIdx] == NULL){
01092 resultData->optimization->solution[solIdx] = new OptimizationSolution();
01093 }
01094 if(resultData->optimization->solution[solIdx]->constraints == NULL){
01095 resultData->optimization->solution[solIdx]->constraints = new ConstraintSolution();
01096 }
01097 if(resultData->optimization->solution[solIdx]->constraints->values == NULL){
01098 resultData->optimization->solution[solIdx]->constraints->values = new ConstraintValues();
01099 }
01100 if(constraintValues == NULL){
01101 resultData->optimization->solution[solIdx]->constraints->values = NULL;
01102 return true;
01103 }
01104
01105
01106 for(int i = 0; i < iNumberOfConstraints; i++){
01107 resultData->optimization->solution[solIdx]->constraints->values->con.push_back( new ConValue());
01108
01109 resultData->optimization->solution[solIdx]->constraints->values->con[i]->idx = i;
01110 resultData->optimization->solution[solIdx]->constraints->values->con[i]->value = constraintValues[i];
01111 }
01112 return true;
01113 }
01114
01115