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