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