69 #include "OSInstance.h"
78 # error do not have ASL
89 #ifdef COIN_HAS_BONMIN
93 #ifdef COIN_HAS_COUENNE
101 #include "CoinError.hpp"
110 # ifdef HAVE_STRING_H
113 # error "don't have header file for string"
117 #include "CoinError.hpp"
118 #include "CoinHelperFunctions.hpp"
139 using std::ostringstream;
162 int main(
int argc,
char **argv)
164 WindowsErrorPopupBlocker();
165 std::ostringstream outStr;
169 ostringstream echo_cl;
178 if (argc > 0) stub = argv[1];
185 std::string amplclient_options =
"";
188 if (strncmp(argv[2],
"-AMPL",5) == 0)
190 char* temp = getenv(
"OSAmplClient_options");
198 for (
int i=2; i<argc; i++)
199 temp2 << argv[i] <<
" ";
201 amplclient_options = temp2.str();
210 echo_cl <<
"HERE ARE THE AMPLCLIENT OPTIONS ";
211 echo_cl << amplclient_options;
212 echo_cl << endl << endl;
214 echo_cl <<
"Try to open file ";
215 echo_cl << stub <<
".nl";
222 oscommandline = oscommandlinereader->
readCommandLine(amplclient_options);
228 delete oscommandlinereader;
229 oscommandlinereader = NULL;
233 if (stub) oscommandline->
nlFile = stub;
242 outStr << std::endl <<
"using print level " << oscommandline->
printLevel <<
" for stdout" << std::endl;
261 if (oscommandline->
logFile !=
"")
269 "Added channel " + oscommandline->
logFile);
273 "Output channel " + oscommandline->
logFile +
" previously defined");
282 outStr << std::endl <<
"using print level " << oscommandline->
filePrintLevel;
283 outStr <<
" for " << oscommandline->
logFile << std::endl;
299 outStr << std::endl << std::endl <<
get_help() << std::endl;
302 delete oscommandlinereader;
303 oscommandlinereader = NULL;
314 delete oscommandlinereader;
315 oscommandlinereader = NULL;
322 delete oscommandlinereader;
323 oscommandlinereader = NULL;
331 outStr <<
"HERE ARE THE OPTION VALUES:" << endl;
332 if(oscommandline->
configFile !=
"") outStr <<
"Config file = " << oscommandline->
configFile << endl;
333 if(oscommandline->
osilFile !=
"") outStr <<
"OSiL file = " << oscommandline->
osilFile << endl;
334 if(oscommandline->
osolFile !=
"") outStr <<
"OSoL file = " << oscommandline->
osolFile << endl;
335 if(oscommandline->
osrlFile !=
"") outStr <<
"OSrL file = " << oscommandline->
osrlFile << endl;
339 if(oscommandline->
mpsFile !=
"") outStr <<
"MPS File Name = " << oscommandline->
mpsFile << endl;
340 if(oscommandline->
nlFile !=
"") outStr <<
"NL File Name = " << oscommandline->
nlFile << endl;
342 if(oscommandline->
browser !=
"") outStr <<
"Browser Value = " << oscommandline->
browser << endl;
343 if(oscommandline->
solverName !=
"") outStr <<
"Selected Solver = " << oscommandline->
solverName << endl;
345 if(oscommandline->
jobID !=
"") outStr <<
"Job ID = " << oscommandline->
jobID << endl;
346 if(oscommandline->
printModel) outStr <<
"print model prior to solve/send" << endl;
348 outStr <<
"print level for stdout: " << oscommandline->
printLevel << endl;
349 if(oscommandline->
logFile !=
"")
351 outStr <<
"also send output to " << oscommandline->
logFile << endl;
352 outStr <<
"print level for file output: " << oscommandline->
filePrintLevel << endl;
361 for (k = 0; k < oscommandline->
solverName.length(); k++)
375 throw ErrorClass(
"No serviceLocation given. Only \'solve\' is available locally.");
380 if (oscommandline->
osil ==
"")
383 throw ErrorClass(
"No instance could be found");
409 if (oscommandline->
osil ==
"")
425 if (oscommandline->
osol !=
"" && oscommandline->
osoption == NULL)
429 if (oscommandline->
osoption == NULL)
446 if (oscommandline->
osoption != NULL)
451 if (oscommandline->
osoption != NULL)
462 send(oscommandline, nl2OS);
464 solve(oscommandline, nl2OS);
480 kill(oscommandline, nl2OS);
482 knock(oscommandline, nl2OS);
490 if (osilreader != NULL)
494 delete oscommandlinereader;
495 oscommandlinereader = NULL;
509 if (osilreader != NULL)
513 delete oscommandlinereader;
514 oscommandlinereader = NULL;
521 if ( (argc > 2) && (strncmp(argv[2],
"-AMPL",5) == 0) )
562 if (oscommandline->
osil ==
"")
579 if (oscommandline->
osoption != NULL || oscommandline->
jobID !=
"" || oscommandline->
osol ==
"")
581 if (oscommandline->
osoption == NULL)
584 if (oscommandline->
osol !=
"")
589 if (oscommandline->
jobID !=
"")
601 if (osolreader != NULL)
616 std::string osrl =
"";
627 oscommandline->
jobID =
"";
630 osrl = osagent->
solve(oscommandline->
osil, oscommandline->
osol);
656 bool always_print =
false;
658 ostringstream outStr;
666 if (oscommandline->
jobID ==
"NEW")
670 if (oscommandline->
osoption != NULL)
678 outStr <<
"Submitting Job " << oscommandline->
jobID << std::endl;
681 bSend = osagent->
send(oscommandline->
osil, oscommandline->
osol);
685 outStr <<
"Job " << oscommandline->
jobID;
689 outStr <<
" successfully submitted." << std::endl;
697 outStr <<
": send failed." << std::endl;
698 outStr <<
"Check to make sure you sent a jobID not on the system." << std::endl;
732 throw ErrorClass(
"please specify service location (url)");
748 std::string osplOutput =
"";
761 std::ostringstream temp;
762 temp <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" <<
763 "<ospl xmlns=\"os.optimizationservices.org\"\n" <<
764 " xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" <<
765 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" <<
766 " xsi:schemaLocation=\"os.optimizationservices.org\n" <<
767 " http://www.optimizationservices.org/schemas/OSpL.xsd\">\n"<<
768 " <processHeader>\n" <<
769 " <request action=\"getAll\"/>\n" <<
770 " </processHeader>\n" <<
771 " <processData/>\n" <<
777 if(oscommandline->
jobID !=
"")
780 if (oscommandline->
osol ==
"")
795 if (osolReader != NULL)
delete osolReader;
820 throw ErrorClass(
"please specify service location (url)");
841 std::string osrl =
"";
853 if (oscommandline->
osol ==
"")
881 throw ErrorClass(
"please specify service location (url)");
902 std::string osplOutput =
"";
910 if (oscommandline->
osol ==
"")
929 osplOutput = osagent->
kill(oscommandline->
osol);
949 throw ErrorClass(
"please specify service location (url)");
972 ostringstream outStr;
980 if (oscommandline->
browser !=
"")
982 std::string str = oscommandline->
browser +
" "
984 const char *ch = &str[0];
994 std::string::size_type pos1 = osrl.find(
"error");
995 if(pos1 == std::string::npos)
1009 if (fileUtil != NULL)
1017 outStr <<
"There was an error parsing the OSrL string" << endl << eclass.
errormsg << endl << endl;
1019 if (fileUtil != NULL)
1030 std::string osrl =
"";
1035 std::string::size_type pos1 = errormsg.find(
"<osrl");
1036 if(pos1 == std::string::npos)
1054 ostringstream outStr;
1056 if (rownumberstring ==
"")
1058 "no row number given; print command ignored");
1063 rownumber = atoi((rownumberstring).c_str());
1068 "invalid row number; print command ignored");
1071 if (osinstance == NULL)
1074 "no instance defined; print command ignored");
1078 outStr << std::endl <<
"Row " << rownumber <<
":" << std::endl << std::endl;
1079 outStr << osinstance->
printModel(rownumber) << std::endl;
1088 std::ostringstream helpMsg;
1090 helpMsg <<
"************************* HELP *************************"
1093 <<
"In this HELP file we assume that the solve service method is used and "
1096 <<
"that we are solving problems locally, that is the solver is on the "
1099 <<
"machine running this OSSolverService. See Section 10.3 of the User\'s "
1102 <<
"Manual for other service methods or calling a server remotely. "
1104 helpMsg <<
"The OSSolverService takes the parameters listed below. "
1107 <<
"The order of the parameters is irrelevant. Not all the parameters "
1109 helpMsg <<
"are required. However, the location of an instance file is "
1112 <<
"required when using the solve service method. The location of the "
1114 helpMsg <<
"instance file is specified using the osil option. " << endl;
1119 <<
"-osil xxx.osil this is the name of the file that contains the "
1121 helpMsg <<
"optimization instance in OSiL format. This option may be "
1123 helpMsg <<
"specified in the OSoL solver options file. " << endl;
1128 <<
"-osol xxx.osol this is the name of the file that contains the solver options. "
1130 helpMsg <<
"It is not necessary to specify this option. " << endl;
1135 <<
"-osrl xxx.osrl this is the name of the file to which the solver solution is written. "
1138 <<
"It is not necessary to specify this option. If this option is not specified, "
1140 helpMsg <<
"the result will be printed to standard out. " << endl;
1145 <<
"-osplInput xxx.ospl this is the name of an input file in the OS Process"
1147 helpMsg <<
" Language (OSpL), this is used as input to the knock method."
1153 <<
"-osplOutput xxx.ospl this is the name of an output file in the OS Process"
1156 <<
"Language (OSpL), this the output string from the knock and kill methods."
1161 helpMsg <<
"-serviceLocation url is the URL of the solver service. "
1164 <<
"This is not required, and if not specified it is assumed that "
1166 helpMsg <<
"the problem is solved locally. " << endl;
1171 <<
"-serviceMethod methodName this is the method on the solver service to be invoked. "
1174 <<
"The options are solve, send, kill, knock, getJobID, and retrieve. "
1177 <<
"This option is not required, and the default value is solve. "
1183 <<
"-mps xxx.mps this is the name of the mps file if the problem instance "
1186 <<
"is in mps format. The default file format is OSiL so this option is not required. "
1192 <<
"-nl xxx.nl this is the name of the AMPL nl file if the problem "
1195 <<
"instance is in AMPL nl format. The default file format is OSiL "
1197 helpMsg <<
"so this option is not required. " << endl;
1202 <<
"-solver solverName Possible values for default OS installation "
1205 <<
"are bonmin(COIN-OR Bonmin), couenne (COIN-OR Couenne), clp (COIN-OR Clp),"
1207 helpMsg <<
"cbc (COIN-OR Cbc), dylp (COIN-OR DyLP), ipopt (COIN-OR Ipopt),"
1209 helpMsg <<
"and symphony (COIN-OR SYMPHONY). Other solvers supported"
1212 <<
"(if the necessary libraries are present) are cplex (Cplex through COIN-OR Osi),"
1215 <<
"glpk (glpk through COIN-OR Osi), knitro (Knitro), and lindo (LINDO)."
1217 helpMsg <<
"If no value is specified for this parameter," << endl;
1218 helpMsg <<
"then cbc is the default value of this parameter." << endl;
1223 <<
"-browser browserName this paramater is a path to the browser on the "
1226 <<
"local machine. If this optional parameter is specified then the "
1228 helpMsg <<
"solver result in OSrL format is transformed using XSLT into "
1230 helpMsg <<
"HTML and displayed in the browser. " << endl;
1235 <<
"-config pathToConfigureFile this parameter specifies a path on "
1239 <<
"the local machine to a text file containing values for the input parameters. "
1242 <<
"This is convenient for the user not wishing to constantly retype parameter values. "
1245 <<
"This configure file can contain values for all of the other parameters. "
1250 helpMsg <<
"--version or -v get the current version of this executable "
1255 helpMsg <<
"--help or -h to get this help file " << endl;
1260 <<
"Note: If you specify a configure file by using the -config option, you can "
1263 <<
"override the values of the options in the configure file by putting them in "
1265 helpMsg <<
"at the command line. " << endl << endl;
1268 <<
"See the OS User\' Manual: http://www.coin-or.org/OS/doc/osUsersManual.pdf"
1270 helpMsg <<
"for more detail on how to use the OS project. " << endl;
1273 helpMsg <<
"********************************************************"
1276 return helpMsg.str();
void getJobID(OSCommandLine *oscommandline, OSnl2OS *osnl2os)
std::string OSgetVersionInfo()
int printLevel
this parameter controls the amount of output to print the higher the number, the more output is gener...
bool invokeHelp
if this parameter is true we print the contents of the file help.txt and return
Used by a client to invoke a remote solver.
#define DEFAULT_OUTPUT_LEVEL
void send(OSCommandLine *oscommandline, OSnl2OS *osnl2os)
bool writeFileFromString(char *fname, std::string thestring)
write a file from an input string.
std::string retrieve(std::string osol)
implement the retrieve() method which is a virtual function in OShL
const OSSmartPtr< OSOutput > osoutput
bool writeVersion
if this parameter is true we print the current version of the OS project
void makeStrings(OSCommandLine *oscommandline)
void reportResults(OSCommandLine *oscommandline, std::string osrl, OSnl2OS *osnl2OS)
Deal with the OSrL output generated by the call to one of the service methods.
std::string osplInput
osplInput is the content of the osplInputFile
std::string serviceLocation
serviceLocation is the URL of the remote solver when a local solver is not used
The OSCommandLineReader Class.
std::string printModel()
Print the infix representation of the problem.
std::string osilOutputFile
osilOutputFile is the name of the file to which the instance can be written in OSiL format...
bool send(std::string osil, std::string osol)
implement the send() method which is a virtual function in OShL
std::string jobID
the JobID
std::string osil
osil is the content of the osilFile
std::string errormsg
errormsg is the error that is causing the exception to be thrown
std::string nlFile
the name of the file that holds an instance in AMPL nl format
int main(int argc, char *argv[])
int AddChannel(std::string name)
Add a channel to the array outputChannel.
int ossslex_init(void **ptr)
bool OSPrint(ENUM_OUTPUT_AREA area, ENUM_OUTPUT_LEVEL level, std::string outStr)
This is the main method to output a string All output generated by the program should ultimately use ...
bool readNl(std::string stub)
read the nl file
bool createOSObjects()
create an OSInstance and OSOption representation from the AMPL nl content (Some of the information in...
void setOsol(std::string osol)
set the osol string
std::string solve(std::string osil, std::string osol)
implement the solve() method which is a virtual function in OShL, this is synchronous ...
void knock(OSCommandLine *oscommandline, OSnl2OS *osnl2os)
Template class for Smart Pointers.
Take an OSResult object and write a string that validates against OSrL.
Take an OSOption object and write a string that validates against the OSoL schema.
std::string browser
this parameter is a path to the browser on the local machine.
OSCommandLine * readCommandLine(const std::string &osss)
Get an OSCommandLine object from a command line string.
void reportErrors(OSCommandLine *oscommandline, std::string errMsg, OSnl2OS *osnl2OS)
Deal with any error messages generated by the call to one of the service methods. ...
std::string osplInputFile
name of an input file with xml in OS process language format, used for example to knock on a server...
OSInstance * readOSiL(const std::string &osil)
parse the OSiL model instance.
int ossslex_destroy(void *scanner)
std::string writeOSrL(OSResult *theosresult)
create an osrl string from an OSResult object
std::string osrlFile
osrlFile is the name of the file where the solver should write the result (in OSrL format) ...
std::string gamsControlFile
the name of the file that holds the GAMS control parameters
std::string logFile
this optional parameter contains the path to a logfile that can be used as an alternate output stream...
struct yy_buffer_state * YY_BUFFER_STATE
OSInstance * osinstance
osinstance is a representation of the instance in OSInstance format
std::string osilFile
osilFile is the name of the file that holds the model instance in OSiL format
std::string osplOutputFile
name of an output file where the solver should write the result of a knock or kill service request ...
void solve(OSCommandLine *oscommandline, OSnl2OS *osnl2os)
Next we have implementations of the six remote service methods solve, send, retrieve, knock, kill, getJobID (Do not bother with local solve; use runSolver instead)
bool printModel
if this parameter is true we print the current instance as read from an osil, nl or mps file ...
Used to read an OSiL string.
std::string osolOutputFile
osolOutputFile is the name of the file to which the solver options can be written in OSoL format...
bool writeSolFile(std::string osrl, ASL *asl, std::string filename)
Convert the solution to AMPL .sol format.
std::string printRowNumberAsString
this parameter contains a string representation (!) of the row number if only a single row (constrain...
std::string configFile
configFile is the name of the file that holds the configuration options if the OSSolverService reads ...
std::string writeOSoL(OSOption *theosoption)
create an osol string from an OSOption object
std::string mpsFile
the name of the file that holds an instance in MPS format
ENUM_OUTPUT_LEVEL
Enumeration for the different verbosity levels that can be used in producing output.
std::string runSolver(std::string solverName, std::string osol, OSInstance *osinstance)
This class is used to invoke a solver locally.
void retrieve(OSCommandLine *oscommandline, OSnl2OS *osnl2os)
int filePrintLevel
this parameter controls the amount of output to send to the log file (if used) the higher the number...
void doPrintRow(OSInstance *osinstance, std::string rownumberstring)
void setyyextra(OSCommandLine *oscommandline, void *scanner)
OSOption * readOSoL(const std::string &osol)
parse the OSoL solver options.
bool setGeneralMessage(std::string message)
Set the general message.
std::string serviceMethod
the service method the OSSolverService should execute, i.e.
bool setGeneralStatusType(std::string type)
Set the general status type, which can be: success, error, warning.
std::string osol
osol is the content of the osolFile
std::string knock(std::string ospl, std::string osol)
implement the knock() method which is a virtual function in OShL
std::string writeOSiL(const OSInstance *theosinstance)
create an osil string from an OSInstance object
Used to read an OSoL string.
std::string osolFile
osolFile is the name of the file that holds the solver options in OSoL format
ASL * getASL(std::string name)
return a pointer to an ASL object
bool findInstance(OSCommandLine *oscommandline, OSnl2OS *osnl2os)
This method tries to find the instance by reading the .nl file.
bool setJobID(std::string jobID)
Set the job ID.
void list_options(OSCommandLine *oscommandline)
void setJobID(std::string jobID)
set the job ID
std::string kill(std::string osol)
implement the kill() 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
int ossslex(void *scanner)
This class is used to store command line options for the OSSolverService executable and to provide me...
The in-memory representation of an OSiL instance..
class used to make it easy to read and write files.
OSInstance * osinstance
osinstance is a pointer to the OSInstance object that gets created from the information in the nl fil...
void kill(OSCommandLine *oscommandline, OSnl2OS *osnl2os)
used for throwing exceptions.
std::string solverName
the name of the solver to be invoked locally, e.g -solver Ipopt
OSOption * osoption
osoption is a representation of the solver options in OSOption format
Take an OSInstance object and write a string that validates against the OSiL schema.
bool SetPrintLevel(std::string name, ENUM_OUTPUT_LEVEL *level, int dim)
Modify all print levels associated with a channel.
YY_BUFFER_STATE osss_scan_string(const char *osss, void *scanner)