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