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

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

Generated on Fri Nov 19 13:31:09 2010 by  doxygen 1.4.7