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