My Project
OSSolverService_old.cpp
Go to the documentation of this file.
1//Id: OSSolverService.cpp 3561 2010-06-24 19:27:07Z kmartin $
69#include "OSCoinSolver.h"
70#include "OSResult.h"
71#include "OSiLReader.h"
72#include "OSiLWriter.h"
73#include "OSoLReader.h"
74#include "OSrLReader.h"
75#include "OSrLWriter.h"
76#include "OSInstance.h"
77#include "OSOption.h"
78#include "OSoLWriter.h"
79#include "OSFileUtil.h"
80#include "OSOutput.h"
81#include "OSConfig.h"
82#include "OSDefaultSolver.h"
83#include "OSWSUtil.h"
84#include "OSSolverAgent.h"
85#include "OShL.h"
86#include "OSErrorClass.h"
87#include "OSmps2osil.h"
88#include "OSBase64.h"
89#include "OSRunSolver.h"
90
91#ifdef COIN_HAS_KNITRO
92#include "OSKnitroSolver.h"
93#endif
94
95#ifdef COIN_HAS_LINDO
96#include "OSLindoSolver.h"
97#endif
98
99#ifdef COIN_HAS_ASL
100#include "OSnl2OS.h"
101#endif
102
103#ifdef COIN_HAS_GAMSUTILS
104#include "OSgams2osil.hpp"
105#endif
106
107#ifdef COIN_HAS_IPOPT
108#ifndef COIN_HAS_ASL
109#include "OSIpoptSolver.h"
110#undef COIN_HAS_ASL
111#else
112#include "OSIpoptSolver.h"
113#endif
114#endif
115
116#ifdef COIN_HAS_BONMIN
117#include "OSBonminSolver.h"
118#endif
119
120#ifdef COIN_HAS_COUENNE
121#include "OSCouenneSolver.h"
122#endif
123
124#include "OSCommandLine.h"
125
126#include <stdio.h>
127#include <map>
128
129using std::cout;
130using std::endl;
131using std::ostringstream;
132using std::string;
133using std::map;
134
135
136#define MAXCHARS 5000
137
139YY_BUFFER_STATE osss_scan_string(const char* osss, void* scanner);
140//void osssset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
141void setyyextra(OSCommandLine *oscommandline, void* scanner);
142int ossslex(void* scanner);
143int ossslex_init(void** ptr);
144int ossslex_destroy(void* scanner);
145
146void interactiveShell();
147
148std::string get_help();
149std::string get_version();
150std::string get_options();
151void list_options(OSCommandLine *oscommandline);
152
153// the serviceMethods
154void solve(OSCommandLine *oscommandline);
155void getJobID(OSCommandLine *oscommandline);
156void send(OSCommandLine *oscommandline);
157void kill(OSCommandLine *oscommandline);
158void retrieve(OSCommandLine *oscommandline);
159void knock(OSCommandLine *oscommandline);
160
161// additional methods
162void getOSiLFromNl( OSCommandLine *oscommandline);
163void getOSiLFromMps( OSCommandLine *oscommandline);
164void getOSiLFromGams(OSCommandLine *oscommandline);
165void doPrintModel(OSCommandLine *oscommandline);
166void doPrintModel(OSInstance *osinstance);
167void doPrintRow(OSCommandLine *oscommandline);
168void doPrintRow(OSInstance *osinstance, std::string rownumberstring);
169
170extern const OSSmartPtr<OSOutput> osoutput;
171
172int main(int argC, const char* argV[])
173{
174 WindowsErrorPopupBlocker();
175 std::ostringstream outStr;
176
177 std::string versionInfo = OSgetVersionInfo();
179
180 if (argC < 2)
181 {
183 return 0;
184 }
185
186 void* scanner;
187 FileUtil *fileUtil = NULL;
188 FileUtil *inputFileUtil = NULL;
189 char osss[MAXCHARS] = " ";
190 const char *space = " ";
191 const char *quote = "\"";
192 //char *config = "-config";
193 std::string configFileName = "";
194 int i;
195
198 // initialize the command line structure
199
200// osoptions = new osOptionsStruc();
201 OSCommandLine *oscommandline = new OSCommandLine();
202 bool scannerActive = false;
203
204 try
205 {
206
207 // make sure we do not exceed max allowed characters in command line
208 i = 1;
209 bool addQuotes;
210 while (i < argC)
211 {
212 addQuotes = false;
213 if (argV[i][0] != '\"')
214 for (int k=0; k<strlen(argV[i]); k++)
215 {
216 if (argV[i][k] == ' ')
217 {
218 addQuotes = true;
219 break;
220 }
221 }
222 if (addQuotes)
223 {
224 if (strlen(osss) + strlen(argV[i]) + 3 > MAXCHARS)
225 throw ErrorClass("The command line exceeds allocated storage. Increase parameter MAXCHARS.");
226 strcat(osss, quote);
227 strcat(osss, argV[i]);
228 strcat(osss, quote);
229 strcat(osss, space);
230 }
231 else
232 {
233 if (strlen(osss) + strlen(argV[i]) + 1 > MAXCHARS)
234 throw ErrorClass("The command line exceeds allocated storage. Increase parameter MAXCHARS.");
235 strcat(osss, argV[i]);
236 strcat(osss, space);
237 }
238 i++;
239 }
240
241#ifndef NDEBUG
242 outStr.str("");
243 outStr.clear();
244 outStr << "Input String = " << osss << std::endl;
246#endif
247
248 scannerActive = true;
250
251#ifndef NDEBUG
252 osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_trace, "Call Text Extra\n");
253#endif
254
255 setyyextra(oscommandline, scanner);
256
257#ifndef NDEBUG
258 osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_trace, "Call scan string\n");
259#endif
260
262
263#ifndef NDEBUG
264 osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_trace, "Call ossslex\n");
265#endif
266
269 scannerActive = false;
270
271#ifndef NDEBUG
272 osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_trace, "Done with call to ossslex\n");
273#endif
274
275 // if there is a config file, get those options
276 if (oscommandline->configFile != "")
277 {
278 scannerActive = true;
280 configFileName = oscommandline->configFile;
281
282#ifndef NDEBUG
283 outStr.str("");
284 outStr.clear();
285 outStr << "configFileName = " << configFileName << std::endl;
287#endif
288
289 std::string configFileOptions = fileUtil->getFileAsString(
290 configFileName.c_str());
291#ifndef NDEBUG
292 osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_trace, "Call Text Extra\n");
293#endif
294
295 setyyextra(oscommandline, scanner);
296
297#ifndef NDEBUG
298 osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_trace, "Done with call Text Extra\n");
299#endif
300
301 osss_scan_string(configFileOptions.c_str(), scanner);
304 scannerActive = false;
305
306
313 scannerActive = true;
315
316#ifndef NDEBUG
317 osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_trace, "Call Text Extra\n");
318#endif
319
320 setyyextra(oscommandline, scanner);
321
322#ifndef NDEBUG
323 osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_trace, "Call scan string\n");
324#endif
325
327
328#ifndef NDEBUG
329 osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_trace, "call ossslex\n");
330#endif
331
334 scannerActive = false;
335
336
338 }
339 }
340 catch (const ErrorClass& eclass)
341 {
342#ifndef NDEBUG
344#endif
345
346 //new stuff on April 17, 2010
347 OSResult *osresult = NULL;
348 OSrLWriter *osrlwriter = NULL;
349 osrlwriter = new OSrLWriter();
350 osresult = new OSResult();
353 std::string osrl = osrlwriter->writeOSrL(osresult);
354 if (oscommandline->osrlFile != "")
355 {
356 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
357 if (oscommandline->browser != "")
358 {
359 std::string str = oscommandline->browser + " "
360 + oscommandline->osrlFile;
361 const char *ch = &str[0];
362 std::system(ch);
363 }
364 }
365 else
366 {
367#ifndef NDEBUG
369#endif
371 }
372 //catch garbage collection
373 delete osresult;
374 osresult = NULL;
375 delete osrlwriter;
376 osrlwriter = NULL;
377 // end new stuff
378
379 delete fileUtil;
380 delete oscommandline;
381 return 1;
382 }
383
386 try
387 {
388 outStr.str("");
389 outStr.clear();
390 outStr << std::endl << "using print level " << oscommandline->printLevel << " for stdout" << std::endl;
391
392 if (oscommandline->printLevel != DEFAULT_OUTPUT_LEVEL)
393 {
394 osoutput->SetPrintLevel("stdout", (ENUM_OUTPUT_LEVEL)oscommandline->printLevel);
396 }
397#ifndef NDEBUG
398 else
399 {
401 }
402#endif
403
404 if (oscommandline->logFile != "")
405 {
406 int status = osoutput->AddChannel(oscommandline->logFile);
407
408 switch(status)
409 {
410 case 0:
412 "Added channel " + oscommandline->logFile);
413 break;
414 case 1:
416 "Output channel " + oscommandline->logFile + " previously defined");
417 break;
418 default:
419 throw ErrorClass("Could not add output channel " + oscommandline->logFile);
420 }//end switch
421
422
423 outStr.str("");
424 outStr.clear();
425 outStr << std::endl << "using print level " << oscommandline->filePrintLevel;
426 outStr << " for " << oscommandline->logFile << std::endl;
427
428 if (oscommandline->filePrintLevel != DEFAULT_OUTPUT_LEVEL)
429 {
430 osoutput->SetPrintLevel(oscommandline->logFile, (ENUM_OUTPUT_LEVEL)oscommandline->filePrintLevel);
431 }
432 else
433 {
435 }
436 }
437
438 if (oscommandline->invokeHelp == true)
439 {
440 outStr.str("");
441 outStr.clear();
442 outStr << std::endl << std::endl << get_help() << std::endl;
444
445 delete oscommandline;
446 oscommandline = NULL;
447 return 0;
448 }
449
450 if (oscommandline->writeVersion == true)
451 {
452 outStr.str("");
453 outStr.clear();
454 outStr << std::endl << std::endl << OSgetVersionInfo() << std::endl;
456
457 delete oscommandline;
458 oscommandline = NULL;
459 return 0;
460 }
461 }
462 catch (const ErrorClass& eclass)
463 {
464#ifndef NDEBUG
466#endif
467
468 //new stuff on April 17, 2010
469 OSResult *osresult = NULL;
470 OSrLWriter *osrlwriter = NULL;
471 osrlwriter = new OSrLWriter();
472 osresult = new OSResult();
475 std::string osrl = osrlwriter->writeOSrL(osresult);
476 if (oscommandline->osrlFile != "")
477 {
478 //fileUtil->writeFileFromString(oscommandline->osrlFile, eclass.errormsg);
479 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
480 if (oscommandline->browser != "")
481 {
482 std::string str = oscommandline->browser + " "
483 + oscommandline->osrlFile;
484 const char *ch = &str[0];
485 std::system(ch);
486 }
487 }
488 else
489 {
490#ifndef NDEBUG
492#endif
494 }
495 //catch garbage collection
496 delete osresult;
497 osresult = NULL;
498 delete osrlwriter;
499 osrlwriter = NULL;
500 // end new stuff
501
502
503 delete oscommandline;
504 oscommandline = NULL;
505 delete inputFileUtil;
506 inputFileUtil = NULL;
507 return 1;
508 }
509
510#ifndef NDEBUG
511 outStr.str("");
512 outStr.clear();
513
514 outStr << "HERE ARE THE OPTION VALUES:" << endl;
515 if(oscommandline->configFile != "") outStr << "Config file = " << oscommandline->configFile << endl;
516 if(oscommandline->osilFile != "") outStr << "OSiL file = " << oscommandline->osilFile << endl;
517 if(oscommandline->osolFile != "") outStr << "OSoL file = " << oscommandline->osolFile << endl;
518 if(oscommandline->osrlFile != "") outStr << "OSrL file = " << oscommandline->osrlFile << endl;
519 //if(oscommandline->insListFile != "") outStr << "Instruction List file = " << oscommandline->insListFile << endl;
520 if(oscommandline->osplInputFile != "") outStr << "OSpL Input file = " << oscommandline->osplInputFile << endl;
521 if(oscommandline->serviceMethod != "") outStr << "Service Method = " << oscommandline->serviceMethod << endl;
522 if(oscommandline->mpsFile != "") outStr << "MPS File Name = " << oscommandline->mpsFile << endl;
523 if(oscommandline->nlFile != "") outStr << "NL File Name = " << oscommandline->nlFile << endl;
524 if(oscommandline->gamsControlFile != "") outStr << "gams Control File Name = " << oscommandline->gamsControlFile << endl;
525 if(oscommandline->browser != "") outStr << "Browser Value = " << oscommandline->browser << endl;
526 if(oscommandline->solverName != "") outStr << "Selected Solver = " << oscommandline->solverName << endl;
527 if(oscommandline->serviceLocation != "") outStr << "Service Location = " << oscommandline->serviceLocation << endl;
528 if(oscommandline->printModel) outStr << "print model prior to solve/send" << endl;
529 if(oscommandline->printRowNumberAsString != "") outStr << "print model row " << oscommandline->printRowNumberAsString << " prior to solve/send" << endl;
530 outStr << "print level for stdout: " << oscommandline->printLevel << endl;
531 if(oscommandline->logFile != "")
532 {
533 outStr << "also send output to " << oscommandline->logFile << endl;
534 outStr << "print level for file output: " << oscommandline->filePrintLevel << endl;
535 }
536
538#endif
539
540 //convert solver name to lower case so there is no ambiguity
541 unsigned int k;
542 for (k = 0; k < oscommandline->solverName.length(); k++)
543 {
544 oscommandline->solverName[k] = (char)tolower(oscommandline->solverName[k]);
545 }
546
547 // get the data from the files
548 fileUtil = new FileUtil();
549 try
550 {
551 if (oscommandline->osolFile != "")
552 {
553 oscommandline->osol = fileUtil->getFileAsString(
554 (oscommandline->osolFile).c_str());
555 }
556
557 if (oscommandline->osilFile != "")
558 {
559 //this takes precedence over what is in the OSoL file
560 oscommandline->osil = fileUtil->getFileAsString(
561 (oscommandline->osilFile).c_str());
562 }
563 /*
564 else{// we were not given an osil file
565 // make sure we don't have a service URI in the file or are using mps or nl
566 // if we have nl or mps assume a local solve
567 if( (oscommandline->osol != "") && (oscommandline->nlFile == "") && (oscommandline->gamsControlFile == "") && (oscommandline->mpsFile == "") && (oscommandline->serviceLocation == "") && (getServiceURI( oscommandline->osol) == "") )
568 oscommandline->osil = fileUtil->getFileAsString( getInstanceLocation( oscommandline->osol).c_str() );
569 }
570 */
571
572 if (oscommandline->osplInputFile != "")
573 oscommandline->osplInput = fileUtil->getFileAsString(
574 (oscommandline->osplInputFile).c_str());
575 }
576 catch (const ErrorClass& eclass)
577 {
578 outStr.str("");
579 outStr.clear();
580 outStr << eclass.errormsg << endl;
581 outStr << "could not open file properly" << endl;
583
584
585 //new stuff on April 17, 2010
586 OSResult *osresult = NULL;
587 OSrLWriter *osrlwriter = NULL;
588 osrlwriter = new OSrLWriter();
589 osresult = new OSResult();
590
593 std::string osrl = osrlwriter->writeOSrL(osresult);
594 if (oscommandline->osrlFile != "")
595 {
596 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
597 if (oscommandline->browser != "")
598 {
599 std::string str = oscommandline->browser + " "
600 + oscommandline->osrlFile;
601 const char *ch = &str[0];
602 std::system(ch);
603 }
604 }
605 else
606 {
608 }
609 //catch garbage collection
610 delete osresult;
611 osresult = NULL;
612 delete osrlwriter;
613 osrlwriter = NULL;
614 // end new stuff
615
616
617 delete oscommandline;
618 oscommandline = NULL;
619 delete fileUtil;
620 fileUtil = NULL;
621 return 1;
622 }
623 // now call the correct serviceMethod
624 // solve is the default
625 if (oscommandline->serviceMethod == "") oscommandline->serviceMethod = "solve";
626 if (oscommandline->serviceMethod[0] == 's')
627 {
628 if (oscommandline->printModel == true)
629 doPrintModel(oscommandline);
630 else if (oscommandline->printRowNumberAsString != "")
631 doPrintRow(oscommandline);
632 if (oscommandline->serviceMethod[1] == 'e')
633 send(oscommandline);
634 else
635 solve(oscommandline);
636 }
637 else
638 {
639 switch (oscommandline->serviceMethod[0])
640 {
641 case 'g':
642 getJobID(oscommandline);
643 break;
644 case 'r':
645 retrieve(oscommandline);
646 break;
647 case 'k':
648 if (oscommandline->serviceMethod[1] == 'i')
649 kill(oscommandline);
650 else
651 knock(oscommandline);
652 break;
653 default:
654
655 break;
656 }
657 }
658 delete oscommandline;
659 oscommandline = NULL;
660 delete fileUtil;
661 fileUtil = NULL;
662 return 0;
663}// end of main()
664
665
670void solve(OSCommandLine *oscommandline)
671{
672 std::string osrl = "";
673 OSiLReader *osilreader = NULL;
674 OSmps2osil *mps2osil = NULL;
675#ifdef COIN_HAS_ASL
676 OSnl2OS *nl2os = NULL;
677#endif
678#ifdef COIN_HAS_GAMSUTILS
679 OSgams2osil *gams2osil = NULL;
680#endif
681 OSSolverAgent* osagent = NULL;
682 FileUtil *fileUtil = NULL;
683 fileUtil = new FileUtil();
684 // now solve either remotely or locally
685 try
686 {
687 if (oscommandline->serviceLocation != "")
688 {
689 // call a method here to get OSiL if we have an nl or mps file
690 if (oscommandline->osil == "")
691 {
692 //we better have an nl file present or mps file or osol file
693 if (oscommandline->nlFile != "")
694 {
695 getOSiLFromNl(oscommandline);
696 }
697 else
698 {
699 if (oscommandline->mpsFile != "")
700 {
701 getOSiLFromMps(oscommandline);
702 }
703 else
704 {
705 if (oscommandline->gamsControlFile != "")
706 {
707
708 getOSiLFromGams(oscommandline);
709 }
710 else // send an empty osil string
711 {
712 oscommandline->osil = "";
713 }
714 }
715 }
716 }
717
718 if (oscommandline->printModel)
719 doPrintModel(oscommandline);
720 else if (oscommandline->printRowNumberAsString != "")
721 doPrintRow(oscommandline);
722
723 // place a remote call
724 osagent = new OSSolverAgent(oscommandline->serviceLocation);
725
726 if (oscommandline->osol == "") // we have no osol string; create a dummy
727 {
728 std::ostringstream outStr;
729 outStr
730 << "<?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/";
731 outStr << OS_SCHEMA_VERSION;
732 outStr << "/OSoL.xsd\"></osol>";
733 oscommandline->osol = outStr.str();
734 }
735 osrl = osagent->solve(oscommandline->osil, oscommandline->osol);
736 if (oscommandline->osrlFile != "")
737 {
738 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
739 if (oscommandline->browser != "")
740 {
741 std::string str = oscommandline->browser + " "
742 + oscommandline->osrlFile;
743 const char *ch = &str[0];
744 std::system(ch);
745 }
746 }
747 else
749 delete osagent;
750 osagent = NULL;
751 }
752 else // solve locally
753 {
754 OSInstance *osinstance;
755 OSOption *osoption = NULL;
756 if (oscommandline->osil != "")
757 {
758 osilreader = new OSiLReader();
759 osinstance = osilreader->readOSiL(oscommandline->osil);
760 }
761 else
762 {
763 //we better have an nl file present or mps file or osol file
764 if (oscommandline->nlFile != "")
765 {
766#ifdef COIN_HAS_ASL
767 //nl2os = new OSnl2OS( oscommandline->nlFile, oscommandline->osol);
768 nl2os = new OSnl2OS();
769 nl2os->readNl(oscommandline->nlFile);
770 nl2os->setOsol(oscommandline->osol);
771 nl2os->createOSObjects() ;
772 osinstance = nl2os->osinstance;
773 if (nl2os->osoption != NULL)
774 {
775 osoption = nl2os->osoption;
776 //write out the options
777 OSoLWriter *osolwriter = NULL;
778 osolwriter = new OSoLWriter();
779 //osolwriter->m_bWhiteSpace = true;
780 std::string sModelOptionName = "modelOptions.osol";
781 if (fileUtil == NULL) fileUtil = new FileUtil();
782 fileUtil->writeFileFromString(sModelOptionName, osolwriter->writeOSoL( osoption) );
783 delete fileUtil;
784 fileUtil = NULL;
785 delete osolwriter;
786 osolwriter = NULL;
787 }
788
789#else
790 throw ErrorClass(
791 "nl file specified locally but ASL not present");
792#endif
793 }
794 else
795 {
796 if (oscommandline->mpsFile != "")
797 {
798 mps2osil = new OSmps2osil(oscommandline->mpsFile);
799 mps2osil->createOSInstance();
800 osinstance = mps2osil->osinstance;
801 }
802 else
803 {
804 if (oscommandline->gamsControlFile != "")
805 {
806#ifdef COIN_HAS_GAMSUTILS
807 gams2osil = new OSgams2osil( oscommandline->gamsControlFile);
808 gams2osil->createOSInstance();
809 osinstance = gams2osil->osinstance;
810#else
811 throw ErrorClass(
812 "a Gams Control specified locally but GAMSIP not present");
813#endif
814
815 }
816 else // need an osol file with an instanceLocation specified
817 {
818 throw ErrorClass(
819 "Error: no osil, GAMSS dat, AMPL nl, or mps file given for a local solve --- \n NOTE: information in the osol file is ignored for local solves.");
820 }
821 }
822 }
823 }
824 if (oscommandline->printModel)
825 doPrintModel(osinstance);
826 else if (oscommandline->printRowNumberAsString != "")
827 doPrintRow(osinstance, oscommandline->printRowNumberAsString);
828
829 osrl = runSolver(oscommandline->solverName, oscommandline->osol, osinstance);
830
831 if (oscommandline->osrlFile != "")
832 {
833 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
834
835 //const char *ch1 = "/Applications/Firefox.app/Contents/MacOS/firefox ";
836 if (oscommandline->browser != "")
837 {
838 std::string str = oscommandline->browser + " "
839 + oscommandline->osrlFile;
840 const char *ch = &str[0];
841 std::system(ch);
842 }
843 }
844 else
846
847 }//end of local solve
848
849
850 //garbage collection
851 if (osilreader != NULL)
852 delete osilreader;
853 osilreader = NULL;
854 if (mps2osil != NULL)
855 delete mps2osil;
856 mps2osil = NULL;
857#ifdef COIN_HAS_ASL
858 if(nl2os != NULL) delete nl2os;
859 nl2os = NULL;
860#endif
861#ifdef COIN_HAS_GAMSUTILS
862 if(gams2osil != NULL) delete gams2osil;
863 gams2osil = NULL;
864#endif
865 delete fileUtil;
866 fileUtil = NULL;
867
868 }//end try
869 catch (const ErrorClass& eclass)
870 {
871 std::string osrl = "";
872 OSResult *osresult = NULL;
873 OSrLWriter *osrlwriter = NULL;
874 //first check to see if we already have OSrL,
875 //if so don't create a new osresult object
876 std::string::size_type pos1 = eclass.errormsg.find( "<osrl");
877 if(pos1 == std::string::npos)
878 {
879 osrlwriter = new OSrLWriter();
880 osresult = new OSResult();
883 osrl = osrlwriter->writeOSrL(osresult);
884 }
885 else
886 {
887 osrl = eclass.errormsg;
888 }
889 if (oscommandline->osrlFile != "")
890 {
891 //fileUtil->writeFileFromString(oscommandline->osrlFile, eclass.errormsg);
892 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
893 if (oscommandline->browser != "")
894 {
895 std::string str = oscommandline->browser + " "
896 + oscommandline->osrlFile;
897 const char *ch = &str[0];
898 std::system(ch);
899 }
900 }
901 else
902 {
904 }
905 //catch garbage collection
906 if(osresult != NULL)
907 {
908 delete osresult;
909 osresult = NULL;
910 }
911 if(osrlwriter != NULL)
912 {
913 delete osrlwriter;
914 osrlwriter = NULL;
915 }
916
917 //regular garbage collection
918 if (osilreader != NULL)
919 delete osilreader;
920 osilreader = NULL;
921 if (mps2osil != NULL)
922 delete mps2osil;
923 mps2osil = NULL;
924#ifdef COIN_HAS_ASL
925 if(nl2os != NULL) delete nl2os;
926 nl2os = NULL;
927#endif
928#ifdef COIN_HAS_GAMSUTILS
929 if(gams2osil != NULL) delete gams2osil;
930 gams2osil = NULL;
931#endif
932 delete fileUtil;
933 fileUtil = NULL;
934 }//end local catch
935
936}//end solve
937
938void getJobID(OSCommandLine *oscommandline)
939{
940 OSSolverAgent* osagent = NULL;
941 try
942 {
943 if (oscommandline->serviceLocation != "")
944 {
945 osagent = new OSSolverAgent(oscommandline->serviceLocation);
946 oscommandline->jobID = osagent->getJobID(oscommandline->osol);
948 delete osagent;
949 osagent = NULL;
950 }
951 else
952 {
953 delete osagent;
954 osagent = NULL;
955 throw ErrorClass("please specify service location (url)");
956 }
957 }
958 catch (const ErrorClass& eclass)
959 {
960 FileUtil *fileUtil = NULL;
961 fileUtil = new FileUtil();
962
963
964 std::string osrl = "";
965 OSResult *osresult = NULL;
966 OSrLWriter *osrlwriter = NULL;
967 //first check to see if we already have OSrL,
968 //if so don't create a new osresult object
969 string::size_type pos1 = eclass.errormsg.find( "<osrl");
970 if(pos1 == std::string::npos)
971 {
972 osrlwriter = new OSrLWriter();
973 osresult = new OSResult();
976 osrl = osrlwriter->writeOSrL(osresult);
977 }
978 else
979 {
980 osrl = eclass.errormsg;
981 }
982
983
984 //catch garbage collection
985 if(osresult != NULL)
986 {
987 delete osresult;
988 osresult = NULL;
989 }
990 if(osrlwriter != NULL)
991 {
992 delete osrlwriter;
993 osrlwriter = NULL;
994 }
995
996
997 delete fileUtil;
998 fileUtil = NULL;
999 }
1000}//end getJobID
1001
1002
1003void knock(OSCommandLine *oscommandline)
1004{
1005 std::string osplOutput = "";
1006 OSSolverAgent* osagent = NULL;
1007 FileUtil *fileUtil = NULL;
1008 fileUtil = new FileUtil();
1009 try
1010 {
1011 if (oscommandline->serviceLocation != "")
1012 {
1013 osagent = new OSSolverAgent(oscommandline->serviceLocation);
1014
1015
1016 if (oscommandline->osol == "")
1017 {
1018 // we need to construct the OSoL
1019 OSOption *osOption = NULL;
1020 osOption = new OSOption();
1021 //set the jobID if there is one
1022 if(oscommandline->jobID == "") osOption->setJobID( oscommandline->jobID);
1023 // now read the osOption object into a string
1024 OSoLWriter *osolWriter = NULL;
1025 osolWriter = new OSoLWriter();
1026 oscommandline->osol = osolWriter->writeOSoL( osOption);
1027 delete osOption;
1028 osOption = NULL;
1029 delete osolWriter;
1030 osolWriter = NULL;
1031 }
1032
1033
1034 osplOutput = osagent->knock(oscommandline->osplInput, oscommandline->osol);
1035 if (oscommandline->osplOutputFile != "")
1036 fileUtil->writeFileFromString(oscommandline->osplOutputFile,
1037 osplOutput);
1038 else
1040 delete osagent;
1041 }
1042 else
1043 {
1044 delete osagent;
1045 throw ErrorClass("please specify service location (url)");
1046 }
1047 delete fileUtil;
1048 fileUtil = NULL;
1049 }
1050 catch (const ErrorClass& eclass)
1051 {
1052 std::string osrl = "";
1053 OSResult *osresult = NULL;
1054 OSrLWriter *osrlwriter = NULL;
1055 //first check to see if we already have OSrL,
1056 //if so don't create a new osresult object
1057 string::size_type pos1 = eclass.errormsg.find( "<osrl");
1058 if(pos1 == std::string::npos)
1059 {
1060 osrlwriter = new OSrLWriter();
1061 osresult = new OSResult();
1064 std::string osrl = osrlwriter->writeOSrL(osresult);
1065 }
1066 else
1067 {
1068 osrl = eclass.errormsg;
1069 }
1070
1071 if(osresult != NULL)
1072 {
1073 delete osresult;
1074 osresult = NULL;
1075 }
1076 if(osrlwriter != NULL)
1077 {
1078 delete osrlwriter;
1079 osrlwriter = NULL;
1080 }
1081
1082
1083 delete fileUtil;
1084 fileUtil = NULL;
1085 }
1086}//end knock
1087
1088
1089void send(OSCommandLine *oscommandline)
1090{
1091 bool bSend = false;
1092
1093
1094 OSSolverAgent* osagent = NULL;
1095 try
1096 {
1097 // call a method here to get OSiL if we have an nl or mps file
1098 if (oscommandline->osil == "")
1099 {
1100 //we better have an nl file present or mps file
1101 if (oscommandline->nlFile != "")
1102 {
1103 getOSiLFromNl(oscommandline);
1104 }
1105 else
1106 {
1107 if (oscommandline->mpsFile != "")
1108 {
1109 getOSiLFromMps(oscommandline);
1110 }
1111 else // send an empty osil string
1112 {
1113 oscommandline->osil = "";
1114 }
1115 }
1116 }
1117 if (oscommandline->serviceLocation != "")
1118 {
1119 osagent = new OSSolverAgent(oscommandline->serviceLocation);
1120 // check to see if there is an osol
1121 if (oscommandline->osol == "")
1122 {
1123 // we need to construct the OSoL
1124 OSOption *osOption = NULL;
1125 osOption = new OSOption();
1126 // get a jobId if necessary
1127 if(oscommandline->jobID == "") oscommandline->jobID = osagent->getJobID("");
1128 //set the jobID
1129
1130 osOption->setJobID( oscommandline->jobID);
1131 // now read the osOption object into a string
1132 OSoLWriter *osolWriter = NULL;
1133 osolWriter = new OSoLWriter();
1134 oscommandline->osol = osolWriter->writeOSoL( osOption);
1135 delete osOption;
1136 osOption = NULL;
1137 delete osolWriter;
1138 osolWriter = NULL;
1139 }
1140 bSend = osagent->send(oscommandline->osil, oscommandline->osol);
1141 if(bSend == true)
1142 osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_info, "Successful send");
1143 else
1145 "Send failed, check to make sure you sent a jobID not on the system.");
1146
1147 delete osagent;
1148 }
1149 else
1150 {
1151 delete osagent;
1152 throw ErrorClass("please specify service location (url)");
1153 }
1154 }
1155 catch (const ErrorClass& eclass)
1156 {
1157 std::string osrl = "";
1158 FileUtil *fileUtil = NULL;
1159 fileUtil = new FileUtil();
1160 OSResult *osresult = NULL;
1161 OSrLWriter *osrlwriter = NULL;
1162 //first check to see if we already have OSrL,
1163 //if so don't create a new osresult object
1164 string::size_type pos1 = eclass.errormsg.find( "<osrl");
1165 if(pos1 == std::string::npos)
1166 {
1167 osrlwriter = new OSrLWriter();
1168 osresult = new OSResult();
1171 osrl = osrlwriter->writeOSrL(osresult);
1172 }
1173 else
1174 {
1175 osrl = eclass.errormsg;
1176 }
1177
1178
1179 if (oscommandline->osrlFile != "")
1180 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
1181 else
1183
1184 if(osresult != NULL)
1185 {
1186 delete osresult;
1187 osresult = NULL;
1188 }
1189 if(osrlwriter != NULL)
1190 {
1191 delete osrlwriter;
1192 osrlwriter = NULL;
1193 }
1194 delete fileUtil;
1195 fileUtil = NULL;
1196 }
1197}//end send
1198
1199void retrieve(OSCommandLine *oscommandline)
1200{
1201 FileUtil *fileUtil = NULL;
1202 fileUtil = new FileUtil();
1203 std::string osrl = "";
1204 OSSolverAgent* osagent = NULL;
1205 try
1206 {
1207 if (oscommandline->serviceLocation != "")
1208 {
1209 osagent = new OSSolverAgent(oscommandline->serviceLocation);
1210
1211
1212 if (oscommandline->osol == "")
1213 {
1214 // we need to construct the OSoL
1215 OSOption *osOption = NULL;
1216 osOption = new OSOption();
1217 // get a jobId if necessary
1218 if(oscommandline->jobID == "")throw ErrorClass("there is no JobID");
1219 //set the jobID
1220 osOption->setJobID( oscommandline->jobID);
1221 // now read the osOption object into a string
1222 OSoLWriter *osolWriter = NULL;
1223 osolWriter = new OSoLWriter();
1224 oscommandline->osol = osolWriter->writeOSoL( osOption);
1225 delete osOption;
1226 osOption = NULL;
1227 delete osolWriter;
1228 osolWriter = NULL;
1229 }
1230
1231 osrl = osagent->retrieve(oscommandline->osol);
1232
1233 if (oscommandline->osrlFile != "")
1234 {
1235 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
1236
1237 std::ostringstream outStr;
1238
1239 outStr.str("");
1240 outStr.clear();
1241 outStr << "Solver Result Written to File: " << oscommandline->osrlFile << endl;
1242 osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_info, outStr.str());
1243 if (oscommandline->browser != "")
1244 {
1245 std::string str = oscommandline->browser + " "
1246 + oscommandline->osrlFile;
1247 const char *ch = &str[0];
1248 std::system(ch);
1249 }
1250 }
1251 else
1253 delete osagent;
1254 osagent = NULL;
1255 }
1256 else
1257 {
1258 delete osagent;
1259 osagent = NULL;
1260 throw ErrorClass("please specify service location (url)");
1261 }
1262 delete fileUtil;
1263 fileUtil = NULL;
1264 }
1265 catch (const ErrorClass& eclass)
1266 {
1267
1268 std::string osrl = "";
1269 OSResult *osresult = NULL;
1270 OSrLWriter *osrlwriter = NULL;
1271 //first check to see if we already have OSrL,
1272 //if so don't create a new osresult object
1273 string::size_type pos1 = eclass.errormsg.find( "<osrl");
1274 if(pos1 == std::string::npos)
1275 {
1276 osrlwriter = new OSrLWriter();
1277 osresult = new OSResult();
1280 osrl = osrlwriter->writeOSrL(osresult);
1281 }
1282 else
1283 {
1284 osrl = eclass.errormsg;
1285 }
1286
1287 if(osresult != NULL)
1288 {
1289 delete osresult;
1290 osresult = NULL;
1291 }
1292 if(osrlwriter != NULL)
1293 {
1294 delete osrlwriter;
1295 osrlwriter = NULL;
1296 }
1297
1298
1299 delete fileUtil;
1300 fileUtil = NULL;
1301 }
1302}//end retrieve
1303
1304void kill(OSCommandLine *oscommandline)
1305{
1306 FileUtil *fileUtil = NULL;
1307 fileUtil = new FileUtil();
1308 std::string osplOutput = "";
1309 OSSolverAgent* osagent = NULL;
1310 try
1311 {
1312 if (oscommandline->serviceLocation != "")
1313 {
1314 osagent = new OSSolverAgent(oscommandline->serviceLocation);
1315
1316 if (oscommandline->osol == "")
1317 {
1318 // we need to construct the OSoL
1319 OSOption *osOption = NULL;
1320 osOption = new OSOption();
1321 // get a jobId if necessary
1322 if(oscommandline->jobID == "")throw ErrorClass("there is no JobID");
1323 //set the jobID
1324 osOption->setJobID( oscommandline->jobID);
1325 // now read the osOption object into a string
1326 OSoLWriter *osolWriter = NULL;
1327 osolWriter = new OSoLWriter();
1328 oscommandline->osol = osolWriter->writeOSoL( osOption);
1329 delete osOption;
1330 osOption = NULL;
1331 delete osolWriter;
1332 osolWriter = NULL;
1333 }
1334
1335 osplOutput = osagent->kill(oscommandline->osol);
1336
1337 if (oscommandline->osplOutputFile != "")
1338 fileUtil->writeFileFromString(oscommandline->osplOutputFile,
1339 osplOutput);
1340 else
1342 delete osagent;
1343 osagent = NULL;
1344 }
1345 else
1346 {
1347 delete osagent;
1348 osagent = NULL;
1349 throw ErrorClass("please specify service location (url)");
1350 }
1351 delete fileUtil;
1352 fileUtil = NULL;
1353 }
1354 catch (const ErrorClass& eclass)
1355 {
1356
1357 std::string osrl = "";
1358 OSResult *osresult = NULL;
1359 OSrLWriter *osrlwriter = NULL;
1360 //first check to see if we already have OSrL,
1361 //if so don't create a new osresult object
1362 string::size_type pos1 = eclass.errormsg.find( "<osrl");
1363 if(pos1 == std::string::npos)
1364 {
1365 osrlwriter = new OSrLWriter();
1366 osresult = new OSResult();
1369 osrl = osrlwriter->writeOSrL(osresult);
1370 }
1371 else
1372 {
1373 osrl = eclass.errormsg;
1374 }
1375
1376
1377 if(osresult != NULL)
1378 {
1379 delete osresult;
1380 osresult = NULL;
1381 }
1382 if(osrlwriter != NULL)
1383 {
1384 delete osrlwriter;
1385 osrlwriter = NULL;
1386 }
1387
1388
1389 delete fileUtil;
1390 fileUtil = NULL;
1391 }
1392}//end kill
1393
1398void getOSiLFromNl(OSCommandLine *oscommandline)
1399{
1400 try
1401 {
1402#ifdef COIN_HAS_ASL
1403 OSnl2OS *nl2os = NULL;
1404 nl2os = new OSnl2OS();
1405 nl2os->readNl(oscommandline->nlFile);
1406 nl2os->setOsol(oscommandline->osol);
1407 nl2os->createOSObjects();
1408 OSiLWriter *osilwriter = NULL;
1409 osilwriter = new OSiLWriter();
1410 std::string osil;
1411 osil = osilwriter->writeOSiL( nl2os->osinstance);
1412 oscommandline->osil = osil;
1413 delete nl2os;
1414 nl2os = NULL;
1415 delete osilwriter;
1416 osilwriter = NULL;
1417#else
1418 throw ErrorClass(
1419 "trying to convert nl to osil without AMPL ASL configured");
1420#endif
1421 }
1422 catch (const ErrorClass& eclass)
1423 {
1425 throw ErrorClass(eclass.errormsg);
1426 }
1427}//getOSiLFromNl
1428
1429
1430void getOSiLFromGams(OSCommandLine *oscommandline)
1431{
1432 try
1433 {
1434#ifdef COIN_HAS_GAMSIO
1435 OSgams2osil *gams2osil = NULL;
1436 gams2osil = new OSgams2osil( oscommandline->gamsControlFile);
1437 gams2osil->createOSInstance();
1438 OSiLWriter *osilwriter = NULL;
1439 osilwriter = new OSiLWriter();
1440 std::string osil;
1441 osil = osilwriter->writeOSiL( gams2osil->osinstance);
1442 oscommandline->osil = osil;
1443 delete gams2osil;
1444 gams2osil = NULL;
1445 delete osilwriter;
1446 osilwriter = NULL;
1447#else
1448 throw ErrorClass(
1449 "trying to convert Gams control file to osil without GAMSUTILS configured");
1450#endif
1451 }
1452 catch (const ErrorClass& eclass)
1453 {
1455 throw ErrorClass(eclass.errormsg);
1456 }
1457}//getOSiLFromGams
1458
1459
1460void getOSiLFromMps(OSCommandLine *oscommandline)
1461{
1462 try
1463 {
1464 OSmps2osil *mps2osil = NULL;
1465 mps2osil = new OSmps2osil(oscommandline->mpsFile);
1466 mps2osil->createOSInstance();
1467 OSiLWriter *osilwriter = NULL;
1468 osilwriter = new OSiLWriter();
1469 std::string osil;
1470 osil = osilwriter->writeOSiL(mps2osil->osinstance);
1471 oscommandline->osil = osil;
1472 delete mps2osil;
1473 mps2osil = NULL;
1474 delete osilwriter;
1475 osilwriter = NULL;
1476 }
1477 catch (const ErrorClass& eclass)
1478 {
1480 throw ErrorClass(eclass.errormsg);
1481 }
1482
1483}//getOSiLFromMps
1484
1485
1488inline void getServiceLocation(OSCommandLine *oscommandline)
1489{
1490 std::cout
1491 << std::endl
1492 << "A service location is required"
1493 << std::endl;
1494 std::cout
1495 << "Please type the URL of the remote service: ";
1496 getline(std::cin, oscommandline->serviceLocation);
1497}
1498
1500{
1501 void* scanner;
1502 FileUtil *fileUtil = NULL;
1503 //char *config = "-config";
1504 std::string configFileName = "";
1505
1506
1507 OSCommandLine *oscommandline = new OSCommandLine();
1508 bool scannerActive = false;
1509
1510 //this is the interactive shell
1511 scannerActive = true;
1513 setyyextra(oscommandline, scanner);
1514 std::string lineText;
1515 //use a blank to separate words
1516 std::string wordSep = " ";
1517 std::string dblQuote = "\"";
1518 std::string optionName = "";
1519 std::string optionValue = "";
1520 std::string::size_type indexStart;
1521 std::string::size_type indexEnd;
1522 unsigned int k;
1523
1524 const int nCommands = 14;
1525 std::string commandArray[nCommands] =
1526 { "solve", "send", "getJobID", "retrieve", "kill", "knock",
1527 "quit", "exit", "reset", "list", "?", "help", "version",
1528 "printModel"
1529 };
1530
1531 const int nOptions = 14;
1532 std::string optionArray[nOptions] =
1533 { "osil", "osrl", "osol", "mps", "nl", "dat",
1534 "serviceLocation", "solver", "osplInput", "osplOutput",
1535 "printRow", "printLevel", "logFile", "fileLogLevel"
1536 };
1537
1538 //fill in the command array into a map
1539
1540 std::map<string, int> commandMap;
1541
1542 for(k = 0; k < nCommands; k++)
1543 {
1544 commandMap[ commandArray[ k] ] = k;
1545 }
1546
1547 //fill in the option array into a map
1548
1549 std::map<string, int> optionMap;
1550
1551 for(k = 0; nOptions; k++)
1552 {
1553 optionMap[ optionArray[ k] ] = k;
1554 }
1555
1556 std::cout << "At the prompt enter a valid command or option value pair.\n";
1557 std::cout << "Enter the \"solve\" command to optimize.\n";
1558 std::cout << "Type \"quit\" or \"exit\" to leave the application. \n";
1559 std::cout << "Type \"help\" or \"?\" for a list of valid options.\n\n";
1560
1561 while (oscommandline->quit != true)
1562 {
1563 std::cout << "Please enter a command, or an option followed by an option value: ";
1564 getline(std::cin, lineText);
1565 lineText = " " + lineText + " ";
1566 //get the name of the option
1567 indexStart = lineText.find_first_not_of(wordSep);
1568 if (indexStart == string::npos)
1569 {
1570 std::cout << std::endl;
1571 std::cout << "You did not enter a valid option. "
1572 << "Type \"help\" or \"?\" for a list of valid options."
1573 << std::endl;
1574 }
1575 else
1576 {
1577 indexEnd = lineText.find_first_of(wordSep, indexStart + 1);
1578 optionName = lineText.substr(indexStart, indexEnd - indexStart);
1579 //std::cout << "Option Name = " << optionName << std::endl;
1580
1581 if( (commandMap.find(optionName) == commandMap.end() ) &&
1582 (optionMap.find(optionName) == optionMap.end() ) )
1583 {
1584 std::cout << std::endl;
1585 std::cout << "You did not enter a valid option. "
1586 << "Type \"help\" or \"?\" for a list of valid options."
1587 << std::endl;
1588 }
1589 else
1590 {
1591 int skipChars;
1592 // get the option value
1593
1594 indexStart = lineText.find_first_not_of(wordSep, indexEnd + 1);
1595 if (indexStart != std::string::npos && lineText[indexStart] == '\"')
1596 {
1597 indexEnd = lineText.find_first_of(dblQuote, indexStart + 1);
1598 skipChars = 1;
1599 }
1600 else
1601 {
1602 indexEnd = lineText.find_first_of(wordSep, indexStart + 1);
1603 skipChars = 0;
1604 }
1605 if (indexStart != std::string::npos && indexEnd != std::string::npos)
1606 {
1607 optionValue = lineText.substr(indexStart + skipChars,
1608 indexEnd - indexStart - skipChars);
1609 }
1610 else
1611 {
1612 optionValue = "";
1613 }
1614
1615 //std::cout << "Option Value = " << optionValue << std::endl;
1616
1617 try
1618 {
1619 // first we process the commands
1620 if( commandMap.find(optionName) != commandMap.end() )
1621 {
1622 switch (commandMap[ optionName] )
1623 {
1624
1625 case 0: // solve command
1626
1627 if(oscommandline->osil == "" && oscommandline->mps == "" && oscommandline->nl == "")
1628 {
1629 std::cout
1630 << std::endl
1631 << "You did not specify an optimization instance!!!\n"
1632 << "Please enter file format option (osil, nl, or mps) \n"
1633 << "followed by the option value which is the file location. \n"
1634 << std::endl;
1635 }
1636 else
1637 {
1638 solve(oscommandline);
1639 if (oscommandline->osrlFile != "")
1640 std::cout << "\nSolve command executed. Please see " << oscommandline->osrlFile << " for results." << std::endl;
1641 }
1642 break;
1643
1644 case 1: // send command
1645
1646 if(oscommandline->serviceLocation == "")
1647 getServiceLocation(oscommandline);
1648 send(oscommandline);
1649 break;
1650
1651
1652 case 2: // getJobID command
1653
1654 if(oscommandline->serviceLocation == "")
1655 getServiceLocation(oscommandline);
1656 getJobID(oscommandline);
1657 break;
1658
1659
1660 case 3: // retrieve command
1661
1662 if(oscommandline->serviceLocation == "")
1663 getServiceLocation(oscommandline);
1664
1665 if( (oscommandline->osolFile == "") && (oscommandline->jobID == "") )
1666 {
1667 std::cout
1668 << std::endl
1669 << "Cannot retrieve: no JobID and no OSoL file"
1670 << std::endl;
1671 }
1672 else
1673 {
1674 retrieve(oscommandline);
1675 }
1676
1677 break;
1678
1679 case 4: // kill command
1680
1681
1682 if(oscommandline->serviceLocation == "")
1683 getServiceLocation(oscommandline);
1684
1685 if( (oscommandline->osolFile == "") && (oscommandline->jobID == "") )
1686 {
1687 std::cout
1688 << std::endl
1689 << "Cannot kill: no JobID and no OSoL file"
1690 << std::endl;
1691 }
1692 else
1693 {
1694 kill(oscommandline);
1695 }
1696
1697
1698 break;
1699
1700
1701 case 5: // knock command
1702
1703 //note -- can have empty OSoL for knock
1704 //however we do need an OSpL file
1705
1706 if(oscommandline->serviceLocation == "")
1707 getServiceLocation(oscommandline);
1708
1709 if( oscommandline->osplInputFile == "")
1710 {
1711 std::cout
1712 << std::endl
1713 << "Cannot knock -- no OSplInputFile specified"
1714 << std::endl;
1715 }
1716 else
1717 {
1718 knock(oscommandline);
1719 }
1720
1721 break;
1722
1723
1724 case 6: // quit command
1725
1726 return;
1727
1728
1729
1730 case 7: // exit command
1731
1732 return;
1733
1734
1735
1736 case 8: // reset command
1737
1738 oscommandline->reset_options();
1739 std::cout << "\nAll options reset.\n";
1740 break;
1741
1742
1743
1744 case 9: // list command
1745
1746 list_options(oscommandline);
1747 break;
1748
1749
1750 case 10: // ? command
1751
1752 std::cout << get_options() << std::endl;
1753 break;
1754
1755
1756 case 11: // help command
1757
1758 std::cout << get_options() << std::endl;
1759 break;
1760
1761
1762 case 12: // version command
1763
1764 std::cout << OSgetVersionInfo() << std::endl;
1765 break;
1766
1767
1768 case 13: // printModel
1769
1770 doPrintModel(oscommandline);
1771 break;
1772
1773
1774 default:
1775 throw ErrorClass("we don't have a valid command");
1776
1777
1778 } //end switch
1779
1780 }
1781 else // now in the case where we require option values
1782 {
1783
1784 if (optionValue == "")
1785 {
1786
1787 if(optionMap.find(optionName) != optionMap.end() )
1788 {
1789
1790 switch (optionMap[ optionName] )
1791 {
1792
1793 case 0: //osil
1794 std::cout
1795 << "Please enter the name of an osil file: ";
1796 break;
1797
1798
1799 case 1: //osrl
1800 std::cout
1801 << "Please enter the name of an osrl file: ";
1802 break;
1803
1804 case 2: //osol
1805 std::cout
1806 << "Please enter the name of an osol file: ";
1807 break;
1808
1809 case 3: //mps
1810 std::cout
1811 << "Please enter the name of an mps file: ";
1812 break;
1813
1814 case 4: //nl
1815 std::cout
1816 << "Please enter the name of an AMPL nl file: ";
1817 break;
1818
1819 case 5: //dat
1820 std::cout
1821 << "Please enter the name of a dat file: ";
1822 break;
1823
1824 case 6: //service location
1825 std::cout
1826 << "Please enter the serviceLocation: ";
1827 break;
1828
1829 case 7: //solver
1830 std::cout
1831 << "Please enter the name of the solver: ";
1832 break;
1833
1834 case 8: //osplInput
1835 std::cout
1836 << "Please enter the name of an osplInput file: ";
1837 break;
1838
1839 case 9: //osplOutput
1840 std::cout
1841 << "Please enter the name of an osplOutput file: ";
1842 break;
1843
1844 case 10: //printRow
1845 std::cout
1846 << "Please enter the number of a constraint (>=0) or objective (<0): ";
1847 break;
1848
1849 case 11: //printLevel
1850 std::cout
1851 << "Please enter the print level (0-"
1853 break;
1854
1855 case 12: //logFile
1856 std::cout
1857 << "Please enter the name of the log file: ";
1858 break;
1859
1860 case 13: //filePrintLevel
1861 std::cout
1862 << "Please enter the print level (0-"
1864 break;
1865
1866
1867 }// end switch
1868
1869 // now get the option value
1870 getline(std::cin, lineText);
1871
1872 int skipChars;
1873
1874 indexStart = lineText.find_first_not_of(wordSep, 0);
1875 if (lineText[indexStart] == '\"')
1876 {
1877 indexEnd = lineText.find_first_of(dblQuote, indexStart + 1);
1878 skipChars = 1;
1879 }
1880 else
1881 {
1882 indexEnd = lineText.find_first_of(wordSep, indexStart + 1);
1883 skipChars = 0;
1884 }
1885 if (indexStart != std::string::npos && indexEnd != std::string::npos)
1886 {
1887 optionValue = lineText.substr(indexStart + skipChars,
1888 indexEnd - indexStart - skipChars);
1889 }
1890 else
1891 {
1892 optionValue = "";
1893 }
1894
1895
1896 }// end if on finding an element in the optionMap
1897
1898 } // end if on whether or not option value is null
1899
1900
1901 if(optionMap.find(optionName) != optionMap.end() )
1902 {
1903 switch (optionMap[ optionName] )
1904 {
1905
1906 case 0: //osil
1907 oscommandline->osilFile = optionValue;
1908 oscommandline->osil
1909 = fileUtil->getFileAsString(
1910 (oscommandline->osilFile).c_str());
1911 break;
1912
1913
1914 case 1: //osrl
1915 oscommandline->osrlFile = optionValue;
1916 break;
1917
1918 case 2: //osol
1919 oscommandline->osolFile = optionValue;
1920 oscommandline->osol
1921 = fileUtil->getFileAsString(
1922 (oscommandline->osolFile).c_str());
1923 break;
1924
1925 case 3: //mps
1926 oscommandline->mpsFile = optionValue;
1927 oscommandline->mps
1928 = fileUtil->getFileAsString(
1929 (oscommandline->mpsFile).c_str());
1930 break;
1931
1932 case 4: //nl
1933 oscommandline->nlFile = optionValue;
1934 oscommandline->nl
1935 = fileUtil->getFileAsString(
1936 (oscommandline->nlFile).c_str());
1937 break;
1938
1939 case 5: //dat
1940 oscommandline->datFile = optionValue;
1941 oscommandline->dat
1942 = fileUtil->getFileAsString(
1943 (oscommandline->datFile).c_str());
1944 break;
1945
1946 case 6: //service location
1947 oscommandline->serviceLocation = optionValue;
1948 break;
1949
1950 case 7: //solver
1951
1952 //make solver name lower case
1953 for (k = 0; k
1954 < oscommandline->solverName.length(); k++)
1955 {
1956 oscommandline->solverName[k] =
1957 (char)tolower(oscommandline->solverName[k]);
1958 }
1959 oscommandline->solverName = optionValue;
1960 break;
1961
1962 case 8: //osplInput
1963 oscommandline->osplInputFile = optionValue;
1964 oscommandline->osplInput
1965 = fileUtil->getFileAsString(
1966 (oscommandline->osplInputFile).c_str());
1967 break;
1968
1969 case 9: //osplOutput
1970 oscommandline->osplOutputFile = optionValue;
1971 break;
1972
1973 case 10: //printRow
1974 oscommandline->printRowNumberAsString = optionValue;
1975 doPrintRow(oscommandline);
1976 break;
1977
1978 case 11: //printLevel
1979 std::cout
1980 << "Please enter the print level (0-"
1982 break;
1983
1984 case 12: //logFile
1985 std::cout
1986 << "Please enter the name of the log file: ";
1987 break;
1988
1989 case 13: //filePrintLevel
1990 std::cout
1991 << "Please enter the print level (0-"
1993 break;
1994
1995 }// end switch
1996 list_options( oscommandline);
1997
1998 }// end if on finding an element in the optionMap
1999
2000 } // end if on options that require a value
2001
2002 std::cout << std::endl;
2003 }//end try
2004 catch (const ErrorClass& eclass)
2005 {
2006 std::cout << eclass.errormsg << std::endl;
2007 }
2008 }
2009 }
2010 }//end while loop
2012 scannerActive = false;
2013 delete oscommandline;
2014 oscommandline = NULL;
2015 delete fileUtil;
2016 fileUtil = NULL;
2017} // end of interactiveShell
2018
2019std::string get_help()
2020{
2021 std::ostringstream helpMsg;
2022
2023 helpMsg << "************************* HELP *************************"
2024 << endl << endl;
2025 helpMsg
2026 << "In this HELP file we assume that the solve service method is used and "
2027 << endl;
2028 helpMsg
2029 << "that we are solving problems locally, that is the solver is on the "
2030 << endl;
2031 helpMsg
2032 << "machine running this OSSolverService. See Section 10.3 of the User\'s "
2033 << endl;
2034 helpMsg
2035 << "Manual for other service methods or calling a server remotely. "
2036 << endl;
2037 helpMsg << "The OSSolverService takes the parameters listed below. "
2038 << endl;
2039 helpMsg
2040 << "The order of the parameters is irrelevant. Not all the parameters "
2041 << endl;
2042 helpMsg << "are required. However, the location of an instance file is "
2043 << endl;
2044 helpMsg
2045 << "required when using the solve service method. The location of the "
2046 << endl;
2047 helpMsg << "instance file is specified using the osil option. " << endl;
2048
2049 helpMsg << endl;
2050
2051 helpMsg
2052 << "-osil xxx.osil this is the name of the file that contains the "
2053 << endl;
2054 helpMsg << "optimization instance in OSiL format. This option may be "
2055 << endl;
2056 helpMsg << "specified in the OSoL solver options file. " << endl;
2057
2058 helpMsg << endl;
2059
2060 helpMsg
2061 << "-osol xxx.osol this is the name of the file that contains the solver options. "
2062 << endl;
2063 helpMsg << "It is not necessary to specify this option. " << endl;
2064
2065 helpMsg << endl;
2066
2067 helpMsg
2068 << "-osrl xxx.osrl this is the name of the file to which the solver solution is written. "
2069 << endl;
2070 helpMsg
2071 << "It is not necessary to specify this option. If this option is not specified, "
2072 << endl;
2073 helpMsg << "the result will be printed to standard out. " << endl;
2074
2075 helpMsg << endl;
2076
2077 helpMsg
2078 << "-osplInput xxx.ospl this is the name of an input file in the OS Process"
2079 << endl;
2080 helpMsg << " Language (OSpL), this is used as input to the knock method."
2081 << endl;
2082
2083 helpMsg << endl;
2084
2085 helpMsg
2086 << "-osplOutput xxx.ospl this is the name of an output file in the OS Process"
2087 << endl;
2088 helpMsg
2089 << "Language (OSpL), this the output string from the knock and kill methods."
2090 << endl;
2091
2092 helpMsg << endl;
2093
2094 helpMsg << "-serviceLocation url is the URL of the solver service. "
2095 << endl;
2096 helpMsg
2097 << "This is not required, and if not specified it is assumed that "
2098 << endl;
2099 helpMsg << "the problem is solved locally. " << endl;
2100
2101 helpMsg << endl;
2102
2103 helpMsg
2104 << "-serviceMethod methodName this is the method on the solver service to be invoked. "
2105 << endl;
2106 helpMsg
2107 << "The options are solve, send, kill, knock, getJobID, and retrieve. "
2108 << endl;
2109 helpMsg
2110 << "This option is not required, and the default value is solve. "
2111 << endl;
2112
2113 helpMsg << endl;
2114
2115 helpMsg
2116 << "-mps xxx.mps this is the name of the mps file if the problem instance "
2117 << endl;
2118 helpMsg
2119 << "is in mps format. The default file format is OSiL so this option is not required. "
2120 << endl;
2121
2122 helpMsg << endl;
2123
2124 helpMsg
2125 << "-nl xxx.nl this is the name of the AMPL nl file if the problem "
2126 << endl;
2127 helpMsg
2128 << "instance is in AMPL nl format. The default file format is OSiL "
2129 << endl;
2130 helpMsg << "so this option is not required. " << endl;
2131
2132 helpMsg << endl;
2133
2134 helpMsg
2135 << "-solver solverName Possible values for default OS installation "
2136 << endl;
2137 helpMsg
2138 << "are bonmin(COIN-OR Bonmin), couenne (COIN-OR Couenne), clp (COIN-OR Clp),"
2139 << endl;
2140 helpMsg << "cbc (COIN-OR Cbc), dylp (COIN-OR DyLP), ipopt (COIN-OR Ipopt),"
2141 << endl;
2142 helpMsg << "and symphony (COIN-OR SYMPHONY). Other solvers supported"
2143 << endl;
2144 helpMsg
2145 << "(if the necessary libraries are present) are cplex (Cplex through COIN-OR Osi),"
2146 << endl;
2147 helpMsg
2148 << "glpk (glpk through COIN-OR Osi), knitro (Knitro), and lindo (LINDO)."
2149 << endl;
2150 helpMsg << "If no value is specified for this parameter," << endl;
2151 helpMsg << "then cbc is the default value of this parameter." << endl;
2152
2153 helpMsg << endl;
2154
2155 helpMsg
2156 << "-browser browserName this paramater is a path to the browser on the "
2157 << endl;
2158 helpMsg
2159 << "local machine. If this optional parameter is specified then the "
2160 << endl;
2161 helpMsg << "solver result in OSrL format is transformed using XSLT into "
2162 << endl;
2163 helpMsg << "HTML and displayed in the browser. " << endl;
2164
2165 helpMsg << endl;
2166
2167 helpMsg
2168 << "-config pathToConfigureFile this parameter specifies a path on "
2169 << endl;
2170 helpMsg
2171 << "the local machine to a text file containing values for the input parameters. "
2172 << endl;
2173 helpMsg
2174 << "This is convenient for the user not wishing to constantly retype parameter values. "
2175 << endl;
2176 helpMsg
2177 << "This configure file can contain values for all of the other parameters. "
2178 << endl;
2179
2180 helpMsg << endl;
2181
2182 helpMsg << "--version or -v get the current version of this executable "
2183 << endl;
2184
2185 helpMsg << endl;
2186
2187 helpMsg << "--help or -h to get this help file " << endl;
2188
2189 helpMsg << endl;
2190
2191 helpMsg
2192 << "Note: If you specify a configure file by using the -config option, you can "
2193 << endl;
2194 helpMsg
2195 << "override the values of the options in the configure file by putting them in "
2196 << endl;
2197 helpMsg << "at the command line. " << endl << endl;
2198
2199 helpMsg
2200 << "See the OS User\' Manual: http://www.coin-or.org/OS/doc/osUsersManual.pdf"
2201 << endl;
2202 helpMsg << "for more detail on how to use the OS project. " << endl;
2203
2204 helpMsg << endl;
2205 helpMsg << "********************************************************"
2206 << endl << endl;
2207
2208 return helpMsg.str();
2209}// get help
2210
2211
2212std::string get_version()
2213{
2214 std::ostringstream versionMsg;
2215 versionMsg << "In order to find the version of this project " << endl;
2216 versionMsg << "connect to the directory where you downloaded " << endl;
2217 versionMsg << "and do: " << endl;
2218 versionMsg << "svn info " << endl;
2219
2220 return versionMsg.str();
2221}// get version
2222
2223std::string get_options()
2224{
2225 std::ostringstream optionMsg;
2226
2227 optionMsg << endl;
2228
2229 optionMsg
2230 << "***************** VALID COMMANDS AND OPTIONS ********************"
2231 << endl ;
2232 optionMsg
2233 << "COMMANDS:"
2234 << endl;
2235 optionMsg
2236 << "quit/exit -- terminate the executable"
2237 << endl;
2238 optionMsg
2239 << "help/? -- produce this list of options"
2240 << endl;
2241 optionMsg
2242 << "reset -- erase all previous option settings"
2243 << endl ;
2244 optionMsg
2245 << "list -- list the current option values"
2246 << endl ;
2247 optionMsg
2248 << "solve -- call the solver synchronously"
2249 << endl ;
2250 optionMsg
2251 << "send -- call the solver asynchronously"
2252 << endl ;
2253 optionMsg
2254 << "kill -- end a job on the remote server"
2255 << endl ;
2256 optionMsg
2257 << "retrieve -- get job result on the remote server"
2258 << endl ;
2259 optionMsg
2260 << "knock -- get job information on the remote server"
2261 << endl ;
2262 optionMsg
2263 << "getJobID -- get a job ID from the remote server"
2264 << endl << endl;
2265
2266
2267 optionMsg
2268 << "OPTIONS (THESE REQUIRE A VALUE):"
2269 << endl;
2270 optionMsg
2271 << "osil -- the location of the model instance in OSiL format"
2272 << endl;
2273 optionMsg
2274 << "mps -- the location of the model instance in MPS format"
2275 << endl ;
2276 optionMsg
2277 << "nl -- the location of the model instance in AMPL nl format"
2278 << endl;
2279 optionMsg
2280 << "osol -- the location of the solver option file in OSoL format"
2281 << endl;
2282 optionMsg
2283 << "osrl -- the location of the solver result file in OSrL format"
2284 << endl;
2285 optionMsg
2286 << "osplInput -- the name of an input file in OSpL format"
2287 << endl;
2288 optionMsg
2289 << "osplOutput -- the name of an output file in the OSpL format"
2290 << endl ;
2291 optionMsg
2292 << "serviceLocation -- the URL of a remote solver service"
2293 << endl;
2294 optionMsg
2295 << "solver -- specify the solver to invoke"
2296 << endl <<endl;
2297 optionMsg
2298 << "See http://www.coin-or.org/OS/"
2299 << endl;
2300 optionMsg
2301 << "for more detail on how to use the OS project."
2302 << endl << endl;
2303
2304 optionMsg
2305 << "PRINT OPTIONS:"
2306 << endl;
2307 optionMsg
2308 << "printModel -- print the currently defined model"
2309 << endl;
2310 optionMsg
2311 << "printRow nnn -- print row n of the currently defined model"
2312 << endl;
2313 optionMsg
2314 << " if nnn >= 0, prints a constraint, otherwise prints an objective row"
2315 << endl;
2316 optionMsg
2317 << "printLevel nnn -- control the amount of output sent to stdout"
2318 << endl;
2319 optionMsg
2320 << " valid values are 0..";
2321#ifdef NDEBUG
2322 optionMsg << ENUM_OUTPUT_LEVEL_info << endl;
2323#else
2324 optionMsg << ENUM_OUTPUT_LEVEL_detailed_trace << endl;
2325#endif
2326 optionMsg
2327 << "logFile --- a secondary output device"
2328 << endl;
2329 optionMsg
2330 << "filePrintLevel nnn -- control the amount of output sent to the secondary output device"
2331 << endl;
2332 optionMsg
2333 << " valid values are 0..";
2334#ifdef NDEBUG
2335 optionMsg << ENUM_OUTPUT_LEVEL_info << endl;
2336#else
2337 optionMsg << ENUM_OUTPUT_LEVEL_detailed_trace << endl;
2338#endif
2339 optionMsg << endl;
2340
2341 optionMsg
2342 << "*****************************************************************"
2343 << endl << endl;
2344 optionMsg
2345 << "At the prompt enter a valid command or option value pair."
2346 << endl;
2347 optionMsg
2348 << "Enter the \"solve\" command to optimize."
2349 << endl;
2350 optionMsg
2351 << "Type \"quit/exit\" to leave the application."
2352 << endl;
2353 optionMsg
2354 << "Type \"help\" or \"?\" for a list of valid options."
2355 << endl;
2356
2357
2358 return optionMsg.str();
2359}// get_options
2360
2361
2362void list_options(OSCommandLine *oscommandline)
2363{
2364 cout
2365 << "HERE ARE THE OPTION VALUES SO FAR:"
2366 << endl;
2367 if (oscommandline->configFile != "")
2368 cout << "Config file = "
2369 << oscommandline->configFile
2370 << endl;
2371 if (oscommandline->osilFile != "")
2372 cout << "OSiL file = "
2373 << oscommandline->osilFile
2374 << endl;
2375 if (oscommandline->osolFile != "")
2376 cout << "OSoL file = "
2377 << oscommandline->osolFile
2378 << endl;
2379 if (oscommandline->osrlFile != "")
2380 cout << "OSrL file = "
2381 << oscommandline->osrlFile
2382 << endl;
2383//if(oscommandline->insListFile != "") cout << "Instruction List file = " << oscommandline->insListFile << endl;
2384 if (oscommandline->osplInputFile != "")
2385 cout << "OSpL Input file = "
2386 << oscommandline->osplInputFile
2387 << endl;
2388 if (oscommandline->serviceMethod != "")
2389 cout << "Service Method = "
2390 << oscommandline->serviceMethod
2391 << endl;
2392 if (oscommandline->mpsFile != "")
2393 cout << "MPS File Name = "
2394 << oscommandline->mpsFile
2395 << endl;
2396 if (oscommandline->nlFile != "")
2397 cout << "NL File Name = "
2398 << oscommandline->nlFile
2399 << endl;
2400 if (oscommandline->solverName != "")
2401 cout << "Selected Solver = "
2402 << oscommandline->solverName
2403 << endl;
2404 if (oscommandline->serviceLocation != "")
2405 cout << "Service Location = "
2406 << oscommandline->serviceLocation
2407 << endl;
2408
2409 if (oscommandline->jobID != "")
2410 cout << "Job ID = "
2411 << oscommandline->jobID
2412 << endl;
2413}// list_options
2414
2415void doPrintModel(OSCommandLine *oscommandline)
2416{
2417 if (oscommandline->osil == "" && oscommandline->mps == "" && oscommandline->nl == "")
2418 {
2419 std::cout
2420 << "no instance defined; print command ignored" << std::endl;
2421 }
2422 else
2423 {
2424 if (oscommandline->osil != "")
2425 {
2426 OSiLReader *osilreader;
2427 osilreader = new OSiLReader();
2428 std::cout << osilreader->readOSiL(oscommandline->osil)->printModel() << std::endl;
2429 delete osilreader;
2430 osilreader = NULL;
2431 }
2432 else if (oscommandline->nl != "")
2433 {
2434#ifdef COIN_HAS_ASL
2435 OSnl2OS *nl2os;
2436// nl2os = new OSnl2OS( oscommandline->nlFile, oscommandline->osol);
2437 nl2os = new OSnl2OS();
2438 nl2os->readNl(oscommandline->nlFile);
2439 nl2os->setOsol(oscommandline->osol);
2440 nl2os->createOSObjects();
2441 std::cout << nl2os->osinstance->printModel() << std::endl;
2442 delete nl2os;
2443 nl2os = NULL;
2444#else
2445 std::cout << "no ASL present to read nl file; print command ignored" << std::endl;
2446#endif
2447 }
2448 else if (oscommandline->mps != "")
2449 {
2450 OSmps2osil *mps2osil;
2451 mps2osil = new OSmps2osil(oscommandline->mpsFile);
2452 mps2osil->createOSInstance();
2453 std::cout << mps2osil->osinstance->printModel() << std::endl;
2454 delete mps2osil;
2455 mps2osil = NULL;
2456 }
2457 }
2458}// doPrintModel(OSCommandLine *oscommandline)
2459
2460void doPrintModel(OSInstance *osinstance)
2461{
2462 if (osinstance == NULL)
2463 {
2464 std::cout
2465 << "no instance defined; print command ignored" << std::endl;
2466 }
2467 else
2468 {
2469 std::cout << osinstance->printModel() << std::endl;
2470 }
2471}// doPrintModel(OSInstance *osinstance)
2472
2473void doPrintRow(OSCommandLine *oscommandline)
2474{
2475 int rownumber;
2476 if (oscommandline->printRowNumberAsString == "")
2477 std::cout << "no line number given; print command ignored" << std::endl;
2478 else
2479 {
2480 try
2481 {
2482 rownumber = atoi((oscommandline->printRowNumberAsString).c_str());
2483 }
2484 catch (const ErrorClass& eclass)
2485 {
2486 std::cout << "invalid row number; print command ignored" << std::endl;
2487 }
2488
2489 if (oscommandline->osil == "" && oscommandline->mps == "" && oscommandline->nl == "")
2490 {
2491 std::cout
2492 << "no instance defined; print command ignored" << std::endl;
2493 }
2494 else
2495 {
2496 std::cout << std::endl << "Row " << rownumber << ":" << std::endl << std::endl;
2497 if (oscommandline->osil != "")
2498 {
2499 OSiLReader *osilreader;
2500 osilreader = new OSiLReader();
2501 std::cout << osilreader->readOSiL(oscommandline->osil)->printModel(rownumber) << std::endl;
2502 delete osilreader;
2503 osilreader = NULL;
2504 }
2505 else if (oscommandline->nl != "")
2506 {
2507#ifdef COIN_HAS_ASL
2508 OSnl2OS *nl2os;
2509// nl2os = new OSnl2OS(oscommandline->nlFile, oscommandline->osol);
2510 nl2os = new OSnl2OS();
2511 nl2os->readNl(oscommandline->nlFile);
2512 nl2os->setOsol(oscommandline->osol);
2513 nl2os->createOSObjects();
2514 std::cout << nl2os->osinstance->printModel(rownumber) << std::endl;
2515 delete nl2os;
2516 nl2os = NULL;
2517#else
2518 std::cout << "no ASL present to read nl file; print command ignored" << std::endl;
2519#endif
2520 }
2521 else if (oscommandline->mps != "")
2522 {
2523 OSmps2osil *mps2osil;
2524 mps2osil = new OSmps2osil(oscommandline->mpsFile);
2525 mps2osil->createOSInstance();
2526 std::cout << mps2osil->osinstance->printModel(rownumber) << std::endl;
2527 delete mps2osil;
2528 mps2osil = NULL;
2529 }
2530 }
2531 }
2532}// doPrintRow(OSCommandLine *oscommandline)
2533
2534void doPrintRow(OSInstance *osinstance, std::string rownumberstring)
2535{
2536 int rownumber;
2537 if (rownumberstring == "")
2538 std::cout << "no line number given; print command ignored" << std::endl;
2539 else
2540 {
2541 try
2542 {
2543 rownumber = atoi((rownumberstring).c_str());
2544 }
2545 catch (const ErrorClass& eclass)
2546 {
2547 std::cout << "invalid row number; print command ignored" << std::endl;
2548 }
2549
2550 if (osinstance == NULL)
2551 {
2552 std::cout
2553 << "no instance defined; print command ignored" << std::endl;
2554 }
2555 else
2556 {
2557 std::cout << std::endl << "Row " << rownumber << ":" << std::endl << std::endl;
2558 std::cout << osinstance->printModel(rownumber) << std::endl;
2559 }
2560 }
2561}// doPrintRow(OSInstance *osinstance, std::string rownumberstring)
2562
std::string OSgetVersionInfo()
#define scanner
OSOption * osoption
std::string runSolver(std::string solverName, std::string osol, OSInstance *osinstance)
This class is used to invoke a solver locally.
void kill(OSCommandLine *oscommandline)
void interactiveShell()
void retrieve(OSCommandLine *oscommandline)
std::string get_options()
int main(int argC, const char *argV[])
struct yy_buffer_state * YY_BUFFER_STATE
void getOSiLFromNl(OSCommandLine *oscommandline)
Some wrappers around routines that allow getting problem instances in other formats: ....
void doPrintModel(OSCommandLine *oscommandline)
int ossslex_destroy(void *scanner)
int ossslex_init(void **ptr)
void getServiceLocation(OSCommandLine *oscommandline)
======================== Interactive shell =========================
void send(OSCommandLine *oscommandline)
YY_BUFFER_STATE osss_scan_string(const char *osss, void *scanner)
std::string get_version()
std::string get_help()
const OSSmartPtr< OSOutput > osoutput
Definition OSOutput.cpp:39
void list_options(OSCommandLine *oscommandline)
void setyyextra(OSCommandLine *oscommandline, void *scanner)
void solve(OSCommandLine *oscommandline)
Next we have implementations of the six service methods solve, send, retrieve, knock,...
void getJobID(OSCommandLine *oscommandline)
void doPrintRow(OSCommandLine *oscommandline)
void getOSiLFromGams(OSCommandLine *oscommandline)
int ossslex(void *scanner)
void getOSiLFromMps(OSCommandLine *oscommandline)
void knock(OSCommandLine *oscommandline)
#define MAXCHARS
used for throwing exceptions.
std::string errormsg
errormsg is the error that is causing the exception to be thrown
class used to make it easy to read and write files.
Definition OSFileUtil.h:38
bool writeFileFromString(char *fname, std::string thestring)
write a file from an input string.
std::string getFileAsString(const char *fname)
read a file and return contents as a string.
This class is used to store command line options for the OSSolverService executable and to provide me...
bool quit
if this parameter is true we quit/exit
std::string jobID
the JobID
std::string nl
the string that holds an instance in AMPL nl format
std::string serviceLocation
serviceLocation is the URL of the remote solver when a local solver is not used
std::string osplInputFile
name of an input file with xml in OS process language format, used for example to knock on a server,...
bool writeVersion
if this parameter is true we print the current version of the OS project
int printLevel
this parameter controls the amount of output to print the higher the number, the more output is gener...
std::string datFile
the name of the file that holds an instance in GAMS dat format
std::string printRowNumberAsString
this parameter contains a string representation (!) of the row number if only a single row (constrain...
std::string nlFile
the name of the file that holds an instance in AMPL nl format
std::string dat
the string that holds an instance in GAMS dat format
std::string logFile
this optional parameter contains the path to a logfile that can be used as an alternate output stream...
std::string osplOutputFile
name of an output file where the solver should write the result of a knock or kill service request
std::string solverName
the name of the solver to be invoked locally, e.g -solver Ipopt
std::string mpsFile
the name of the file that holds an instance in MPS format
bool invokeHelp
if this parameter is true we print the contents of the file help.txt and return
std::string osolFile
osolFile is the name of the file that holds the solver options in OSoL format
std::string osplInput
osplInput is the content of the osplInputFile
std::string browser
this parameter is a path to the browser on the local machine.
int filePrintLevel
this parameter controls the amount of output to send to the log file (if used) the higher the number,...
std::string configFile
configFile is the name of the file that holds the configuration options if the OSSolverService reads ...
void reset_options()
a function to reset the command line to default values useful especially in the interactive shell
std::string gamsControlFile
the name of the file that holds the GAMS control parameters
std::string osil
osil is the content of the osilFile
bool printModel
if this parameter is true we print the current instance as read from an osil, nl or mps file
std::string osrlFile
osrlFile is the name of the file where the solver should write the result (in OSrL format)
std::string serviceMethod
the service method the OSSolverService should execute, i.e.
std::string mps
the string that holds an instance in MPS format
std::string osilFile
osilFile is the name of the file that holds the model instance in OSiL format
std::string osol
osol is the content of the osolFile
The in-memory representation of an OSiL instance..
std::string printModel()
Print the infix representation of the problem.
The Option Class.
Definition OSOption.h:3565
bool setJobID(std::string jobID)
Set the job ID.
The Result Class.
Definition OSResult.h:2549
bool setGeneralMessage(std::string message)
Set the general message.
bool setGeneralStatusType(std::string type)
Set the general status type, which can be: success, error, warning.
Template class for Smart Pointers.
Used by a client to invoke a remote solver.
std::string retrieve(std::string osol)
implement the retrieve() method which is a virtual function in OShL
bool send(std::string osil, std::string osol)
implement the send() method which is a virtual function in OShL
std::string getJobID(std::string osol)
implement the getJobID() method which is a virtual function in OShL
std::string solve(std::string osil, std::string osol)
implement the solve() method which is a virtual function in OShL, this is synchronous
std::string knock(std::string ospl, std::string osol)
implement the knock() method which is a virtual function in OShL
std::string kill(std::string osol)
implement the kill() method which is a virtual function in OShL
Creating a OSInstance from a GAMS model given as GAMS Modeling Object (GMO).
bool createOSInstance()
Creates an OSInstance from the GAMS smag instance representation.
OSInstance * osinstance
Used to read an OSiL string.
Definition OSiLReader.h:38
OSInstance * readOSiL(const std::string &osil)
parse the OSiL model instance.
Take an OSInstance object and write a string that validates against the OSiL schema.
Definition OSiLWriter.h:30
std::string writeOSiL(const OSInstance *theosinstance)
create an osil string from an OSInstance object
The OSmps2osil Class.
Definition OSmps2osil.h:40
bool createOSInstance()
create an OSInstance from the MPS instance representation
OSInstance * osinstance
osinstance is a pointer to the OSInstance object that gets created from the instance represented in N...
Definition OSmps2osil.h:58
The OSnl2OS Class.
Definition OSnl2OS.h:79
OSInstance * osinstance
osinstance is a pointer to the OSInstance object that gets created from the information in the nl fil...
Definition OSnl2OS.h:172
bool readNl(std::string stub)
read the nl file
Definition OSnl2OS.cpp:109
bool createOSObjects()
create an OSInstance and OSOption representation from the AMPL nl content (Some of the information in...
Definition OSnl2OS.cpp:504
OSOption * osoption
osoption is a pointer to the OSOption object that gets created from the information in the nl file (a...
Definition OSnl2OS.h:177
void setOsol(std::string osol)
set the osol string
Definition OSnl2OS.cpp:99
Take an OSOption object and write a string that validates against the OSoL schema.
Definition OSoLWriter.h:30
std::string writeOSoL(OSOption *theosoption)
create an osol string from an OSOption object
Take an OSResult object and write a string that validates against OSrL.
Definition OSrLWriter.h:31
std::string writeOSrL(OSResult *theosresult)
create an osrl string from an OSResult object
#define OS_SCHEMA_VERSION
#define DEFAULT_OUTPUT_LEVEL
ENUM_OUTPUT_LEVEL
Enumeration for the different verbosity levels that can be used in producing output.
@ ENUM_OUTPUT_LEVEL_detailed_trace
@ ENUM_OUTPUT_LEVEL_debug
@ ENUM_OUTPUT_LEVEL_trace
@ ENUM_OUTPUT_LEVEL_error
@ ENUM_OUTPUT_LEVEL_info
@ ENUM_OUTPUT_LEVEL_summary
@ ENUM_OUTPUT_LEVEL_NUMBER_OF_LEVELS
@ ENUM_OUTPUT_LEVEL_always
@ ENUM_OUTPUT_AREA_main
OSResult * osresult