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