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];
181 char* temp = getenv(
"OSAmplClient_options");
183 std::string amplclient_options;
187 amplclient_options = temp2.str();
188 std::cout << amplclient_options << std::endl;
192 amplclient_options =
"serviceMethod retrieve serviceLocation http://74.94.100.129:8080/OSServer/services/OSSolverService printLevel 4 jobID gus-10-apr-2013-0001";
197 echo_cl <<
"HERE ARE THE AMPLCLIENT OPTIONS ";
198 echo_cl << amplclient_options;
199 echo_cl << endl << endl;
201 echo_cl <<
"Try to open file ";
202 echo_cl << stub <<
".nl";
209 oscommandline = oscommandlinereader->
readCommandLine(amplclient_options);
215 delete oscommandlinereader;
216 oscommandlinereader = NULL;
220 if (stub) oscommandline->
nlFile = stub;
229 outStr << std::endl <<
"using print level " << oscommandline->
printLevel <<
" for stdout" << std::endl;
248 if (oscommandline->
logFile !=
"")
256 "Added channel " + oscommandline->
logFile);
260 "Output channel " + oscommandline->
logFile +
" previously defined");
269 outStr << std::endl <<
"using print level " << oscommandline->
filePrintLevel;
270 outStr <<
" for " << oscommandline->
logFile << std::endl;
286 outStr << std::endl << std::endl <<
get_help() << std::endl;
289 delete oscommandlinereader;
290 oscommandlinereader = NULL;
301 delete oscommandlinereader;
302 oscommandlinereader = NULL;
309 delete oscommandlinereader;
310 oscommandlinereader = NULL;
318 outStr <<
"HERE ARE THE OPTION VALUES:" << endl;
319 if(oscommandline->
configFile !=
"") outStr <<
"Config file = " << oscommandline->
configFile << endl;
320 if(oscommandline->
osilFile !=
"") outStr <<
"OSiL file = " << oscommandline->
osilFile << endl;
321 if(oscommandline->
osolFile !=
"") outStr <<
"OSoL file = " << oscommandline->
osolFile << endl;
322 if(oscommandline->
osrlFile !=
"") outStr <<
"OSrL file = " << oscommandline->
osrlFile << endl;
326 if(oscommandline->
mpsFile !=
"") outStr <<
"MPS File Name = " << oscommandline->
mpsFile << endl;
327 if(oscommandline->
nlFile !=
"") outStr <<
"NL File Name = " << oscommandline->
nlFile << endl;
329 if(oscommandline->
browser !=
"") outStr <<
"Browser Value = " << oscommandline->
browser << endl;
330 if(oscommandline->
solverName !=
"") outStr <<
"Selected Solver = " << oscommandline->
solverName << endl;
332 if(oscommandline->
jobID !=
"") outStr <<
"Job ID = " << oscommandline->
jobID << endl;
333 if(oscommandline->
printModel) outStr <<
"print model prior to solve/send" << endl;
335 outStr <<
"print level for stdout: " << oscommandline->
printLevel << endl;
336 if(oscommandline->
logFile !=
"")
338 outStr <<
"also send output to " << oscommandline->
logFile << endl;
339 outStr <<
"print level for file output: " << oscommandline->
filePrintLevel << endl;
348 for (k = 0; k < oscommandline->
solverName.length(); k++)
362 throw ErrorClass(
"No serviceLocation given. Only \'solve\' is available locally.");
367 if (oscommandline->
osil ==
"")
370 throw ErrorClass(
"No instance could be found");
396 if (oscommandline->
osil ==
"")
412 if (oscommandline->
osol !=
"" && oscommandline->
osoption == NULL)
416 if (oscommandline->
osoption == NULL)
433 if (oscommandline->
osoption != NULL)
438 if (oscommandline->
osoption != NULL)
449 send(oscommandline, nl2OS);
451 solve(oscommandline, nl2OS);
467 kill(oscommandline, nl2OS);
469 knock(oscommandline, nl2OS);
477 if (osilreader != NULL)
481 delete oscommandlinereader;
482 oscommandlinereader = NULL;
496 if (osilreader != NULL)
500 delete oscommandlinereader;
501 oscommandlinereader = NULL;
546 if (oscommandline->
osil ==
"")
563 if (oscommandline->
osoption != NULL || oscommandline->
jobID !=
"" || oscommandline->
osol ==
"")
565 if (oscommandline->
osoption == NULL)
568 if (oscommandline->
osol !=
"")
573 if (oscommandline->
jobID !=
"")
585 if (osolreader != NULL)
600 std::string osrl =
"";
611 oscommandline->
jobID =
"";
614 osrl = osagent->
solve(oscommandline->
osil, oscommandline->
osol);
640 bool always_print =
false;
642 ostringstream outStr;
650 if (oscommandline->
jobID ==
"NEW")
654 if (oscommandline->
osoption != NULL)
662 outStr <<
"Submitting Job " << oscommandline->
jobID << std::endl;
665 bSend = osagent->
send(oscommandline->
osil, oscommandline->
osol);
669 outStr <<
"Job " << oscommandline->
jobID;
673 outStr <<
" successfully submitted." << std::endl;
681 outStr <<
": send failed." << std::endl;
682 outStr <<
"Check to make sure you sent a jobID not on the system." << std::endl;
716 throw ErrorClass(
"please specify service location (url)");
732 std::string osplOutput =
"";
742 if (oscommandline->
osol ==
"")
770 throw ErrorClass(
"please specify service location (url)");
791 std::string osrl =
"";
803 if (oscommandline->
osol ==
"")
831 throw ErrorClass(
"please specify service location (url)");
852 std::string osplOutput =
"";
860 if (oscommandline->
osol ==
"")
879 osplOutput = osagent->
kill(oscommandline->
osol);
892 throw ErrorClass(
"please specify service location (url)");
915 ostringstream outStr;
923 if (oscommandline->
browser !=
"")
925 std::string str = oscommandline->
browser +
" "
927 const char *ch = &str[0];
937 std::cout << osrl << std::endl << std::endl;
939 std::string::size_type pos1 = osrl.find(
"error");
940 if(pos1 == std::string::npos)
954 if (fileUtil != NULL)
962 outStr <<
"There was an error parsing the OSrL string" << endl << eclass.
errormsg << endl << endl;
964 if (fileUtil != NULL)
975 std::string osrl =
"";
980 std::string::size_type pos1 = errormsg.find(
"<osrl");
981 if(pos1 == std::string::npos)
999 ostringstream outStr;
1001 if (rownumberstring ==
"")
1003 "no row number given; print command ignored");
1008 rownumber = atoi((rownumberstring).c_str());
1013 "invalid row number; print command ignored");
1016 if (osinstance == NULL)
1019 "no instance defined; print command ignored");
1023 outStr << std::endl <<
"Row " << rownumber <<
":" << std::endl << std::endl;
1024 outStr << osinstance->
printModel(rownumber) << std::endl;
1033 std::ostringstream helpMsg;
1035 helpMsg <<
"************************* HELP *************************"
1038 <<
"In this HELP file we assume that the solve service method is used and "
1041 <<
"that we are solving problems locally, that is the solver is on the "
1044 <<
"machine running this OSSolverService. See Section 10.3 of the User\'s "
1047 <<
"Manual for other service methods or calling a server remotely. "
1049 helpMsg <<
"The OSSolverService takes the parameters listed below. "
1052 <<
"The order of the parameters is irrelevant. Not all the parameters "
1054 helpMsg <<
"are required. However, the location of an instance file is "
1057 <<
"required when using the solve service method. The location of the "
1059 helpMsg <<
"instance file is specified using the osil option. " << endl;
1064 <<
"-osil xxx.osil this is the name of the file that contains the "
1066 helpMsg <<
"optimization instance in OSiL format. This option may be "
1068 helpMsg <<
"specified in the OSoL solver options file. " << endl;
1073 <<
"-osol xxx.osol this is the name of the file that contains the solver options. "
1075 helpMsg <<
"It is not necessary to specify this option. " << endl;
1080 <<
"-osrl xxx.osrl this is the name of the file to which the solver solution is written. "
1083 <<
"It is not necessary to specify this option. If this option is not specified, "
1085 helpMsg <<
"the result will be printed to standard out. " << endl;
1090 <<
"-osplInput xxx.ospl this is the name of an input file in the OS Process"
1092 helpMsg <<
" Language (OSpL), this is used as input to the knock method."
1098 <<
"-osplOutput xxx.ospl this is the name of an output file in the OS Process"
1101 <<
"Language (OSpL), this the output string from the knock and kill methods."
1106 helpMsg <<
"-serviceLocation url is the URL of the solver service. "
1109 <<
"This is not required, and if not specified it is assumed that "
1111 helpMsg <<
"the problem is solved locally. " << endl;
1116 <<
"-serviceMethod methodName this is the method on the solver service to be invoked. "
1119 <<
"The options are solve, send, kill, knock, getJobID, and retrieve. "
1122 <<
"This option is not required, and the default value is solve. "
1128 <<
"-mps xxx.mps this is the name of the mps file if the problem instance "
1131 <<
"is in mps format. The default file format is OSiL so this option is not required. "
1137 <<
"-nl xxx.nl this is the name of the AMPL nl file if the problem "
1140 <<
"instance is in AMPL nl format. The default file format is OSiL "
1142 helpMsg <<
"so this option is not required. " << endl;
1147 <<
"-solver solverName Possible values for default OS installation "
1150 <<
"are bonmin(COIN-OR Bonmin), couenne (COIN-OR Couenne), clp (COIN-OR Clp),"
1152 helpMsg <<
"cbc (COIN-OR Cbc), dylp (COIN-OR DyLP), ipopt (COIN-OR Ipopt),"
1154 helpMsg <<
"and symphony (COIN-OR SYMPHONY). Other solvers supported"
1157 <<
"(if the necessary libraries are present) are cplex (Cplex through COIN-OR Osi),"
1160 <<
"glpk (glpk through COIN-OR Osi), knitro (Knitro), and lindo (LINDO)."
1162 helpMsg <<
"If no value is specified for this parameter," << endl;
1163 helpMsg <<
"then cbc is the default value of this parameter." << endl;
1168 <<
"-browser browserName this paramater is a path to the browser on the "
1171 <<
"local machine. If this optional parameter is specified then the "
1173 helpMsg <<
"solver result in OSrL format is transformed using XSLT into "
1175 helpMsg <<
"HTML and displayed in the browser. " << endl;
1180 <<
"-config pathToConfigureFile this parameter specifies a path on "
1184 <<
"the local machine to a text file containing values for the input parameters. "
1187 <<
"This is convenient for the user not wishing to constantly retype parameter values. "
1190 <<
"This configure file can contain values for all of the other parameters. "
1195 helpMsg <<
"--version or -v get the current version of this executable "
1200 helpMsg <<
"--help or -h to get this help file " << endl;
1205 <<
"Note: If you specify a configure file by using the -config option, you can "
1208 <<
"override the values of the options in the configure file by putting them in "
1210 helpMsg <<
"at the command line. " << endl << endl;
1213 <<
"See the OS User\' Manual: http://www.coin-or.org/OS/doc/osUsersManual.pdf"
1215 helpMsg <<
"for more detail on how to use the OS project. " << endl;
1218 helpMsg <<
"********************************************************"
1221 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 ossslex_init(void **ptr)
OSResult * readOSrL(const std::string &posrl)
Get an OSResult object from an OSrL string.
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)
Take an OSResult object and write a string that validates against OSrL.
This class handles all the output from OSSolverService, OSAmplClient and other executables derived fr...
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.
The Default Solver Class.
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.
YY_BUFFER_STATE osss_scan_string(const char *osss, void *scanner)