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