00001
00070 #include "OSCoinSolver.h"
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 "OSFileUtil.h"
00078 #include "OSConfig.h"
00079 #include "OSDefaultSolver.h"
00080 #include "OSWSUtil.h"
00081 #include "OSSolverAgent.h"
00082 #include "OShL.h"
00083 #include "OSErrorClass.h"
00084 #include "OSmps2osil.h"
00085 #include "OSBase64.h"
00086 #include "OSCommonUtil.h"
00087
00088
00089
00090 #ifdef COIN_HAS_KNITRO
00091 #include "OSKnitroSolver.h"
00092 #endif
00093
00094
00095
00096
00097
00098 #ifdef COIN_HAS_LINDO
00099 #include "OSLindoSolver.h"
00100 #endif
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 #ifdef COIN_HAS_ASL
00114 #include "OSnl2osil.h"
00115 #endif
00116
00117
00118
00119
00120
00121
00122
00123 #ifdef COIN_HAS_IPOPT
00124 #ifndef COIN_HAS_ASL
00125 #include "OSIpoptSolver.h"
00126 #undef COIN_HAS_ASL
00127 #else
00128 #include "OSIpoptSolver.h"
00129 #endif
00130 #endif
00131
00132
00133
00134 #ifdef COIN_HAS_BONMIN
00135 #include "OSBonminSolver.h"
00136 #endif
00137
00138
00139 #include "OSOptionsStruc.h"
00140
00141
00142 using std::cout;
00143 using std::endl;
00144 using std::ostringstream;
00145 using std::string;
00146
00147
00148
00149 #define MAXCHARS 5000
00150
00151 typedef struct yy_buffer_state *YY_BUFFER_STATE;
00152 YY_BUFFER_STATE osss_scan_string(const char* osss, void* scanner );
00153
00154 void setyyextra(osOptionsStruc *osoptions, void* scanner);
00155 int ossslex(void* scanner );
00156 int ossslex_init(void** ptr);
00157 int ossslex_destroy (void* scanner );
00158
00159 std::string get_help();
00160 std::string get_version();
00161
00162 std::string get_help();
00163 std::string get_version();
00164
00165
00166
00167 void solve();
00168 void getJobID();
00169 void send();
00170 void kill();
00171 void retrieve();
00172 void knock();
00173
00174
00175 void getOSiLFromNl();
00176 void getOSiLFromMps();
00177 string getServiceURI( std::string osol);
00178 string getInstanceLocation( std::string osol);
00179 string getSolverName( std::string osol);
00180
00181
00182
00183
00184 osOptionsStruc *osoptions;
00185
00186
00187 int main(int argC, const char* argV[])
00188 {
00189 WindowsErrorPopupBlocker();
00190 void* scanner;
00191 FileUtil *fileUtil = NULL;
00192 FileUtil *inputFileUtil = NULL;
00193 char osss[MAXCHARS] = " ";
00194 const char *space = " ";
00195
00196 std::string configFileName = "";
00197 int i;
00198
00199
00200
00201 osoptions = new osOptionsStruc();
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->solverName = "";
00218 osoptions->browser = "";
00219 osoptions->invokeHelp = false;
00220 osoptions->writeVersion = false;
00221 try{
00222 if(argC < 2){
00223 std::cout << "There must be at least one command line argument" << std::endl;
00224 std::cout << "Try -help or --help" << std::endl;
00225 delete osoptions;
00226 return 1;
00227 }
00228
00229 i = 1;
00230 while(i < argC) {
00231 if(strlen(osss) + strlen(argV[ i]) + 1 > MAXCHARS) throw ErrorClass( "the command line has too many arguments");
00232 strcat(osss, argV[ i]);
00233 strcat(osss, space);
00234 i++;
00235 }
00236 cout << "Input String = " << osss << endl;
00237 ossslex_init( &scanner);
00238
00239 setyyextra( osoptions, scanner);
00240
00241 osss_scan_string( osss, scanner);
00242 std::cout << "call ossslex" << std::endl;
00243 ossslex( scanner);
00244 ossslex_destroy( scanner);
00245 std::cout << "done with call to ossslex" << std::endl;
00246
00247 if(osoptions->configFile != ""){
00248 ossslex_init( &scanner);
00249 configFileName = osoptions->configFile;
00250 cout << "configFileName = " << configFileName << endl;
00251 std::string osolfileOptions = fileUtil->getFileAsString( configFileName.c_str() );
00252 std::cout << "Call Text Extra" << std::endl;
00253 setyyextra( osoptions, scanner);
00254 std::cout << "Done with call Text Extra" << std::endl;
00255 osss_scan_string( osolfileOptions.c_str() , scanner);
00256 ossslex(scanner );
00257 ossslex_destroy( scanner);
00258 }
00259 }
00260 catch(const ErrorClass& eclass){
00261 cout << eclass.errormsg << endl;
00262 cout << "try -help or --help" << endl;
00263 ossslex_destroy( scanner);
00264 delete fileUtil;
00265 delete osoptions;
00266 return 1;
00267 }
00268 try{
00269 if(osoptions->invokeHelp == true){
00270 std::string helpTxt = get_help();
00271 std::cout << std::endl << std::endl;
00272 std::cout << helpTxt << std::endl;
00273 delete osoptions;
00274 osoptions = NULL;
00275 return 0;
00276 }
00277 if(osoptions->writeVersion == true){
00278 std::string writeTxt = get_version();
00279 std::cout << std::endl << std::endl;
00280 std::cout << writeTxt << std::endl;
00281 delete osoptions;
00282 osoptions = NULL;
00283 return 0;
00284 }
00285 }
00286 catch(const ErrorClass& eclass){
00287 cout << eclass.errormsg << endl;
00288 cout << "try -help or --help" << endl;
00289 delete osoptions;
00290 osoptions = NULL;
00291 delete inputFileUtil;
00292 inputFileUtil = NULL;
00293 return 1;
00294 }
00295 cout << "HERE ARE THE OPTION VALUES:" << endl;
00296 if(osoptions->configFile != "") cout << "Config file = " << osoptions->configFile << endl;
00297 if(osoptions->osilFile != "") cout << "OSiL file = " << osoptions->osilFile << endl;
00298 if(osoptions->osolFile != "") cout << "OSoL file = " << osoptions->osolFile << endl;
00299 if(osoptions->osrlFile != "") cout << "OSrL file = " << osoptions->osrlFile << endl;
00300 if(osoptions->insListFile != "") cout << "Instruction List file = " << osoptions->insListFile << endl;
00301 if(osoptions->osplInputFile != "") cout << "OSpL Input file = " << osoptions->osplInputFile << endl;
00302 if(osoptions->serviceMethod != "") cout << "Service Method = " << osoptions->serviceMethod << endl;
00303 if(osoptions->mpsFile != "") cout << "MPS File Name = " << osoptions->mpsFile << endl;
00304 if(osoptions->nlFile != "") cout << "NL File Name = " << osoptions->nlFile << endl;
00305 if(osoptions->browser != "") cout << "Browser Value = " << osoptions->browser << endl;
00306
00307 fileUtil = new FileUtil();
00308 try{
00309 if(osoptions->insListFile != "") osoptions->insList = fileUtil->getFileAsChar( (osoptions->insListFile).c_str() );
00310 if(osoptions->osolFile != ""){
00311 osoptions->osol = fileUtil->getFileAsString( (osoptions->osolFile).c_str() );
00312 }
00313 if(osoptions->serviceLocation != ""){
00314 cout << "Service Location = " << osoptions->serviceLocation << endl;
00315 }
00316 else{
00317
00318
00319
00320
00321 }
00322 if(osoptions->osilFile != ""){
00323
00324 osoptions->osil = fileUtil->getFileAsString( (osoptions->osilFile).c_str() );
00325 }
00326 else{
00327
00328 if( (osoptions->osol != "") && (osoptions->serviceLocation == "") && (getServiceURI( osoptions->osol) == "") )
00329 osoptions->osil = fileUtil->getFileAsString( getInstanceLocation( osoptions->osol).c_str() );
00330 }
00331
00332 if(osoptions->solverName != ""){
00333 cout << "Solver Name = " << osoptions->solverName << endl;
00334 }
00335 else{
00336 if(osoptions->osol != ""){
00337 osoptions->solverName = getSolverName( osoptions->osolFile.c_str() );
00338 }
00339 }
00340
00341 if(osoptions->osplInputFile != "") osoptions->osplInput = fileUtil->getFileAsString( (osoptions->osplInputFile).c_str() );
00342
00343 if(osoptions->osplOutputFile != "") osoptions->osplOutput = fileUtil->getFileAsString( (osoptions->osplOutputFile).c_str() );
00344 }
00345 catch(const ErrorClass& eclass){
00346
00347 cout << "could not open file properly" << endl;
00348 cout << "try -help or --help" << endl;
00349 delete osoptions;
00350 osoptions = NULL;
00351 delete fileUtil;
00352 fileUtil = NULL;
00353 return 1;
00354 }
00355
00356
00357 if( osoptions->serviceMethod == "") solve();
00358 else{
00359 switch(osoptions->serviceMethod[ 0]){
00360 case 'g':
00361 getJobID();
00362 break;
00363 case 'r':
00364 retrieve();
00365 break;
00366 case 's':
00367 if( osoptions->serviceMethod[ 1] == 'e') send();
00368 else solve();
00369 break;
00370 case 'k':
00371 if(osoptions->serviceMethod[ 1] == 'i') kill();
00372 else knock();
00373 break;
00374 default:
00375 break;
00376 }
00377 }
00378 delete osoptions;
00379 osoptions = NULL;
00380 delete fileUtil;
00381 fileUtil = NULL;
00382 return 0;
00383 }
00384
00385 void solve(){
00386 std::string osrl = "";
00387 OSiLReader *osilreader = NULL;
00388 OSSolverAgent* osagent = NULL;
00389 DefaultSolver *solverType = NULL;
00390 FileUtil *fileUtil = NULL;
00391 fileUtil = new FileUtil();
00392 try{
00393
00394 if( osoptions->serviceLocation != "" ){
00395
00396 if(osoptions->osil == ""){
00397
00398 if(osoptions->nlFile != ""){
00399 getOSiLFromNl();
00400 }
00401 else{
00402 if(osoptions->mpsFile != ""){
00403 getOSiLFromMps();
00404 }
00405 else{
00406 if( osoptions->osol.find( "<instanceLocation") == std::string::npos){
00407 throw ErrorClass("solve called and no osil, osol with osil specified, nl, or mps file given");
00408 }
00409 }
00410 }
00411 }
00412
00413 osagent = new OSSolverAgent( osoptions->serviceLocation );
00414 if(osoptions->solverName != ""){
00415 string::size_type iStringpos;
00416
00417 if(osoptions->osol != ""){
00418
00419 iStringpos = osoptions->osol.find("os_solver");
00420 if(iStringpos == std::string::npos) {
00421 iStringpos = osoptions->osol.find("</osol");
00422 osoptions->osol.insert(iStringpos, "<other name=\"os_solver\">"
00423 + osoptions->solverName + "</other>");
00424 }
00425 }
00426 else{
00427 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>";
00428 iStringpos = osoptions->osol.find("</osol");
00429 osoptions->osol.insert(iStringpos, "<other name=\"os_solver\">"
00430 + osoptions->solverName + "</other>");
00431 }
00432 }
00433 std::cout << std::endl;
00434 if(osoptions->osol.length() > 0){
00435 std::cout << "HERE IS THE OSoL FILE" << std::endl;
00436 std::cout << osoptions->osol << std::endl << std::endl;
00437 }
00438 osrl = osagent->solve(osoptions->osil , osoptions->osol);
00439 if(osoptions->osrlFile != ""){
00440 fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00441
00442 if(osoptions->browser != ""){
00443 std::string str = osoptions->browser + " " + osoptions->osrlFile;
00444 const char *ch = &str[ 0];
00445 std::system( ch );
00446 }
00447 }
00448 else cout << osrl << endl;
00449 delete osagent;
00450 osagent = NULL;
00451 }
00452 else{
00453
00454 if(osoptions->solverName == "" ){
00455 string sSolverName = "cbc";
00456 osoptions->solverName = sSolverName;
00457 }
00458 if( osoptions->solverName.find( "ipopt") != std::string::npos) {
00459
00460 bool bIpoptIsPresent = false;
00461 #ifdef COIN_HAS_IPOPT
00462 bIpoptIsPresent = true;
00463 solverType = new IpoptSolver();
00464 #endif
00465 if(bIpoptIsPresent == false) throw ErrorClass( "the Ipopt solver requested is not present");
00466 }
00467 else{
00468 if( osoptions->solverName.find( "lindo") != std::string::npos) {
00469
00470 bool bLindoIsPresent = false;
00471 #ifdef COIN_HAS_LINDO
00472 bLindoIsPresent = true;
00473 std::cout << "calling the LINDO Solver " << std::endl;
00474 solverType = new LindoSolver();
00475 std::cout << "DONE calling the LINDO Solver " << std::endl;
00476 #endif
00477 if(bLindoIsPresent == false) throw ErrorClass( "the Lindo solver requested is not present");
00478 }
00479 else{
00480 if( osoptions->solverName.find( "clp") != std::string::npos){
00481 solverType = new CoinSolver();
00482 solverType->sSolverName = "clp";
00483 }
00484 else{
00485 if( osoptions->solverName.find( "cplex") != std::string::npos){
00486 solverType = new CoinSolver();
00487 solverType->sSolverName = "cplex";
00488 }
00489 else{
00490 if( osoptions->solverName.find( "glpk") != std::string::npos){
00491 solverType = new CoinSolver();
00492 solverType->sSolverName = "glpk";
00493 }
00494 else{
00495 if( osoptions->solverName.find( "dylp") != std::string::npos){
00496 bool bDYlPIsPresent = false;
00497 #ifdef COIN_HAS_DYLP
00498 solverType = new CoinSolver();
00499 solverType->sSolverName = "dylp";
00500 bDYlPIsPresent = true;
00501 #endif
00502 if(bDYlPIsPresent == false) throw ErrorClass( "the DyLP solver requested is not present");
00503 }
00504 else{
00505 if( osoptions->solverName.find( "symphony") != std::string::npos){
00506 solverType = new CoinSolver();
00507 solverType->sSolverName = "symphony";
00508 }
00509 else{
00510 if( osoptions->solverName.find( "knitro") != std::string::npos){
00511 bool bKnitroIsPresent = false;
00512 #ifdef COIN_HAS_KNITRO
00513 bKnitroIsPresent = true;
00514 std::cout << "calling the KNITRO Solver " << std::endl;
00515 solverType = new KnitroSolver();
00516 std::cout << "DONE calling the KNITRO Solver " << std::endl;
00517 #endif
00518 if(bKnitroIsPresent == false) throw ErrorClass( "the Knitro solver requested is not present");
00519 }
00520 else{
00521 if( osoptions->solverName.find( "vol") != std::string::npos){
00522 solverType = new CoinSolver();
00523 solverType->sSolverName = "vol";
00524 }
00525 else{
00526 if(osoptions->solverName.find( "bonmin") != std::string::npos){
00527
00528 bool bBonminIsPresent = false;
00529 #ifdef COIN_HAS_BONMIN
00530 bBonminIsPresent = true;
00531 solverType = new BonminSolver();
00532 #endif
00533 }
00534 else{
00535 solverType = new CoinSolver();
00536 solverType->sSolverName = "cbc";
00537 }
00538 }
00539 }
00540 }
00541 }
00542 }
00543 }
00544 }
00545 }
00546 }
00547 std::cout << "CALL SOLVE" << std::endl;
00548 solverType->osol = osoptions->osol;
00549 if(osoptions->osil != ""){
00550 osilreader = new OSiLReader();
00551 std::cout << "CREATING AN OSINSTANCE FROM AN OSIL FILE" << std::endl;
00552 solverType->osinstance = osilreader->readOSiL( osoptions->osil );
00553 solverType->buildSolverInstance();
00554 solverType->solve();
00555 osrl = solverType->osrl;
00556 }
00557 else{
00558
00559 if(osoptions->nlFile != ""){
00560 #ifdef COIN_HAS_ASL
00561 std::cout << "CREATING AN OSINSTANCE FROM AN NL FILE" << std::endl;
00562 OSnl2osil *nl2osil = new OSnl2osil( osoptions->nlFile);
00563 nl2osil->createOSInstance() ;
00564 solverType->osinstance = nl2osil->osinstance;
00565 solverType->buildSolverInstance();
00566 solverType->solve();
00567 osrl = solverType->osrl;
00568 delete nl2osil;
00569 #else
00570 throw ErrorClass("nlFile specified locally but ASL not present");
00571 #endif
00572 }
00573 else{
00574 if(osoptions->mpsFile != ""){
00575 std::cout << "CREATING AN OSINSTANCE FROM AN MPS FILE" << std::endl;
00576 OSmps2osil *mps2osil = new OSmps2osil( osoptions->mpsFile);
00577 mps2osil->createOSInstance() ;
00578 solverType->osinstance = mps2osil->osinstance;
00579 solverType->buildSolverInstance();
00580 solverType->solve();
00581 osrl = solverType->osrl;
00582
00583 delete mps2osil;
00584 }
00585 else{
00586 if( osoptions->osol.find( "<instanceLocation") == std::string::npos){
00587 throw ErrorClass("solve called and no osil, osol with osil specified, nl, or mps file given");
00588 }
00589 }
00590 }
00591 }
00592
00593 if(osoptions->osrlFile != ""){
00594 fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00595
00596 if(osoptions->browser != ""){
00597 std::string str = osoptions->browser + " " + osoptions->osrlFile;
00598 const char *ch = &str[ 0];
00599 std::system( ch );
00600 }
00601 }
00602 else cout << osrl << endl;
00603 }
00604 }
00605 catch(const ErrorClass& eclass){
00606 if(osoptions->osrlFile != ""){
00607 fileUtil->writeFileFromString(osoptions->osrlFile, eclass.errormsg);
00608 if(osoptions->browser != ""){
00609 std::string str = osoptions->browser + " " + osoptions->osrlFile;
00610 const char *ch = &str[ 0];
00611 std::system( ch );
00612 }
00613 }
00614 else{
00615 OSResult *osresult = NULL;
00616 OSrLWriter *osrlwriter = NULL;
00617 osrlwriter = new OSrLWriter();
00618 osresult = new OSResult();
00619 osresult->setGeneralMessage( eclass.errormsg);
00620 osresult->setGeneralStatusType( "error");
00621 std::string osrl = osrlwriter->writeOSrL( osresult);
00622 std::cout << osrl << std::endl;
00623 delete osresult;
00624 delete osrlwriter;
00625 }
00626 }
00627 if(osilreader != NULL) delete osilreader;
00628 if(solverType != NULL) delete solverType;
00629 delete fileUtil;
00630 fileUtil = NULL;
00631 }
00632
00633 void getJobID(){
00634 std::string jobID = "";
00635 OSSolverAgent* osagent = NULL;
00636 try{
00637 if(osoptions->serviceLocation != ""){
00638 osagent = new OSSolverAgent( osoptions->serviceLocation );
00639 jobID = osagent->getJobID( osoptions->osol);
00640 cout << jobID << endl;
00641 delete osagent;
00642 osagent = NULL;
00643 }
00644 else{
00645 delete osagent;
00646 osagent = NULL;
00647 throw ErrorClass("please specify service location (url)");
00648 }
00649 }
00650 catch(const ErrorClass& eclass){
00651 FileUtil *fileUtil = NULL;
00652 fileUtil = new FileUtil();
00653 OSResult *osresult = NULL;
00654 OSrLWriter *osrlwriter = NULL;
00655 osrlwriter = new OSrLWriter();
00656 osresult = new OSResult();
00657 osresult->setGeneralMessage( eclass.errormsg);
00658 osresult->setGeneralStatusType( "error");
00659 std::string osrl = osrlwriter->writeOSrL( osresult);
00660 if(osoptions->osrlFile != "") fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00661 else cout << osrl << endl;
00662 delete osresult;
00663 osresult = NULL;
00664 delete osrlwriter;
00665 osrlwriter = NULL;
00666 delete fileUtil;
00667 fileUtil = NULL;
00668 }
00669 }
00670
00671
00672 void knock(){
00673 std::string osplOutput = "";
00674 OSSolverAgent* osagent = NULL;
00675 FileUtil *fileUtil = NULL;
00676 fileUtil = new FileUtil();
00677 try{
00678 if(osoptions->serviceLocation != ""){
00679 osagent = new OSSolverAgent( osoptions->serviceLocation );
00680 osplOutput = osagent->knock(osoptions->osplInput, osoptions->osol);
00681 if(osoptions->osplOutputFile != "") fileUtil->writeFileFromString(osoptions->osplOutputFile, osplOutput);
00682 else cout << osplOutput << endl;
00683 delete osagent;
00684 }
00685 else{
00686 delete osagent;
00687 throw ErrorClass( "please specify service location (url)" );
00688 }
00689 delete fileUtil;
00690 fileUtil = NULL;
00691 }
00692 catch(const ErrorClass& eclass){
00693 OSResult *osresult = NULL;
00694 OSrLWriter *osrlwriter = NULL;
00695 osrlwriter = new OSrLWriter();
00696 osresult = new OSResult();
00697 osresult->setGeneralMessage( eclass.errormsg);
00698 osresult->setGeneralStatusType( "error");
00699 std::string osrl = osrlwriter->writeOSrL( osresult);
00700 if(osoptions->osrlFile != "") fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00701 else cout << osrl << endl;
00702 delete osresult;
00703 osresult = NULL;
00704 delete osrlwriter;
00705 osrlwriter = NULL;
00706 delete fileUtil;
00707 fileUtil = NULL;
00708 }
00709 }
00710
00711
00712 void send(){
00713 bool bSend = false;
00714 std::string jobID = "";
00715 OSSolverAgent* osagent = NULL;
00716
00717 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>";
00718 string::size_type iStringpos;
00719 try{
00720
00721 if(osoptions->osil == ""){
00722
00723 if(osoptions->nlFile != ""){
00724 getOSiLFromNl();
00725 }
00726 else{
00727 if(osoptions->mpsFile != ""){
00728 getOSiLFromMps();
00729 }
00730 else{
00731 throw ErrorClass("solve called and no osil, nl, or mps file given");
00732 }
00733 }
00734 }
00735 if(osoptions->serviceLocation != ""){
00736 osagent = new OSSolverAgent( osoptions->serviceLocation );
00737
00738 if(osoptions->osolFile == ""){
00739
00740 jobID = osagent->getJobID( sOSoL) ;
00741
00742 iStringpos = sOSoL.find("</general");
00743 cout << "startel == " << iStringpos << endl;
00744 if(iStringpos != std::string::npos) sOSoL.insert(iStringpos, "<jobID>" + jobID+ "</jobID>");
00745 }
00746 else{
00747
00748 sOSoL = osoptions->osol;
00749
00750 iStringpos = sOSoL.find("<jobID");
00751
00752 if(iStringpos == std::string::npos){
00753
00754 jobID = osagent->getJobID( osoptions->osol) ;
00755 iStringpos = sOSoL.find("</general");
00756 if(iStringpos != std::string::npos) sOSoL.insert(iStringpos, "<jobID>" + jobID+ "</jobID>");
00757 }
00758 }
00759 cout << sOSoL << endl;
00760 bSend = osagent->send(osoptions->osil, sOSoL);
00761 if(bSend == true) cout << "send is true" << endl;
00762 else cout << "send is false" << endl;
00763 delete osagent;
00764 }
00765 else{
00766 delete osagent;
00767 throw ErrorClass( "please specify service location (url)" );
00768 }
00769 }
00770 catch(const ErrorClass& eclass){
00771 FileUtil *fileUtil = NULL;
00772 fileUtil = new FileUtil();
00773 OSResult *osresult = NULL;
00774 OSrLWriter *osrlwriter = NULL;
00775 osrlwriter = new OSrLWriter();
00776 osresult = new OSResult();
00777 osresult->setGeneralMessage( eclass.errormsg);
00778 osresult->setGeneralStatusType( "error");
00779 std::string osrl = osrlwriter->writeOSrL( osresult);
00780 if(osoptions->osrlFile != "") fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00781 else cout << osrl << endl;
00782 delete osresult;
00783 osresult = NULL;
00784 delete osrlwriter;
00785 osrlwriter = NULL;
00786 delete fileUtil;
00787 fileUtil = NULL;
00788 }
00789 }
00790
00791 void retrieve(){
00792 FileUtil *fileUtil = NULL;
00793 fileUtil = new FileUtil();
00794 std::string osrl = "";
00795 OSSolverAgent* osagent = NULL;
00796 try{
00797 if(osoptions->serviceLocation != ""){
00798 osagent = new OSSolverAgent( osoptions->serviceLocation );
00799 std::cout << "HERE ARE THE OSOL OPTIONS " << osoptions->osol << std::endl;
00800 osrl = osagent->retrieve( osoptions->osol);
00801 if(osoptions->osrlFile != "") {
00802 fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00803 if(osoptions->browser != ""){
00804 std::string str = osoptions->browser + " " + osoptions->osrlFile ;
00805 const char *ch = &str[ 0];
00806 std::system( ch );
00807 }
00808 }
00809 else cout << osrl << endl;
00810 delete osagent;
00811 osagent = NULL;
00812 }
00813 else{
00814 delete osagent;
00815 osagent = NULL;
00816 throw ErrorClass( "please specify service location (url)" );
00817 }
00818 delete fileUtil;
00819 fileUtil = NULL;
00820 }
00821 catch(const ErrorClass& eclass){
00822 OSResult *osresult = NULL;
00823 OSrLWriter *osrlwriter = NULL;
00824 osrlwriter = new OSrLWriter();
00825 osresult = new OSResult();
00826 osresult->setGeneralMessage( eclass.errormsg);
00827 osresult->setGeneralStatusType( "error");
00828 std::string osrl = osrlwriter->writeOSrL( osresult);
00829 if(osoptions->osrlFile != "") fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00830 else cout << osrl << endl;
00831 delete osresult;
00832 osresult = NULL;
00833 delete osrlwriter;
00834 osrlwriter = NULL;
00835 delete fileUtil;
00836 fileUtil = NULL;
00837 }
00838 }
00839
00840 void kill(){
00841 FileUtil *fileUtil = NULL;
00842 fileUtil = new FileUtil();
00843 std::string osplOutput = "";
00844 OSSolverAgent* osagent = NULL;
00845 try{
00846 if(osoptions->serviceLocation != ""){
00847 osagent = new OSSolverAgent( osoptions->serviceLocation );
00848 osplOutput = osagent->kill( osoptions->osol);
00849 if(osoptions->osplOutputFile != "") fileUtil->writeFileFromString(osoptions->osplOutputFile, osplOutput);
00850 else cout << osplOutput << endl;
00851 delete osagent;
00852 osagent = NULL;
00853 }
00854 else{
00855 delete osagent;
00856 osagent = NULL;
00857 throw ErrorClass( "please specify service location (url)" );
00858 }
00859 delete fileUtil;
00860 fileUtil = NULL;
00861 }
00862 catch(const ErrorClass& eclass){
00863 OSResult *osresult = NULL;
00864 OSrLWriter *osrlwriter = NULL;
00865 osrlwriter = new OSrLWriter();
00866 osresult = new OSResult();
00867 osresult->setGeneralMessage( eclass.errormsg);
00868 osresult->setGeneralStatusType( "error");
00869 std::string osrl = osrlwriter->writeOSrL( osresult);
00870 if(osoptions->osrlFile != "") fileUtil->writeFileFromString(osoptions->osrlFile, osrl);
00871 else cout << osrl << endl;
00872 delete osresult;
00873 osresult = NULL;
00874 delete osrlwriter;
00875 osrlwriter = NULL;
00876 delete fileUtil;
00877 fileUtil = NULL;
00878 }
00879 }
00880
00881 void getOSiLFromNl(){
00882 try{
00883 #ifdef COIN_HAS_ASL
00884 OSnl2osil *nl2osil = NULL;
00885 nl2osil = new OSnl2osil( osoptions->nlFile);
00886 nl2osil->createOSInstance() ;
00887 OSiLWriter *osilwriter = NULL;
00888 osilwriter = new OSiLWriter();
00889 std::string osil;
00890 osil = osilwriter->writeOSiL( nl2osil->osinstance) ;
00891 osoptions->osil = osil;
00892 delete nl2osil;
00893 nl2osil = NULL;
00894 delete osilwriter;
00895 osilwriter = NULL;
00896 #else
00897 throw ErrorClass("trying to convert nl to osil without AMPL ASL configured");
00898 #endif
00899 }
00900 catch(const ErrorClass& eclass){
00901 std::cout << eclass.errormsg << std::endl;
00902 throw ErrorClass( eclass.errormsg) ;
00903 }
00904 }
00905
00906
00907 void getOSiLFromMps(){
00908 try{
00909 OSmps2osil *mps2osil = NULL;
00910 mps2osil = new OSmps2osil( osoptions->mpsFile);
00911 mps2osil->createOSInstance() ;
00912 OSiLWriter *osilwriter = NULL;
00913 osilwriter = new OSiLWriter();
00914 std::string osil;
00915 osil = osilwriter->writeOSiL( mps2osil->osinstance) ;
00916 osoptions->osil = osil;
00917 delete mps2osil;
00918 mps2osil = NULL;
00919 delete osilwriter;
00920 osilwriter = NULL;
00921 }
00922 catch(const ErrorClass& eclass){
00923 std::cout << eclass.errormsg << std::endl;
00924 throw ErrorClass( eclass.errormsg) ;
00925 }
00926
00927 }
00928
00929 string getServiceURI( std::string osol){
00930 if(osol == "") return osol;
00931 string::size_type pos2;
00932 string::size_type pos1 = osol.find( "<serviceURI");
00933 if(pos1 != std::string::npos){
00934
00935 pos1 = osol.find(">", pos1 + 1);
00936 if(pos1 != std::string::npos){
00937
00938 pos2 = osol.find( "</serviceURI", pos1 + 1);
00939 if( pos2 != std::string::npos){
00940
00941 return osol.substr( pos1 + 1, pos2 - pos1 - 1);
00942 }
00943 else return "";
00944 }
00945 else return "";
00946 }
00947 else return "";
00948 }
00949
00950 string getInstanceLocation( std::string osol){
00951 if(osol == "") return osol;
00952 string::size_type pos2;
00953 string::size_type pos1 = osol.find( "<instanceLocation");
00954 if(pos1 != std::string::npos){
00955
00956 pos1 = osol.find(">", pos1 + 1);
00957 if(pos1 != std::string::npos){
00958
00959 pos2 = osol.find( "</instanceLocation", pos1 + 1);
00960 if( pos2 != std::string::npos){
00961
00962 return osol.substr( pos1 + 1, pos2 - pos1 - 1);
00963 }
00964 else return "";
00965 }
00966 else return "";
00967 }
00968 else return "";
00969 }
00970
00971 string getSolverName( std::string osol){
00972 if(osol == "") return osol;
00973 string::size_type pos2;
00974 string::size_type pos1 = osol.find( "os_solver");
00975 if(pos1 != std::string::npos){
00976
00977 pos1 = osol.find(">", pos1 + 1);
00978 if(pos1 != std::string::npos){
00979
00980 pos2 = osol.find( "</other", pos1 + 1);
00981 if( pos2 != std::string::npos){
00982
00983 return osol.substr( pos1 + 1, pos2 - pos1 - 1);
00984 }
00985 else return "";
00986 }
00987 else return "";
00988 }
00989 else return "";
00990 }
00991
00992 std::string get_help(){
00993
00994 std::ostringstream helpMsg;
00995
00996
00997 helpMsg << "************************* HELP *************************" << endl << endl;
00998 helpMsg << "In this HELP file we assume that the solve service method is used and " << endl;
00999 helpMsg << "that we are solving problems locally, that is the solver is on the " << endl;
01000 helpMsg << "machine running this OSSolverService. See Section 10.3 of the User\'s " << endl;
01001 helpMsg << "Manual for other service methods or calling a server remotely. " << endl;
01002 helpMsg << "The OSSolverService takes the parameters listed below. " << endl;
01003 helpMsg << "The order of the parameters is irrelevant. Not all the parameters " << endl;
01004 helpMsg << "are required. However, the location of an instance file is " << endl;
01005 helpMsg << "required when using the solve service method. The location of the " << endl;
01006 helpMsg << "instance file is specified using the osil option. " << endl;
01007
01008 helpMsg << endl;
01009
01010 helpMsg << "-osil xxx.osil this is the name of the file that contains the " << endl;
01011 helpMsg << "optimization instance in OSiL format. This option may be " << endl;
01012 helpMsg << "specified in the OSoL solver options file. " << endl;
01013
01014 helpMsg << endl;
01015
01016 helpMsg << "-osol xxx.osol this is the name of the file that contains the solver options. " << endl;
01017 helpMsg << "It is not necessary to specify this option. " << endl;
01018
01019 helpMsg << endl;
01020
01021 helpMsg << "-osrl xxx.osrl this is the name of the file to which the solver solution is written. " << endl;
01022 helpMsg << "It is not necessary to specify this option. If this option is not specified, " << endl;
01023 helpMsg << "the result will be printed to standard out. " << endl;
01024
01025 helpMsg << endl;
01026
01027 helpMsg << "-serviceLocation url is the URL of the solver service. " << endl;
01028 helpMsg << "This is not required, and if not specified it is assumed that " << endl;
01029 helpMsg << "the problem is solved locally. " << endl;
01030
01031 helpMsg << endl;
01032
01033 helpMsg << "-serviceMethod methodName this is the method on the solver service to be invoked. " << endl;
01034 helpMsg << "The options are solve, send, kill, knock, getJobID, and t retrieve. " << endl;
01035 helpMsg << "This option is not required, and the default value is solve. " << endl;
01036
01037 helpMsg << endl;
01038
01039 helpMsg << "-mps xxx.mps this is the name of the mps file if the problem instance " << endl;
01040 helpMsg << "is in mps format. The default file format is OSiL so this option is not required. " << endl;
01041
01042 helpMsg << endl;
01043
01044 helpMsg << "-nl xxx.nl this is the name of the AMPL nl file if the problem " << endl;
01045 helpMsg << "instance is in AMPL nl format. The default file format is OSiL " << endl;
01046 helpMsg << "so this option is not required. " << endl;
01047
01048 helpMsg << endl;
01049
01050 helpMsg << "-solver solverName Possible values for default OS installation " << endl;
01051 helpMsg << "are bonmn(COIN-OR Bonmin), clp (COIN-OR Clp), cbc (COIN-OR Cbc), " << endl;
01052 helpMsg << "dylp (COIN-OR DyLP), and symphony (COIN-OR SYMPHONY). Other solvers supported " << endl;
01053 helpMsg << "(if the necessary libraries are present) are cplex (Cplex through COIN-OR Osi), " << endl;
01054 helpMsg << "glpk (glpk through COIN-OR Osi), ipopt (COIN-OR Ipopt), " << endl;
01055 helpMsg << "knitro (Knitro), and lindo (LINDO). If no value is specified for this " << endl;
01056 helpMsg << "parameter, then cbc is the default value of this parameter. " << endl;
01057
01058 helpMsg << endl;
01059
01060 helpMsg << "-browser browserName this paramater is a path to the browser on the " << endl;
01061 helpMsg << "local machine. If this optional parameter is specified then the " << endl;
01062 helpMsg << "solver result in OSrL format is transformed using XSLT into " << endl;
01063 helpMsg << "HTML and displayed in the browser. " << endl;
01064
01065 helpMsg << endl;
01066
01067 helpMsg << "-config pathToConfigureFile this parameter specifies a path on " << endl;
01068 helpMsg << "the local machine to a text file containing values for the input parameters. " << endl;
01069 helpMsg << "This is convenient for the user not wishing to constantly retype parameter values. " << endl;
01070 helpMsg << "This configure file can contain values for all of the other parameters. " << endl;
01071
01072 helpMsg << endl;
01073
01074 helpMsg << "--version or -v get the current version of this executable " << endl;
01075
01076 helpMsg << endl;
01077
01078 helpMsg << "--help or -h to get this help file " << endl;
01079
01080
01081 helpMsg << endl;
01082
01083 helpMsg << "Note: If you specify a configure file by using the -config option, you can " << endl;
01084 helpMsg << "override the values of the options in the configure file by putting them in " << endl;
01085 helpMsg << "at the command line. " << endl << endl;
01086
01087 helpMsg << "See the OS User\' Manual: http://www.coin-or.org/OS/doc/osUsersManual_1.1.pdf" << endl;
01088 helpMsg << "for more detail on how to use the OS project. " << endl;
01089
01090 helpMsg << endl;
01091 helpMsg << "********************************************************" << endl << endl;
01092
01093 return helpMsg.str();
01094 }
01095
01096
01097 std::string get_version(){
01098
01099 std::ostringstream versionMsg;
01100 versionMsg << "In order to find the version of this project " << endl;
01101 versionMsg << "connect to the directory where you downloaded " << endl;
01102 versionMsg << "and do: " << endl;
01103 versionMsg << "svn info " << endl;
01104
01105
01106 return versionMsg.str();
01107 }
01108
01109
01110
01111
01112