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