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