172int main(
int argC,
const char* argV[])
174 WindowsErrorPopupBlocker();
175 std::ostringstream outStr;
190 const char *space =
" ";
191 const char *quote =
"\"";
193 std::string configFileName =
"";
202 bool scannerActive =
false;
213 if (argV[i][0] !=
'\"')
214 for (
int k=0; k<strlen(argV[i]); k++)
216 if (argV[i][k] ==
' ')
224 if (strlen(osss) + strlen(argV[i]) + 3 >
MAXCHARS)
225 throw ErrorClass(
"The command line exceeds allocated storage. Increase parameter MAXCHARS.");
227 strcat(osss, argV[i]);
233 if (strlen(osss) + strlen(argV[i]) + 1 >
MAXCHARS)
234 throw ErrorClass(
"The command line exceeds allocated storage. Increase parameter MAXCHARS.");
235 strcat(osss, argV[i]);
244 outStr <<
"Input String = " << osss << std::endl;
248 scannerActive =
true;
269 scannerActive =
false;
276 if (oscommandline->configFile !=
"")
278 scannerActive =
true;
280 configFileName = oscommandline->configFile;
285 outStr <<
"configFileName = " << configFileName << std::endl;
289 std::string configFileOptions = fileUtil->getFileAsString(
290 configFileName.c_str());
304 scannerActive =
false;
313 scannerActive =
true;
334 scannerActive =
false;
354 if (oscommandline->osrlFile !=
"")
356 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
357 if (oscommandline->browser !=
"")
359 std::string str = oscommandline->browser +
" "
360 + oscommandline->osrlFile;
361 const char *ch = &str[0];
380 delete oscommandline;
390 outStr << std::endl <<
"using print level " << oscommandline->printLevel <<
" for stdout" << std::endl;
404 if (oscommandline->logFile !=
"")
406 int status =
osoutput->AddChannel(oscommandline->logFile);
412 "Added channel " + oscommandline->logFile);
416 "Output channel " + oscommandline->logFile +
" previously defined");
419 throw ErrorClass(
"Could not add output channel " + oscommandline->logFile);
425 outStr << std::endl <<
"using print level " << oscommandline->filePrintLevel;
426 outStr <<
" for " << oscommandline->logFile << std::endl;
438 if (oscommandline->invokeHelp ==
true)
442 outStr << std::endl << std::endl <<
get_help() << std::endl;
445 delete oscommandline;
446 oscommandline = NULL;
450 if (oscommandline->writeVersion ==
true)
457 delete oscommandline;
458 oscommandline = NULL;
476 if (oscommandline->osrlFile !=
"")
479 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
480 if (oscommandline->browser !=
"")
482 std::string str = oscommandline->browser +
" "
483 + oscommandline->osrlFile;
484 const char *ch = &str[0];
503 delete oscommandline;
504 oscommandline = NULL;
505 delete inputFileUtil;
506 inputFileUtil = NULL;
514 outStr <<
"HERE ARE THE OPTION VALUES:" << endl;
515 if(oscommandline->configFile !=
"") outStr <<
"Config file = " << oscommandline->configFile << endl;
516 if(oscommandline->osilFile !=
"") outStr <<
"OSiL file = " << oscommandline->osilFile << endl;
517 if(oscommandline->osolFile !=
"") outStr <<
"OSoL file = " << oscommandline->osolFile << endl;
518 if(oscommandline->osrlFile !=
"") outStr <<
"OSrL file = " << oscommandline->osrlFile << endl;
520 if(oscommandline->osplInputFile !=
"") outStr <<
"OSpL Input file = " << oscommandline->osplInputFile << endl;
521 if(oscommandline->serviceMethod !=
"") outStr <<
"Service Method = " << oscommandline->serviceMethod << endl;
522 if(oscommandline->mpsFile !=
"") outStr <<
"MPS File Name = " << oscommandline->mpsFile << endl;
523 if(oscommandline->nlFile !=
"") outStr <<
"NL File Name = " << oscommandline->nlFile << endl;
524 if(oscommandline->gamsControlFile !=
"") outStr <<
"gams Control File Name = " << oscommandline->gamsControlFile << endl;
525 if(oscommandline->browser !=
"") outStr <<
"Browser Value = " << oscommandline->browser << endl;
526 if(oscommandline->solverName !=
"") outStr <<
"Selected Solver = " << oscommandline->solverName << endl;
527 if(oscommandline->serviceLocation !=
"") outStr <<
"Service Location = " << oscommandline->serviceLocation << endl;
528 if(oscommandline->printModel) outStr <<
"print model prior to solve/send" << endl;
529 if(oscommandline->printRowNumberAsString !=
"") outStr <<
"print model row " << oscommandline->printRowNumberAsString <<
" prior to solve/send" << endl;
530 outStr <<
"print level for stdout: " << oscommandline->printLevel << endl;
531 if(oscommandline->logFile !=
"")
533 outStr <<
"also send output to " << oscommandline->logFile << endl;
534 outStr <<
"print level for file output: " << oscommandline->filePrintLevel << endl;
542 for (k = 0; k < oscommandline->solverName.length(); k++)
544 oscommandline->solverName[k] = (char)tolower(oscommandline->solverName[k]);
551 if (oscommandline->osolFile !=
"")
553 oscommandline->osol = fileUtil->getFileAsString(
554 (oscommandline->osolFile).c_str());
557 if (oscommandline->osilFile !=
"")
560 oscommandline->osil = fileUtil->getFileAsString(
561 (oscommandline->osilFile).c_str());
572 if (oscommandline->osplInputFile !=
"")
573 oscommandline->osplInput = fileUtil->getFileAsString(
574 (oscommandline->osplInputFile).c_str());
580 outStr << eclass.errormsg << endl;
581 outStr <<
"could not open file properly" << endl;
594 if (oscommandline->osrlFile !=
"")
596 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
597 if (oscommandline->browser !=
"")
599 std::string str = oscommandline->browser +
" "
600 + oscommandline->osrlFile;
601 const char *ch = &str[0];
617 delete oscommandline;
618 oscommandline = NULL;
625 if (oscommandline->serviceMethod ==
"") oscommandline->serviceMethod =
"solve";
626 if (oscommandline->serviceMethod[0] ==
's')
628 if (oscommandline->printModel ==
true)
630 else if (oscommandline->printRowNumberAsString !=
"")
632 if (oscommandline->serviceMethod[1] ==
'e')
635 solve(oscommandline);
639 switch (oscommandline->serviceMethod[0])
648 if (oscommandline->serviceMethod[1] ==
'i')
651 knock(oscommandline);
658 delete oscommandline;
659 oscommandline = NULL;
672 std::string osrl =
"";
678#ifdef COIN_HAS_GAMSUTILS
687 if (oscommandline->serviceLocation !=
"")
690 if (oscommandline->osil ==
"")
693 if (oscommandline->nlFile !=
"")
699 if (oscommandline->mpsFile !=
"")
705 if (oscommandline->gamsControlFile !=
"")
712 oscommandline->osil =
"";
718 if (oscommandline->printModel)
720 else if (oscommandline->printRowNumberAsString !=
"")
726 if (oscommandline->osol ==
"")
728 std::ostringstream outStr;
730 <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?> <osol xmlns=\"os.optimizationservices.org\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"os.optimizationservices.org http://www.optimizationservices.org/schemas/";
732 outStr <<
"/OSoL.xsd\"></osol>";
733 oscommandline->osol = outStr.str();
735 osrl = osagent->solve(oscommandline->osil, oscommandline->osol);
736 if (oscommandline->osrlFile !=
"")
738 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
739 if (oscommandline->browser !=
"")
741 std::string str = oscommandline->browser +
" "
742 + oscommandline->osrlFile;
743 const char *ch = &str[0];
756 if (oscommandline->osil !=
"")
759 osinstance = osilreader->readOSiL(oscommandline->osil);
764 if (oscommandline->nlFile !=
"")
769 nl2os->readNl(oscommandline->nlFile);
770 nl2os->setOsol(oscommandline->osol);
771 nl2os->createOSObjects() ;
772 osinstance = nl2os->osinstance;
773 if (nl2os->osoption != NULL)
780 std::string sModelOptionName =
"modelOptions.osol";
781 if (fileUtil == NULL) fileUtil =
new FileUtil();
782 fileUtil->writeFileFromString(sModelOptionName, osolwriter->writeOSoL(
osoption) );
791 "nl file specified locally but ASL not present");
796 if (oscommandline->mpsFile !=
"")
798 mps2osil =
new OSmps2osil(oscommandline->mpsFile);
799 mps2osil->createOSInstance();
800 osinstance = mps2osil->osinstance;
804 if (oscommandline->gamsControlFile !=
"")
806#ifdef COIN_HAS_GAMSUTILS
807 gams2osil =
new OSgams2osil( oscommandline->gamsControlFile);
808 gams2osil->createOSInstance();
809 osinstance = gams2osil->osinstance;
812 "a Gams Control specified locally but GAMSIP not present");
819 "Error: no osil, GAMSS dat, AMPL nl, or mps file given for a local solve --- \n NOTE: information in the osol file is ignored for local solves.");
824 if (oscommandline->printModel)
826 else if (oscommandline->printRowNumberAsString !=
"")
827 doPrintRow(osinstance, oscommandline->printRowNumberAsString);
829 osrl =
runSolver(oscommandline->solverName, oscommandline->osol, osinstance);
831 if (oscommandline->osrlFile !=
"")
833 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
836 if (oscommandline->browser !=
"")
838 std::string str = oscommandline->browser +
" "
839 + oscommandline->osrlFile;
840 const char *ch = &str[0];
851 if (osilreader != NULL)
854 if (mps2osil != NULL)
858 if(nl2os != NULL)
delete nl2os;
861#ifdef COIN_HAS_GAMSUTILS
862 if(gams2osil != NULL)
delete gams2osil;
871 std::string osrl =
"";
876 std::string::size_type pos1 = eclass.errormsg.find(
"<osrl");
877 if(pos1 == std::string::npos)
887 osrl = eclass.errormsg;
889 if (oscommandline->osrlFile !=
"")
892 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
893 if (oscommandline->browser !=
"")
895 std::string str = oscommandline->browser +
" "
896 + oscommandline->osrlFile;
897 const char *ch = &str[0];
911 if(osrlwriter != NULL)
918 if (osilreader != NULL)
921 if (mps2osil != NULL)
925 if(nl2os != NULL)
delete nl2os;
928#ifdef COIN_HAS_GAMSUTILS
929 if(gams2osil != NULL)
delete gams2osil;
1504 std::string configFileName =
"";
1508 bool scannerActive =
false;
1511 scannerActive =
true;
1514 std::string lineText;
1516 std::string wordSep =
" ";
1517 std::string dblQuote =
"\"";
1518 std::string optionName =
"";
1519 std::string optionValue =
"";
1520 std::string::size_type indexStart;
1521 std::string::size_type indexEnd;
1524 const int nCommands = 14;
1525 std::string commandArray[nCommands] =
1526 {
"solve",
"send",
"getJobID",
"retrieve",
"kill",
"knock",
1527 "quit",
"exit",
"reset",
"list",
"?",
"help",
"version",
1531 const int nOptions = 14;
1532 std::string optionArray[nOptions] =
1533 {
"osil",
"osrl",
"osol",
"mps",
"nl",
"dat",
1534 "serviceLocation",
"solver",
"osplInput",
"osplOutput",
1535 "printRow",
"printLevel",
"logFile",
"fileLogLevel"
1540 std::map<string, int> commandMap;
1542 for(k = 0; k < nCommands; k++)
1544 commandMap[ commandArray[ k] ] = k;
1549 std::map<string, int> optionMap;
1551 for(k = 0; nOptions; k++)
1553 optionMap[ optionArray[ k] ] = k;
1556 std::cout <<
"At the prompt enter a valid command or option value pair.\n";
1557 std::cout <<
"Enter the \"solve\" command to optimize.\n";
1558 std::cout <<
"Type \"quit\" or \"exit\" to leave the application. \n";
1559 std::cout <<
"Type \"help\" or \"?\" for a list of valid options.\n\n";
1561 while (oscommandline->quit !=
true)
1563 std::cout <<
"Please enter a command, or an option followed by an option value: ";
1564 getline(std::cin, lineText);
1565 lineText =
" " + lineText +
" ";
1567 indexStart = lineText.find_first_not_of(wordSep);
1568 if (indexStart == string::npos)
1570 std::cout << std::endl;
1571 std::cout <<
"You did not enter a valid option. "
1572 <<
"Type \"help\" or \"?\" for a list of valid options."
1577 indexEnd = lineText.find_first_of(wordSep, indexStart + 1);
1578 optionName = lineText.substr(indexStart, indexEnd - indexStart);
1581 if( (commandMap.find(optionName) == commandMap.end() ) &&
1582 (optionMap.find(optionName) == optionMap.end() ) )
1584 std::cout << std::endl;
1585 std::cout <<
"You did not enter a valid option. "
1586 <<
"Type \"help\" or \"?\" for a list of valid options."
1594 indexStart = lineText.find_first_not_of(wordSep, indexEnd + 1);
1595 if (indexStart != std::string::npos && lineText[indexStart] ==
'\"')
1597 indexEnd = lineText.find_first_of(dblQuote, indexStart + 1);
1602 indexEnd = lineText.find_first_of(wordSep, indexStart + 1);
1605 if (indexStart != std::string::npos && indexEnd != std::string::npos)
1607 optionValue = lineText.substr(indexStart + skipChars,
1608 indexEnd - indexStart - skipChars);
1620 if( commandMap.find(optionName) != commandMap.end() )
1622 switch (commandMap[ optionName] )
1627 if(oscommandline->osil ==
"" && oscommandline->mps ==
"" && oscommandline->nl ==
"")
1631 <<
"You did not specify an optimization instance!!!\n"
1632 <<
"Please enter file format option (osil, nl, or mps) \n"
1633 <<
"followed by the option value which is the file location. \n"
1638 solve(oscommandline);
1639 if (oscommandline->osrlFile !=
"")
1640 std::cout <<
"\nSolve command executed. Please see " << oscommandline->osrlFile <<
" for results." << std::endl;
1646 if(oscommandline->serviceLocation ==
"")
1648 send(oscommandline);
1654 if(oscommandline->serviceLocation ==
"")
1662 if(oscommandline->serviceLocation ==
"")
1665 if( (oscommandline->osolFile ==
"") && (oscommandline->jobID ==
"") )
1669 <<
"Cannot retrieve: no JobID and no OSoL file"
1682 if(oscommandline->serviceLocation ==
"")
1685 if( (oscommandline->osolFile ==
"") && (oscommandline->jobID ==
"") )
1689 <<
"Cannot kill: no JobID and no OSoL file"
1694 kill(oscommandline);
1706 if(oscommandline->serviceLocation ==
"")
1709 if( oscommandline->osplInputFile ==
"")
1713 <<
"Cannot knock -- no OSplInputFile specified"
1718 knock(oscommandline);
1738 oscommandline->reset_options();
1739 std::cout <<
"\nAll options reset.\n";
1775 throw ErrorClass(
"we don't have a valid command");
1784 if (optionValue ==
"")
1787 if(optionMap.find(optionName) != optionMap.end() )
1790 switch (optionMap[ optionName] )
1795 <<
"Please enter the name of an osil file: ";
1801 <<
"Please enter the name of an osrl file: ";
1806 <<
"Please enter the name of an osol file: ";
1811 <<
"Please enter the name of an mps file: ";
1816 <<
"Please enter the name of an AMPL nl file: ";
1821 <<
"Please enter the name of a dat file: ";
1826 <<
"Please enter the serviceLocation: ";
1831 <<
"Please enter the name of the solver: ";
1836 <<
"Please enter the name of an osplInput file: ";
1841 <<
"Please enter the name of an osplOutput file: ";
1846 <<
"Please enter the number of a constraint (>=0) or objective (<0): ";
1851 <<
"Please enter the print level (0-"
1857 <<
"Please enter the name of the log file: ";
1862 <<
"Please enter the print level (0-"
1870 getline(std::cin, lineText);
1874 indexStart = lineText.find_first_not_of(wordSep, 0);
1875 if (lineText[indexStart] ==
'\"')
1877 indexEnd = lineText.find_first_of(dblQuote, indexStart + 1);
1882 indexEnd = lineText.find_first_of(wordSep, indexStart + 1);
1885 if (indexStart != std::string::npos && indexEnd != std::string::npos)
1887 optionValue = lineText.substr(indexStart + skipChars,
1888 indexEnd - indexStart - skipChars);
1901 if(optionMap.find(optionName) != optionMap.end() )
1903 switch (optionMap[ optionName] )
1907 oscommandline->osilFile = optionValue;
1909 = fileUtil->getFileAsString(
1910 (oscommandline->osilFile).c_str());
1915 oscommandline->osrlFile = optionValue;
1919 oscommandline->osolFile = optionValue;
1921 = fileUtil->getFileAsString(
1922 (oscommandline->osolFile).c_str());
1926 oscommandline->mpsFile = optionValue;
1928 = fileUtil->getFileAsString(
1929 (oscommandline->mpsFile).c_str());
1933 oscommandline->nlFile = optionValue;
1935 = fileUtil->getFileAsString(
1936 (oscommandline->nlFile).c_str());
1940 oscommandline->datFile = optionValue;
1942 = fileUtil->getFileAsString(
1943 (oscommandline->datFile).c_str());
1947 oscommandline->serviceLocation = optionValue;
1954 < oscommandline->solverName.length(); k++)
1956 oscommandline->solverName[k] =
1957 (char)tolower(oscommandline->solverName[k]);
1959 oscommandline->solverName = optionValue;
1963 oscommandline->osplInputFile = optionValue;
1964 oscommandline->osplInput
1965 = fileUtil->getFileAsString(
1966 (oscommandline->osplInputFile).c_str());
1970 oscommandline->osplOutputFile = optionValue;
1974 oscommandline->printRowNumberAsString = optionValue;
1980 <<
"Please enter the print level (0-"
1986 <<
"Please enter the name of the log file: ";
1991 <<
"Please enter the print level (0-"
2002 std::cout << std::endl;
2006 std::cout << eclass.errormsg << std::endl;
2012 scannerActive =
false;
2013 delete oscommandline;
2014 oscommandline = NULL;
2365 <<
"HERE ARE THE OPTION VALUES SO FAR:"
2367 if (oscommandline->configFile !=
"")
2368 cout <<
"Config file = "
2369 << oscommandline->configFile
2371 if (oscommandline->osilFile !=
"")
2372 cout <<
"OSiL file = "
2373 << oscommandline->osilFile
2375 if (oscommandline->osolFile !=
"")
2376 cout <<
"OSoL file = "
2377 << oscommandline->osolFile
2379 if (oscommandline->osrlFile !=
"")
2380 cout <<
"OSrL file = "
2381 << oscommandline->osrlFile
2384 if (oscommandline->osplInputFile !=
"")
2385 cout <<
"OSpL Input file = "
2386 << oscommandline->osplInputFile
2388 if (oscommandline->serviceMethod !=
"")
2389 cout <<
"Service Method = "
2390 << oscommandline->serviceMethod
2392 if (oscommandline->mpsFile !=
"")
2393 cout <<
"MPS File Name = "
2394 << oscommandline->mpsFile
2396 if (oscommandline->nlFile !=
"")
2397 cout <<
"NL File Name = "
2398 << oscommandline->nlFile
2400 if (oscommandline->solverName !=
"")
2401 cout <<
"Selected Solver = "
2402 << oscommandline->solverName
2404 if (oscommandline->serviceLocation !=
"")
2405 cout <<
"Service Location = "
2406 << oscommandline->serviceLocation
2409 if (oscommandline->jobID !=
"")
2411 << oscommandline->jobID