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

Go to the documentation of this file.
00001 
00071 #include "OSResult.h" 
00072 #include "OSiLReader.h"        
00073 #include "OSiLWriter.h" 
00074 #include "OSrLReader.h"        
00075 #include "OSrLWriter.h"      
00076 #include "OSInstance.h"  
00077 #include "FileUtil.h"  
00078 #include "OSConfig.h"  
00079 #include "CoinSolver.h"
00080 #include "DefaultSolver.h"  
00081 #include "WSUtil.h" 
00082 #include "OSSolverAgent.h"   
00083 #include "OShL.h"     
00084 #include "ErrorClass.h"
00085 #include "OSmps2osil.h"   
00086 #include "Base64.h"
00087 #include "CommonUtil.h"
00088 
00089 #ifdef COIN_HAS_KNITRO    
00090 #include "KnitroSolver.h"
00091 #endif
00092 
00093 #ifdef COIN_HAS_ASL
00094 #include "OSnl2osil.h"
00095 #endif
00096 
00097 
00098 #ifdef COIN_HAS_LINDO    
00099 #include "LindoSolver.h"
00100 #endif 
00101  
00102 #ifdef COIN_HAS_IPOPT    
00103 #include "IpoptSolver.h"
00104 #endif 
00105 
00106 #ifdef COIN_HAS_KNITRO    
00107 #include "KnitroSolver.h"
00108 #endif 
00109 
00110 
00111 
00112 
00113 
00114 #include "osOptionsStruc.h"  
00115 
00116 
00117 using std::cout;
00118 using std::endl;
00119 using std::ostringstream;
00120 using std::string;
00121 
00122     
00123 
00124 #define MAXCHARS 5000 
00125 
00126 typedef struct yy_buffer_state *YY_BUFFER_STATE;
00127 YY_BUFFER_STATE osss_scan_string(const char* osss, void* scanner ); 
00128 //void osssset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
00129 void setyyextra(osOptionsStruc *osoptions, void* scanner);
00130 int ossslex(void* scanner );
00131 int ossslex_init(void** ptr);
00132  
00133 // the serviceMethods  
00134 void solve();  
00135 void getJobID(); 
00136 void send();
00137 void kill();
00138 void retrieve(); 
00139 void knock();
00140 
00141 // additional methods
00142 void getOSiLFromNl(); 
00143 void getOSiLFromMps();
00144 string getServiceURI( std::string osol);
00145 string getInstanceLocation( std::string osol);
00146 string getSolverName( std::string osol);
00147 
00148 //options structure
00149 // this is the only global variable but 
00150 // this is not a problem since this is a main routine
00151 osOptionsStruc *osoptions; 
00152 
00153 
00154 int main(int argC, const char* argV[])
00155 {  
00156 
00157 #ifdef COIN_HAS_ASL
00158 ASL_alloc(ASL_read_fg);
00159 #endif  
00160         void* scanner;
00161         FileUtil *fileUtil = NULL;
00162         char osss[MAXCHARS] = " ";
00163         const char *space = " "; 
00164         //char *config = "-config";
00165         std::string configFileName = "";
00166         int i;
00167 
00168         // initialize the OS options structure
00169 
00170         osoptions = new osOptionsStruc();
00171         osoptions->configFile = ""; 
00172         osoptions->osilFile = ""; 
00173         osoptions->osil = ""; 
00174         osoptions->osolFile = ""; 
00175         osoptions->osol = "";  
00176         osoptions->osrlFile = ""; 
00177         osoptions->osrl = ""; 
00178         osoptions->insListFile = ""; 
00179         osoptions->insList = ""; 
00180         osoptions->serviceLocation = ""; 
00181         osoptions->serviceMethod = ""; 
00182         osoptions->osplInputFile = ""; 
00183         osoptions->osplOutputFile = ""; 
00184         osoptions->mpsFile = ""; 
00185         osoptions->nlFile = ""; 
00186         osoptions->solverName = ""; 
00187         osoptions->browser = ""; 
00188         try{
00189                 if(argC < 2) throw ErrorClass( "there must be at least one command line argument");
00190                 // see if the first argument is a file name
00191                 i = 1;
00192                 while(i < argC) {
00193                         if(strlen(osss) + strlen(argV[ i]) + 1 > MAXCHARS) throw ErrorClass( "the command line has too many arguments");
00194                         strcat(osss, argV[ i]);
00195                         strcat(osss, space);
00196                         i++;
00197                 }
00198                 cout << "Input String = "  << osss << endl;
00199                 ossslex_init( &scanner);
00200                 std::cout << "Call Text Extra" << std::endl;
00201                 setyyextra( osoptions, scanner);
00202                 std::cout << "Call scan string " << std::endl;
00203                 osss_scan_string( osss, scanner); 
00204                 std::cout << "call ossslex" << std::endl;
00205                 ossslex( scanner);
00206                 std::cout << "done with call to ossslex" << std::endl;
00207                 // if there is a config file, get those options
00208                 if(osoptions->configFile != ""){
00209                         configFileName = osoptions->configFile;
00210                         cout << "configFileName = " << configFileName << endl;
00211                         std::string osolfileOptions = fileUtil->getFileAsString( &configFileName[ 0]);
00212                         ossslex_init( &scanner);
00213                         std::cout << "Call Text Extra" << std::endl;
00214                         setyyextra( osoptions, scanner);
00215                         std::cout << "Done with call Text Extra" << std::endl;
00216                         osss_scan_string( &osolfileOptions[0], scanner);
00217                         ossslex(scanner );              
00218                 }
00219         }
00220                 catch(const ErrorClass& eclass){
00221                 cout << eclass.errormsg <<  endl;
00222                 return 0;
00223         } 
00224                 cout << "HERE ARE THE OPTION VALUES:" << endl;
00225                 if(osoptions->configFile != "") cout << "Config file = " << osoptions->configFile << endl;
00226                 if(osoptions->osilFile != "") cout << "OSiL file = " << osoptions->osilFile << endl;
00227                 if(osoptions->osolFile != "") cout << "OSoL file = " << osoptions->osolFile << endl;
00228                 if(osoptions->osrlFile != "") cout << "OSrL file = " << osoptions->osrlFile << endl;
00229                 if(osoptions->insListFile != "") cout << "Instruction List file = " << osoptions->insListFile << endl;
00230                 if(osoptions->osplInputFile != "") cout << "OSpL Input file = " << osoptions->osplInputFile << endl;
00231                 if(osoptions->serviceMethod != "") cout << "Service Method = " << osoptions->serviceMethod << endl;
00232                 if(osoptions->mpsFile != "") cout << "MPS File Name = " << osoptions->mpsFile << endl;
00233                 if(osoptions->nlFile != "") cout << "NL File Name = " << osoptions->nlFile << endl;
00234                 if(osoptions->browser != "") cout << "Browser Value = " << osoptions->browser << endl;
00235                 // get the data from the files
00236                 fileUtil = new FileUtil();
00237                 try{    
00238                         if(osoptions->insListFile != "") osoptions->insList = fileUtil->getFileAsChar( &osoptions->insListFile[0]);
00239                         if(osoptions->osolFile != "") osoptions->osol = fileUtil->getFileAsChar( &osoptions->osolFile[0]);
00240                         if(osoptions->serviceLocation != ""){
00241                                  cout << "Service Location = " << osoptions->serviceLocation << endl;
00242                         }
00243                         else{
00244                                 //if( getServiceURI( osoptions->osol) != ""){
00245                                 //      osoptions->serviceLocation = &getServiceURI( osoptions->osol)[0];
00246                                 //      cout << "Service Location = " << osoptions->serviceLocation << endl;
00247                                 //}
00248                         }
00249                         if(osoptions->osilFile != ""){
00250                                 //this takes precedence over what is in the OSoL file
00251                                  osoptions->osil = fileUtil->getFileAsString( &osoptions->osilFile[0]);
00252                         }
00253                         else{//get <instanceLocation if we are doing a local solve
00254                                 // make sure we don't have a service URI in the file
00255                                         if( (osoptions->osol != "") &&  (osoptions->serviceLocation == "")  &&  (getServiceURI( osoptions->osol) == "") ) 
00256                                                 osoptions->osil = fileUtil->getFileAsString( &getInstanceLocation( osoptions->osol)[ 0] );
00257                         }
00258                         // see if there is a solver specified
00259                         if(osoptions->solverName != ""){ 
00260                                 cout << "Solver Name = " << osoptions->solverName << endl;
00261                         }
00262                         else{
00263                                 if(osoptions->osol != ""){
00264                                 osoptions->solverName  =    &getSolverName( &osoptions->osolFile[0] )[0];
00265                                 }
00266                         }
00267                         if(osoptions->osplInputFile != "") osoptions->osplInput = fileUtil->getFileAsChar( &osoptions->osplInputFile[0]);
00268                         if(osoptions->osplOutputFile != "") osoptions->osplOutput = fileUtil->getFileAsChar( &osoptions->osplOutputFile[0]);
00269                 }
00270                 catch(const ErrorClass& eclass){
00271                         //cout << eclass.errormsg <<  endl;
00272                         cout << "could not open file properly" << endl;
00273                         return 0;
00274                 }       
00275                 // now call the correct serviceMethod
00276                 // solve is the default
00277                 if( osoptions->serviceMethod == "") solve();
00278                 else{
00279                         switch(osoptions->serviceMethod[ 0]){
00280                                 case 'g': 
00281                                         getJobID();
00282                                         break;
00283                                 case 'r':
00284                                         retrieve();
00285                                         break;
00286                                 case 's':
00287                                         if( osoptions->serviceMethod[ 1] == 'e') send();
00288                                         else solve();
00289                                         break;
00290                                 case 'k':
00291                                         if(osoptions->serviceMethod[ 1] == 'i') kill();
00292                                         else knock();
00293                                         break;
00294                                 default:
00295                                         break;
00296                         }
00297                 }
00298         return 0;
00299 }
00300 
00301 void solve(){
00302         std::string osrl = "";
00303         OSSolverAgent* osagent = NULL;
00304         DefaultSolver *solverType  = NULL;
00305         FileUtil *fileUtil = NULL;
00306         fileUtil = new FileUtil();
00307         try{
00308                 // call a method here to get OSiL if we have an nl or mps file
00309                 if(osoptions->osil == ""){
00310                         //we better have an nl file present or mps file or osol file
00311                         if(osoptions->nlFile != ""){
00312                                 getOSiLFromNl();
00313                         }
00314                         else{
00315                                 if(osoptions->mpsFile != ""){
00316                                         getOSiLFromMps();
00317                                 }
00318                                 else{// need an osol file with an instanceLocation specified
00319                                         if( osoptions->osol.find( "<instanceLocation") == std::string::npos){
00320                                                 throw ErrorClass("solve called and no osil, osol with osil specified, nl, or mps file given");
00321                                         }
00322                                 }
00323                         }
00324                 }
00325                 // now solve either remotely or locally
00326                 if( osoptions->serviceLocation != "" ){
00327                         // place a remote call
00328                         osagent = new OSSolverAgent( osoptions->serviceLocation );
00329                         if(osoptions->solverName != ""){
00330                                 string::size_type iStringpos;
00331                                 //see if there is an osol file
00332                                 if(osoptions->osol != ""){// we have an osol string
00333                                         // see if a solver is listed, if so don't do anything
00334                                         iStringpos = osoptions->osol.find("os_solver");
00335                                         if(iStringpos == std::string::npos) { //don't have a solver specify, we must do so
00336                                                 iStringpos = osoptions->osol.find("</osol");
00337                                                         osoptions->osol.insert(iStringpos, "<other name=\"os_solver\">"
00338                                                         + osoptions->solverName  + "</other>");
00339                                         }
00340                                 }
00341                                 else{// no osol string
00342                                         osoptions->osol = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <osol xmlns=\"os.optimizationservices.org\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"os.optimizationservices.org http://www.optimizationservices.org/schemas/OSoL.xsd\"><other> </other></osol>";       
00343                                         iStringpos = osoptions->osol.find("</osol");
00344                                         osoptions->osol.insert(iStringpos, "<other name=\"os_solver\">"
00345                                                         + osoptions->solverName  + "</other>");
00346                                 }
00347                         }
00348                         std::cout  << std::endl;
00349                         if(osoptions->osol.length() > 0){
00350                                 std::cout << "HERE IS THE OSoL FILE" << std::endl;
00351                                 std::cout << osoptions->osol << std::endl << std::endl;
00352                         }
00353                         osrl = osagent->solve(osoptions->osil  , osoptions->osol);
00354                         if(osoptions->osrlFile != ""){
00355                                 fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00356                                 //const char *ch1 = "/Applications/Firefox.app/Contents/MacOS/firefox  ";
00357                                 if(osoptions->browser != ""){
00358                                         std::string str = osoptions->browser + "  " +  osoptions->osrlFile;
00359                                         const char *ch = &str[ 0];
00360                                         std::system( ch );
00361                                 }
00362                         }
00363                         else cout << osrl << endl;
00364                         delete osagent;
00365                         osagent = NULL;
00366                 }
00367                 else{
00368                         // solve locally
00369                         if(osoptions->solverName == "" ){
00370                                 string sSolverName = "cbc";
00371                                 osoptions->solverName = &sSolverName[0];
00372                         }
00373                         if( osoptions->solverName.find( "ipopt") != std::string::npos) {
00374                                 // we are requesting the Ipopt solver
00375                                 bool bIpoptIsPresent = false;
00376                                 #ifdef COIN_HAS_IPOPT
00377                                 bIpoptIsPresent = true;
00378                                 SmartPtr<IpoptSolver> ipoptSolver  = new IpoptSolver(); 
00379                                 ipoptSolver->osol = osoptions->osol;
00380                                 ipoptSolver->osil = osoptions->osil;
00381                                 ipoptSolver->osinstance = NULL;
00382                                 ipoptSolver->solve();
00383                                 osrl = ipoptSolver->osrl ;
00384                                 #endif
00385                                 if(bIpoptIsPresent == false) throw ErrorClass( "the Ipopt solver requested is not present");
00386                         }
00387                         else{
00388                                 if( osoptions->solverName.find( "lindo") != std::string::npos) {
00389                                         // we are requesting the Lindo solver
00390                                         bool bLindoIsPresent = false;
00391                                         #ifdef COIN_HAS_LINDO
00392                                         bLindoIsPresent = true;
00393                                         std::cout << "calling the LINDO Solver " << std::endl;
00394                                         solverType = new LindoSolver();
00395                                         std::cout << "DONE calling the LINDO Solver " << std::endl;
00396                                         #endif
00397                                         if(bLindoIsPresent == false) throw ErrorClass( "the Lindo solver requested is not present");
00398                                 }
00399                                 else{ 
00400                                         if( osoptions->solverName.find( "clp") != std::string::npos){
00401                                                 solverType = new CoinSolver();
00402                                                 solverType->sSolverName = "clp";
00403                                         }
00404                                         else{
00405                                                 if( osoptions->solverName.find( "cplex") != std::string::npos){
00406                                                         solverType = new CoinSolver();
00407                                                         solverType->sSolverName = "cplex";
00408                                                 }
00409                                                 else{
00410                                                         if( osoptions->solverName.find( "glpk") != std::string::npos){
00411                                                                 solverType = new CoinSolver();
00412                                                                 solverType->sSolverName = "glpk";
00413                                                         }
00414                                                         else{
00415                                                                 if( osoptions->solverName.find( "dylp") != std::string::npos){
00416                                                                         solverType = new CoinSolver();
00417                                                                         solverType->sSolverName = "dylp";
00418                                                                 }
00419                                                                 else{
00420                                                                         if( osoptions->solverName.find( "symphony") != std::string::npos){
00421                                                                                 solverType = new CoinSolver();
00422                                                                                 solverType->sSolverName = "symphony";
00423                                                                         }
00424                                                                         else{
00425                                                                                 if( osoptions->solverName.find( "knitro") != std::string::npos){
00426                                                                                         bool bKnitroIsPresent = false;
00427                                                                                         #ifdef COIN_HAS_KNITRO
00428                                                                                         bKnitroIsPresent = true;
00429                                                                                         std::cout << "calling the KNITRO Solver " << std::endl;
00430                                                                                         solverType = new KnitroSolver();
00431                                                                                         std::cout << "DONE calling the KNITRO Solver " << std::endl;
00432                                                                                         #endif
00433                                                                                         if(bKnitroIsPresent == false) throw ErrorClass( "the Knitro solver requested is not present");          
00434                                                                                 }
00435                                                                                 else{ 
00436                                                                                         if( osoptions->solverName.find( "vol") != std::string::npos){
00437                                                                                                 solverType = new CoinSolver();
00438                                                                                                 solverType->sSolverName = "vol";
00439                                                                                         }
00440                                                                                         else{ //cbc is the default
00441                                                                                                 solverType = new CoinSolver();
00442                                                                                                 solverType->sSolverName = "cbc";
00443                                                                                         }
00444                                                                                 }                                                                       
00445                                                                         }
00446                                                                 }
00447                                                         }
00448                                                 }
00449                                         }
00450                                 }
00451                         }
00452                         // treat non-ipopt solvers differently
00453                         if( osoptions->solverName.find( "ipopt") == std::string::npos){
00454                                 solverType->osil = osoptions->osil;
00455                                 solverType->osol = osoptions->osol;
00456                                 solverType->osinstance = NULL;
00457                                 solverType->solve();
00458                                 osrl = solverType->osrl;
00459                                 delete solverType;
00460                                 solverType = NULL;
00461                         }
00462                         if(osoptions->osrlFile != ""){
00463                                 fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00464                                 //const char *ch1 = "/Applications/Firefox.app/Contents/MacOS/firefox  ";
00465                                 if(osoptions->browser != ""){
00466                                         std::string str = osoptions->browser + "  " +  osoptions->osrlFile;
00467                                         const char *ch = &str[ 0];
00468                                         std::system( ch );
00469                                 }
00470                         }
00471                         else cout << osrl << endl;
00472                 }
00473         }//end try
00474         catch(const ErrorClass& eclass){
00475                 if(osoptions->osrlFile != ""){
00476                         fileUtil->writeFileFromString(osoptions->osrlFile, eclass.errormsg);
00477                         if(osoptions->browser != ""){
00478                                 std::string str = osoptions->browser + "  " +  osoptions->osrlFile;
00479                                 const char *ch = &str[ 0];
00480                                 std::system( ch );
00481                         }
00482                 }
00483                 else{
00484                         OSResult *osresult = NULL;
00485                         OSrLWriter *osrlwriter = NULL;
00486                         osrlwriter = new OSrLWriter();
00487                         osresult = new OSResult();
00488                         osresult->setGeneralMessage( eclass.errormsg);
00489                         osresult->setGeneralStatusType( "error");
00490                         std::string osrl = osrlwriter->writeOSrL( osresult);
00491                         std::cout << osrl << std::endl;
00492                 }
00493         }       
00494 }//end solve
00495 
00496 void getJobID(){
00497         std::string jobID = "";
00498         OSSolverAgent* osagent = NULL;
00499         FileUtil *fileUtil = NULL;
00500         fileUtil = new FileUtil();
00501         try{
00502                 if(osoptions->serviceLocation != ""){
00503                         osagent = new OSSolverAgent( osoptions->serviceLocation );
00504                         jobID = osagent->getJobID( osoptions->osol);
00505                         cout << jobID << endl;
00506                 }
00507                 else{
00508                         throw ErrorClass("please specify service location (url)");
00509                 }
00510         }
00511         catch(const ErrorClass& eclass){
00512                 OSResult *osresult = NULL;
00513                 OSrLWriter *osrlwriter = NULL;
00514                 osrlwriter = new OSrLWriter();
00515                 osresult = new OSResult();
00516                 osresult->setGeneralMessage( eclass.errormsg);
00517                 osresult->setGeneralStatusType( "error");
00518                 std::string osrl = osrlwriter->writeOSrL( osresult);
00519                 if(osoptions->osrlFile != "") fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00520                 else cout << osrl << endl;
00521                 delete osresult;
00522                 osresult = NULL;
00523                 delete osrlwriter;
00524                 osrlwriter = NULL;
00525         }       
00526 }//end getJobID
00527  
00528 
00529 void knock(){
00530         std::string osplOutput = "";
00531         OSSolverAgent* osagent = NULL;
00532         FileUtil *fileUtil = NULL;
00533         fileUtil = new FileUtil();
00534         try{
00535                 if(osoptions->serviceLocation != ""){
00536                         osagent = new OSSolverAgent( osoptions->serviceLocation );
00537                         osplOutput = osagent->knock(osoptions->osplInput,  osoptions->osol);
00538                         if(osoptions->osplOutputFile != "") fileUtil->writeFileFromString(osoptions->osplOutputFile, osplOutput);
00539                         else cout << osplOutput << endl;
00540                 }
00541                 else{
00542                         throw ErrorClass( "please specify service location (url)" );
00543                 }
00544         }
00545         catch(const ErrorClass& eclass){
00546                 OSResult *osresult = NULL;
00547                 OSrLWriter *osrlwriter = NULL;
00548                 osrlwriter = new OSrLWriter();
00549                 osresult = new OSResult();
00550                 osresult->setGeneralMessage( eclass.errormsg);
00551                 osresult->setGeneralStatusType( "error");
00552                 std::string osrl = osrlwriter->writeOSrL( osresult);
00553                 if(osoptions->osrlFile != "") fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00554                 else cout << osrl << endl;
00555                 delete osresult;
00556                 osresult = NULL;
00557                 delete osrlwriter;
00558                 osrlwriter = NULL;
00559         }       
00560 }//end knock
00561 
00562 
00563 void send(){
00564         bool bSend = false;
00565         std::string jobID = "";
00566         OSSolverAgent* osagent = NULL;
00567         FileUtil *fileUtil = NULL;
00568         fileUtil = new FileUtil();
00569         // first get the jobID
00570         std::string sOSoL = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <osol xmlns=\"os.optimizationservices.org\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"os.optimizationservices.org http://www.optimizationservices.org/schemas/OSoL.xsd\"><general> </general></osol>";
00571         string::size_type iStringpos;
00572         try{
00573                 // call a method here to get OSiL if we have an nl or mps file
00574                 if(osoptions->osil == ""){
00575                         //we better have an osil file present or mps file
00576                         if(osoptions->nlFile != ""){
00577                                 getOSiLFromNl();
00578                         }
00579                         else{
00580                                 if(osoptions->mpsFile != ""){
00581                                         getOSiLFromMps();
00582                                 }
00583                                 else{
00584                                         throw ErrorClass("solve called and no osil, nl, or mps file given");
00585                                 }
00586                         }
00587                 }
00588                 if(osoptions->serviceLocation != ""){
00589                         osagent = new OSSolverAgent( osoptions->serviceLocation );
00590                         // check to see if there is an osol 
00591                         if(osoptions->osolFile == ""){
00592                                 // get a jobID
00593                                 jobID =  osagent->getJobID( sOSoL) ;
00594                                 // insert the jobID into the default osol
00595                                 iStringpos = sOSoL.find("</general");
00596                                 cout << "startel ==  " << iStringpos << endl;
00597                                 if(iStringpos != std::string::npos) sOSoL.insert(iStringpos, "<jobID>" + jobID+ "</jobID>");
00598                         }
00599                         else{
00600                                 // we have an osol file use it for the sOSoL
00601                                 sOSoL = osoptions->osol;
00602                                 // see if we have a jobID
00603                                 iStringpos = sOSoL.find("<jobID");
00604                                 // if we have a jobId send out the osil and osol files
00605                                 if(iStringpos == std::string::npos){
00606                                         // get a jobID and insert it
00607                                         jobID =  osagent->getJobID( osoptions->osol) ;
00608                                         iStringpos = sOSoL.find("</general");
00609                                         if(iStringpos != std::string::npos) sOSoL.insert(iStringpos, "<jobID>" + jobID+ "</jobID>");
00610                                 }
00611                         }
00612                         cout << sOSoL << endl;
00613                         bSend = osagent->send(osoptions->osil, sOSoL);
00614                         if(bSend == true) cout << "send is true" << endl;
00615                         else cout << "send is false" << endl;
00616                 }
00617                 else{
00618                         throw ErrorClass( "please specify service location (url)" );
00619                 }
00620         }
00621         catch(const ErrorClass& eclass){
00622                 OSResult *osresult = NULL;
00623                 OSrLWriter *osrlwriter = NULL;
00624                 osrlwriter = new OSrLWriter();
00625                 osresult = new OSResult();
00626                 osresult->setGeneralMessage( eclass.errormsg);
00627                 osresult->setGeneralStatusType( "error");
00628                 std::string osrl = osrlwriter->writeOSrL( osresult);
00629                 if(osoptions->osrlFile != "") fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00630                 else cout << osrl << endl;
00631                 delete osresult;
00632                 osresult = NULL;
00633                 delete osrlwriter;
00634                 osrlwriter = NULL;
00635         }       
00636 }//end send
00637 
00638 void retrieve(){
00639         std::string osrl = "";
00640         OSSolverAgent* osagent = NULL;
00641         FileUtil *fileUtil = NULL;
00642         fileUtil = new FileUtil();
00643         try{
00644                 if(osoptions->serviceLocation != ""){
00645                         osagent = new OSSolverAgent( osoptions->serviceLocation );
00646                         std::cout << "HERE ARE THE OSOL OPTIONS " <<  osoptions->osol << std::endl;
00647                         osrl = osagent->retrieve( osoptions->osol);
00648                         if(osoptions->osrlFile != "") {
00649                                 fileUtil->writeFileFromString(osoptions->osrlFile, osrl); 
00650                                 if(osoptions->browser != ""){
00651                                         std::string str = osoptions->browser + "  " + osoptions->osrlFile ;
00652                                         const char *ch = &str[ 0];
00653                                         std::system( ch );
00654                                 }
00655                         }
00656                         else cout << osrl << endl;
00657                 }
00658                 else{
00659                         throw ErrorClass( "please specify service location (url)" );
00660                 }
00661 
00662         }
00663         catch(const ErrorClass& eclass){
00664                 OSResult *osresult = NULL;
00665                 OSrLWriter *osrlwriter = NULL;
00666                 osrlwriter = new OSrLWriter();
00667                 osresult = new OSResult();
00668                 osresult->setGeneralMessage( eclass.errormsg);
00669                 osresult->setGeneralStatusType( "error");
00670                 std::string osrl = osrlwriter->writeOSrL( osresult);
00671                 if(osoptions->osrlFile != "") fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00672                 else cout << osrl << endl;
00673                 delete osresult;
00674                 osresult = NULL;
00675                 delete osrlwriter;
00676                 osrlwriter = NULL;
00677         }       
00678 }//end retrieve
00679 
00680 void kill(){
00681         std::string osplOutput = "";
00682         OSSolverAgent* osagent = NULL;
00683         FileUtil *fileUtil = NULL;
00684         fileUtil = new FileUtil();
00685         try{
00686                 if(osoptions->serviceLocation != ""){
00687                         osagent = new OSSolverAgent( osoptions->serviceLocation );
00688                         osplOutput = osagent->kill( osoptions->osol);
00689                         if(osoptions->osplOutputFile != "") fileUtil->writeFileFromString(osoptions->osplOutputFile, osplOutput);
00690                         else cout << osplOutput << endl;
00691                 }
00692                 else{
00693                         throw ErrorClass( "please specify service location (url)" );
00694                 }
00695         }
00696         catch(const ErrorClass& eclass){
00697                 OSResult *osresult = NULL;
00698                 OSrLWriter *osrlwriter = NULL;
00699                 osrlwriter = new OSrLWriter();
00700                 osresult = new OSResult();
00701                 osresult->setGeneralMessage( eclass.errormsg);
00702                 osresult->setGeneralStatusType( "error");
00703                 std::string osrl = osrlwriter->writeOSrL( osresult);
00704                 if(osoptions->osrlFile != "") fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00705                 else cout << osrl << endl;
00706                 delete osresult;
00707                 osresult = NULL;
00708                 delete osrlwriter;
00709                 osrlwriter = NULL;
00710         }       
00711 }//end kill
00712 
00713 void getOSiLFromNl(){
00714         try{
00715                 #ifdef COIN_HAS_ASL
00716                 OSnl2osil *nl2osil = NULL;
00717                 nl2osil = new OSnl2osil( osoptions->nlFile);
00718                 nl2osil->createOSInstance() ;
00719                 OSiLWriter *osilwriter = NULL;
00720                 osilwriter = new OSiLWriter();
00721                 std::string osil;
00722                 osil = osilwriter->writeOSiL(  nl2osil->osinstance) ;
00723                 osoptions->osil = osil;
00724                 delete nl2osil;
00725                 nl2osil = NULL;
00726                 delete osilwriter;
00727                 osilwriter = NULL;      
00728                 #else
00729                 throw("trying to convert nl to osil without AMPL ASL configured");
00730                 #endif
00731         }
00732         catch(const ErrorClass& eclass){
00733                 std::cout << eclass.errormsg <<  std::endl;
00734         }       
00735 }//getOSiLFromNl
00736 
00737 
00738 void getOSiLFromMps(){
00739         try{
00740                 OSmps2osil *mps2osil = NULL;
00741                 mps2osil = new OSmps2osil( osoptions->mpsFile);
00742                 mps2osil->createOSInstance() ;
00743                 OSiLWriter *osilwriter = NULL;
00744                 osilwriter = new OSiLWriter();
00745                 std::string osil;
00746                 osil = osilwriter->writeOSiL(  mps2osil->osinstance) ;
00747                 osoptions->osil = osil;
00748                 delete mps2osil;
00749                 mps2osil = NULL;
00750                 delete osilwriter;
00751                 osilwriter = NULL;      
00752         }
00753         catch(const ErrorClass& eclass){
00754                 std::cout << eclass.errormsg <<  std::endl;
00755         }       
00756         
00757 }//getOSiLFromMps
00758 
00759 string getServiceURI( std::string osol){
00760         if(osol == "") return osol;
00761         string::size_type pos2;
00762         string::size_type  pos1 = osol.find( "<serviceURI");
00763         if(pos1 != std::string::npos){
00764                 // get the end of the serviceURI start tag
00765                 pos1 = osol.find(">", pos1 + 1);
00766                 if(pos1 != std::string::npos){
00767                         // get the start of serviceURI end tag
00768                         pos2 = osol.find( "</serviceURI", pos1 + 1);
00769                         if( pos2 != std::string::npos){
00770                                 // get the substring
00771                                 return osol.substr( pos1 + 1, pos2 - pos1 - 1); 
00772                         }
00773                         else return "";
00774                 }
00775                 else return "";
00776         }
00777         else return "";
00778 }//getServiceURI
00779 
00780 string getInstanceLocation( std::string osol){
00781         if(osol == "") return osol;
00782         string::size_type pos2;
00783         string::size_type pos1 = osol.find( "<instanceLocation");
00784         if(pos1 != std::string::npos){
00785                 // get the end of the instanceLocation start tag
00786                 pos1 = osol.find(">", pos1 + 1);
00787                 if(pos1 != std::string::npos){
00788                         // get the start of instanceLocation end tag
00789                         pos2 = osol.find( "</instanceLocation", pos1 + 1);
00790                         if( pos2 != std::string::npos){
00791                                 // get the substring
00792                                 return osol.substr( pos1 + 1, pos2 - pos1 - 1); 
00793                         }
00794                         else return "";
00795                 }
00796                 else return "";
00797         }
00798         else return "";
00799 }//getInstanceLocation
00800 
00801 string getSolverName( std::string osol){
00802         if(osol == "") return osol;
00803         string::size_type pos2;
00804         string::size_type pos1 = osol.find( "os_solver");
00805         if(pos1 != std::string::npos){
00806                 // get the end of the instanceLocation start tag
00807                 pos1 = osol.find(">", pos1 + 1);
00808                 if(pos1 != std::string::npos){
00809                         // get the start of instanceLocation end tag
00810                         pos2 = osol.find( "</other", pos1 + 1);
00811                         if( pos2 != std::string::npos){
00812                                 // get the substring
00813                                 return osol.substr( pos1 + 1, pos2 - pos1 - 1); 
00814                         }
00815                         else return "";
00816                 }
00817                 else return "";
00818         }
00819         else return "";
00820 }//getSolverName
00821 
00822 
00823 
00824 
00825 

Generated on Thu May 15 22:15:05 2008 by  doxygen 1.4.7