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

Go to the documentation of this file.
00001 //Id: OSSolverService.cpp 3561 2010-06-24 19:27:07Z kmartin $
00069 #include "OSCoinSolver.h"
00070 #include "OSResult.h"
00071 #include "OSiLReader.h"
00072 #include "OSiLWriter.h"
00073 #include "OSoLReader.h"
00074 #include "OSrLReader.h"
00075 #include "OSrLWriter.h"
00076 #include "OSInstance.h"
00077 #include "OSOption.h"
00078 #include "OSoLWriter.h"
00079 #include "OSFileUtil.h"
00080 #include "OSConfig.h"
00081 #include "OSDefaultSolver.h"
00082 #include "OSWSUtil.h"
00083 #include "OSSolverAgent.h"
00084 #include "OShL.h"
00085 #include "OSErrorClass.h"
00086 #include "OSmps2osil.h"
00087 #include "OSBase64.h"
00088 #include "OSRunSolver.h"
00089 
00090 #ifdef COIN_HAS_KNITRO
00091 #include "OSKnitroSolver.h"
00092 #endif
00093 
00094 #ifdef COIN_HAS_LINDO
00095 #include "OSLindoSolver.h"
00096 #endif
00097 
00098 #ifdef COIN_HAS_ASL
00099 #include "OSnl2osil.h"
00100 #endif
00101 
00102 #ifdef COIN_HAS_GAMSUTILS
00103 #include "OSgams2osil.hpp"
00104 #endif
00105 
00106 //#ifdef COIN_HAS_IPOPT
00107 //#include "OSIpoptSolver.h"
00108 //#endif
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 #ifdef COIN_HAS_BONMIN
00120 #include "OSBonminSolver.h"
00121 #endif
00122 
00123 #ifdef COIN_HAS_COUENNE
00124 #include "OSCouenneSolver.h"
00125 #endif
00126 
00127 #include "OSOptionsStruc.h"
00128 
00129 #include<stdio.h>
00130 #include <map>
00131 
00132 
00133 using std::cout;
00134 using std::endl;
00135 using std::ostringstream;
00136 using std::string;
00137 using std::map;
00138 
00139 #define DEBUG_CL_INTERFACE
00140 
00141 
00142 #define MAXCHARS 5000
00143 
00144 typedef struct yy_buffer_state *YY_BUFFER_STATE;
00145 YY_BUFFER_STATE osss_scan_string(const char* osss, void* scanner);
00146 //void osssset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
00147 void setyyextra(osOptionsStruc *osoptions, void* scanner);
00148 int ossslex(void* scanner);
00149 int ossslex_init(void** ptr);
00150 int ossslex_destroy(void* scanner);
00151 
00152 std::string get_help();
00153 std::string get_version();
00154 std::string get_options();
00155 void reset_options();
00156 
00157 // the serviceMethods
00158 void solve();
00159 void getJobID();
00160 void send();
00161 void kill();
00162 void retrieve();
00163 void knock();
00164 
00165 // additional methods
00166 void getOSiLFromNl();
00167 void getOSiLFromMps();
00168 void getOSiLFromGams();
00169 //std::string buildSolver(std::string solverName, std::string osol,
00170 //                        OSInstance *osinstance);
00171 void listOptions(osOptionsStruc *osoptions);
00172 
00173 //std::string getServiceURI( std::string osol);
00174 //std::string getInstanceLocation( std::string osol);
00175 //std::string getSolverName( std::string osol);
00176 //std::string setSolverName( std::string osol, std::string solverName);
00177 
00178 
00179 //options structure
00180 // this is the only global variable but
00181 // this is not a problem since this is a main routine
00182 osOptionsStruc *osoptions;
00183 
00184 int main(int argC, const char* argV[])
00185 {
00186     WindowsErrorPopupBlocker();
00187     void* scanner;
00188     FileUtil *fileUtil = NULL;
00189     FileUtil *inputFileUtil = NULL;
00190     char osss[MAXCHARS] = " ";
00191     const char *space = " ";
00192     //char *config = "-config";
00193     std::string configFileName = "";
00194     int i;
00195 
00196     std::cout << OSgetVersionInfo();
00197 
00198     // initialize the OS options structure
00199 
00200     osoptions = new osOptionsStruc();
00201     reset_options();
00202     bool scannerActive = false;
00203 
00204     try
00205     {
00206         if (argC < 2)
00207         {
00208             //std::cout << "There must be at least one command line argument" << std::endl;
00209             //std::cout << "Try -h or --help" << std::endl;
00210             //throw ErrorClass(
00211             //          "There must be at least one command line argument\n  Try -h or --help");
00212             //delete osoptions;
00213             //return 1;
00214             //OSgetVersionInfo();
00215             //this is the interactive shell
00216             scannerActive = true;
00217             ossslex_init(&scanner);
00218             setyyextra(osoptions, scanner);
00219             std::string lineText;
00220             bool validName;
00221             //use a blank to separate words
00222             std::string wordSep = " ";
00223             std::string optionName = "";
00224             std::string optionValue = "";
00225             std::string::size_type indexStart;
00226             std::string::size_type indexEnd;
00227             unsigned int k;
00228 
00229 
00230             std::string commandArray[12] = { "solve", "send", "getJobID", "retrieve", "kill", "knock",
00231                                              "quit", "exit",  "reset", "list", "?", "help"
00232                                            };
00233 
00234 
00235             std::string optionArray[10] = { "osil", "osrl", "osol", "mps", "nl", "dat",
00236                                             "serviceLocation", "solver", "osplInput",  "osplOutput"
00237                                           };
00238 
00239 
00240             size_t size_of_commandArray = (sizeof commandArray)
00241                                           / (sizeof commandArray[0]);
00242 
00243             size_t size_of_optionArray = (sizeof optionArray)
00244                                          / (sizeof optionArray[0]);
00245 
00246 
00247             //fill in the command array into a map
00248 
00249             std::map<string, int> commandMap;
00250             //std::map<string, int>::const_iterator iter;
00251 
00252             for(k = 0; k < size_of_commandArray; k++)
00253             {
00254                 commandMap[ commandArray[ k] ] = k;
00255             }
00256 
00257             //fill in the option array into a map
00258 
00259             std::map<string, int> optionMap;
00260 
00261 
00262             for(k = 0; k < size_of_optionArray; k++)
00263             {
00264                 optionMap[ optionArray[ k] ] = k;
00265             }
00266 
00267             //for (iter=optionMap.begin(); iter != optionMap.end(); ++iter) {
00268             //    cout << iter->second << " " << iter->first << endl;
00269             //}
00270 
00271             std::cout << "At the prompt enter a valid command or option value pair.\n";
00272             std::cout << "Enter the \"solve\" command to optimize.\n";
00273             std::cout << "Type \"quit\" or \"exit\" to leave the application. \n";
00274             std::cout << "Type \"help\" or \"?\" for a list of valid options.\n\n";
00275 
00276             //std::cout << "Number of Options = " <<  size_of_array << std::endl;
00277             while (osoptions->quit != true && osoptions->exit != true)
00278             {
00279                 /*                              std::cout << "At the prompt enter a valid command or option value pair.\n";
00280                                                 std::cout << "Enter the \"solve\" command to optimize.\n";
00281                                                 std::cout << "Type \"quit/exit\" to leave the application. \n";
00282                                                 std::cout << "Type \"help\" or \"?\" for a list of valid options.\n\n";
00283                 */
00284                 std::cout <<  "Please enter a command, or an option followed by an option value: ";
00285                 getline(std::cin, lineText);
00286                 lineText = " " + lineText + " ";
00287                 //get the name of the option
00288                 indexStart = lineText.find_first_not_of(wordSep);
00289                 if (indexStart == string::npos)
00290                 {
00291                     std::cout << std::endl;
00292                     std::cout << "You did not enter a valid option."
00293                               << std::endl;
00294                 }
00295                 else
00296                 {
00297                     indexEnd = lineText.find_first_of(wordSep, indexStart + 1);
00298                     optionName = lineText.substr(indexStart, indexEnd
00299                                                  - indexStart);
00300                     //std::cout << "Option Name = " << optionName << std::endl;
00301 
00302                     validName = false;
00303                     if( (commandMap.find(optionName) != commandMap.end() ) ||
00304                             (optionMap.find(optionName) != optionMap.end() ) )
00305                     {
00306                         validName = true;
00307                     }
00308                     if (validName == false)
00309                     {
00310                         std::cout << std::endl;
00311                         std::cout << "You did not enter a valid option."
00312                                   << std::endl;
00313                     }
00314                     else
00315                     {
00316 
00317                         // get the option value
00318                         indexStart = lineText.find_first_not_of(wordSep,
00319                                                                 indexEnd + 1);
00320                         indexEnd = lineText.find_first_of(wordSep, indexStart
00321                                                           + 1);
00322                         if (indexStart != std::string::npos && indexEnd
00323                                 != std::string::npos)
00324                         {
00325                             optionValue = lineText.substr(indexStart, indexEnd
00326                                                           - indexStart);
00327                         }
00328                         else
00329                         {
00330                             optionValue = "";
00331                         }
00332 
00333                         //std::cout << "Option Value = " << optionValue << std::endl;
00334 
00335                         try
00336                         {
00337                             //first we process the commands
00338                             if( commandMap.find(optionName) != commandMap.end()  )
00339                             {
00340                                 switch (commandMap[ optionName] )
00341                                 {
00342 
00343                                 case 0: // solve command
00344 
00345                                     if(osoptions->osil == "" && osoptions->mps == "" &&  osoptions->nl == "")
00346                                     {
00347                                         std::cout
00348                                                 << std::endl
00349                                                 << "You did not specify an optimization instance!!!\n"
00350                                                 << "Please enter file format option (osil, nl, or mps) \n"
00351                                                 << "followed by the option value which is the file location. \n"
00352                                                 << std::endl;
00353                                         //std::cout
00354                                         //      << "Please enter the path and optimization instance file name: ";
00355                                         //getline(std::cin, osoptions->osilFile);
00356                                         //osoptions->osil
00357                                         //      = fileUtil->getFileAsString(
00358                                         //                      (osoptions->osilFile).c_str());
00359                                     }
00360                                     else
00361                                     {
00362                                         solve();
00363                                         if (osoptions->osrlFile != "")
00364                                             std::cout <<  "\nSolve command executed. Please see " << osoptions->osrlFile  << " for results." << std::endl;
00365                                     }
00366                                     break;
00367 
00368                                 case 1: // send command
00369 
00370                                     if(osoptions->serviceLocation == "")
00371                                     {
00372                                         std::cout
00373                                                 << std::endl
00374                                                 << "A service location is required"
00375                                                 << std::endl;
00376                                         std::cout
00377                                                 << "Please type the URL of the remote service: ";
00378                                         getline(std::cin, osoptions->serviceLocation);
00379                                     }
00380                                     send();
00381                                     break;
00382 
00383 
00384                                 case 2: // getJobID command
00385 
00386                                     if(osoptions->serviceLocation == "")
00387                                     {
00388                                         std::cout
00389                                                 << std::endl
00390                                                 << "A service location is required"
00391                                                 << std::endl;
00392                                         std::cout
00393                                                 << "Please type the URL of the remote service: ";
00394                                         getline(std::cin, osoptions->serviceLocation);
00395                                     }
00396 
00397                                     getJobID();
00398                                     break;
00399 
00400 
00401                                 case 3: // retrieve command
00402 
00403                                     if(osoptions->serviceLocation == "")
00404                                     {
00405                                         std::cout
00406                                                 << std::endl
00407                                                 << "A service location is required"
00408                                                 << std::endl;
00409                                         std::cout
00410                                                 << "Please type the URL of the remote service: ";
00411                                         getline(std::cin, osoptions->serviceLocation);
00412                                     }
00413                                     if( (osoptions->osolFile == "") && (osoptions->jobID == "") )
00414                                     {
00415                                         std::cout
00416                                                 << std::endl
00417                                                 << "Cannot retrieve: no JobID and no OSoL file"
00418                                                 << std::endl;
00419                                     }
00420                                     else
00421                                     {
00422                                         retrieve();
00423                                     }
00424 
00425                                     break;
00426 
00427                                 case 4: // kill command
00428 
00429 
00430                                     if(osoptions->serviceLocation == "")
00431                                     {
00432                                         std::cout
00433                                                 << std::endl
00434                                                 << "A service location is required"
00435                                                 << std::endl;
00436                                         std::cout
00437                                                 << "Please type the URL of the remote service: ";
00438                                         getline(std::cin, osoptions->serviceLocation);
00439                                     }
00440                                     if( (osoptions->osolFile == "") && (osoptions->jobID == "") )
00441                                     {
00442                                         std::cout
00443                                                 << std::endl
00444                                                 << "Cannot kill: no JobID and no OSoL file"
00445                                                 << std::endl;
00446                                     }
00447                                     else
00448                                     {
00449                                         kill();
00450                                     }
00451 
00452 
00453                                     break;
00454 
00455 
00456                                 case 5: // knock command
00457 
00458                                     //note -- can have empty OSoL for knock
00459                                     //however we do need an OSpL file
00460 
00461                                     if(osoptions->serviceLocation == "")
00462                                     {
00463                                         std::cout
00464                                                 << std::endl
00465                                                 << "A service location is required"
00466                                                 << std::endl;
00467                                         std::cout
00468                                                 << "Please type the URL of the remote service: ";
00469                                         getline(std::cin, osoptions->serviceLocation);
00470                                     }
00471 
00472                                     if( osoptions->osplInputFile == "")
00473                                     {
00474                                         std::cout
00475                                                 << std::endl
00476                                                 << "Cannot knock -- no OSplInputFile specificed"
00477                                                 << std::endl;
00478                                     }
00479                                     else
00480                                     {
00481                                         knock();
00482                                     }
00483 
00484                                     break;
00485 
00486 
00487                                 case 6: // quit command
00488 
00489                                     return 0;
00490 
00491 
00492 
00493                                 case 7: // exit command
00494 
00495                                     return 0;
00496 
00497 
00498 
00499                                 case 8: // reset command
00500 
00501                                     reset_options();
00502                                     std::cout << "\nAll options reset.\n";
00503                                     break;
00504 
00505 
00506 
00507                                 case 9: // list command
00508 
00509                                     listOptions( osoptions);
00510                                     break;
00511 
00512 
00513                                 case 10: // ? command
00514 
00515                                     std::cout << get_options() << std::endl;
00516                                     break;
00517 
00518 
00519                                 case 11: // help command
00520 
00521                                     std::cout << get_options() << std::endl;
00522                                     break;
00523 
00524 
00525                                 default:
00526                                     throw ErrorClass("we don't have a valid  command");
00527 
00528 
00529                                 } //end switch
00530 
00531                             }
00532                             else     // now in the case where we require option values
00533                             {
00534 
00535                                 if (optionValue == "")
00536                                 {
00537 
00538 
00539 
00540                                     if(optionMap.find(optionName) != optionMap.end() )
00541                                     {
00542 
00543 
00544                                         switch (optionMap[ optionName] )
00545                                         {
00546 
00547                                         case 0: //osil
00548                                             std::cout
00549                                                     << "Please enter the name of an osil file: ";
00550                                             break;
00551 
00552 
00553                                         case 1: //osrl
00554                                             std::cout
00555                                                     << "Please enter the name of an osrl file: ";
00556                                             break;
00557 
00558                                         case 2: //osol
00559                                             std::cout
00560                                                     << "Please enter the name of an osol file: ";
00561                                             break;
00562 
00563                                         case 3: //mps
00564                                             std::cout
00565                                                     << "Please enter the name of an mps file: ";
00566                                             break;
00567 
00568                                         case 4: //nl
00569                                             std::cout
00570                                                     << "Please enter the name of an AMPL nl file: ";
00571                                             break;
00572 
00573                                         case 5: //dat
00574                                             std::cout
00575                                                     << "Please enter the name of a dat file: ";
00576                                             break;
00577 
00578                                         case 6: //service location
00579                                             std::cout
00580                                                     << "Please enter the serviceLocation: ";
00581                                             break;
00582 
00583                                         case 7: //solver
00584                                             std::cout
00585                                                     << "Please enter the name of the solver: ";
00586                                             break;
00587 
00588                                         case 8: //osplInput
00589                                             std::cout
00590                                                     << "Please enter the name of an osplInput file: ";
00591                                             break;
00592 
00593                                         case 9: //osplOutput
00594                                             std::cout
00595                                                     << "Please enter the name of an osplOutput file: ";
00596                                             break;
00597 
00598 
00599                                         }// end switch
00600                                         // now get the option value
00601                                         getline(std::cin, optionValue);
00602                                     }// end if on finding an element in the optionMap
00603 
00604                                 } // end if on whether or not option value is null
00605 
00606                                 lineText = optionName + " "
00607                                            + optionValue + " ";
00608                                 osss_scan_string(lineText.c_str(),
00609                                                  scanner);
00610                                 ossslex(scanner);
00611                                 listOptions( osoptions);
00612 
00613                                 if(optionMap.find(optionName) != optionMap.end() )
00614                                 {
00615 
00616 
00617                                     switch (optionMap[ optionName] )
00618                                     {
00619 
00620                                     case 0: //osil
00621 
00622                                         osoptions->osil
00623                                             = fileUtil->getFileAsString(
00624                                                   (osoptions->osilFile).c_str());
00625                                         break;
00626 
00627 
00628                                     case 1: //osrl
00629 
00630                                         break;
00631 
00632                                     case 2: //osol
00633 
00634                                         osoptions->osol
00635                                             = fileUtil->getFileAsString(
00636                                                   (osoptions->osolFile).c_str());
00637                                         break;
00638 
00639                                     case 3: //mps
00640 
00641                                         osoptions->mps
00642                                             = fileUtil->getFileAsString(
00643                                                   (osoptions->mpsFile).c_str());
00644                                         break;
00645 
00646                                     case 4: //nl
00647 
00648                                         osoptions->nl
00649                                             = fileUtil->getFileAsString(
00650                                                   (osoptions->nlFile).c_str());
00651                                         break;
00652 
00653                                     case 5: //dat
00654 
00655                                         osoptions->dat
00656                                             = fileUtil->getFileAsString(
00657                                                   (osoptions->datFile).c_str());
00658                                         break;
00659 
00660                                     case 6: //service location
00661 
00662                                         break;
00663 
00664                                     case 7: //solver
00665 
00666                                         //make solver name lower case 
00667                                         for (k = 0; k
00668                                                 < osoptions->solverName.length(); k++)
00669                                         {
00670                                             osoptions->solverName[k] = tolower(
00671                                                                            osoptions->solverName[k]);
00672                                         }
00673                                         break;
00674 
00675                                     case 8: //osplInput
00676 
00677                                         osoptions->osplInput
00678                                             = fileUtil->getFileAsString(
00679                                                   (osoptions->osplInputFile).c_str());
00680                                         break;
00681 
00682                                     case 9: //osplOutput
00683 
00684                                         break;
00685 
00686 
00687 
00688                                     }// end switch
00689 
00690                                 }// end if on finding an element in the optionMap
00691 
00692                             } // end if on options that require a value
00693 
00694                             std::cout << std::endl;
00695                         }//end try
00696                         catch (const ErrorClass& eclass)
00697                         {
00698                             std::cout << eclass.errormsg << std::endl;
00699                         }
00700                     }
00701                 }
00702             }//end while loop
00703             ossslex_destroy(scanner);
00704             scannerActive = false;
00705             delete osoptions;
00706             osoptions = NULL;
00707             delete fileUtil;
00708             fileUtil = NULL;
00709 
00710             return 0;
00711 
00712         }// end of if (argC < 2)
00713         // make sure we do not exceed max allowed characters in command line
00714         i = 1;
00715         while (i < argC)
00716         {
00717             if (strlen(osss) + strlen(argV[i]) + 1 > MAXCHARS)
00718                 throw ErrorClass("the command line has too many characters");
00719             strcat(osss, argV[i]);
00720             strcat(osss, space);
00721             i++;
00722         }
00723 #ifdef DEBUG_CL_INTERFACE
00724         cout << "Input String = " << osss << endl;
00725 #endif
00726         scannerActive = true;
00727         ossslex_init(&scanner);
00728         //std::cout << "Call Text Extra" << std::endl;
00729         setyyextra(osoptions, scanner);
00730         //std::cout << "Call scan string " << std::endl;
00731         osss_scan_string(osss, scanner);
00732 #ifdef DEBUG_CL_INTERFACE
00733         std::cout << "call ossslex" << std::endl;
00734 #endif
00735         ossslex(scanner);
00736         ossslex_destroy(scanner);
00737         scannerActive = false;
00738 #ifdef DEBUG_CL_INTERFACE
00739         std::cout << "done with call to ossslex" << std::endl;
00740 #endif
00741         // if there is a config file, get those options
00742         if (osoptions->configFile != "")
00743         {
00744             scannerActive = true;
00745             ossslex_init(&scanner);
00746             configFileName = osoptions->configFile;
00747 #ifdef DEBUG_CL_INTERFACE
00748             cout << "configFileName = " << configFileName << endl;
00749 #endif
00750             std::string osolfileOptions = fileUtil->getFileAsString(
00751                                               configFileName.c_str());
00752 #ifdef DEBUG_CL_INTERFACE
00753             std::cout << "Call Text Extra" << std::endl;
00754 #endif
00755             setyyextra(osoptions, scanner);
00756 #ifdef DEBUG_CL_INTERFACE
00757             std::cout << "Done with call Text Extra" << std::endl;
00758 #endif
00759             osss_scan_string(osolfileOptions.c_str(), scanner);
00760             ossslex(scanner);
00761             ossslex_destroy(scanner);
00762             scannerActive = false;
00763             
00764             
00771             scannerActive = true;
00772             ossslex_init(&scanner);
00773             //std::cout << "Call Text Extra" << std::endl;
00774             setyyextra(osoptions, scanner);
00775             //std::cout << "Call scan string " << std::endl;
00776             osss_scan_string(osss, scanner);
00777     #ifdef DEBUG_CL_INTERFACE
00778             std::cout << "call ossslex" << std::endl;
00779     #endif
00780             ossslex(scanner);
00781             ossslex_destroy(scanner);
00782             scannerActive = false;           
00783             
00784             
00786         }
00787     }
00788     catch (const ErrorClass& eclass)
00789     {
00790         //cout << eclass.errormsg <<  endl;
00791         //cout << "try -h or --help for more information" <<  endl;
00792 
00793         //new stuff on April 17, 2010
00794         OSResult *osresult = NULL;
00795         OSrLWriter *osrlwriter = NULL;
00796         osrlwriter = new OSrLWriter();
00797         osresult = new OSResult();
00798         osresult->setGeneralMessage(eclass.errormsg);
00799         osresult->setGeneralStatusType("error");
00800         std::string osrl = osrlwriter->writeOSrL(osresult);
00801         if (osoptions->osrlFile != "")
00802         {
00803             //fileUtil->writeFileFromString(osoptions->osrlFile,  eclass.errormsg);
00804             fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00805             if (osoptions->browser != "")
00806             {
00807                 std::string str = osoptions->browser + "  "
00808                                   + osoptions->osrlFile;
00809                 const char *ch = &str[0];
00810                 std::system(ch);
00811             }
00812         }
00813         else
00814         {
00815             //std::cout <<  eclass.errormsg << std::endl;
00816             std::cout << osrl << std::endl;
00817         }
00818         //catch garbage collection
00819         delete osresult;
00820         osresult = NULL;
00821         delete osrlwriter;
00822         osrlwriter = NULL;
00823         // end new stuff
00824 
00825         if (scannerActive == true)
00826             ossslex_destroy(scanner);
00827         delete fileUtil;
00828         delete osoptions;
00829         return 1;
00830     }
00831     try
00832     {
00833         if (osoptions->invokeHelp == true)
00834         {
00835             std::string helpTxt = get_help();
00836             std::cout << std::endl << std::endl;
00837             std::cout << helpTxt << std::endl;
00838             delete osoptions;
00839             osoptions = NULL;
00840             return 0;
00841         }
00842         if (osoptions->writeVersion == true)
00843         {
00844             std::string writeTxt = get_version();
00845             std::cout << std::endl << std::endl;
00846             std::cout << writeTxt << std::endl;
00847             delete osoptions;
00848             osoptions = NULL;
00849             return 0;
00850         }
00851     }
00852     catch (const ErrorClass& eclass)
00853     {
00854         //cout << eclass.errormsg <<  endl;
00855         //cout << "try -h or --help" <<  endl;
00856 
00857 
00858         //new stuff on April 17, 2010
00859         OSResult *osresult = NULL;
00860         OSrLWriter *osrlwriter = NULL;
00861         osrlwriter = new OSrLWriter();
00862         osresult = new OSResult();
00863         osresult->setGeneralMessage(eclass.errormsg);
00864         osresult->setGeneralStatusType("error");
00865         std::string osrl = osrlwriter->writeOSrL(osresult);
00866         if (osoptions->osrlFile != "")
00867         {
00868             //fileUtil->writeFileFromString(osoptions->osrlFile,  eclass.errormsg);
00869             fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00870             if (osoptions->browser != "")
00871             {
00872                 std::string str = osoptions->browser + "  "
00873                                   + osoptions->osrlFile;
00874                 const char *ch = &str[0];
00875                 std::system(ch);
00876             }
00877         }
00878         else
00879         {
00880             //std::cout <<  eclass.errormsg << std::endl;
00881             std::cout << osrl << std::endl;
00882         }
00883         //catch garbage collection
00884         delete osresult;
00885         osresult = NULL;
00886         delete osrlwriter;
00887         osrlwriter = NULL;
00888         // end new stuff
00889 
00890 
00891         delete osoptions;
00892         osoptions = NULL;
00893         delete inputFileUtil;
00894         inputFileUtil = NULL;
00895         return 1;
00896     }
00897 
00898 #ifdef DEBUG_CL_INTERFACE
00899     cout << "HERE ARE THE OPTION VALUES:" << endl;
00900     if(osoptions->configFile != "") cout << "Config file = " << osoptions->configFile << endl;
00901     if(osoptions->osilFile != "") cout << "OSiL file = " << osoptions->osilFile << endl;
00902     if(osoptions->osolFile != "") cout << "OSoL file = " << osoptions->osolFile << endl;
00903     if(osoptions->osrlFile != "") cout << "OSrL file = " << osoptions->osrlFile << endl;
00904     //if(osoptions->insListFile != "") cout << "Instruction List file = " << osoptions->insListFile << endl;
00905     if(osoptions->osplInputFile != "") cout << "OSpL Input file = " << osoptions->osplInputFile << endl;
00906     if(osoptions->serviceMethod != "") cout << "Service Method = " << osoptions->serviceMethod << endl;
00907     if(osoptions->mpsFile != "") cout << "MPS File Name = " << osoptions->mpsFile << endl;
00908     if(osoptions->nlFile != "") cout << "NL File Name = " << osoptions->nlFile << endl;
00909     if(osoptions->gamsControlFile != "") cout << "gams Control File Name = " << osoptions->gamsControlFile << endl;
00910     if(osoptions->browser != "") cout << "Browser Value = " << osoptions->browser << endl;
00911     if(osoptions->solverName != "") cout << "Selected Solver = " << osoptions->solverName << endl;
00912     if(osoptions->serviceLocation != "") cout << "Service Location = " << osoptions->serviceLocation << endl;
00913 #endif
00914 
00915     //convert to lower case so there is no solver name ambiguity
00916     unsigned int k;
00917     for (k = 0; k < osoptions->solverName.length(); k++)
00918     {
00919         osoptions->solverName[k] = tolower(osoptions->solverName[k]);
00920     }
00921 
00922     // get the data from the files
00923     fileUtil = new FileUtil();
00924     try
00925     {
00926         //if(osoptions->insListFile != "") osoptions->insList = fileUtil->getFileAsChar( (osoptions->insListFile).c_str() );
00927         if (osoptions->osolFile != "")
00928         {
00929 
00930             osoptions->osol = fileUtil->getFileAsString(
00931                                   (osoptions->osolFile).c_str());
00932 
00933         }
00934 
00935         if (osoptions->osilFile != "")
00936         {
00937             //this takes precedence over what is in the OSoL file
00938             osoptions->osil = fileUtil->getFileAsString(
00939                                   (osoptions->osilFile).c_str());
00940         }
00941         /*
00942          else{// we were not given an osil file
00943          // make sure we don't have a service URI in the file or are using mps or nl
00944          // if we have nl or mps assume a local solve
00945          if( (osoptions->osol != "") && (osoptions->nlFile == "") && (osoptions->gamsControlFile == "") && (osoptions->mpsFile == "") && (osoptions->serviceLocation == "")  &&  (getServiceURI( osoptions->osol) == "") )
00946          osoptions->osil = fileUtil->getFileAsString( getInstanceLocation( osoptions->osol).c_str()  );
00947          }
00948          */
00949 
00950         //if(osoptions->osplInputFile != "") osoptions->osplInput = fileUtil->getFileAsChar( (osoptions->osplInputFile).c_str()  );
00951         if (osoptions->osplInputFile != "")
00952             osoptions->osplInput = fileUtil->getFileAsString(
00953                                        (osoptions->osplInputFile).c_str());
00954         //if(osoptions->osplOutputFile != "") osoptions->osplOutput = fileUtil->getFileAsChar( (osoptions->osplOutputFile).c_str() );
00955         if (osoptions->osplOutputFile != "")
00956             osoptions->osplOutput = fileUtil->getFileAsString(
00957                                         (osoptions->osplOutputFile).c_str());
00958     }
00959     catch (const ErrorClass& eclass)
00960     {
00961         //cout << eclass.errormsg <<  endl;
00962         //cout << "could not open file properly" << endl;
00963         //cout << "try -h or --help" <<  endl;
00964 
00965 
00966         //new stuff on April 17, 2010
00967         OSResult *osresult = NULL;
00968         OSrLWriter *osrlwriter = NULL;
00969         osrlwriter = new OSrLWriter();
00970         osresult = new OSResult();
00971         osresult->setGeneralMessage(eclass.errormsg);
00972         osresult->setGeneralStatusType("error");
00973         std::string osrl = osrlwriter->writeOSrL(osresult);
00974         if (osoptions->osrlFile != "")
00975         {
00976             //fileUtil->writeFileFromString(osoptions->osrlFile,  eclass.errormsg);
00977             fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00978             if (osoptions->browser != "")
00979             {
00980                 std::string str = osoptions->browser + "  "
00981                                   + osoptions->osrlFile;
00982                 const char *ch = &str[0];
00983                 std::system(ch);
00984             }
00985         }
00986         else
00987         {
00988             //std::cout <<  eclass.errormsg << std::endl;
00989             std::cout << osrl << std::endl;
00990         }
00991         //catch garbage collection
00992         delete osresult;
00993         osresult = NULL;
00994         delete osrlwriter;
00995         osrlwriter = NULL;
00996         // end new stuff
00997 
00998 
00999         delete osoptions;
01000         osoptions = NULL;
01001         delete fileUtil;
01002         fileUtil = NULL;
01003         return 1;
01004     }
01005     // now call the correct serviceMethod
01006     // solve is the default
01007     if (osoptions->serviceMethod == "")
01008         solve();
01009     if ((osoptions->serviceMethod[0] == 's') && (osoptions->serviceMethod[1]
01010             == 'o'))
01011         solve();
01012     else
01013     {
01014         switch (osoptions->serviceMethod[0])
01015         {
01016         case 'g':
01017             getJobID();
01018             break;
01019         case 'r':
01020             retrieve();
01021             break;
01022         case 's':
01023             send();
01024             break;
01025         case 'k':
01026             if (osoptions->serviceMethod[1] == 'i')
01027                 kill();
01028             else
01029                 knock();
01030             break;
01031         default:
01032 
01033             break;
01034         }
01035     }
01036     delete osoptions;
01037     osoptions = NULL;
01038     delete fileUtil;
01039     fileUtil = NULL;
01040     return 0;
01041 }
01042 
01043 void solve()
01044 {
01045     std::string osrl = "";
01046     OSiLReader *osilreader = NULL;
01047     OSmps2osil *mps2osil = NULL;
01048 #ifdef COIN_HAS_ASL
01049     OSnl2osil *nl2osil = NULL;
01050 #endif
01051 #ifdef COIN_HAS_GAMSUTILS
01052     OSgams2osil *gams2osil = NULL;
01053 #endif
01054     OSSolverAgent* osagent = NULL;
01055     FileUtil *fileUtil = NULL;
01056     fileUtil = new FileUtil();
01057     // now solve either remotely or locally
01058     try
01059     {
01060         if (osoptions->serviceLocation != "")
01061         {
01062             // call a method here to get OSiL if we have an nl or mps file
01063             if (osoptions->osil == "")
01064             {
01065                 //we better have an nl file present or mps file or osol file
01066                 if (osoptions->nlFile != "")
01067                 {
01068                     getOSiLFromNl();
01069                 }
01070                 else
01071                 {
01072                     if (osoptions->mpsFile != "")
01073                     {
01074                         getOSiLFromMps();
01075                     }
01076                     else
01077                     {
01078                         if (osoptions->gamsControlFile != "")
01079                         {
01080 
01081                             getOSiLFromGams();
01082                         }
01083                         else    // send an empty osil string
01084                         {
01085                             osoptions->osil = "";
01086                         }
01087                     }
01088                 }
01089             }
01090             // place a remote call
01091 
01092             osagent = new OSSolverAgent(osoptions->serviceLocation);
01093 
01094             if (osoptions->osol == "")  // we have no osol string
01095             {
01096 
01097                 std::ostringstream outStr;
01098                 outStr
01099                         << "<?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/";
01100                 outStr << OS_SCHEMA_VERSION;
01101                 outStr << "/OSoL.xsd\"></osol>";
01102                 osoptions->osol = outStr.str();
01103             }
01104             osrl = osagent->solve(osoptions->osil, osoptions->osol);
01105             if (osoptions->osrlFile != "")
01106             {
01107                 fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
01108                 //const char *ch1 = "/Applications/Firefox.app/Contents/MacOS/firefox  ";
01109                 if (osoptions->browser != "")
01110                 {
01111                     std::string str = osoptions->browser + "  "
01112                                       + osoptions->osrlFile;
01113                     const char *ch = &str[0];
01114                     std::system(ch);
01115                 }
01116             }
01117             else
01118                 cout << osrl << endl;
01119             delete osagent;
01120             osagent = NULL;
01121 
01122         }
01123         else    // solve locally
01124         {
01125             if (osoptions->osil != "")
01126             {
01127                 osilreader = new OSiLReader();
01128                 
01129                
01130                 //osrl = buildSolver(osoptions->solverName, osoptions->osol,
01131                 //                   osilreader->readOSiL(osoptions->osil));
01132                 
01133                 osrl = runSolver(osoptions->solverName, osoptions->osol,
01134                                    osilreader->readOSiL(osoptions->osil));
01135             }
01136             else
01137             {
01138                 //we better have an nl file present or mps file or osol file
01139                 if (osoptions->nlFile != "")
01140                 {
01141 #ifdef COIN_HAS_ASL
01142                     nl2osil = new OSnl2osil( osoptions->nlFile);
01143                     nl2osil->createOSInstance();
01144                     osrl = runSolver(osoptions->solverName, osoptions->osol, nl2osil->osinstance);
01145 #else
01146                     throw ErrorClass(
01147                         "nl file specified locally but ASL not present");
01148 #endif
01149                 }
01150                 else
01151                 {
01152                     if (osoptions->mpsFile != "")
01153                     {
01154                         mps2osil = new OSmps2osil(osoptions->mpsFile);
01155                         mps2osil->createOSInstance();
01156                         osrl = runSolver(osoptions->solverName,
01157                                            osoptions->osol, mps2osil->osinstance);
01158                     }
01159                     else
01160                     {
01161                         if (osoptions->gamsControlFile != "")
01162                         {
01163 #ifdef COIN_HAS_GAMSUTILS
01164                             gams2osil = new OSgams2osil( osoptions->gamsControlFile);
01165                             gams2osil->createOSInstance();
01166                             osrl = runSolver(osoptions->solverName, osoptions->osol, gams2osil->osinstance);
01167 #else
01168                             throw ErrorClass(
01169                                 "a Gams Control specified locally but GAMSIP not present");
01170 #endif
01171 
01172                         }
01173                         else    // need an osol file with an instanceLocation specified
01174                         {
01175                             //if( osoptions->osol.find( "<instanceLocation") == std::string::npos){
01176                             throw ErrorClass(
01177                                 "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.");
01178                             //}
01179                         }
01180                     }
01181                 }
01182             }
01183             //delete fileUtil;
01184             if (osoptions->osrlFile != "")
01185             {
01186 
01187                 fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
01188 
01189                 //const char *ch1 = "/Applications/Firefox.app/Contents/MacOS/firefox  ";
01190                 if (osoptions->browser != "")
01191                 {
01192                     std::string str = osoptions->browser + "  "
01193                                       + osoptions->osrlFile;
01194                     const char *ch = &str[0];
01195                     std::system(ch);
01196                 }
01197             }
01198             else
01199                 cout << osrl << endl;
01200 
01201         }//end of local solve
01202 
01203 
01204         //garbage collection
01205         if (osilreader != NULL)
01206             delete osilreader;
01207         osilreader = NULL;
01208         if (mps2osil != NULL)
01209             delete mps2osil;
01210         mps2osil = NULL;
01211 #ifdef COIN_HAS_ASL
01212         if(nl2osil != NULL) delete nl2osil;
01213         nl2osil = NULL;
01214 #endif
01215 #ifdef COIN_HAS_GAMSUTILS
01216         if(gams2osil != NULL) delete gams2osil;
01217         gams2osil = NULL;
01218 #endif
01219         delete fileUtil;
01220         fileUtil = NULL;
01221 
01222     }//end try
01223     catch (const ErrorClass& eclass)
01224     {
01225         std::string osrl = "";
01226         OSResult *osresult = NULL;
01227         OSrLWriter *osrlwriter = NULL;
01228         //first check to see if we already have OSrL,
01229         //if so don't create a new osresult object
01230         string::size_type  pos1 = eclass.errormsg.find( "<osrl");
01231         if(pos1 == std::string::npos)
01232         {
01233             osrlwriter = new OSrLWriter();
01234             osresult = new OSResult();
01235             osresult->setGeneralMessage(eclass.errormsg);
01236             osresult->setGeneralStatusType("error");
01237             osrl = osrlwriter->writeOSrL(osresult);
01238         }
01239         else
01240         {
01241             osrl = eclass.errormsg;
01242         }
01243         if (osoptions->osrlFile != "")
01244         {
01245             //fileUtil->writeFileFromString(osoptions->osrlFile,  eclass.errormsg);
01246             fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
01247             if (osoptions->browser != "")
01248             {
01249                 std::string str = osoptions->browser + "  "
01250                                   + osoptions->osrlFile;
01251                 const char *ch = &str[0];
01252                 std::system(ch);
01253             }
01254         }
01255         else
01256         {
01257             //std::cout <<  eclass.errormsg << std::endl;
01258             std::cout << osrl << std::endl;
01259         }
01260         //catch garbage collection
01261         if(osresult != NULL)
01262         {
01263             delete osresult;
01264             osresult = NULL;
01265         }
01266         if(osrlwriter != NULL)
01267         {
01268             delete osrlwriter;
01269             osrlwriter = NULL;
01270         }
01271 
01272         //regular garbage collection
01273         if (osilreader != NULL)
01274             delete osilreader;
01275         osilreader = NULL;
01276         if (mps2osil != NULL)
01277             delete mps2osil;
01278         mps2osil = NULL;
01279 #ifdef COIN_HAS_ASL
01280         if(nl2osil != NULL) delete nl2osil;
01281         nl2osil = NULL;
01282 #endif
01283 #ifdef COIN_HAS_GAMSUTILS
01284         if(gams2osil != NULL) delete gams2osil;
01285         gams2osil = NULL;
01286 #endif
01287         delete fileUtil;
01288         fileUtil = NULL;
01289     }//end local catch
01290 
01291 }//end solve
01292 
01293 void getJobID()
01294 {
01295     OSSolverAgent* osagent = NULL;
01296     try
01297     {
01298         if (osoptions->serviceLocation != "")
01299         {
01300             osagent = new OSSolverAgent(osoptions->serviceLocation);
01301             osoptions->jobID = osagent->getJobID(osoptions->osol);
01302             cout << osoptions->jobID << endl;
01303             delete osagent;
01304             osagent = NULL;
01305         }
01306         else
01307         {
01308             delete osagent;
01309             osagent = NULL;
01310             throw ErrorClass("please specify service location (url)");
01311         }
01312     }
01313     catch (const ErrorClass& eclass)
01314     {
01315         FileUtil *fileUtil = NULL;
01316         fileUtil = new FileUtil();
01317 
01318 
01319         std::string osrl = "";
01320         OSResult *osresult = NULL;
01321         OSrLWriter *osrlwriter = NULL;
01322         //first check to see if we already have OSrL,
01323         //if so don't create a new osresult object
01324         string::size_type  pos1 = eclass.errormsg.find( "<osrl");
01325         if(pos1 == std::string::npos)
01326         {
01327             osrlwriter = new OSrLWriter();
01328             osresult = new OSResult();
01329             osresult->setGeneralMessage(eclass.errormsg);
01330             osresult->setGeneralStatusType("error");
01331             osrl = osrlwriter->writeOSrL(osresult);
01332         }
01333         else
01334         {
01335             osrl = eclass.errormsg;
01336         }
01337 
01338 
01339         //catch garbage collection
01340         if(osresult != NULL)
01341         {
01342             delete osresult;
01343             osresult = NULL;
01344         }
01345         if(osrlwriter != NULL)
01346         {
01347             delete osrlwriter;
01348             osrlwriter = NULL;
01349         }
01350 
01351 
01352         delete fileUtil;
01353         fileUtil = NULL;
01354     }
01355 }//end getJobID
01356 
01357 
01358 void knock()
01359 {
01360     std::string osplOutput = "";
01361     OSSolverAgent* osagent = NULL;
01362     FileUtil *fileUtil = NULL;
01363     fileUtil = new FileUtil();
01364     try
01365     {
01366         if (osoptions->serviceLocation != "")
01367         {
01368             osagent = new OSSolverAgent(osoptions->serviceLocation);
01369 
01370 
01371             if (osoptions->osol == "")
01372             {
01373                 // we need to construct the OSoL
01374                 OSOption *osOption = NULL;
01375                 osOption = new OSOption();
01376                 //set the jobID if there is one
01377                 if(osoptions->jobID == "") osOption->setJobID( osoptions->jobID);
01378                 // now read the osOption object into a string
01379                 OSoLWriter *osolWriter = NULL;
01380                 osolWriter = new OSoLWriter();
01381                 osoptions->osol = osolWriter->writeOSoL( osOption);
01382                 delete osOption;
01383                 osOption = NULL;
01384                 delete osolWriter;
01385                 osolWriter = NULL;
01386             }
01387 
01388 
01389             osplOutput = osagent->knock(osoptions->osplInput, osoptions->osol);
01390             if (osoptions->osplOutputFile != "")
01391                 fileUtil->writeFileFromString(osoptions->osplOutputFile,
01392                                               osplOutput);
01393             else
01394                 cout << osplOutput << endl;
01395             delete osagent;
01396         }
01397         else
01398         {
01399             delete osagent;
01400             throw ErrorClass("please specify service location (url)");
01401         }
01402         delete fileUtil;
01403         fileUtil = NULL;
01404     }
01405     catch (const ErrorClass& eclass)
01406     {
01407         std::string osrl = "";
01408         OSResult *osresult = NULL;
01409         OSrLWriter *osrlwriter = NULL;
01410         //first check to see if we already have OSrL,
01411         //if so don't create a new osresult object
01412         string::size_type  pos1 = eclass.errormsg.find( "<osrl");
01413         if(pos1 == std::string::npos)
01414         {
01415             osrlwriter = new OSrLWriter();
01416             osresult = new OSResult();
01417             osresult->setGeneralMessage(eclass.errormsg);
01418             osresult->setGeneralStatusType("error");
01419             std::string osrl = osrlwriter->writeOSrL(osresult);
01420         }
01421         else
01422         {
01423             osrl = eclass.errormsg;
01424         }
01425 
01426         if(osresult != NULL)
01427         {
01428             delete osresult;
01429             osresult = NULL;
01430         }
01431         if(osrlwriter != NULL)
01432         {
01433             delete osrlwriter;
01434             osrlwriter = NULL;
01435         }
01436 
01437         delete fileUtil;
01438         fileUtil = NULL;
01439     }
01440 }//end knock
01441 
01442 
01443 void send()
01444 {
01445     bool bSend = false;
01446     OSSolverAgent* osagent = NULL;
01447     try
01448     {
01449         // call a method here to get OSiL if we have an nl or mps file
01450         if (osoptions->osil == "")
01451         {
01452             //we better have an nl file present or mps file
01453             if (osoptions->nlFile != "")
01454             {
01455                 getOSiLFromNl();
01456             }
01457             else
01458             {
01459                 if (osoptions->mpsFile != "")
01460                 {
01461                     getOSiLFromMps();
01462                 }
01463                 else    // send an empty osil string
01464                 {
01465                     osoptions->osil = "";
01466                 }
01467             }
01468         }
01469         if (osoptions->serviceLocation != "")
01470         {
01471             osagent = new OSSolverAgent(osoptions->serviceLocation);
01472             // check to see if there is an osol
01473             if (osoptions->osol == "")
01474             {
01475                 // we need to construct the OSoL
01476                 OSOption *osOption = NULL;
01477                 osOption = new OSOption();
01478                 // get a jobId if necessary
01479                 if(osoptions->jobID == "") osoptions->jobID = osagent->getJobID("");
01480                 //set the jobID
01481 
01482                 osOption->setJobID( osoptions->jobID);
01483                 // now read the osOption object into a string
01484                 OSoLWriter *osolWriter = NULL;
01485                 osolWriter = new OSoLWriter();
01486                 osoptions->osol = osolWriter->writeOSoL( osOption);
01487                 delete osOption;
01488                 osOption = NULL;
01489                 delete osolWriter;
01490                 osolWriter = NULL;
01491             }
01492             bSend = osagent->send(osoptions->osil, osoptions->osol);
01493             std::cout << "Result of send: " << bSend << std::endl;
01494             delete osagent;
01495         }
01496         else
01497         {
01498             delete osagent;
01499             throw ErrorClass("please specify service location (url)");
01500         }
01501     }
01502     catch (const ErrorClass& eclass)
01503     {
01504         std::string osrl = "";
01505         FileUtil *fileUtil = NULL;
01506         fileUtil = new FileUtil();
01507         OSResult *osresult = NULL;
01508         OSrLWriter *osrlwriter = NULL;
01509         //first check to see if we already have OSrL,
01510         //if so don't create a new osresult object
01511         string::size_type  pos1 = eclass.errormsg.find( "<osrl");
01512         if(pos1 == std::string::npos)
01513         {
01514             osrlwriter = new OSrLWriter();
01515             osresult = new OSResult();
01516             osresult->setGeneralMessage(eclass.errormsg);
01517             osresult->setGeneralStatusType("error");
01518             osrl = osrlwriter->writeOSrL(osresult);
01519         }
01520         else
01521         {
01522             osrl = eclass.errormsg;
01523         }
01524 
01525 
01526         if (osoptions->osrlFile != "")
01527             fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
01528         else
01529             cout << osrl << endl;
01530 
01531         if(osresult != NULL)
01532         {
01533             delete osresult;
01534             osresult = NULL;
01535         }
01536         if(osrlwriter != NULL)
01537         {
01538             delete osrlwriter;
01539             osrlwriter = NULL;
01540         }
01541         delete fileUtil;
01542         fileUtil = NULL;
01543     }
01544 }//end send
01545 
01546 void retrieve()
01547 {
01548     FileUtil *fileUtil = NULL;
01549     fileUtil = new FileUtil();
01550     std::string osrl = "";
01551     OSSolverAgent* osagent = NULL;
01552     try
01553     {
01554         if (osoptions->serviceLocation != "")
01555         {
01556             osagent = new OSSolverAgent(osoptions->serviceLocation);
01557 
01558 
01559             if (osoptions->osol == "")
01560             {
01561                 // we need to construct the OSoL
01562                 OSOption *osOption = NULL;
01563                 osOption = new OSOption();
01564                 // get a jobId if necessary
01565                 if(osoptions->jobID == "")throw ErrorClass("there is no JobID");
01566                 //set the jobID
01567                 osOption->setJobID( osoptions->jobID);
01568                 // now read the osOption object into a string
01569                 OSoLWriter *osolWriter = NULL;
01570                 osolWriter = new OSoLWriter();
01571                 osoptions->osol = osolWriter->writeOSoL( osOption);
01572                 delete osOption;
01573                 osOption = NULL;
01574                 delete osolWriter;
01575                 osolWriter = NULL;
01576             }
01577 
01578             osrl = osagent->retrieve(osoptions->osol);
01579 
01580             if (osoptions->osrlFile != "")
01581             {
01582                 fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
01583                 if (osoptions->browser != "")
01584                 {
01585                     std::string str = osoptions->browser + "  "
01586                                       + osoptions->osrlFile;
01587                     const char *ch = &str[0];
01588                     std::system(ch);
01589                 }
01590             }
01591             else
01592                 cout << osrl << endl;
01593             delete osagent;
01594             osagent = NULL;
01595         }
01596         else
01597         {
01598             delete osagent;
01599             osagent = NULL;
01600             throw ErrorClass("please specify service location (url)");
01601         }
01602         delete fileUtil;
01603         fileUtil = NULL;
01604     }
01605     catch (const ErrorClass& eclass)
01606     {
01607 
01608         std::string osrl = "";
01609         OSResult *osresult = NULL;
01610         OSrLWriter *osrlwriter = NULL;
01611         //first check to see if we already have OSrL,
01612         //if so don't create a new osresult object
01613         string::size_type  pos1 = eclass.errormsg.find( "<osrl");
01614         if(pos1 == std::string::npos)
01615         {
01616             osrlwriter = new OSrLWriter();
01617             osresult = new OSResult();
01618             osresult->setGeneralMessage(eclass.errormsg);
01619             osresult->setGeneralStatusType("error");
01620             osrl = osrlwriter->writeOSrL(osresult);
01621         }
01622         else
01623         {
01624             osrl = eclass.errormsg;
01625         }
01626 
01627         if(osresult != NULL)
01628         {
01629             delete osresult;
01630             osresult = NULL;
01631         }
01632         if(osrlwriter != NULL)
01633         {
01634             delete osrlwriter;
01635             osrlwriter = NULL;
01636         }
01637 
01638 
01639         delete fileUtil;
01640         fileUtil = NULL;
01641     }
01642 }//end retrieve
01643 
01644 void kill()
01645 {
01646     FileUtil *fileUtil = NULL;
01647     fileUtil = new FileUtil();
01648     std::string osplOutput = "";
01649     OSSolverAgent* osagent = NULL;
01650     try
01651     {
01652         if (osoptions->serviceLocation != "")
01653         {
01654             osagent = new OSSolverAgent(osoptions->serviceLocation);
01655 
01656 
01657             if (osoptions->osol == "")
01658             {
01659                 // we need to construct the OSoL
01660                 OSOption *osOption = NULL;
01661                 osOption = new OSOption();
01662                 // get a jobId if necessary
01663                 if(osoptions->jobID == "")throw ErrorClass("there is no JobID");
01664                 //set the jobID
01665                 osOption->setJobID( osoptions->jobID);
01666                 // now read the osOption object into a string
01667                 OSoLWriter *osolWriter = NULL;
01668                 osolWriter = new OSoLWriter();
01669                 osoptions->osol = osolWriter->writeOSoL( osOption);
01670                 delete osOption;
01671                 osOption = NULL;
01672                 delete osolWriter;
01673                 osolWriter = NULL;
01674             }
01675 
01676             osplOutput = osagent->kill(osoptions->osol);
01677 
01678             if (osoptions->osplOutputFile != "")
01679                 fileUtil->writeFileFromString(osoptions->osplOutputFile,
01680                                               osplOutput);
01681             else
01682                 cout << osplOutput << endl;
01683             delete osagent;
01684             osagent = NULL;
01685         }
01686         else
01687         {
01688             delete osagent;
01689             osagent = NULL;
01690             throw ErrorClass("please specify service location (url)");
01691         }
01692         delete fileUtil;
01693         fileUtil = NULL;
01694     }
01695     catch (const ErrorClass& eclass)
01696     {
01697         std::string osrl = "";
01698         OSResult *osresult = NULL;
01699         OSrLWriter *osrlwriter = NULL;
01700         //first check to see if we already have OSrL,
01701         //if so don't create a new osresult object
01702         string::size_type  pos1 = eclass.errormsg.find( "<osrl");
01703         if(pos1 == std::string::npos)
01704         {
01705             osrlwriter = new OSrLWriter();
01706             osresult = new OSResult();
01707             osresult->setGeneralMessage(eclass.errormsg);
01708             osresult->setGeneralStatusType("error");
01709             osrl = osrlwriter->writeOSrL(osresult);
01710         }
01711         else
01712         {
01713             osrl = eclass.errormsg;
01714         }
01715 
01716 
01717         if(osresult != NULL)
01718         {
01719             delete osresult;
01720             osresult = NULL;
01721         }
01722         if(osrlwriter != NULL)
01723         {
01724             delete osrlwriter;
01725             osrlwriter = NULL;
01726         }
01727 
01728 
01729         delete fileUtil;
01730         fileUtil = NULL;
01731     }
01732 }//end kill
01733 
01734 void getOSiLFromNl()
01735 {
01736     try
01737     {
01738 #ifdef COIN_HAS_ASL
01739         OSnl2osil *nl2osil = NULL;
01740         nl2osil = new OSnl2osil( osoptions->nlFile);
01741         nl2osil->createOSInstance();
01742         OSiLWriter *osilwriter = NULL;
01743         osilwriter = new OSiLWriter();
01744         std::string osil;
01745         osil = osilwriter->writeOSiL( nl2osil->osinstance);
01746         osoptions->osil = osil;
01747         delete nl2osil;
01748         nl2osil = NULL;
01749         delete osilwriter;
01750         osilwriter = NULL;
01751 #else
01752         throw ErrorClass(
01753             "trying to convert nl to osil without AMPL ASL configured");
01754 #endif
01755     }
01756     catch (const ErrorClass& eclass)
01757     {
01758         std::cout << eclass.errormsg << std::endl;
01759         throw ErrorClass(eclass.errormsg);
01760     }
01761 }//getOSiLFromNl
01762 
01763 
01764 void getOSiLFromGams()
01765 {
01766     try
01767     {
01768 #ifdef COIN_HAS_GAMSIO
01769         OSgams2osil *gams2osil = NULL;
01770         gams2osil = new OSgams2osil( osoptions->gamsControlFile);
01771         gams2osil->createOSInstance();
01772         OSiLWriter *osilwriter = NULL;
01773         osilwriter = new OSiLWriter();
01774         std::string osil;
01775         osil = osilwriter->writeOSiL( gams2osil->osinstance);
01776         osoptions->osil = osil;
01777         delete gams2osil;
01778         gams2osil = NULL;
01779         delete osilwriter;
01780         osilwriter = NULL;
01781 #else
01782         throw ErrorClass(
01783             "trying to convert Gams control file to osil without GAMSUTILS configured");
01784 #endif
01785     }
01786     catch (const ErrorClass& eclass)
01787     {
01788         std::cout << eclass.errormsg << std::endl;
01789         throw ErrorClass(eclass.errormsg);
01790     }
01791 }//getOSiLFromGams
01792 
01793 
01794 void getOSiLFromMps()
01795 {
01796     try
01797     {
01798         OSmps2osil *mps2osil = NULL;
01799         mps2osil = new OSmps2osil(osoptions->mpsFile);
01800         mps2osil->createOSInstance();
01801         OSiLWriter *osilwriter = NULL;
01802         osilwriter = new OSiLWriter();
01803         std::string osil;
01804         osil = osilwriter->writeOSiL(mps2osil->osinstance);
01805         osoptions->osil = osil;
01806         delete mps2osil;
01807         mps2osil = NULL;
01808         delete osilwriter;
01809         osilwriter = NULL;
01810     }
01811     catch (const ErrorClass& eclass)
01812     {
01813         std::cout << eclass.errormsg << std::endl;
01814         throw ErrorClass(eclass.errormsg);
01815     }
01816 
01817 }//getOSiLFromMps
01818 
01819 //string getServiceURI( std::string osol){
01820 //      if(osol == "") return osol;
01821 //      string::size_type pos2;
01822 //      string::size_type  pos1 = osol.find( "<serviceURI");
01823 //      if(pos1 != std::string::npos){
01824 //              // get the end of the serviceURI start tag
01825 //              pos1 = osol.find(">", pos1 + 1);
01826 //              if(pos1 != std::string::npos){
01827 //                      // get the start of serviceURI end tag
01828 //                      pos2 = osol.find( "</serviceURI", pos1 + 1);
01829 //                      if( pos2 != std::string::npos){
01830 //                              // get the substring
01831 //                              return osol.substr( pos1 + 1, pos2 - pos1 - 1);
01832 //                      }
01833 //                      else return "";
01834 //              }
01835 //              else return "";
01836 //      }
01837 //      else return "";
01838 //}//getServiceURI
01839 
01840 //string getInstanceLocation( std::string osol){
01841 //      if(osol == "") return osol;
01842 //      string::size_type pos2;
01843 //      string::size_type pos1 = osol.find( "<instanceLocation");
01844 //      if(pos1 != std::string::npos){
01845 //              // get the end of the instanceLocation start tag
01846 //              pos1 = osol.find(">", pos1 + 1);
01847 //              if(pos1 != std::string::npos){
01848 //                      // get the start of instanceLocation end tag
01849 //                      pos2 = osol.find( "</instanceLocation", pos1 + 1);
01850 //                      if( pos2 != std::string::npos){
01851 //                              // get the substring
01852 //                              return osol.substr( pos1 + 1, pos2 - pos1 - 1);
01853 //                      }
01854 //                      else return "";
01855 //              }
01856 //              else return "";
01857 //      }
01858 //      else return "";
01859 //}//getInstanceLocation
01860 
01861 
01862 //std::string getSolverName( std::string osol){
01863 //#ifdef DEBUG_CL_INTERFACE
01864 //      std::cout << "inside getSolverName" << std::endl;
01865 //      std::cout <<  osol << std::endl;
01866 //      std::cout << "done with osol" << std::endl;
01867 //#endif
01868 //      OSOption *osoption = NULL;
01869 //      OSoLReader *osolreader = NULL;
01870 //      osolreader = new OSoLReader();
01871 //
01872 //      osoption = osolreader->readOSoL( osol);
01873 //#ifdef DEBUG_CL_INTERFACE
01874 //      std::cout <<  "invoke getSolverToInvoke" << std::endl;
01875 //#endif
01876 //      std::string optionstring = osoption->getSolverToInvoke();
01877 //#ifdef DEBUG_CL_INTERFACE
01878 //      std::cout <<  "done with invoke getSolverToInvoke" << std::endl;
01879 //#endif
01881 //      delete osolreader;
01882 //      return optionstring;
01883 //      /*
01884 //      if(osol == "") return osol;
01885 //      string::size_type pos2;
01886 //      string::size_type pos1 = osol.find( "solverToInvoke");
01887 //      if(pos1 != std::string::npos){
01888 //              // get the end of the instanceLocation start tag
01889 //              pos1 = osol.find(">", pos1 + 1);
01890 //              if(pos1 != std::string::npos){
01891 //                      // get the start of instanceLocation end tag
01892 //                      pos2 = osol.find( "</solverToInvoke", pos1 + 1);
01893 //                      if( pos2 != std::string::npos){
01894 //                              // get the substring
01895 //                              return osol.substr( pos1 + 1, pos2 - pos1 - 1);
01896 //                      }
01897 //                      else return "";
01898 //              }
01899 //              else return "";
01900 //      }
01901 //      else return "";
01902 //      */
01903 //}//getSolverName
01904 
01905 
01906 //std::string setSolverName( std::string osol, std::string solverName){
01907 //#ifdef DEBUG_CL_INTERFACE
01908 //      std::cout << "inside setSolverName" << std::endl;
01909 //#endif
01910 //      OSOption *osoption = NULL;
01911 //      OSoLReader *osolreader = NULL;
01912 //      osolreader = new OSoLReader();
01913 //      osoption = osolreader->readOSoL( osol);
01915 //      osoption->setSolverToInvoke( solverName);
01918 //      OSoLWriter *osolwriter = NULL;
01919 //      osolwriter = new OSoLWriter();
01920 //      std::string newOSoL = osolwriter->writeOSoL( osoption);
01924 //      delete osolreader;
01925 //      delete osolwriter;
01926 //      return newOSoL;
01927 //}//setSolverName
01928 
01929 std::string get_help()
01930 {
01931 
01932     std::ostringstream helpMsg;
01933 
01934     helpMsg << "************************* HELP *************************"
01935             << endl << endl;
01936     helpMsg
01937             << "In this HELP file we assume that the solve service method is used and "
01938             << endl;
01939     helpMsg
01940             << "that we are solving problems locally, that is the solver is on the "
01941             << endl;
01942     helpMsg
01943             << "machine running this OSSolverService.  See Section 10.3 of the User\'s  "
01944             << endl;
01945     helpMsg
01946             << "Manual for other service methods or calling a server remotely. "
01947             << endl;
01948     helpMsg << "The OSSolverService takes the parameters listed below.  "
01949             << endl;
01950     helpMsg
01951             << "The order of the parameters is irrelevant.  Not all the parameters  "
01952             << endl;
01953     helpMsg << "are required.  However, the location of an instance file is  "
01954             << endl;
01955     helpMsg
01956             << "required when using the solve service method. The location of the "
01957             << endl;
01958     helpMsg << "instance file is specified using the osil option. " << endl;
01959 
01960     helpMsg << endl;
01961 
01962     helpMsg
01963             << "-osil xxx.osil this is the name of the file that contains the  "
01964             << endl;
01965     helpMsg << "optimization instance in OSiL format.  This option may be  "
01966             << endl;
01967     helpMsg << "specified in the OSoL solver options file. " << endl;
01968 
01969     helpMsg << endl;
01970 
01971     helpMsg
01972             << "-osol xxx.osol  this is the name of the file that contains the solver options.   "
01973             << endl;
01974     helpMsg << "It is not necessary to specify this option. " << endl;
01975 
01976     helpMsg << endl;
01977 
01978     helpMsg
01979             << "-osrl xxx.osrl  this is the name of the file to which the solver solution is written.  "
01980             << endl;
01981     helpMsg
01982             << "It is not necessary to specify this option. If this option is not specified,  "
01983             << endl;
01984     helpMsg << "the result will be printed to standard out.  " << endl;
01985 
01986     helpMsg << endl;
01987 
01988     helpMsg
01989             << "-osplInput xxx.ospl  this is the name of an input file in the OS Process"
01990             << endl;
01991     helpMsg << " Language (OSpL), this is used as input  to the knock method."
01992             << endl;
01993 
01994     helpMsg << endl;
01995 
01996     helpMsg
01997             << "-osplOutput xxx.ospl this is the name of an output file in the  OS Process"
01998             << endl;
01999     helpMsg
02000             << "Language (OSpL), this the output string from the knock and kill methods."
02001             << endl;
02002 
02003     helpMsg << endl;
02004 
02005     helpMsg << "-serviceLocation url is the URL of the solver service.  "
02006             << endl;
02007     helpMsg
02008             << "This is not required, and if not specified it is assumed that   "
02009             << endl;
02010     helpMsg << "the problem is solved locally.  " << endl;
02011 
02012     helpMsg << endl;
02013 
02014     helpMsg
02015             << "-serviceMethod  methodName this is the method on the solver service to be invoked.  "
02016             << endl;
02017     helpMsg
02018             << "The options are  solve,  send,  kill,  knock,  getJobID, and retrieve.   "
02019             << endl;
02020     helpMsg
02021             << "This option is not required, and the default value is  solve.  "
02022             << endl;
02023 
02024     helpMsg << endl;
02025 
02026     helpMsg
02027             << "-mps  xxx.mps  this is the name of the mps file if the problem instance  "
02028             << endl;
02029     helpMsg
02030             << "is in mps format. The default file format is OSiL so this option is not required.  "
02031             << endl;
02032 
02033     helpMsg << endl;
02034 
02035     helpMsg
02036             << "-nl  xxx.nl  this is the name of the AMPL nl file if the problem  "
02037             << endl;
02038     helpMsg
02039             << "instance is in AMPL nl  format. The default file format is OSiL  "
02040             << endl;
02041     helpMsg << "so this option is not required.  " << endl;
02042 
02043     helpMsg << endl;
02044 
02045     helpMsg
02046             << "-solver  solverName  Possible values for default OS installation  "
02047             << endl;
02048     helpMsg
02049             << "are  bonmin(COIN-OR Bonmin), couenne (COIN-OR Couenne), clp (COIN-OR Clp),"
02050             << endl;
02051     helpMsg << "cbc (COIN-OR Cbc), dylp (COIN-OR DyLP), ipopt (COIN-OR Ipopt),"
02052             << endl;
02053     helpMsg << "and symphony (COIN-OR SYMPHONY). Other solvers supported"
02054             << endl;
02055     helpMsg
02056             << "(if the necessary libraries are present) are cplex (Cplex through COIN-OR Osi),"
02057             << endl;
02058     helpMsg
02059             << "glpk (glpk through COIN-OR Osi), knitro (Knitro), and lindo (LINDO)."
02060             << endl;
02061     helpMsg << "If no value is specified for this parameter," << endl;
02062     helpMsg << "then cbc is the default value of this parameter." << endl;
02063 
02064     helpMsg << endl;
02065 
02066     helpMsg
02067             << "-browser  browserName this paramater is a path to the browser on the  "
02068             << endl;
02069     helpMsg
02070             << "local machine. If this optional parameter is specified then the  "
02071             << endl;
02072     helpMsg << "solver result in OSrL format is transformed using XSLT into  "
02073             << endl;
02074     helpMsg << "HTML and displayed in the browser.  " << endl;
02075 
02076     helpMsg << endl;
02077 
02078     helpMsg
02079             << "-config pathToConfigureFile this parameter specifies a path on  "
02080             << endl;
02081     helpMsg
02082             << "the local machine to a text file containing values for the input parameters.  "
02083             << endl;
02084     helpMsg
02085             << "This is convenient for the user not wishing to constantly retype parameter values.  "
02086             << endl;
02087     helpMsg
02088             << "This configure file can contain values for all of the other parameters. "
02089             << endl;
02090 
02091     helpMsg << endl;
02092 
02093     helpMsg << "--version or -v get the current version of this executable  "
02094             << endl;
02095 
02096     helpMsg << endl;
02097 
02098     helpMsg << "--help or -h  to get this help file " << endl;
02099 
02100     helpMsg << endl;
02101 
02102     helpMsg
02103             << "Note: If you specify a configure file by using the -config option, you can  "
02104             << endl;
02105     helpMsg
02106             << "override the values of the options in the configure file by putting them in   "
02107             << endl;
02108     helpMsg << "at the command line. " << endl << endl;
02109 
02110     helpMsg
02111             << "See the OS User\' Manual: http://www.coin-or.org/OS/doc/osUsersManual_2.0.pdf"
02112             << endl;
02113     helpMsg << "for more detail on how to use the OS project. " << endl;
02114 
02115     helpMsg << endl;
02116     helpMsg << "********************************************************"
02117             << endl << endl;
02118 
02119     return helpMsg.str();
02120 }// get help
02121 
02122 
02123 std::string get_version()
02124 {
02125 
02126     std::ostringstream versionMsg;
02127     versionMsg << "In order to find the version of this project " << endl;
02128     versionMsg << "connect to the directory where you downloaded " << endl;
02129     versionMsg << "and do: " << endl;
02130     versionMsg << "svn info " << endl;
02131 
02132     return versionMsg.str();
02133 }// get version
02134 
02135 /*
02136 std::string buildSolver(std::string solverName, std::string osol,
02137                         OSInstance *osinstance)
02138 {
02139     DefaultSolver *solverType = NULL;
02140     //std::cout << "SOLVER NAME = " << solverName << std::endl;
02141     try
02142     {
02143         if (solverName == "")  // must determine the default solver
02144         {
02145             if (osinstance == NULL)
02146                 throw ErrorClass(
02147                     "there was a NULL instance sent to buildSolver");
02148             //see if we have an integer program
02149             if (osinstance->getNumberOfIntegerVariables()
02150                     + osinstance->getNumberOfBinaryVariables() > 0)  //we have an integer program
02151             {
02152                 if ((osinstance->getNumberOfNonlinearExpressions() > 0)
02153                         || (osinstance->getNumberOfQuadraticTerms() > 0))   // we are nonlinear and integer
02154                 {
02155                     solverName = "bonmin";
02156                 }
02157                 else    //we are linear integer
02158                 {
02159                     solverName = "cbc";
02160                 }
02161             }
02162             else    // we have a continuous problem
02163             {
02164                 if ((osinstance->getNumberOfNonlinearExpressions() > 0)
02165                         || (osinstance->getNumberOfQuadraticTerms() > 0))   // we are nonlinear and continuous
02166                 {
02167                     solverName = "ipopt";
02168                 }
02169                 else    //we have linear program
02170                 {
02171                     solverName = "clp";
02172                 }
02173             }
02174         }//end of if on solverName
02175 
02176         //now build the solver through its constructor
02177 
02178         //std::cout << "SOLVER NAME =  " << solverName << std::endl;
02179 
02180         if (solverName.find("ipopt") != std::string::npos)
02181         {
02182             // we are requesting the Ipopt solver
02183             bool bIpoptIsPresent = false; 
02184 #ifdef COIN_HAS_IPOPT
02185             bIpoptIsPresent = true;
02186             solverType = new IpoptSolver();
02187 #endif
02188             if (bIpoptIsPresent == false)
02189                 throw ErrorClass("the Ipopt solver requested is not present");
02190         }
02191         else
02192         {
02193             if (solverName.find("lindo") != std::string::npos)
02194             {
02195                 // we are requesting the Lindo solver
02196                 bool bLindoIsPresent = false;
02197 #ifdef COIN_HAS_LINDO
02198                 bLindoIsPresent = true;
02199                 std::cout << "calling the LINDO Solver " << std::endl;
02200                 solverType = new LindoSolver();
02201                 std::cout << "DONE calling the LINDO Solver " << std::endl;
02202 #endif
02203                 if (bLindoIsPresent == false)
02204                     throw ErrorClass(
02205                         "the Lindo solver requested is not present");
02206             }
02207             else
02208             {
02209                 if (solverName.find("clp") != std::string::npos)
02210                 {
02211                     //std::cout << "NEWING SOLVER TYPE " << std::endl;
02212                     solverType = new CoinSolver();
02213                     //std::cout << "END NEWING SOLVER TYPE " << std::endl;
02214                     solverType->sSolverName = "clp";
02215                 }
02216                 else
02217                 {
02218                     if (solverName.find("cplex") != std::string::npos)
02219                     {
02220                         bool bCplexIsPresent = false;
02221 #ifdef COIN_HAS_CPX
02222                         bCplexIsPresent = true;
02223                         solverType = new CoinSolver();
02224                         solverType->sSolverName = "cplex";
02225 #endif
02226                         if (bCplexIsPresent == false)
02227                             throw ErrorClass(
02228                                 "the Cplex solver requested is not present");
02229                     }
02230                     else
02231                     {
02232                         if (solverName.find("glpk") != std::string::npos)
02233                         {
02234                             bool bGlpkIsPresent = false;
02235 #ifdef COIN_HAS_GLPK
02236                             bGlpkIsPresent = true;
02237                             solverType = new CoinSolver();
02238                             solverType->sSolverName = "glpk";
02239 #endif
02240                             if (bGlpkIsPresent == false)
02241                                 throw ErrorClass(
02242                                     "the GLPK solver requested is not present");
02243                         }
02244                         else
02245                         {
02246                             if (solverName.find("dylp") != std::string::npos)
02247                             {
02248                                 bool bDyLPIsPresent = false;
02249 #ifdef COIN_HAS_DYLP
02250                                 bDyLPIsPresent = true;
02251                                 solverType = new CoinSolver();
02252                                 solverType->sSolverName = "dylp";
02253                                 bDyLPIsPresent = true;
02254 #endif
02255                                 if (bDyLPIsPresent == false)
02256                                     throw ErrorClass(
02257                                         "the DyLP solver requested is not present");
02258                             }
02259                             else
02260                             {
02261                                 if (solverName.find("symphony")
02262                                         != std::string::npos)
02263                                 {
02264                                     bool bSymphonyIsPresent = false;
02265 #ifdef COIN_HAS_SYMPHONY
02266                                     bSymphonyIsPresent = true;
02267                                     solverType = new CoinSolver();
02268                                     solverType->sSolverName = "symphony";
02269 #endif
02270                                     if (bSymphonyIsPresent == false)
02271                                         throw ErrorClass(
02272                                             "the SYMPHONY solver requested is not present");
02273                                 }
02274                                 else
02275                                 {
02276                                     if (solverName.find("knitro")
02277                                             != std::string::npos)
02278                                     {
02279                                         bool bKnitroIsPresent = false;
02280 #ifdef COIN_HAS_KNITRO
02281                                         bKnitroIsPresent = true;
02282                                         std::cout << "calling the KNITRO Solver " << std::endl;
02283                                         solverType = new KnitroSolver();
02284                                         std::cout << "DONE calling the KNITRO Solver " << std::endl;
02285 #endif
02286                                         if (bKnitroIsPresent == false)
02287                                             throw ErrorClass(
02288                                                 "the Knitro solver requested is not present");
02289                                     }
02290                                     else
02291                                     {
02292                                         if (solverName.find("vol")
02293                                                 != std::string::npos)
02294                                         {
02295                                             bool bVolIsPresent = false;
02296 #ifdef COIN_HAS_VOL
02297                                             bVolIsPresent = true;
02298                                             solverType = new CoinSolver();
02299                                             solverType->sSolverName = "vol";
02300 #endif
02301                                             if (bVolIsPresent == false)
02302                                                 throw ErrorClass(
02303                                                     "the Vol solver requested is not present");
02304                                         }
02305                                         else
02306                                         {
02307                                             if (solverName.find("bonmin")
02308                                                     != std::string::npos)
02309                                             {
02310                                                 // we are requesting the Bonmin solver
02311                                                 bool bBonminIsPresent = false;
02312 #ifdef COIN_HAS_BONMIN
02313                                                 bBonminIsPresent = true;
02314                                                 solverType = new BonminSolver();
02315 #endif
02316                                                 if (bBonminIsPresent == false)
02317                                                     throw ErrorClass(
02318                                                         "the Bonmin solver requested is not present");
02319                                             }
02320                                             else
02321                                             {
02322                                                 if (solverName.find("couenne")
02323                                                         != std::string::npos)
02324                                                 {
02325                                                     // we are requesting the Couenne solver
02326                                                     bool bCouenneIsPresent =
02327                                                         false;
02328 #ifdef COIN_HAS_COUENNE
02329                                                     bCouenneIsPresent = true;
02330                                                     solverType = new CouenneSolver();
02331 #endif
02332                                                     if (bCouenneIsPresent
02333                                                             == false)
02334                                                         throw ErrorClass(
02335                                                             "the Couenne solver requested is not present");
02336                                                 }
02337                                                 else     //cbc is the default
02338                                                 {
02339                                                     solverType
02340                                                         = new CoinSolver();
02341                                                     solverType->sSolverName
02342                                                         = "cbc";
02343                                                 }
02344                                             }
02345                                         }
02346                                     }
02347                                 }
02348                             }
02349                         }
02350                     }
02351                 }
02352             }
02353         }
02354 
02355         //std::cout << "SET SOLVER INSTANCE " << std::endl;
02356         solverType->osinstance = osinstance;
02357         solverType->osol = osol;
02358         solverType->buildSolverInstance();
02359         solverType->setSolverOptions();
02360         solverType->solve();
02361         std::string resultString = solverType->osrl;
02362         if (solverType != NULL)
02363             delete solverType;
02364         solverType = NULL;
02365         return resultString;
02366 
02367     }
02368     catch (const ErrorClass& eclass)
02369     {
02370         throw eclass;
02371     }
02372 
02373 }//buildSolver
02374 */
02375 
02376 void reset_options()
02377 {
02378     osoptions->configFile = "";
02379     osoptions->osilFile = "";
02380     osoptions->osil = "";
02381     osoptions->osolFile = "";
02382     osoptions->osol = "";
02383     osoptions->osrlFile = "";
02384     osoptions->osrl = "";
02385     //osoptions->insListFile = "";
02386     osoptions->insList = "";
02387     osoptions->serviceLocation = "";
02388     osoptions->serviceMethod = "";
02389     osoptions->osplInputFile = "";
02390     osoptions->osplOutputFile = "";
02391     osoptions->osplInput = "";
02392     osoptions->osplOutput = "";
02393     osoptions->mpsFile = "";
02394     osoptions->mps = "";
02395     osoptions->nlFile = "";
02396     osoptions->nl = "";
02397     osoptions->gamsControlFile = "";
02398     osoptions->solverName = "";
02399     osoptions->browser = "";
02400     osoptions->jobID = "";
02401     osoptions->invokeHelp = false;
02402     osoptions->writeVersion = false;
02403     osoptions->quit = false;
02404     osoptions->exit = false;
02405 
02406 }//reset_options
02407 
02408 
02409 
02410 std::string get_options()
02411 {
02412 
02413     std::ostringstream optionMsg;
02414 
02415 
02416     optionMsg << endl;
02417 
02418     optionMsg
02419             << "***************** VALID COMMANDS AND OPTIONS ********************"
02420             << endl ;
02421     optionMsg
02422             << "COMMANDS:"
02423             << endl;
02424     optionMsg
02425             << "quit/exit -- terminate the executable"
02426             << endl;
02427     optionMsg
02428             << "help/? -- produce this list of options"
02429             << endl;
02430     optionMsg
02431             << "reset -- erase all previous option settings"
02432             << endl     ;
02433     optionMsg
02434             << "list -- list the current option values"
02435             << endl     ;
02436     optionMsg
02437             << "solve -- call the solver synchronously"
02438             << endl ;
02439     optionMsg
02440             << "send -- call the solver asynchronously"
02441             << endl ;
02442     optionMsg
02443             << "kill -- end a job on the remote server"
02444             << endl ;
02445     optionMsg
02446             << "retrieve -- get job result on the remote server"
02447             << endl ;
02448     optionMsg
02449             << "knock -- get job information on the remote server"
02450             << endl ;
02451     optionMsg
02452             << "getJobID -- get a job ID from the remote server"
02453             << endl << endl;
02454 
02455 
02456     optionMsg
02457             << "OPTIONS (THESE REQUIRE A VALUE):"
02458             << endl;
02459     optionMsg
02460             << "osil -- the location of the model instance in OSiL format"
02461             << endl;
02462     optionMsg
02463             << "mps  -- the location of the model instance in MPS format"
02464             << endl     ;
02465     optionMsg
02466             << "nl -- the location of the model instance in AMPL nl format"
02467             << endl;
02468 
02469     optionMsg
02470             << "osol -- the location of the solver option file in OSoL format"
02471             << endl;
02472     optionMsg
02473             << "osrl -- the location of the solver result file in OSrL format"
02474             << endl;
02475     optionMsg
02476             << "osplInput -- the name of an input file in OSpL format"
02477             << endl;
02478     optionMsg
02479             << "osplOutput --  the name of an output file in the OSpL format"
02480             << endl     ;
02481 
02482     optionMsg
02483             << "serviceLocation -- the  URL of a remote solver service"
02484             << endl;
02485 
02486 
02487     optionMsg
02488             << "solver -- specify the solver to invoke"
02489             << endl <<endl;
02490 
02491 
02492     optionMsg
02493             << "See  http://www.coin-or.org/OS/"
02494             << endl;
02495     optionMsg
02496             << "for more detail on how to use the OS project."
02497             << endl;
02498     optionMsg
02499             << "*****************************************************************"
02500             << endl << endl;
02501     optionMsg
02502             << "At the prompt enter a valid command or option value pair."
02503             << endl;
02504     optionMsg
02505             << "Enter the \"solve\" command to optimize."
02506             << endl;
02507     optionMsg
02508             << "Type \"quit/exit\" to leave the application."
02509             << endl;
02510     optionMsg
02511             << "Type \"help\" or \"?\" for a list of valid options."
02512             << endl;
02513 
02514 
02515     return optionMsg.str();
02516 }// get_options
02517 
02518 
02519 void listOptions(osOptionsStruc *osoptions)
02520 {
02521     cout
02522             << "HERE ARE THE OPTION VALUES SO FAR:"
02523             << endl;
02524     if (osoptions->configFile != "")
02525         cout << "Config file = "
02526              << osoptions->configFile
02527              << endl;
02528     if (osoptions->osilFile != "")
02529         cout << "OSiL file = "
02530              << osoptions->osilFile
02531              << endl;
02532     if (osoptions->osolFile != "")
02533         cout << "OSoL file = "
02534              << osoptions->osolFile
02535              << endl;
02536     if (osoptions->osrlFile != "")
02537         cout << "OSrL file = "
02538              << osoptions->osrlFile
02539              << endl;
02540 //if(osoptions->insListFile != "") cout << "Instruction List file = " << osoptions->insListFile << endl;
02541     if (osoptions->osplInputFile != "")
02542         cout << "OSpL Input file = "
02543              << osoptions->osplInputFile
02544              << endl;
02545     if (osoptions->serviceMethod != "")
02546         cout << "Service Method = "
02547              << osoptions->serviceMethod
02548              << endl;
02549     if (osoptions->mpsFile != "")
02550         cout << "MPS File Name = "
02551              << osoptions->mpsFile
02552              << endl;
02553     if (osoptions->nlFile != "")
02554         cout << "NL File Name = "
02555              << osoptions->nlFile
02556              << endl;
02557     if (osoptions->solverName != "")
02558         cout << "Selected Solver = "
02559              << osoptions->solverName
02560              << endl;
02561     if (osoptions->serviceLocation != "")
02562         cout << "Service Location = "
02563              << osoptions->serviceLocation
02564              << endl;
02565 
02566     if (osoptions->jobID != "")
02567         cout << "Job ID = "
02568              << osoptions->jobID
02569              << endl;
02570 }// listOptions
02571 

Generated on Thu Sep 22 03:06:04 2011 by  doxygen 1.4.7