/home/coin/SVN-release/OS-2.1.0/OS/src/OSSolverService.cpp

Go to the documentation of this file.
00001 //$Id: OSSolverService.cpp 3309 2010-03-20 05:00:24Z kmartin $
00071 #include "OSCoinSolver.h"
00072 #include "OSResult.h" 
00073 #include "OSiLReader.h"        
00074 #include "OSiLWriter.h" 
00075 #include "OSoLReader.h"
00076 #include "OSrLReader.h"        
00077 #include "OSrLWriter.h"      
00078 #include "OSInstance.h"  
00079 #include "OSOption.h"
00080 #include "OSoLWriter.h"
00081 #include "OSFileUtil.h"  
00082 #include "OSConfig.h"  
00083 #include "OSDefaultSolver.h"  
00084 #include "OSWSUtil.h" 
00085 #include "OSSolverAgent.h"   
00086 #include "OShL.h"     
00087 #include "OSErrorClass.h"
00088 #include "OSmps2osil.h"   
00089 #include "OSBase64.h"
00090 
00091 
00092 
00093 
00094 using std::ostringstream;
00095 
00096 
00097 #ifdef COIN_HAS_KNITRO    
00098 #include "OSKnitroSolver.h"
00099 #endif 
00100 
00101 
00102 
00103 
00104 
00105 #ifdef COIN_HAS_LINDO    
00106 #include "OSLindoSolver.h"
00107 #endif 
00108 
00109 /*
00110 #ifdef COIN_HAS_IPOPT  
00111         #ifndef COIN_HAS_ASL
00112                 #include "OSIpoptSolver.h"
00113                 #undef COIN_HAS_ASL
00114         #else
00115                 #include "OSIpoptSolver.h"
00116 #endif
00117 #endif 
00118 */
00119 
00120 #ifdef COIN_HAS_ASL
00121 #include "OSnl2osil.h"
00122 #endif
00123 
00124 #ifdef COIN_HAS_GAMSUTILS
00125 #include "OSgams2osil.hpp"
00126 #endif
00127 
00128 //#ifdef COIN_HAS_IPOPT  
00129 //#include "OSIpoptSolver.h"
00130 //#endif
00131 
00132 #ifdef COIN_HAS_IPOPT  
00133         #ifndef COIN_HAS_ASL
00134                 #include "OSIpoptSolver.h"
00135                 #undef COIN_HAS_ASL
00136         #else
00137                 #include "OSIpoptSolver.h"
00138         #endif
00139 #endif
00140 
00141 
00142 
00143 #ifdef COIN_HAS_BONMIN   
00144 #include "OSBonminSolver.h"
00145 #endif 
00146 
00147 #ifdef COIN_HAS_COUENNE
00148 #include "OSCouenneSolver.h"
00149 #endif 
00150 
00151 
00152 #include "OSOptionsStruc.h"  
00153 
00154 
00155 using std::cout;
00156 using std::endl;
00157 using std::ostringstream;
00158 using std::string;
00159 
00160 //#define DEBUG_CL_INTERFACE
00161 
00162 
00163 #define MAXCHARS 5000 
00164 
00165 typedef struct yy_buffer_state *YY_BUFFER_STATE;
00166 YY_BUFFER_STATE osss_scan_string(const char* osss, void* scanner ); 
00167 //void osssset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
00168 void setyyextra(osOptionsStruc *osoptions, void* scanner);
00169 int ossslex(void* scanner );
00170 int ossslex_init(void** ptr);
00171 int ossslex_destroy (void* scanner );
00172 
00173 std::string get_help();
00174 std::string get_version();
00175 
00176 // the serviceMethods  
00177 void solve();  
00178 void getJobID(); 
00179 void send();
00180 void kill();
00181 void retrieve(); 
00182 void knock();
00183 
00184 // additional methods
00185 void getOSiLFromNl(); 
00186 void getOSiLFromMps();
00187 void getOSiLFromGams();
00188 std::string buildSolver(std::string solverName, std::string osol, OSInstance *osinstance);
00189 
00190 
00191 //std::string getServiceURI( std::string osol);
00192 //std::string getInstanceLocation( std::string osol);
00193 //std::string getSolverName( std::string osol);
00194 //std::string setSolverName( std::string osol, std::string solverName);
00195 
00196 
00197 //options structure
00198 // this is the only global variable but 
00199 // this is not a problem since this is a main routine
00200 osOptionsStruc *osoptions; 
00201 
00202 
00203 int main(int argC, const char* argV[])
00204 {       
00205         WindowsErrorPopupBlocker();
00206         void* scanner;
00207         FileUtil *fileUtil = NULL;
00208         FileUtil *inputFileUtil = NULL; 
00209         char osss[MAXCHARS] = " ";
00210         const char *space = " "; 
00211         //char *config = "-config";
00212         std::string configFileName = "";
00213         int i;
00214     printf("\n\n");
00215     printf("------- %s -------\n\n", OS_RELEASE_MESSAGE);
00216 
00217         // initialize the OS options structure
00218 
00219         osoptions = new osOptionsStruc();
00220         osoptions->configFile = ""; 
00221         osoptions->osilFile = ""; 
00222         osoptions->osil = ""; 
00223         osoptions->osolFile = ""; 
00224         osoptions->osol = "";  
00225         osoptions->osrlFile = ""; 
00226         osoptions->osrl = ""; 
00227         //osoptions->insListFile = ""; 
00228         osoptions->insList = ""; 
00229         osoptions->serviceLocation = "";
00230         osoptions->serviceMethod = ""; 
00231         osoptions->osplInputFile = ""; 
00232         osoptions->osplOutputFile = ""; 
00233         osoptions->mpsFile = ""; 
00234         osoptions->nlFile = ""; 
00235         osoptions->gamsControlFile = "";
00236         osoptions->solverName = ""; 
00237         osoptions->browser = ""; 
00238         osoptions->invokeHelp = false;
00239         osoptions->writeVersion = false;
00240         try{
00241                 if(argC < 2){
00242                         std::cout << "There must be at least one command line argument" << std::endl;
00243                         std::cout << "Try -help or --help" << std::endl;
00244                         delete osoptions;
00245                         return 1;
00246                 }
00247                 // see if the first argument is a file name
00248                 i = 1;
00249                 while(i < argC) {
00250                         if(strlen(osss) + strlen(argV[ i]) + 1 > MAXCHARS) throw ErrorClass( "the command line has too many arguments");
00251                         strcat(osss, argV[ i]);
00252                         strcat(osss, space);
00253                         i++;
00254                 }
00255 #ifdef DEBUG_CL_INTERFACE
00256                 cout << "Input String = "  << osss << endl;
00257 #endif
00258                 ossslex_init( &scanner);
00259                 //std::cout << "Call Text Extra" << std::endl;
00260                 setyyextra( osoptions, scanner);
00261                 //std::cout << "Call scan string " << std::endl;
00262                 osss_scan_string( osss, scanner); 
00263 #ifdef DEBUG_CL_INTERFACE
00264                 std::cout << "call ossslex" << std::endl;
00265 #endif
00266                 ossslex( scanner);
00267                 ossslex_destroy( scanner);
00268 #ifdef DEBUG_CL_INTERFACE
00269                 std::cout << "done with call to ossslex" << std::endl;
00270 #endif
00271                 // if there is a config file, get those options
00272                 if(osoptions->configFile != ""){
00273                         ossslex_init( &scanner);
00274                         configFileName = osoptions->configFile;
00275 #ifdef DEBUG_CL_INTERFACE
00276                         cout << "configFileName = " << configFileName << endl;
00277 #endif
00278                         std::string osolfileOptions = fileUtil->getFileAsString( configFileName.c_str() );
00279 #ifdef DEBUG_CL_INTERFACE
00280                         std::cout << "Call Text Extra" << std::endl;
00281 #endif
00282                         setyyextra( osoptions, scanner);
00283 #ifdef DEBUG_CL_INTERFACE
00284                         std::cout << "Done with call Text Extra" << std::endl;
00285 #endif
00286                         osss_scan_string( osolfileOptions.c_str() , scanner);
00287                         ossslex(scanner );      
00288                         ossslex_destroy( scanner);
00289                 }
00290         }
00291                 catch(const ErrorClass& eclass){
00292                 cout << eclass.errormsg <<  endl;
00293                 cout << "try -help or --help" <<  endl;
00294                 ossslex_destroy( scanner);
00295                 delete fileUtil;
00296                 delete osoptions;
00297                 return 1;
00298         } 
00299                 try{
00300                         if(osoptions->invokeHelp == true){ 
00301                                 std::string helpTxt = get_help();
00302                                 std::cout << std::endl << std::endl;
00303                                 std::cout << helpTxt << std::endl;
00304                                 delete  osoptions;
00305                                 osoptions = NULL;       
00306                                 return 0;
00307                         }
00308                         if(osoptions->writeVersion == true){ 
00309                                 std::string writeTxt = get_version();
00310                                 std::cout << std::endl << std::endl;
00311                                 std::cout << writeTxt << std::endl;
00312                                 delete  osoptions;
00313                                 osoptions = NULL;       
00314                                 return 0;
00315                         }
00316                 }
00317                 catch(const ErrorClass& eclass){
00318                         cout << eclass.errormsg <<  endl;
00319                         cout << "try -help or --help" <<  endl;
00320                         delete  osoptions;
00321                         osoptions = NULL;       
00322                         delete inputFileUtil;
00323                         inputFileUtil  = NULL;
00324                         return 1;
00325                 } 
00326 
00327 #ifdef DEBUG_CL_INTERFACE
00328                 cout << "HERE ARE THE OPTION VALUES:" << endl;
00329                 if(osoptions->configFile != "") cout << "Config file = " << osoptions->configFile << endl;
00330                 if(osoptions->osilFile != "") cout << "OSiL file = " << osoptions->osilFile << endl;
00331                 if(osoptions->osolFile != "") cout << "OSoL file = " << osoptions->osolFile << endl;
00332                 if(osoptions->osrlFile != "") cout << "OSrL file = " << osoptions->osrlFile << endl;
00333                 //if(osoptions->insListFile != "") cout << "Instruction List file = " << osoptions->insListFile << endl;
00334                 if(osoptions->osplInputFile != "") cout << "OSpL Input file = " << osoptions->osplInputFile << endl;
00335                 if(osoptions->serviceMethod != "") cout << "Service Method = " << osoptions->serviceMethod << endl;
00336                 if(osoptions->mpsFile != "") cout << "MPS File Name = " << osoptions->mpsFile << endl;
00337                 if(osoptions->nlFile != "") cout << "NL File Name = " << osoptions->nlFile << endl;
00338                 if(osoptions->gamsControlFile != "") cout << "gams Control File Name = " << osoptions->gamsControlFile << endl;
00339                 if(osoptions->browser != "") cout << "Browser Value = " << osoptions->browser << endl;
00340                 if(osoptions->solverName != "") cout << "Selected Solver = " << osoptions->solverName << endl;     
00341                 if(osoptions->serviceLocation != "") cout << "Service Location = " << osoptions->serviceLocation << endl;
00342 #endif
00343 
00344 
00345         //convert to lower case so there is no solver name ambiguity
00346         unsigned int k;
00347         for(k = 0; k < osoptions->solverName.length(); k++){
00348             osoptions->solverName[ k] = tolower( osoptions->solverName[ k]);
00349         }
00350 
00351                 // get the data from the files
00352                 fileUtil = new FileUtil();
00353                 try{    
00354                         //if(osoptions->insListFile != "") osoptions->insList = fileUtil->getFileAsChar( (osoptions->insListFile).c_str() );
00355                         if(osoptions->osolFile != ""){
00356                         
00357                                 osoptions->osol = fileUtil->getFileAsString( (osoptions->osolFile).c_str() );
00358                                 
00359                                 
00360                         }
00361                         
00362                         if(osoptions->osilFile != ""){
00363                                 //this takes precedence over what is in the OSoL file
00364                                  osoptions->osil = fileUtil->getFileAsString( (osoptions->osilFile).c_str()   );
00365                         }
00366                         /*
00367                         else{// we were not given an osil file
00368                                 // make sure we don't have a service URI in the file or are using mps or nl
00369                                 // if we have nl or mps assume a local solve
00370                                         if( (osoptions->osol != "") && (osoptions->nlFile == "") && (osoptions->gamsControlFile == "") && (osoptions->mpsFile == "") && (osoptions->serviceLocation == "")  &&  (getServiceURI( osoptions->osol) == "") ) 
00371                                                 osoptions->osil = fileUtil->getFileAsString( getInstanceLocation( osoptions->osol).c_str()  );
00372                         }
00373                         */
00374                         
00375                         //if(osoptions->osplInputFile != "") osoptions->osplInput = fileUtil->getFileAsChar( (osoptions->osplInputFile).c_str()  );
00376                         if(osoptions->osplInputFile != "") osoptions->osplInput = fileUtil->getFileAsString( (osoptions->osplInputFile).c_str() );
00377                         //if(osoptions->osplOutputFile != "") osoptions->osplOutput = fileUtil->getFileAsChar( (osoptions->osplOutputFile).c_str() );
00378                         if(osoptions->osplOutputFile != "") osoptions->osplOutput = fileUtil->getFileAsString( (osoptions->osplOutputFile).c_str() );
00379                 }
00380                 catch(const ErrorClass& eclass){
00381                         //cout << eclass.errormsg <<  endl;
00382                         cout << "could not open file properly" << endl;
00383                         cout << "try -help or --help" <<  endl;
00384                         delete  osoptions;
00385                         osoptions = NULL;       
00386                         delete fileUtil;
00387                         fileUtil = NULL;
00388                         return 1;
00389                 }       
00390                 // now call the correct serviceMethod
00391                 // solve is the default
00392                 if( osoptions->serviceMethod == "") solve();
00393                 if( (osoptions->serviceMethod[ 0] == 's') && (osoptions->serviceMethod[ 1] == 'o') )  solve();
00394                 else{
00395                         switch(osoptions->serviceMethod[ 0]){
00396                                 case 'g': 
00397                                         getJobID();
00398                                         break;
00399                                 case 'r':
00400                                         retrieve();
00401                                         break;
00402                                 case 's':
00403                                         if( osoptions->serviceMethod[ 1] == 'e') send();
00404                                         else solve();
00405                                         break;
00406                                 case 'k':
00407                                         if(osoptions->serviceMethod[ 1] == 'i') kill();
00408                                         else knock();
00409                                         break;
00410                                 default:
00411                                         
00412                                         break;
00413                         }
00414                 }
00415         delete  osoptions;
00416         osoptions = NULL;       
00417         delete fileUtil;
00418         fileUtil = NULL;
00419         return 0;
00420 }
00421 
00422 void solve(){
00423         std::string osrl = "";
00424         OSiLReader *osilreader = NULL; 
00425         OSmps2osil *mps2osil = NULL;
00426         #ifdef COIN_HAS_ASL
00427         OSnl2osil *nl2osil = NULL;
00428         #endif
00429         #ifdef COIN_HAS_GAMSUTILS
00430         OSgams2osil *gams2osil = NULL;                                  
00431         #endif 
00432         OSSolverAgent* osagent = NULL;
00433         FileUtil *fileUtil = NULL;
00434         fileUtil = new FileUtil();
00435         // now solve either remotely or locally
00436         try{
00437                 if( osoptions->serviceLocation != "" ){
00438                         // call a method here to get OSiL if we have an nl or mps file
00439                         if(osoptions->osil == ""){
00440                                 //we better have an nl file present or mps file or osol file
00441                                 if(osoptions->nlFile != ""){
00442                                         getOSiLFromNl();
00443                                 }
00444                                 else{
00445                                         if(osoptions->mpsFile != ""){
00446                                                 getOSiLFromMps();
00447                                         }
00448                                         else{
00449                                                 if(osoptions->gamsControlFile != ""){
00450                                                         
00451                                                         getOSiLFromGams();
00452                                         }
00453                                                 else{// send an empty osil string
00454                                                                 osoptions->osil = "";
00455                                                 }
00456                                         }
00457                                 }
00458                         }
00459                         // place a remote call
00460                 
00461                         osagent = new OSSolverAgent( osoptions->serviceLocation );
00462                         
00463                         if(osoptions->osol == ""){// we have no osol string
00464                         
00465                                 std::ostringstream outStr; 
00466                                 outStr <<  "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <osol xmlns=\"os.optimizationservices.org\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"os.optimizationservices.org http://www.optimizationservices.org/schemas/" ;
00467                                 outStr << OS_SCHEMA_VERSION ;
00468                                 outStr <<  "/OSoL.xsd\"></osol>";       
00469                                 osoptions->osol = outStr.str();
00470                         }
00471                         osrl = osagent->solve(osoptions->osil  , osoptions->osol);
00472                         if(osoptions->osrlFile != ""){
00473                                 fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00474                                 //const char *ch1 = "/Applications/Firefox.app/Contents/MacOS/firefox  ";
00475                                 if(osoptions->browser != ""){
00476                                         std::string str = osoptions->browser + "  " +  osoptions->osrlFile;
00477                                         const char *ch = &str[ 0];
00478                                         std::system( ch );
00479                                 }
00480                         }
00481                         else cout << osrl << endl;
00482                         delete osagent;
00483                         osagent = NULL;
00484 
00485                 } else{// solve locally
00486 
00487                         if(osoptions->osil != ""){
00488                                 osilreader = new OSiLReader();
00489                                 osrl = buildSolver(osoptions->solverName, osoptions->osol, osilreader->readOSiL( osoptions->osil));
00490                         }
00491                         else{
00492                                 //we better have an nl file present or mps file or osol file
00493                                 if(osoptions->nlFile != ""){
00494                                         #ifdef COIN_HAS_ASL
00495                                         nl2osil = new OSnl2osil( osoptions->nlFile); 
00496                                         nl2osil->createOSInstance() ;
00497                                         osrl = buildSolver(osoptions->solverName, osoptions->osol, nl2osil->osinstance);
00498                                         #else
00499                                                 throw ErrorClass("nlFile specified locally but ASL not present");
00500                                         #endif
00501                                 }
00502                                 else{
00503                                         if(osoptions->mpsFile != ""){
00504                                                 mps2osil = new OSmps2osil( osoptions->mpsFile);
00505                                                 mps2osil->createOSInstance() ;
00506                                                 osrl = buildSolver(osoptions->solverName, osoptions->osol, mps2osil->osinstance);
00507                                         }
00508                                         else{
00509                                                 if(osoptions->gamsControlFile != ""){
00510                                                 #ifdef COIN_HAS_GAMSUTILS
00511                                                 gams2osil =     new OSgams2osil( osoptions->gamsControlFile); 
00512                                                 gams2osil->createOSInstance();
00513                                                 osrl = buildSolver(osoptions->solverName, osoptions->osol, gams2osil->osinstance);
00514                                                 #else
00515                                                 throw ErrorClass("a Gams Control specified locally but GAMSIP not present");
00516                                                 #endif
00517                                                         
00518                                                 }
00519                                                 else{// need an osol file with an instanceLocation specified
00520                                                          //if( osoptions->osol.find( "<instanceLocation") == std::string::npos){
00521                                                                 throw ErrorClass("Error: no osil, GAMS dat, AMPL nl, or mps file given for a local solve --- \n information in the osol file is ignored for local solves.");
00522                                                         //}
00523                                                 }
00524                                         }
00525                                 }
00526                         }
00527                         //delete fileUtil;
00528                         if(osoptions->osrlFile != ""){
00529                         
00530                                 fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00531 
00532                                 //const char *ch1 = "/Applications/Firefox.app/Contents/MacOS/firefox  ";
00533                                 if(osoptions->browser != ""){
00534                                         std::string str = osoptions->browser + "  " +  osoptions->osrlFile;
00535                                         const char *ch = &str[ 0];
00536                                         std::system( ch );
00537                                 }
00538                         }
00539                         else cout << osrl << endl;
00540                         
00541 
00542                         
00543                 }//end of local solve
00544                 
00545                 
00546                 //garbage collection
00547                 if(osilreader != NULL) delete osilreader;
00548                 osilreader = NULL;
00549                 if(mps2osil != NULL) delete mps2osil;
00550                 mps2osil = NULL;
00551                 #ifdef COIN_HAS_ASL
00552                 if(nl2osil != NULL)  delete nl2osil;
00553                 nl2osil = NULL;
00554                 #endif
00555                 #ifdef COIN_HAS_GAMSUTILS
00556                 if(gams2osil != NULL)  delete gams2osil;
00557                 gams2osil = NULL;
00558                 #endif 
00559                 delete fileUtil;
00560                 fileUtil  = NULL;
00561         
00562         }//end try
00563         catch(const ErrorClass& eclass){
00564                 
00565                 OSResult *osresult = NULL;
00566                 OSrLWriter *osrlwriter = NULL;
00567                 osrlwriter = new OSrLWriter();
00568                 osresult = new OSResult();
00569                 osresult->setGeneralMessage( eclass.errormsg);
00570                 osresult->setGeneralStatusType( "error");
00571                 std::string osrl = osrlwriter->writeOSrL( osresult);
00572                 if(osoptions->osrlFile != ""){
00573                         //fileUtil->writeFileFromString(osoptions->osrlFile,  eclass.errormsg);
00574                         fileUtil->writeFileFromString(osoptions->osrlFile,  osrl);
00575                         if(osoptions->browser != ""){
00576                                 std::string str = osoptions->browser + "  " +  osoptions->osrlFile;
00577                                 const char *ch = &str[ 0];
00578                                 std::system( ch );
00579                         }
00580                 }
00581                 else{
00582                         //std::cout <<  eclass.errormsg << std::endl;
00583                         std::cout <<  osrl << std::endl;
00584                 }
00585                 //catch garbage collection
00586                 delete osresult;
00587                 osresult = NULL;
00588                 delete osrlwriter;
00589                 osrlwriter = NULL;
00590                 
00591                 //regular garbage collection
00592                 if(osilreader != NULL) delete osilreader;
00593                 osilreader = NULL;
00594                 if(mps2osil != NULL) delete mps2osil;
00595                 mps2osil = NULL;
00596 #ifdef COIN_HAS_ASL
00597                 if(nl2osil != NULL)  delete nl2osil;
00598                 nl2osil = NULL;
00599 #endif
00600 #ifdef COIN_HAS_GAMSUTILS
00601                 if(gams2osil != NULL)  delete gams2osil;
00602                 gams2osil = NULL;
00603 #endif          
00604                 delete fileUtil;
00605                 fileUtil = NULL;
00606         }//end local catch
00607         
00608 }//end solve
00609 
00610 void getJobID(){
00611         std::string jobID = "";
00612         OSSolverAgent* osagent = NULL;
00613         try{
00614                 if(osoptions->serviceLocation != ""){
00615                         osagent = new OSSolverAgent( osoptions->serviceLocation );
00616                         jobID = osagent->getJobID( osoptions->osol);
00617                         cout << jobID << endl;
00618                         delete osagent;
00619                         osagent = NULL;
00620                 }
00621                 else{
00622                         delete osagent;
00623                         osagent = NULL;
00624                         throw ErrorClass("please specify service location (url)");
00625                 }
00626         }
00627         catch(const ErrorClass& eclass){
00628                 FileUtil *fileUtil = NULL;
00629                 fileUtil = new FileUtil();
00630                 OSResult *osresult = NULL;
00631                 OSrLWriter *osrlwriter = NULL;
00632                 osrlwriter = new OSrLWriter();
00633                 osresult = new OSResult();
00634                 osresult->setGeneralMessage( eclass.errormsg);
00635                 osresult->setGeneralStatusType( "error");
00636                 std::string osrl = osrlwriter->writeOSrL( osresult);
00637                 if(osoptions->osrlFile != "") fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00638                 else cout << osrl << endl;
00639                 delete osresult;
00640                 osresult = NULL;
00641                 delete osrlwriter;
00642                 osrlwriter = NULL;
00643                 delete fileUtil;
00644                 fileUtil = NULL;
00645         }       
00646 }//end getJobID
00647  
00648 
00649 void knock(){
00650         std::string osplOutput = "";
00651         OSSolverAgent* osagent = NULL;
00652         FileUtil *fileUtil = NULL;
00653         fileUtil = new FileUtil();
00654         try{
00655                 if(osoptions->serviceLocation != ""){
00656                         osagent = new OSSolverAgent( osoptions->serviceLocation );
00657                         osplOutput = osagent->knock(osoptions->osplInput,  osoptions->osol);
00658                         if(osoptions->osplOutputFile != "") fileUtil->writeFileFromString(osoptions->osplOutputFile, osplOutput);
00659                         else cout << osplOutput << endl;
00660                         delete osagent;
00661                 }
00662                 else{
00663                         delete osagent;
00664                         throw ErrorClass( "please specify service location (url)" );
00665                 }
00666                 delete fileUtil;
00667                 fileUtil = NULL;
00668         }
00669         catch(const ErrorClass& eclass){
00670                 OSResult *osresult = NULL;
00671                 OSrLWriter *osrlwriter = NULL;
00672                 osrlwriter = new OSrLWriter();
00673                 osresult = new OSResult();
00674                 osresult->setGeneralMessage( eclass.errormsg);
00675                 osresult->setGeneralStatusType( "error");
00676                 std::string osrl = osrlwriter->writeOSrL( osresult);
00677                 if(osoptions->osrlFile != "") fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00678                 else cout << osrl << endl;
00679                 delete osresult;
00680                 osresult = NULL;
00681                 delete osrlwriter;
00682                 osrlwriter = NULL;
00683                 delete fileUtil;
00684                 fileUtil = NULL;
00685         }       
00686 }//end knock
00687 
00688 
00689 void send(){
00690         bool bSend = false;
00691         std::string jobID = "";
00692         OSSolverAgent* osagent = NULL;
00693         // first get the jobID
00694         std::string sOSoL = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <osol xmlns=\"os.optimizationservices.org\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"os.optimizationservices.org http://www.optimizationservices.org/schemas/OSoL.xsd\"><general> </general></osol>";
00695         string::size_type iStringpos;
00696         try{
00697                 // call a method here to get OSiL if we have an nl or mps file
00698                 if(osoptions->osil == ""){
00699                         //we better have an nl file present or mps file
00700                         if(osoptions->nlFile != ""){
00701                                 getOSiLFromNl();
00702                         }
00703                         else{
00704                                 if(osoptions->mpsFile != ""){
00705                                         getOSiLFromMps();
00706                                 }
00707                                 else{// send an empty osil string
00708                                         osoptions->osil = "";
00709                                 }
00710                         }
00711                 }
00712                 if(osoptions->serviceLocation != ""){
00713                         osagent = new OSSolverAgent( osoptions->serviceLocation );
00714                         // check to see if there is an osol 
00715                         if(osoptions->osolFile == ""){
00716                                 // get a jobID
00717                                 jobID =  osagent->getJobID( sOSoL) ;
00718                                 // insert the jobID into the default osol
00719                                 iStringpos = sOSoL.find("</general");
00720                                 if(iStringpos != std::string::npos) sOSoL.insert(iStringpos, "<jobID>" + jobID+ "</jobID>");
00721                         }
00722                         else {
00723                                 sOSoL = osoptions->osolFile;
00724                         }
00725 
00726                         bSend = osagent->send(osoptions->osil, sOSoL);
00727                         delete  osagent;
00728                 }
00729                 else{
00730                         delete  osagent;
00731                         throw ErrorClass( "please specify service location (url)" );
00732                 }
00733         }
00734         catch(const ErrorClass& eclass){
00735                 FileUtil *fileUtil = NULL;
00736                 fileUtil = new FileUtil();
00737                 OSResult *osresult = NULL;
00738                 OSrLWriter *osrlwriter = NULL;
00739                 osrlwriter = new OSrLWriter();
00740                 osresult = new OSResult();
00741                 osresult->setGeneralMessage( eclass.errormsg);
00742                 osresult->setGeneralStatusType( "error");
00743                 std::string osrl = osrlwriter->writeOSrL( osresult);
00744                 if(osoptions->osrlFile != "") fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00745                 else cout << osrl << endl;
00746                 delete osresult;
00747                 osresult = NULL;
00748                 delete osrlwriter;
00749                 osrlwriter = NULL;
00750                 delete fileUtil;
00751                 fileUtil = NULL;
00752         }       
00753 }//end send
00754 
00755 void retrieve(){
00756         FileUtil *fileUtil = NULL;
00757         fileUtil = new FileUtil();
00758         std::string osrl = "";
00759         OSSolverAgent* osagent = NULL;
00760         try{
00761                 if(osoptions->serviceLocation != ""){
00762                         osagent = new OSSolverAgent( osoptions->serviceLocation );
00763 #ifdef DEBUG_CL_INTERFACE
00764                         std::cout << "HERE ARE THE OSOL OPTIONS " <<  osoptions->osol << std::endl;
00765 #endif
00766                         osrl = osagent->retrieve( osoptions->osol);
00767                         if(osoptions->osrlFile != "") {
00768                                 fileUtil->writeFileFromString(osoptions->osrlFile, osrl); 
00769                                 if(osoptions->browser != ""){
00770                                         std::string str = osoptions->browser + "  " + osoptions->osrlFile ;
00771                                         const char *ch = &str[ 0];
00772                                         std::system( ch );
00773                                 }
00774                         }
00775                         else cout << osrl << endl;
00776                         delete osagent;
00777                         osagent = NULL;
00778                 }
00779                 else{
00780                         delete osagent;
00781                         osagent = NULL;
00782                         throw ErrorClass( "please specify service location (url)" );
00783                 }
00784                 delete fileUtil;
00785                 fileUtil = NULL;
00786         }
00787         catch(const ErrorClass& eclass){
00788                 OSResult *osresult = NULL;
00789                 OSrLWriter *osrlwriter = NULL;
00790                 osrlwriter = new OSrLWriter();
00791                 osresult = new OSResult();
00792                 osresult->setGeneralMessage( eclass.errormsg);
00793                 osresult->setGeneralStatusType( "error");
00794                 std::string osrl = osrlwriter->writeOSrL( osresult);
00795                 if(osoptions->osrlFile != "") fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00796                 else cout << osrl << endl;
00797                 delete osresult;
00798                 osresult = NULL;
00799                 delete osrlwriter;
00800                 osrlwriter = NULL;
00801                 delete fileUtil;
00802                 fileUtil = NULL;
00803         }       
00804 }//end retrieve
00805 
00806 void kill(){
00807         FileUtil *fileUtil = NULL;
00808         fileUtil = new FileUtil();
00809         std::string osplOutput = "";
00810         OSSolverAgent* osagent = NULL;
00811         try{
00812                 if(osoptions->serviceLocation != ""){
00813                         osagent = new OSSolverAgent( osoptions->serviceLocation );
00814                         osplOutput = osagent->kill( osoptions->osol);
00815                         if(osoptions->osplOutputFile != "") fileUtil->writeFileFromString(osoptions->osplOutputFile, osplOutput);
00816                         else cout << osplOutput << endl;
00817                         delete osagent;
00818                         osagent = NULL;
00819                 }
00820                 else{
00821                         delete osagent;
00822                         osagent = NULL;
00823                         throw ErrorClass( "please specify service location (url)" );
00824                 }
00825                 delete fileUtil;
00826                 fileUtil = NULL;
00827         }
00828         catch(const ErrorClass& eclass){
00829                 OSResult *osresult = NULL;
00830                 OSrLWriter *osrlwriter = NULL;
00831                 osrlwriter = new OSrLWriter();
00832                 osresult = new OSResult();
00833                 osresult->setGeneralMessage( eclass.errormsg);
00834                 osresult->setGeneralStatusType( "error");
00835                 std::string osrl = osrlwriter->writeOSrL( osresult);
00836                 if(osoptions->osrlFile != "") fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00837                 else cout << osrl << endl;
00838                 delete osresult;
00839                 osresult = NULL;
00840                 delete osrlwriter;
00841                 osrlwriter = NULL;
00842                 delete fileUtil;
00843                 fileUtil = NULL;
00844         }       
00845 }//end kill
00846 
00847 void getOSiLFromNl(){
00848         try{
00849                 #ifdef COIN_HAS_ASL
00850                 OSnl2osil *nl2osil = NULL;
00851                 nl2osil = new OSnl2osil( osoptions->nlFile);
00852                 nl2osil->createOSInstance() ;
00853                 OSiLWriter *osilwriter = NULL;
00854                 osilwriter = new OSiLWriter();
00855                 std::string osil;
00856                 osil = osilwriter->writeOSiL(  nl2osil->osinstance) ;
00857                 osoptions->osil = osil;
00858                 delete nl2osil;
00859                 nl2osil = NULL;
00860                 delete osilwriter;
00861                 osilwriter = NULL;      
00862                 #else
00863                 throw ErrorClass("trying to convert nl to osil without AMPL ASL configured");
00864                 #endif
00865         }
00866         catch(const ErrorClass& eclass){
00867                 std::cout << eclass.errormsg <<  std::endl;
00868                 throw ErrorClass( eclass.errormsg) ;
00869         }       
00870 }//getOSiLFromNl
00871 
00872 
00873 
00874 void getOSiLFromGams(){
00875         try{
00876                 #ifdef COIN_HAS_GAMSIO  
00877                 OSgams2osil *gams2osil = NULL;
00878                 gams2osil = new OSgams2osil( osoptions->gamsControlFile);
00879                 gams2osil->createOSInstance() ;
00880                 OSiLWriter *osilwriter = NULL;
00881                 osilwriter = new OSiLWriter();
00882                 std::string osil;
00883                 osil = osilwriter->writeOSiL(  gams2osil->osinstance) ;
00884                 osoptions->osil = osil;
00885                 delete gams2osil;
00886                 gams2osil = NULL;
00887                 delete osilwriter;
00888                 osilwriter = NULL;      
00889                 #else
00890                 throw ErrorClass("trying to convert Gams control file to osil without GAMSUTILS configured");
00891                 #endif
00892         }
00893         catch(const ErrorClass& eclass){
00894                 std::cout << eclass.errormsg <<  std::endl;
00895                 throw ErrorClass( eclass.errormsg) ;
00896         }       
00897 }//getOSiLFromGams
00898 
00899 
00900 void getOSiLFromMps(){
00901         try{
00902                 OSmps2osil *mps2osil = NULL;
00903                 mps2osil = new OSmps2osil( osoptions->mpsFile);
00904                 mps2osil->createOSInstance() ;
00905                 OSiLWriter *osilwriter = NULL;
00906                 osilwriter = new OSiLWriter();
00907                 std::string osil;
00908                 osil = osilwriter->writeOSiL(  mps2osil->osinstance) ;
00909                 osoptions->osil = osil;
00910                 delete mps2osil;
00911                 mps2osil = NULL;
00912                 delete osilwriter;
00913                 osilwriter = NULL;      
00914         }
00915         catch(const ErrorClass& eclass){
00916                 std::cout << eclass.errormsg <<  std::endl;
00917                 throw ErrorClass( eclass.errormsg) ;
00918         }       
00919         
00920 }//getOSiLFromMps
00921 
00922 //string getServiceURI( std::string osol){
00923 //      if(osol == "") return osol;
00924 //      string::size_type pos2;
00925 //      string::size_type  pos1 = osol.find( "<serviceURI");
00926 //      if(pos1 != std::string::npos){
00927 //              // get the end of the serviceURI start tag
00928 //              pos1 = osol.find(">", pos1 + 1);
00929 //              if(pos1 != std::string::npos){
00930 //                      // get the start of serviceURI end tag
00931 //                      pos2 = osol.find( "</serviceURI", pos1 + 1);
00932 //                      if( pos2 != std::string::npos){
00933 //                              // get the substring
00934 //                              return osol.substr( pos1 + 1, pos2 - pos1 - 1); 
00935 //                      }
00936 //                      else return "";
00937 //              }
00938 //              else return "";
00939 //      }
00940 //      else return "";
00941 //}//getServiceURI
00942 
00943 //string getInstanceLocation( std::string osol){
00944 //      if(osol == "") return osol;
00945 //      string::size_type pos2;
00946 //      string::size_type pos1 = osol.find( "<instanceLocation");
00947 //      if(pos1 != std::string::npos){
00948 //              // get the end of the instanceLocation start tag
00949 //              pos1 = osol.find(">", pos1 + 1);
00950 //              if(pos1 != std::string::npos){
00951 //                      // get the start of instanceLocation end tag
00952 //                      pos2 = osol.find( "</instanceLocation", pos1 + 1);
00953 //                      if( pos2 != std::string::npos){
00954 //                              // get the substring
00955 //                              return osol.substr( pos1 + 1, pos2 - pos1 - 1); 
00956 //                      }
00957 //                      else return "";
00958 //              }
00959 //              else return "";
00960 //      }
00961 //      else return "";
00962 //}//getInstanceLocation
00963 
00964 
00965 
00966 //std::string getSolverName( std::string osol){
00967 //#ifdef DEBUG_CL_INTERFACE
00968 //      std::cout << "inside getSolverName" << std::endl;
00969 //      std::cout <<  osol << std::endl;
00970 //      std::cout << "done with osol" << std::endl;
00971 //#endif
00972 //      OSOption *osoption = NULL;
00973 //      OSoLReader *osolreader = NULL;
00974 //      osolreader = new OSoLReader();
00975 //
00976 //      osoption = osolreader->readOSoL( osol);
00977 //#ifdef DEBUG_CL_INTERFACE
00978 //      std::cout <<  "invoke getSolverToInvoke" << std::endl;
00979 //#endif
00980 //      std::string optionstring = osoption->getSolverToInvoke();
00981 //#ifdef DEBUG_CL_INTERFACE
00982 //      std::cout <<  "done with invoke getSolverToInvoke" << std::endl;
00983 //#endif
00985 //      delete osolreader;
00986 //      return optionstring;
00987 //      /*
00988 //      if(osol == "") return osol;
00989 //      string::size_type pos2;
00990 //      string::size_type pos1 = osol.find( "solverToInvoke");
00991 //      if(pos1 != std::string::npos){
00992 //              // get the end of the instanceLocation start tag
00993 //              pos1 = osol.find(">", pos1 + 1);
00994 //              if(pos1 != std::string::npos){
00995 //                      // get the start of instanceLocation end tag
00996 //                      pos2 = osol.find( "</solverToInvoke", pos1 + 1);
00997 //                      if( pos2 != std::string::npos){
00998 //                              // get the substring
00999 //                              return osol.substr( pos1 + 1, pos2 - pos1 - 1); 
01000 //                      }
01001 //                      else return "";
01002 //              }
01003 //              else return "";
01004 //      }
01005 //      else return "";
01006 //      */
01007 //}//getSolverName
01008 
01009 
01010 
01011 
01012 //std::string setSolverName( std::string osol, std::string solverName){
01013 //#ifdef DEBUG_CL_INTERFACE
01014 //      std::cout << "inside setSolverName" << std::endl;
01015 //#endif
01016 //      OSOption *osoption = NULL;
01017 //      OSoLReader *osolreader = NULL;
01018 //      osolreader = new OSoLReader();
01019 //      osoption = osolreader->readOSoL( osol);
01021 //      osoption->setSolverToInvoke( solverName);
01024 //      OSoLWriter *osolwriter = NULL;
01025 //      osolwriter = new OSoLWriter();
01026 //      std::string newOSoL = osolwriter->writeOSoL( osoption);
01030 //      delete osolreader;
01031 //      delete osolwriter;
01032 //      return newOSoL;
01033 //}//setSolverName
01034 
01035 std::string get_help(){
01036 
01037         std::ostringstream helpMsg;
01038 
01039         
01040         helpMsg << "************************* HELP *************************" << endl << endl;
01041         helpMsg << "In this HELP file we assume that the solve service method is used and " << endl; 
01042         helpMsg << "that we are solving problems locally, that is the solver is on the " << endl; 
01043         helpMsg << "machine running this OSSolverService.  See Section 10.3 of the User\'s  " << endl;
01044         helpMsg << "Manual for other service methods or calling a server remotely. " << endl; 
01045         helpMsg << "The OSSolverService takes the parameters listed below.  " << endl;
01046         helpMsg << "The order of the parameters is irrelevant.  Not all the parameters  " << endl;
01047         helpMsg << "are required.  However, the location of an instance file is  " << endl;
01048         helpMsg << "required when using the solve service method. The location of the " << endl;
01049         helpMsg << "instance file is specified using the osil option. " << endl;
01050 
01051         helpMsg << endl;
01052         
01053         helpMsg << "-osil xxx.osil this is the name of the file that contains the  " << endl;
01054         helpMsg << "optimization instance in OSiL format.  This option may be  " << endl;
01055         helpMsg << "specified in the OSoL solver options file. " << endl;
01056         
01057         helpMsg << endl;
01058 
01059         helpMsg << "-osol xxx.osol  this is the name of the file that contains the solver options.   " << endl;
01060         helpMsg << "It is not necessary to specify this option. " << endl; 
01061         
01062         helpMsg << endl;
01063 
01064         helpMsg << "-osrl xxx.osrl  this is the name of the file to which the solver solution is written.  " << endl; 
01065         helpMsg << "It is not necessary to specify this option. If this option is not specified,  " << endl;
01066         helpMsg << "the result will be printed to standard out.  " << endl;
01067         
01068         helpMsg << endl;
01069         
01070         helpMsg << "-osplInput xxx.ospl  this is the name of an input file in the OS Process" << endl;
01071         helpMsg <<  " Language (OSpL), this is used as input  to the knock method." << endl;
01072         
01073         helpMsg << endl;
01074 
01075         helpMsg << "-osplOutput xxx.ospl this is the name of an output file in the  OS Process" << endl;
01076         helpMsg <<  "Language (OSpL), this the output string from the knock and kill methods." << endl;
01077         
01078         helpMsg << endl;
01079 
01080         helpMsg << "-serviceLocation url is the URL of the solver service.  " << endl;
01081         helpMsg << "This is not required, and if not specified it is assumed that   " << endl;
01082         helpMsg << "the problem is solved locally.  " << endl;
01083         
01084         helpMsg << endl;
01085 
01086         helpMsg << "-serviceMethod  methodName this is the method on the solver service to be invoked.  " << endl; 
01087         helpMsg << "The options are  solve,  send,  kill,  knock,  getJobID, and retrieve.   " << endl;
01088         helpMsg << "This option is not required, and the default value is  solve.  " << endl;
01089         
01090         helpMsg << endl;
01091 
01092         helpMsg << "-mps  xxx.mps  this is the name of the mps file if the problem instance  " << endl;
01093         helpMsg << "is in mps format. The default file format is OSiL so this option is not required.  " << endl;
01094         
01095         helpMsg << endl;
01096 
01097         helpMsg << "-nl  xxx.nl  this is the name of the AMPL nl file if the problem  " << endl;
01098         helpMsg << "instance is in AMPL nl  format. The default file format is OSiL  " << endl;
01099         helpMsg << "so this option is not required.  " << endl;
01100         
01101         helpMsg << endl;
01102 
01103         helpMsg << "-solver  solverName  Possible values for default OS installation  " << endl;
01104         helpMsg << "are  bonmin(COIN-OR Bonmin), couenne (COIN-OR Couenne), clp (COIN-OR Clp)," << endl;
01105         helpMsg << "cbc (COIN-OR Cbc), dylp (COIN-OR DyLP), ipopt (COIN-OR Ipopt)," << endl;
01106         helpMsg << "and symphony (COIN-OR SYMPHONY). Other solvers supported" << endl;
01107         helpMsg << "(if the necessary libraries are present) are cplex (Cplex through COIN-OR Osi)," << endl;
01108         helpMsg << "glpk (glpk through COIN-OR Osi), knitro (Knitro), and lindo (LINDO)." << endl;
01109         helpMsg << "If no value is specified for this parameter," << endl;
01110         helpMsg << "then cbc is the default value of this parameter." << endl; 
01111         
01112         helpMsg << endl;
01113 
01114         helpMsg << "-browser  browserName this paramater is a path to the browser on the  " << endl; 
01115         helpMsg << "local machine. If this optional parameter is specified then the  " << endl; 
01116         helpMsg << "solver result in OSrL format is transformed using XSLT into  " << endl; 
01117         helpMsg << "HTML and displayed in the browser.  " << endl; 
01118         
01119         helpMsg << endl;
01120 
01121         helpMsg << "-config pathToConfigureFile this parameter specifies a path on  " << endl; 
01122         helpMsg << "the local machine to a text file containing values for the input parameters.  " << endl; 
01123         helpMsg << "This is convenient for the user not wishing to constantly retype parameter values.  " << endl;
01124         helpMsg << "This configure file can contain values for all of the other parameters. " << endl;
01125         
01126         helpMsg << endl;
01127 
01128         helpMsg << "--version or -v get the current version of this executable  " << endl;
01129         
01130         helpMsg << endl;
01131 
01132         helpMsg << "--help or -h  to get this help file " << endl;
01133 
01134         
01135         helpMsg << endl;
01136         
01137         helpMsg << "Note: If you specify a configure file by using the -config option, you can  " << endl;
01138         helpMsg << "override the values of the options in the configure file by putting them in   " << endl;
01139         helpMsg << "at the command line. " << endl << endl;
01140         
01141         helpMsg << "See the OS User\' Manual: http://www.coin-or.org/OS/doc/osUsersManual_2.0.pdf" << endl;
01142         helpMsg << "for more detail on how to use the OS project. " << endl;
01143         
01144         helpMsg << endl;
01145         helpMsg << "********************************************************" << endl << endl;
01146 
01147         return helpMsg.str();
01148 }// get help
01149 
01150 
01151 std::string get_version(){
01152 
01153         std::ostringstream versionMsg;
01154         versionMsg << "In order to find the version of this project " << endl;
01155         versionMsg << "connect to the directory where you downloaded " << endl;
01156         versionMsg << "and do: " << endl;
01157         versionMsg << "svn info " << endl;
01158         
01159         
01160         return versionMsg.str();
01161 }// get version
01162 
01163 
01164 
01165 std::string  buildSolver(std::string solverName, std::string osol, OSInstance *osinstance){
01166         DefaultSolver *solverType  = NULL;
01167         //std::cout << "SOLVER NAME = " << solverName << std::endl;
01168         try{
01169                 if (solverName == "") {// must determine the default solver
01170                         if(osinstance == NULL) throw ErrorClass("there was a NULL instance sent to buildSolver");
01171                         //see if we have an integer program 
01172                         if(osinstance->getNumberOfIntegerVariables() + osinstance->getNumberOfBinaryVariables() > 0){//we have an integer program
01173                                 if( (osinstance->getNumberOfNonlinearExpressions() > 0)
01174                                    || (osinstance->getNumberOfQuadraticTerms() > 0) ){ // we are nonlinear and integer
01175                                         solverName = "bonmin";
01176                                 }else{//we are linear integer 
01177                                         solverName = "cbc";
01178                                 }
01179                         }else{// we have a continuous problem
01180                                 if( (osinstance->getNumberOfNonlinearExpressions() > 0)
01181                                    || (osinstance->getNumberOfQuadraticTerms() > 0) ){ // we are nonlinear and continuous
01182                                         solverName = "ipopt";
01183                                 }else{//we have linear program 
01184                                         solverName = "clp";
01185                                 }
01186                         }
01187                 }//end of if on solverName
01188                 
01189                 //now build the solver through its constructor
01190                 
01191                 //std::cout << "SOLVER NAME =  " << solverName << std::endl;
01192 
01193                 if( solverName.find( "ipopt") != std::string::npos) {
01194                         // we are requesting the Ipopt solver
01195                         bool bIpoptIsPresent = false;
01196 #ifdef COIN_HAS_IPOPT
01197                         bIpoptIsPresent = true;
01198                         solverType = new IpoptSolver(); 
01199 #endif
01200                         if(bIpoptIsPresent == false) throw ErrorClass( "the Ipopt solver requested is not present");
01201                 }
01202                 else{
01203                         if( solverName.find( "lindo") != std::string::npos) {
01204                                 // we are requesting the Lindo solver
01205                                 bool bLindoIsPresent = false;
01206 #ifdef COIN_HAS_LINDO
01207                                 bLindoIsPresent = true;
01208                                 std::cout << "calling the LINDO Solver " << std::endl;
01209                                 solverType = new LindoSolver();
01210                                 std::cout << "DONE calling the LINDO Solver " << std::endl;
01211 #endif
01212                                 if(bLindoIsPresent == false) throw ErrorClass( "the Lindo solver requested is not present");
01213                         }
01214                         else{ 
01215                                 if( solverName.find( "clp") != std::string::npos){
01216                                         //std::cout << "NEWING SOLVER TYPE " << std::endl;
01217                                         solverType = new CoinSolver();
01218                                         //std::cout << "END NEWING SOLVER TYPE " << std::endl;
01219                                         solverType->sSolverName = "clp";
01220                                 }
01221                                 else{
01222                                         if( solverName.find( "cplex") != std::string::npos){
01223                                                 bool bCplexIsPresent = false;
01224 #ifdef COIN_HAS_CPX
01225                                                 bCplexIsPresent = true;
01226                                                 solverType = new CoinSolver();
01227                                                 solverType->sSolverName = "cplex";
01228 #endif
01229                                                 if(bCplexIsPresent == false) throw ErrorClass( "the Cplex solver requested is not present");
01230                                         }
01231                                         else{
01232                                                 if( solverName.find( "glpk") != std::string::npos){
01233                                                         bool bGlpkIsPresent = false;
01234 #ifdef COIN_HAS_GLPK
01235                                                         bGlpkIsPresent = true;
01236                                                         solverType = new CoinSolver();
01237                                                         solverType->sSolverName = "glpk";
01238 #endif
01239                                                         if(bGlpkIsPresent == false) throw ErrorClass( "the GLPK solver requested is not present");
01240                                                 }
01241                                                 else{
01242                                                         if( solverName.find( "dylp") != std::string::npos){
01243                                                                 bool bDyLPIsPresent  = false;
01244 #ifdef COIN_HAS_DYLP
01245                                                                 bDyLPIsPresent  = true;
01246                                                                 solverType = new CoinSolver();
01247                                                                 solverType->sSolverName = "dylp";
01248                                                                 bDyLPIsPresent = true;
01249 #endif
01250                                                                 if(bDyLPIsPresent == false) throw ErrorClass( "the DyLP solver requested is not present");
01251                                                         }
01252                                                         else{
01253                                                                 if( solverName.find( "symphony") != std::string::npos){
01254                                                                         bool bSymphonyIsPresent  = false;
01255 #ifdef COIN_HAS_SYMPHONY
01256                                                                         bSymphonyIsPresent  = true;
01257                                                                         solverType = new CoinSolver();
01258                                                                         solverType->sSolverName = "symphony";
01259 #endif
01260                                                                         if(bSymphonyIsPresent == false) throw ErrorClass( "the SYMPHONY solver requested is not present");
01261                                                                 }
01262                                                                 else{
01263                                                                         if( solverName.find( "knitro") != std::string::npos){
01264                                                                                 bool bKnitroIsPresent = false;
01265 #ifdef COIN_HAS_KNITRO
01266                                                                                 bKnitroIsPresent = true;
01267                                                                                 std::cout << "calling the KNITRO Solver " << std::endl;
01268                                                                                 solverType = new KnitroSolver();
01269                                                                                 std::cout << "DONE calling the KNITRO Solver " << std::endl;
01270 #endif
01271                                                                                 if(bKnitroIsPresent == false) throw ErrorClass( "the Knitro solver requested is not present");          
01272                                                                         }
01273                                                                         else{ 
01274                                                                                 if( solverName.find( "vol") != std::string::npos){
01275                                                                                         bool bVolIsPresent = false;
01276 #ifdef COIN_HAS_VOL
01277                                                                                         bVolIsPresent = true;
01278                                                                                         solverType = new CoinSolver();
01279                                                                                         solverType->sSolverName = "vol";
01280 #endif
01281                                                                                         if(bVolIsPresent == false) throw ErrorClass( "the Vol solver requested is not present");                
01282                                                                                 }
01283                                                                                 else{
01284                                                                                         if( solverName.find( "bonmin") != std::string::npos){
01285                                                                                                 // we are requesting the Bonmin solver
01286                                                                                                 bool bBonminIsPresent = false;
01287 #ifdef COIN_HAS_BONMIN
01288                                                                                                 bBonminIsPresent = true;
01289                                                                                                 solverType = new BonminSolver();        
01290 #endif                                                                                          
01291                                                                                                 if(bBonminIsPresent == false) throw ErrorClass( "the Bonmin solver requested is not present");          
01292                                                                                         }
01293                                                                                         else{
01294                                                                                                 if( solverName.find( "couenne") != std::string::npos){
01295                                                                                                         // we are requesting the Couenne solver
01296                                                                                                         bool bCouenneIsPresent = false;
01297 #ifdef COIN_HAS_COUENNE
01298                                                                                                         bCouenneIsPresent = true;
01299                                                                                                         solverType = new CouenneSolver();       
01300 #endif                                                                                          
01301                                                                                                         if(bCouenneIsPresent == false) throw ErrorClass( "the Couenne solver requested is not present");                
01302                                                                                                 }
01303                                                                                                 else{ //cbc is the default
01304                                                                                                         solverType = new CoinSolver();
01305                                                                                                         solverType->sSolverName = "cbc";
01306                                                                                                 }
01307                                                                                         }
01308                                                                                 }
01309                                                                         }                                                                       
01310                                                                 }
01311                                                         }
01312                                                 }
01313                                         }
01314                                 }
01315                         }
01316                 }               
01317                 
01318                 //std::cout << "SET SOLVER INSTANCE " << std::endl;
01319                 solverType->osinstance = osinstance;
01320                 solverType->osol = osol;
01321                 solverType->buildSolverInstance();
01322                 solverType->setSolverOptions();
01323                 solverType->solve()     ;
01324                 std::string resultString = solverType->osrl ;
01325                 if(solverType != NULL) delete solverType;
01326                 solverType = NULL;
01327                 return  resultString ;
01328 
01329         }
01330         catch(const ErrorClass& eclass){
01331                 throw eclass;
01332         }
01333                 
01334         
01335 }//buildSolver
01336 

Generated on Tue Mar 30 03:04:42 2010 by  doxygen 1.4.7