76 #include "OSInstance.h"
91 #ifdef COIN_HAS_KNITRO
103 #ifdef COIN_HAS_GAMSUTILS
107 #ifdef COIN_HAS_IPOPT
116 #ifdef COIN_HAS_BONMIN
120 #ifdef COIN_HAS_COUENNE
135 using std::ostringstream;
140 #define MAXCHARS 5000
179 int main(
int argC,
const char* argV[])
181 WindowsErrorPopupBlocker();
182 std::ostringstream outStr;
202 std::ostringstream osss;
203 const char *space =
" ";
204 const char *quote =
"\"";
206 std::string configFileName =
"";
214 bool scannerActive =
false;
222 for (i = 1; i < argC; i++)
225 if (argV[i][0] !=
'\"')
226 for (
int k=0;
k<strlen(argV[i]);
k++)
228 if (argV[i][
k] ==
' ')
250 tempBuffer[i] <<
"Input String = " << osss.str() << std::endl;
253 scannerActive =
true;
258 tempBuffer[i] <<
"Call Text Extra\n" << std::endl;
265 tempBuffer[i] <<
"Call scan string\n" << std::endl;
272 tempBuffer[i] <<
"Call ossslex\n" << std::endl;
277 scannerActive =
false;
281 tempBuffer[i] <<
"Done with call to ossslex\n" << std::endl;
287 scannerActive =
true;
293 tempBuffer[i] <<
"configFileName = " << configFileName << std::endl;
297 configFileName.c_str());
300 tempBuffer[i] <<
"Call Text Extra\n" << std::endl;
307 tempBuffer[i] <<
"Done with call Text Extra\n" << std::endl;
319 tempBuffer[i] <<
"Call Text Extra\n" << std::endl;
326 tempBuffer[i] <<
"Call scan string\n" << std::endl;
333 tempBuffer[i] <<
"call ossslex\n" << std::endl;
338 scannerActive =
false;
345 tempBuffer[i] << eclass.
errormsg << std::endl;
354 std::string osrl = osrlwriter->writeOSrL(
osresult);
358 if (oscommandline->
browser !=
"")
360 std::string str = oscommandline->
browser +
" "
362 const char *ch = &str[0];
367 "Results written to file " + oscommandline->
osrlFile);
381 delete oscommandline;
393 tempBuffer[i] << std::endl <<
"using print level "
394 << oscommandline->
printLevel <<
" for stdout" << std::endl;
400 tempBuffer[i] << std::endl <<
"using print level "
401 << oscommandline->
printLevel <<
" for stdout" << std::endl;
406 int printArea = (oscommandline->
printLevel) / 100;
409 tempBuffer[(oscommandline->
printLevel)%100].str());
412 if (oscommandline->
logFile !=
"")
420 "Added channel " + oscommandline->
logFile);
424 "Output channel " + oscommandline->
logFile +
" previously defined");
433 outStr << std::endl <<
"using print level " << oscommandline->
filePrintLevel;
434 outStr <<
" for " << oscommandline->
logFile << std::endl;
450 outStr << std::endl << std::endl <<
get_help() << std::endl;
453 delete oscommandline;
454 oscommandline = NULL;
465 delete oscommandline;
466 oscommandline = NULL;
483 std::string osrl = osrlwriter->
writeOSrL(osresult);
488 if (oscommandline->
browser !=
"")
490 std::string str = oscommandline->
browser +
" "
492 const char *ch = &str[0];
497 "Results written to file " + oscommandline->
osrlFile);
514 delete oscommandline;
515 oscommandline = NULL;
516 delete inputFileUtil;
517 inputFileUtil = NULL;
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;
533 if(oscommandline->
mpsFile !=
"") outStr <<
"MPS File Name = " << oscommandline->
mpsFile << endl;
534 if(oscommandline->
nlFile !=
"") outStr <<
"NL File Name = " << oscommandline->
nlFile << endl;
536 if(oscommandline->
browser !=
"") outStr <<
"Browser Value = " << oscommandline->
browser << endl;
537 if(oscommandline->
solverName !=
"") outStr <<
"Selected Solver = " << oscommandline->
solverName << endl;
539 if(oscommandline->
printModel) outStr <<
"print model prior to solve/send" << endl;
541 outStr <<
"print level for stdout: " << oscommandline->
printLevel << endl;
542 if(oscommandline->
logFile !=
"")
544 outStr <<
"also send output to " << oscommandline->
logFile << endl;
545 outStr <<
"print level for file output: " << oscommandline->
filePrintLevel << endl;
553 for (k = 0; k < oscommandline->
solverName.length(); k++)
592 outStr <<
"could not open file properly" << endl;
604 std::string osrl = osrlwriter->
writeOSrL(osresult);
608 if (oscommandline->
browser !=
"")
610 std::string str = oscommandline->
browser +
" "
612 const char *ch = &str[0];
617 "Results written to file " + oscommandline->
osrlFile);
631 delete oscommandline;
632 oscommandline = NULL;
649 solve(oscommandline);
665 knock(oscommandline);
672 delete oscommandline;
673 oscommandline = NULL;
686 std::string osrl =
"";
692 #ifdef COIN_HAS_GAMSUTILS
704 if (oscommandline->
osil ==
"")
705 getOS(oscommandline);
718 if (oscommandline->
osol ==
"")
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/";
726 outStr <<
"/OSoL.xsd\"></osol>";
727 oscommandline->
osol = outStr.str();
730 osrl = osagent->
solve(oscommandline->
osil, oscommandline->
osol);
734 if (oscommandline->
browser !=
"")
736 std::string str = oscommandline->
browser +
" "
738 const char *ch = &str[0];
743 "Results written to file " + oscommandline->
osrlFile);
754 if (oscommandline->
osil !=
"")
762 if (oscommandline->
nlFile !=
"")
778 std::string sModelOptionName =
"modelOptions.osol";
779 if (fileUtil == NULL) fileUtil =
new FileUtil();
789 "nl file specified locally but ASL not present");
794 if (oscommandline->
mpsFile !=
"")
804 #ifdef COIN_HAS_GAMSUTILS
810 "a Gams Control specified locally but GAMSIP not present");
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.");
834 if (oscommandline->
browser !=
"")
836 std::string str = oscommandline->
browser +
" "
838 const char *ch = &str[0];
843 "Results written to file " + oscommandline->
osrlFile);
852 if (osilreader != NULL)
855 if (mps2osil != NULL)
859 if(nl2os != NULL)
delete nl2os;
862 #ifdef COIN_HAS_GAMSUTILS
863 if(gams2osil != NULL)
delete gams2osil;
872 std::string osrl =
"";
877 std::string::size_type pos1 = eclass.
errormsg.find(
"<osrl");
878 if(pos1 == std::string::npos)
899 if(osrlwriter != NULL)
906 if (osilreader != NULL)
909 if (mps2osil != NULL)
913 if(nl2os != NULL)
delete nl2os;
916 #ifdef COIN_HAS_GAMSUTILS
917 if(gams2osil != NULL)
delete gams2osil;
936 "JobID:\n\n" + oscommandline->
jobID);
944 throw ErrorClass(
"please specify service location (url)");
953 std::string osrl =
"";
958 string::size_type pos1 = eclass.
errormsg.find(
"<osrl");
959 if(pos1 == std::string::npos)
978 if(osrlwriter != NULL)
993 std::string osplOutput =
"";
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" <<
1022 if(oscommandline->
jobID !=
"")
1036 throw ErrorClass(
"please specify service location (url)");
1043 std::string osrl =
"";
1048 string::size_type pos1 = eclass.
errormsg.find(
"<osrl");
1049 if(pos1 == std::string::npos)
1055 std::string osrl = osrlwriter->
writeOSrL(osresult);
1062 if(osresult != NULL)
1067 if(osrlwriter != NULL)
1088 if (oscommandline->
osil ==
"")
1089 getOS(oscommandline);
1098 bSend = osagent->
send(oscommandline->
osil, oscommandline->
osol);
1104 "Send failed, check to make sure you sent a jobID not on the system.");
1111 throw ErrorClass(
"please specify service location (url)");
1116 std::string osrl =
"";
1123 string::size_type pos1 = eclass.
errormsg.find(
"<osrl");
1124 if(pos1 == std::string::npos)
1141 "Results written to file " + oscommandline->
osrlFile);
1146 if(osresult != NULL)
1151 if(osrlwriter != NULL)
1165 std::string osrl =
"";
1174 if(oscommandline->
jobID !=
"")
1183 std::ostringstream outStr;
1187 outStr <<
"Solver Result Written to File: " << oscommandline->
osrlFile << endl;
1189 if (oscommandline->
browser !=
"")
1191 std::string str = oscommandline->
browser +
" "
1193 const char *ch = &str[0];
1198 "Results written to file " + oscommandline->
osrlFile);
1209 throw ErrorClass(
"please specify service location (url)");
1216 std::string osrl =
"";
1221 string::size_type pos1 = eclass.
errormsg.find(
"<osrl");
1222 if(pos1 == std::string::npos)
1235 if(osresult != NULL)
1240 if(osrlwriter != NULL)
1254 std::string osplOutput =
"";
1263 if(oscommandline->
jobID !=
"")
1266 osplOutput = osagent->
kill(oscommandline->
osol);
1286 throw ErrorClass(
"please specify service location (url)");
1293 std::string osrl =
"";
1298 string::size_type pos1 = eclass.
errormsg.find(
"<osrl");
1299 if(pos1 == std::string::npos)
1312 if(osresult != NULL)
1317 if(osrlwriter != NULL)
1337 if (oscommandline->
osol ==
"")
1352 if (osolReader != NULL)
delete osolReader;
1369 std::string osrl =
"";
1374 string::size_type pos1 = eclass.
errormsg.find(
"<osrl");
1375 if(pos1 == std::string::npos)
1388 if (osresult != NULL)
1393 if (osrlwriter != NULL)
1407 if (oscommandline->
nlFile !=
"")
1413 if (oscommandline->
mpsFile !=
"")
1425 oscommandline->
osil =
"";
1446 oscommandline->
osil = osil;
1453 "trying to convert nl to osil without AMPL ASL configured");
1468 #ifdef COIN_HAS_GAMSIO
1476 oscommandline->
osil = osil;
1483 "trying to convert Gams control file to osil without GAMSUTILS configured");
1505 oscommandline->
osil = osil;
1515 if (mps2osil != NULL)
delete mps2osil;
1517 if (osilwriter != NULL)
delete osilwriter;
1530 <<
"A service location is required"
1533 <<
"Please type the URL of the remote service: ";
1542 std::string configFileName =
"";
1544 bool logfileset =
false;
1545 bool fileprintlevelset =
false;
1546 int save_fileprintlevel = -1;
1547 std::string logfilename;
1550 bool scannerActive =
false;
1553 scannerActive =
true;
1556 std::string lineText;
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;
1566 const int nCommands = 13;
1567 std::string commandArray[nCommands] =
1568 {
"solve",
"send",
"getJobID",
"retrieve",
"kill",
"knock",
1569 "quit",
"exit",
"reset",
"?",
"help",
"version",
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"
1582 std::map<string, int> commandMap;
1584 for(k = 0; k < nCommands; k++)
1586 commandMap[ commandArray[
k] ] =
k;
1591 std::map<string, int> optionMap;
1593 for(k = 0; k < nOptions; k++)
1595 optionMap[ optionArray[
k] ] =
k;
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";
1603 while (oscommandline->
quit !=
true)
1605 std::cout <<
"Please enter a command, or an option followed by an option value: ";
1606 getline(std::cin, lineText);
1607 lineText =
" " + lineText +
" ";
1609 indexStart = lineText.find_first_not_of(wordSep);
1610 if (indexStart == string::npos)
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."
1619 indexEnd = lineText.find_first_of(wordSep, indexStart + 1);
1620 optionName = lineText.substr(indexStart, indexEnd - indexStart);
1623 if( (commandMap.find(optionName) == commandMap.end() ) &&
1624 (optionMap.find(optionName) == optionMap.end() ) )
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."
1636 indexStart = lineText.find_first_not_of(wordSep, indexEnd + 1);
1637 if (indexStart != std::string::npos && lineText[indexStart] ==
'\"')
1639 indexEnd = lineText.find_first_of(dblQuote, indexStart + 1);
1644 indexEnd = lineText.find_first_of(wordSep, indexStart + 1);
1648 if (indexStart != std::string::npos)
1650 if (indexEnd != std::string::npos)
1651 optionValue = lineText.substr(indexStart + skipChars,
1652 indexEnd - indexStart - skipChars);
1654 optionValue = lineText.substr(indexStart + skipChars,
1655 lineText.length() - indexStart - skipChars);
1665 if( commandMap.find(optionName) != commandMap.end() )
1667 switch (commandMap[ optionName] )
1672 if(oscommandline->
osil ==
"" && oscommandline->
mps ==
"" && oscommandline->
nl ==
"")
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"
1683 solve(oscommandline);
1685 std::cout <<
"\nSolve command executed. Please see "
1686 << oscommandline->
osrlFile <<
" for results." << std::endl;
1694 send(oscommandline);
1711 if( (oscommandline->
osolFile ==
"") && (oscommandline->
jobID ==
"") )
1715 <<
"Cannot retrieve: no JobID and no OSoL file"
1731 if( (oscommandline->
osolFile ==
"") && (oscommandline->
jobID ==
"") )
1735 <<
"Cannot kill: no JobID and no OSoL file"
1740 kill(oscommandline);
1759 <<
"Cannot knock -- no OSplInputFile specified"
1764 knock(oscommandline);
1785 std::cout <<
"\nAll options reset.\n";
1814 throw ErrorClass(
"we don't have a valid command");
1823 if (optionValue ==
"")
1826 if(optionMap.find(optionName) != optionMap.end() )
1829 switch (optionMap[ optionName] )
1834 <<
"Please enter the name of an osil file: ";
1840 <<
"Please enter the name of an osrl file: ";
1845 <<
"Please enter the name of an osol file: ";
1850 <<
"Please enter the name of an mps file: ";
1855 <<
"Please enter the name of an AMPL nl file: ";
1860 <<
"Please enter the name of a dat file: ";
1865 <<
"Please enter the serviceLocation: ";
1870 <<
"Please enter the name of the solver: ";
1875 <<
"Please enter the name of an osplInput file: ";
1880 <<
"Please enter the name of an osplOutput file: ";
1885 <<
"Please enter the number of a constraint (>=0) or objective (<0): ";
1890 <<
"Please enter the print level (0-"
1896 <<
"Please enter the name of the log file: ";
1901 <<
"Please enter the print level (0-"
1902 << ENUM_OUTPUT_LEVEL_NUMBER_OF_LEVELS <<
"): ";
1907 <<
"Please select what to list (\"options\" or \"solvers\"): ";
1913 getline(std::cin, lineText);
1917 indexStart = lineText.find_first_not_of(wordSep, 0);
1918 if (lineText[indexStart] ==
'\"')
1920 indexEnd = lineText.find_first_of(dblQuote, indexStart + 1);
1925 indexEnd = lineText.find_first_of(wordSep, indexStart + 1);
1928 if (indexStart != std::string::npos)
1930 if (indexEnd != std::string::npos)
1931 optionValue = lineText.substr(indexStart + skipChars,
1932 indexEnd - indexStart - skipChars);
1934 optionValue = lineText.substr(indexStart + skipChars,
1935 lineText.length() - indexStart - skipChars);
1948 if(optionMap.find(optionName) != optionMap.end() )
1950 switch (optionMap[ optionName] )
1954 oscommandline->
osilFile = optionValue;
1957 (oscommandline->
osilFile).c_str());
1962 oscommandline->
osrlFile = optionValue;
1966 oscommandline->
osolFile = optionValue;
1969 (oscommandline->
osolFile).c_str());
1973 oscommandline->
mpsFile = optionValue;
1976 (oscommandline->
mpsFile).c_str());
1980 oscommandline->
nlFile = optionValue;
1983 (oscommandline->
nlFile).c_str());
1987 oscommandline->
datFile = optionValue;
1990 (oscommandline->
datFile).c_str());
2031 if (fileprintlevelset)
2034 logfilename = optionValue;
2041 fileprintlevelset =
true;
2042 save_fileprintlevel = atoi(optionValue.c_str());
2047 if (optionValue ==
"solvers")
2049 else if (optionValue ==
"options")
2052 std::cout <<
"unrecognized option value \""
2053 << optionValue <<
"\"" << std::endl;
2063 std::cout << std::endl;
2067 std::cout << eclass.
errormsg << std::endl;
2073 scannerActive =
false;
2074 delete oscommandline;
2075 oscommandline = NULL;
2082 std::ostringstream helpMsg;
2084 helpMsg <<
"************************* HELP *************************"
2087 <<
"In this HELP file we assume that the solve service method is used and "
2090 <<
"that we are solving problems locally, that is the solver is on the "
2093 <<
"machine running this OSSolverService. See Section 10.3 of the User\'s "
2096 <<
"Manual for other service methods or calling a server remotely. "
2098 helpMsg <<
"The OSSolverService takes the parameters listed below. "
2101 <<
"The order of the parameters is irrelevant. Not all the parameters "
2103 helpMsg <<
"are required. However, the location of an instance file is "
2106 <<
"required when using the solve service method. The location of the "
2108 helpMsg <<
"instance file is specified using the osil option. " << endl;
2113 <<
"-osil xxx.osil this is the name of the file that contains the "
2115 helpMsg <<
"optimization instance in OSiL format. This option may be "
2117 helpMsg <<
"specified in the OSoL solver options file. " << endl;
2122 <<
"-osol xxx.osol this is the name of the file that contains the solver options. "
2124 helpMsg <<
"It is not necessary to specify this option. " << endl;
2129 <<
"-osrl xxx.osrl this is the name of the file to which the solver solution is written. "
2132 <<
"It is not necessary to specify this option. If this option is not specified, "
2134 helpMsg <<
"the result will be printed to standard out. " << endl;
2139 <<
"-osplInput xxx.ospl this is the name of an input file in the OS Process"
2141 helpMsg <<
" Language (OSpL), this is used as input to the knock method."
2147 <<
"-osplOutput xxx.ospl this is the name of an output file in the OS Process"
2150 <<
"Language (OSpL), this the output string from the knock and kill methods."
2155 helpMsg <<
"-serviceLocation url is the URL of the solver service. "
2158 <<
"This is not required, and if not specified it is assumed that "
2160 helpMsg <<
"the problem is solved locally. " << endl;
2165 <<
"-serviceMethod methodName this is the method on the solver service to be invoked. "
2168 <<
"The options are solve, send, kill, knock, getJobID, and retrieve. "
2171 <<
"This option is not required, and the default value is solve. "
2177 <<
"-mps xxx.mps this is the name of the mps file if the problem instance "
2180 <<
"is in mps format. The default file format is OSiL so this option is not required. "
2186 <<
"-nl xxx.nl this is the name of the AMPL nl file if the problem "
2189 <<
"instance is in AMPL nl format. The default file format is OSiL "
2191 helpMsg <<
"so this option is not required. " << endl;
2196 <<
"-solver solverName Possible values for default OS installation "
2199 <<
"are bonmin(COIN-OR Bonmin), couenne (COIN-OR Couenne), clp (COIN-OR Clp),"
2201 helpMsg <<
"cbc (COIN-OR Cbc), dylp (COIN-OR DyLP), ipopt (COIN-OR Ipopt),"
2203 helpMsg <<
"and symphony (COIN-OR SYMPHONY). Other solvers supported"
2206 <<
"(if the necessary libraries are present) are cplex (Cplex through COIN-OR Osi),"
2209 <<
"glpk (glpk through COIN-OR Osi), and lindo (LINDO)."
2211 helpMsg <<
"If no value is specified for this parameter," << endl;
2212 helpMsg <<
"then cbc is the default value of this parameter." << endl;
2217 <<
"-browser browserName this parameter is a path to the browser on the "
2220 <<
"local machine. If this optional parameter is specified then the "
2222 helpMsg <<
"solver result in OSrL format is transformed using XSLT into "
2224 helpMsg <<
"HTML and displayed in the browser. " << endl;
2229 <<
"-config pathToConfigureFile this parameter specifies a path on "
2232 <<
"the local machine to a text file containing values for the input parameters. "
2235 <<
"This is convenient for the user not wishing to constantly retype parameter values. "
2238 <<
"This configure file can contain values for all of the other parameters. "
2243 helpMsg <<
"--version or -v get the current version of this executable "
2248 helpMsg <<
"--help or -h to get this help file " << endl;
2253 <<
"Note: If you specify a configure file by using the -config option, you can "
2256 <<
"override the values of the options in the configure file by putting them in "
2258 helpMsg <<
"at the command line. " << endl << endl;
2261 <<
"See the OS User\' Manual: http://www.coin-or.org/OS/doc/osUsersManual.pdf"
2263 helpMsg <<
"for more detail on how to use the OS project. " << endl;
2266 helpMsg <<
"********************************************************"
2269 return helpMsg.str();
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;
2281 return versionMsg.str();
2286 std::ostringstream optionMsg;
2291 <<
"***************** VALID COMMANDS AND OPTIONS ********************"
2297 <<
"quit/exit -- terminate the executable"
2300 <<
"help/? -- produce this list of options"
2303 <<
"reset -- erase all previous option settings"
2306 <<
"list options -- list the current option values"
2309 <<
"list solvers -- list the locally available solvers"
2312 <<
"solve -- call a remote solver synchronously"
2315 <<
"send -- call a remote solver asynchronously"
2318 <<
"kill -- end a job on the remote server"
2321 <<
"retrieve -- get job result on the remote server"
2324 <<
"knock -- get job information on the remote server"
2327 <<
"getJobID -- get a job ID from the remote server"
2332 <<
"OPTIONS (THESE REQUIRE A VALUE):"
2335 <<
"osil -- the location of the model instance in OSiL format"
2338 <<
"mps -- the location of the model instance in MPS format"
2341 <<
"nl -- the location of the model instance in AMPL nl format"
2344 <<
"osol -- the location of the solver option file in OSoL format"
2347 <<
"osrl -- the location of the solver result file in OSrL format"
2350 <<
"osplInput -- the name of an input file in OSpL format"
2353 <<
"osplOutput -- the name of an output file in OSpL format"
2356 <<
"serviceLocation -- the URL of a remote solver service"
2359 <<
"solver -- specify the solver to invoke"
2362 <<
"See http://www.coin-or.org/OS/"
2365 <<
"for more detail on how to use the OS project."
2372 <<
"printModel -- print the currently defined model"
2375 <<
"printRow nnn -- print row n of the currently defined model"
2378 <<
" if nnn >= 0, prints a constraint, otherwise prints an objective row"
2381 <<
"printLevel nnn -- control the amount of output sent to stdout"
2384 <<
" valid values are 0..";
2391 <<
"logFile -- a secondary output device"
2394 <<
"filePrintLevel nnn -- control the amount of output sent to logFile"
2397 <<
" valid values are 0..";
2406 <<
"*****************************************************************"
2409 <<
"At the prompt enter a valid command or option value pair."
2412 <<
"Enter the \"solve\" command to optimize."
2415 <<
"Type \"quit/exit\" to leave the application."
2418 <<
"Type \"help\" or \"?\" for a list of valid options."
2422 return optionMsg.str();
2428 std::string header =
"This OSSolverService is configured with the following solvers:";
2429 bool writeheader =
true;
2432 if (writeheader) temp << header << std::endl;
2433 temp <<
" Clp" << std::endl;
2434 writeheader =
false;
2438 if (writeheader) temp << header << std::endl;
2439 temp <<
" Cbc" << std::endl;
2440 writeheader =
false;
2443 #ifdef COIN_HAS_DYLP
2444 if (writeheader) temp << header << std::endl;
2445 temp <<
" DyLP" << std::endl;
2446 writeheader =
false;
2449 #ifdef COIN_HAS_SYMPHONY
2450 if (writeheader) temp << header << std::endl;
2451 temp <<
" SYMPHONY" << std::endl;
2452 writeheader =
false;
2456 if (writeheader) temp << header << std::endl;
2457 temp <<
" Vol" << std::endl;
2458 writeheader =
false;
2461 #ifdef COIN_HAS_IPOPT
2462 if (writeheader) temp << header << std::endl;
2463 temp <<
" Ipopt" << std::endl;
2464 writeheader =
false;
2467 #ifdef COIN_HAS_BONMIN
2468 if (writeheader) temp << header << std::endl;
2469 temp <<
" Bonmin" << std::endl;
2470 writeheader =
false;
2473 #ifdef COIN_HAS_COUENNE
2474 if (writeheader) temp << header << std::endl;
2475 temp <<
" Couenne" << std::endl;
2476 writeheader =
false;
2479 #ifdef COIN_HAS_GLPK
2480 if (writeheader) temp << header << std::endl;
2481 temp <<
" GLPK" << std::endl;
2482 writeheader =
false;
2485 #ifdef COIN_HAS_CSDP
2486 if (writeheader) temp << header << std::endl;
2487 temp <<
" CSDP" << std::endl;
2488 writeheader =
false;
2492 if (writeheader) temp << header << std::endl;
2493 temp <<
" CPLEX" << std::endl;
2494 writeheader =
false;
2498 if (writeheader) temp << header << std::endl;
2499 temp <<
" Gurobi" << std::endl;
2500 writeheader =
false;
2503 #ifdef COIN_HAS_KNITRO
2504 if (writeheader) temp << header << std::endl;
2505 temp <<
" Knitro" << std::endl;
2506 writeheader =
false;
2509 #ifdef COIN_HAS_LINDO
2510 if (writeheader) temp << header << std::endl;
2511 temp <<
" Lindo" << std::endl;
2512 writeheader =
false;
2516 if (writeheader) temp << header << std::endl;
2517 temp <<
" Mosek" << std::endl;
2518 writeheader =
false;
2521 #ifdef COIN_HAS_SOPLEX
2522 if (writeheader) temp << header << std::endl;
2523 temp <<
" SoPlex" << std::endl;
2524 writeheader =
false;
2528 if (writeheader) temp << header << std::endl;
2529 temp <<
" XPRESS" << std::endl;
2530 writeheader =
false;
2534 temp <<
"This OSSolverService is configured without any solvers!";
2540 <<
"HERE ARE THE OPTION VALUES SO FAR:"
2543 cout <<
"Config file = "
2547 cout <<
"OSiL file = "
2551 cout <<
"OSoL file = "
2555 cout <<
"OSrL file = "
2560 cout <<
"OSpL Input file = "
2564 cout <<
"Service Method = "
2567 if (oscommandline->
mpsFile !=
"")
2568 cout <<
"MPS File Name = "
2571 if (oscommandline->
nlFile !=
"")
2572 cout <<
"NL File Name = "
2576 cout <<
"Selected Solver = "
2580 cout <<
"Service Location = "
2584 if (oscommandline->
jobID !=
"")
2586 << oscommandline->
jobID
2592 if (oscommandline->
osil ==
"" && oscommandline->
mps ==
"" && oscommandline->
nl ==
"")
2595 <<
"no instance defined; print command ignored" << std::endl;
2599 if (oscommandline->
osil !=
"")
2607 else if (oscommandline->
nl !=
"")
2620 std::cout <<
"no ASL present to read nl file; print command ignored" << std::endl;
2623 else if (oscommandline->
mps !=
"")
2637 if (osinstance == NULL)
2640 <<
"no instance defined; print command ignored" << std::endl;
2644 std::cout << osinstance->
printModel() << std::endl;
2652 std::cout <<
"no line number given; print command ignored" << std::endl;
2661 std::cout <<
"invalid row number; print command ignored" << std::endl;
2664 if (oscommandline->
osil ==
"" && oscommandline->
mps ==
"" && oscommandline->
nl ==
"")
2667 <<
"no instance defined; print command ignored" << std::endl;
2671 std::cout << std::endl <<
"Row " << rownumber <<
":" << std::endl << std::endl;
2672 if (oscommandline->
osil !=
"")
2680 else if (oscommandline->
nl !=
"")
2693 std::cout <<
"no ASL present to read nl file; print command ignored" << std::endl;
2696 else if (oscommandline->
mps !=
"")
2712 if (rownumberstring ==
"")
2713 std::cout <<
"no line number given; print command ignored" << std::endl;
2718 rownumber = atoi((rownumberstring).c_str());
2722 std::cout <<
"invalid row number; print command ignored" << std::endl;
2725 if (osinstance == NULL)
2728 <<
"no instance defined; print command ignored" << std::endl;
2732 std::cout << std::endl <<
"Row " << rownumber <<
":" << std::endl << std::endl;
2733 std::cout << osinstance->
printModel(rownumber) << std::endl;
std::string datFile
the name of the file that holds an instance in GAMS dat format
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
std::string dat
the string that holds an instance in GAMS dat format
bool writeVersion
if this parameter is true we print the current version of the OS project
void getOSFromMps(OSCommandLine *oscommandline)
void merge_CL_options(OSCommandLine *oscommandline)
This routine merges command line options destined for the remote system with any options already foun...
void doPrintModel(OSCommandLine *oscommandline)
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
std::string printModel()
Print the infix representation of the problem.
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
bool interactiveShell(std::string *schema, std::string *testFileName, std::string *outFileName, bool *compress, bool *addWhiteSpace, bool *verifyObjects, bool *useRandomObjects, unsigned int *seed, int *nrep, double *density, bool *conformant)
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 ...
std::string get_solverlist()
OSInstance * osinstance
osinstance is a pointer to the OSInstance object that gets created from the instance represented in M...
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.
std::string nl
the string that holds an instance in AMPL nl format
std::string get_version()
bool setSolverToInvoke(std::string solverToInvoke)
Set the solver to be invoked.
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.
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.
void getOS(OSCommandLine *oscommandline)
Some wrappers around routines that allow getting problem instances in other formats: ...
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
std::string mps
the string that holds an instance in MPS format
void getOSFromNl(OSCommandLine *oscommandline)
bool createOSInstance()
Creates an OSInstance from the GAMS smag instance representation.
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)
void getOSFromGams(OSCommandLine *oscommandline)
bool printModel
if this parameter is true we print the current instance as read from an osil, nl or mps file ...
#define OS_SCHEMA_VERSION
Used to read an OSiL string.
void getServiceLocation(OSCommandLine *oscommandline)
======================== Interactive shell =========================
OSOption * osoption
osoption is a pointer to the OSOption object that gets created from the information in the nl file (a...
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.
bool createOSObjects()
create an OSInstance from the MPS instance representation and an OSOption in case of nonstandard sect...
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.
bool quit
if this parameter is true we quit/exit
std::string osolFile
osolFile is the name of the file that holds the solver options in OSoL format
std::string getFileAsString(const char *fname)
read a file and return contents as a string.
bool setJobID(std::string jobID)
Set the job ID.
std::string get_options()
void list_options(OSCommandLine *oscommandline)
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...
Creating a OSInstance from a GAMS model given as GAMS Modeling Object (GMO).
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
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)
void reset_options()
a function to reset the command line to default values useful especially in the interactive shell ...