/home/coin/SVN-release/OS-2.3.4/ApplicationTemplates/osDip/solvers/OSDipBlockSlpSolver.cpp

Go to the documentation of this file.
00001 /* $Id: OSBlockSlpSolver.cpp 3038 2009-11-07 11:43:44Z Gassmann $ */
00017 #include "OSDipBlockSlpSolver.h"
00018 #include "OSErrorClass.h" 
00019 #include "OSDataStructures.h"
00020 
00021 
00022 
00023 OSDipBlockSlpSolver::OSDipBlockSlpSolver():
00024         m_osinstance(NULL) {
00025         std::cout << "INSIDE OSDipBlockCoinSolver CONSTRUCTOR" << std::endl;
00026 }//end OSDipBlockSlpSolver
00027 
00028 
00029 OSDipBlockSlpSolver::OSDipBlockSlpSolver( OSInstance *osinstance) {
00030         
00031         try{
00032                 m_osinstance = osinstance;
00033                 m_numberOfVar = m_osinstance->getVariableNumber();
00034         
00035         } catch (const ErrorClass& eclass) {
00036 
00037                 throw ErrorClass(eclass.errormsg);
00038 
00039         }       
00040 
00041 }//end OSDipBlockSlpSolver
00042 
00043 OSDipBlockSlpSolver::~OSDipBlockSlpSolver(){
00044         
00045         std::cout << "INSIDED ~OSDipBlockSlpSolver()" << std::endl;
00046 
00047 
00048         std::vector<IndexValuePair*>::iterator  vit;
00049         
00050         for (vit = m_primalVals.begin(); vit != m_primalVals.end(); vit++) {
00051                 
00052                 delete *vit;
00053         }
00054         //if(m_osrlreader != NULL) delete m_osrlreader;
00055 }//end ~OSDipBlockSlpSolver
00056 
00057 void OSDipBlockSlpSolver::solve(double *cost, std::vector<IndexValuePair*> *solIndexValPair, double *optVal){
00058 
00059         try{
00060                 struct IndexValuePair *primalValPair;
00061 
00062                 std::vector<IndexValuePair*>::iterator  vit;
00063                 
00064                 for (vit = m_primalVals.begin(); vit != m_primalVals.end(); vit++) {
00065                         
00066                         delete *vit;
00067                 }
00068                 m_primalVals.clear();
00069                 //sum up negative coefficient
00070                 // -- critical -- we assume last variable is the y variable
00071                 // this is just for illustration
00072                 *optVal = 0;
00073                 for(int i = 0 ; i < m_numberOfVar - 1; i++){
00074                         
00075                         m_osinstance->instanceData->objectives->obj[0]->coef[i]->value 
00076                                         = cost[ i];
00077                         
00078                         
00079                         primalValPair = new IndexValuePair();
00080                         
00081                         primalValPair->value = 0.0;
00082                         primalValPair->idx = i;
00083                         
00084                         if (cost[ i] < 0){
00085                                 
00086                                 *optVal = *optVal + cost[ i];
00087                                  primalValPair->value = 1.0;
00088                         }
00089                         
00090                         m_primalVals.push_back( primalValPair);
00091                         
00092                         
00093                 }//end for
00094                 
00095                 //now set the y variable to 1 if optVal is negative
00096                 //otherwise 0
00097                 primalValPair = new IndexValuePair();
00098                 primalValPair->idx = m_numberOfVar - 1;
00099                 
00100                 if(*optVal < 0){
00101                         
00102                         primalValPair->value = 1.0;
00103                         *optVal = *optVal + cost[ m_numberOfVar - 1];
00104                         
00105                 }else{
00106                         
00107                         primalValPair->value = 0.0;     
00108                 }
00109                 
00110                 m_primalVals.push_back( primalValPair);
00111                 
00112                 
00113                 m_osinstance->bObjectivesModified = true;
00114                 std::cout << m_osinstance->printModel( ) << std::endl;
00115                 //
00116                 
00117                 std::cout << "NUMBER OF VARIABLES m_primalVals = " <<  m_primalVals.size() << std::endl;
00118                 
00119                 for (vit = m_primalVals.begin(); vit != m_primalVals.end(); vit++) {
00120                         
00121                         //solIndexValPair.push_back( *vit);
00122                         
00123                 }
00124                 
00125                  *solIndexValPair = m_primalVals;
00126                 // the argument is the solution index
00127                 
00128                 
00129                 //solStatus = m_osresult->getSolutionStatusType( 0 );
00130                 
00131                 //std::cout << "SOLUTION STATUS " << solStatus << std::endl;
00132                 // if solStatus is optimal get the optimal solution value
00133                 //if( solStatus.find("ptimal") != string::npos ){
00134                 //first index is objIdx, second is solution index
00135                 //      *optVal = m_osresult->getOptimalObjValue( -1, 0);
00136                 //      *solIndexValPair = m_osresult->getOptimalPrimalVariableValues( 0);                      
00137                 //}else{
00138                 //      throw ErrorClass("problem -- did not optimize a subproblem");
00139                 //}     
00140                         
00141         } catch (const ErrorClass& eclass) {
00142 
00143                 throw ErrorClass(eclass.errormsg);
00144 
00145         }       
00146         
00147 }//end solve
00148 
00149 
00150 void OSDipBlockSlpSolver::solve(double *cost, std::string *osrl){
00151 
00152         
00153         try{
00154                 //not implemented
00155                         
00156         } catch (const ErrorClass& eclass) {
00157 
00158                 throw ErrorClass(eclass.errormsg);
00159 
00160         }       
00161         
00162 }//end solve
00163 

Generated on Wed Mar 23 03:05:44 2011 by  doxygen 1.4.7