/Users/kmartin/Documents/files/code/cpp/OScpp/COIN-OS/OS/src/OSCommonInterfaces/OSResult.cpp

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

Generated on Sat Mar 29 22:38:02 2008 by  doxygen 1.5.3