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