179int 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 (
size_t 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;
285 if (oscommandline->configFile !=
"")
287 scannerActive =
true;
289 configFileName = oscommandline->configFile;
293 tempBuffer[i] <<
"configFileName = " << configFileName << std::endl;
296 std::string configFileOptions = fileUtil->getFileAsString(
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;
355 if (oscommandline->osrlFile !=
"")
357 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
358 if (oscommandline->browser !=
"")
360 std::string str = oscommandline->browser +
" "
361 + oscommandline->osrlFile;
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 !=
"")
414 int status =
osoutput->AddChannel(oscommandline->logFile);
420 "Added channel " + oscommandline->logFile);
424 "Output channel " + oscommandline->logFile +
" previously defined");
427 throw ErrorClass(
"Could not add output channel " + oscommandline->logFile);
433 outStr << std::endl <<
"using print level " << oscommandline->filePrintLevel;
434 outStr <<
" for " << oscommandline->logFile << std::endl;
446 if (oscommandline->invokeHelp ==
true)
450 outStr << std::endl << std::endl <<
get_help() << std::endl;
453 delete oscommandline;
454 oscommandline = NULL;
458 if (oscommandline->writeVersion ==
true)
465 delete oscommandline;
466 oscommandline = NULL;
484 if (oscommandline->osrlFile !=
"")
487 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
488 if (oscommandline->browser !=
"")
490 std::string str = oscommandline->browser +
" "
491 + oscommandline->osrlFile;
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;
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 !=
"")
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++)
555 oscommandline->solverName[k] = (char)tolower(oscommandline->solverName[k]);
562 if (oscommandline->osolFile !=
"")
564 oscommandline->osol = fileUtil->getFileAsString(
565 (oscommandline->osolFile).c_str());
568 if (oscommandline->osilFile !=
"")
571 oscommandline->osil = fileUtil->getFileAsString(
572 (oscommandline->osilFile).c_str());
583 if (oscommandline->osplInputFile !=
"")
584 oscommandline->osplInput = fileUtil->getFileAsString(
585 (oscommandline->osplInputFile).c_str());
591 outStr << eclass.errormsg << endl;
592 outStr <<
"could not open file properly" << endl;
605 if (oscommandline->osrlFile !=
"")
607 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
608 if (oscommandline->browser !=
"")
610 std::string str = oscommandline->browser +
" "
611 + oscommandline->osrlFile;
612 const char *ch = &str[0];
617 "Results written to file " + oscommandline->osrlFile);
631 delete oscommandline;
632 oscommandline = NULL;
639 if (oscommandline->serviceMethod ==
"") oscommandline->serviceMethod =
"solve";
640 if (oscommandline->serviceMethod[0] ==
's')
642 if (oscommandline->printModel ==
true)
644 else if (oscommandline->printRowNumberAsString !=
"")
646 if (oscommandline->serviceMethod[1] ==
'e')
649 solve(oscommandline);
653 switch (oscommandline->serviceMethod[0])
662 if (oscommandline->serviceMethod[1] ==
'i')
665 knock(oscommandline);
672 delete oscommandline;
673 oscommandline = NULL;
686 std::string osrl =
"";
692#ifdef COIN_HAS_GAMSUTILS
701 if (oscommandline->serviceLocation !=
"")
704 if (oscommandline->osil ==
"")
705 getOS(oscommandline);
707 if (oscommandline->printModel)
709 else if (oscommandline->printRowNumberAsString !=
"")
715 if (oscommandline->solverName !=
"")
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);
731 if (oscommandline->osrlFile !=
"")
733 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
734 if (oscommandline->browser !=
"")
736 std::string str = oscommandline->browser +
" "
737 + oscommandline->osrlFile;
738 const char *ch = &str[0];
743 "Results written to file " + oscommandline->osrlFile);
754 if (oscommandline->osil !=
"")
757 osinstance = osilreader->readOSiL(oscommandline->osil);
762 if (oscommandline->nlFile !=
"")
767 nl2os->readNl(oscommandline->nlFile);
768 nl2os->setOsol(oscommandline->osol);
769 nl2os->createOSObjects();
770 osinstance = nl2os->osinstance;
771 if (nl2os->osoption != NULL)
778 std::string sModelOptionName =
"modelOptions.osol";
779 if (fileUtil == NULL) fileUtil =
new FileUtil();
780 fileUtil->writeFileFromString(sModelOptionName, osolwriter->writeOSoL(
osoption) );
789 "nl file specified locally but ASL not present");
794 if (oscommandline->mpsFile !=
"")
796 mps2osil =
new OSmps2OS(oscommandline->mpsFile);
797 mps2osil->createOSObjects();
798 osinstance = mps2osil->osinstance;
802 if (oscommandline->gamsControlFile !=
"")
804#ifdef COIN_HAS_GAMSUTILS
805 gams2osil =
new OSgams2osil( oscommandline->gamsControlFile);
806 gams2osil->createOSInstance();
807 osinstance = gams2osil->osinstance;
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.");
822 if (oscommandline->printModel)
824 else if (oscommandline->printRowNumberAsString !=
"")
825 doPrintRow(osinstance, oscommandline->printRowNumberAsString);
827 osrl =
runSolver(oscommandline->solverName, oscommandline->osol, osinstance);
829 if (oscommandline->osrlFile !=
"")
831 fileUtil->writeFileFromString(oscommandline->osrlFile, osrl);
834 if (oscommandline->browser !=
"")
836 std::string str = oscommandline->browser +
" "
837 + oscommandline->osrlFile;
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)
888 osrl = eclass.errormsg;
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;
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);
1684 if (oscommandline->osrlFile !=
"")
1685 std::cout <<
"\nSolve command executed. Please see "
1686 << oscommandline->osrlFile <<
" for results." << std::endl;
1692 if(oscommandline->serviceLocation ==
"")
1694 send(oscommandline);
1700 if(oscommandline->serviceLocation ==
"")
1708 if(oscommandline->serviceLocation ==
"")
1711 if( (oscommandline->osolFile ==
"") && (oscommandline->jobID ==
"") )
1715 <<
"Cannot retrieve: no JobID and no OSoL file"
1728 if(oscommandline->serviceLocation ==
"")
1731 if( (oscommandline->osolFile ==
"") && (oscommandline->jobID ==
"") )
1735 <<
"Cannot kill: no JobID and no OSoL file"
1740 kill(oscommandline);
1752 if(oscommandline->serviceLocation ==
"")
1755 if( oscommandline->osplInputFile ==
"")
1759 <<
"Cannot knock -- no OSplInputFile specified"
1764 knock(oscommandline);
1784 oscommandline->reset_options();
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-"
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;
1956 = fileUtil->getFileAsString(
1957 (oscommandline->osilFile).c_str());
1962 oscommandline->osrlFile = optionValue;
1966 oscommandline->osolFile = optionValue;
1968 = fileUtil->getFileAsString(
1969 (oscommandline->osolFile).c_str());
1973 oscommandline->mpsFile = optionValue;
1975 = fileUtil->getFileAsString(
1976 (oscommandline->mpsFile).c_str());
1980 oscommandline->nlFile = optionValue;
1982 = fileUtil->getFileAsString(
1983 (oscommandline->nlFile).c_str());
1987 oscommandline->datFile = optionValue;
1989 = fileUtil->getFileAsString(
1990 (oscommandline->datFile).c_str());
1994 oscommandline->serviceLocation = optionValue;
2001 < oscommandline->solverName.length(); k++)
2003 oscommandline->solverName[k] =
2004 (char)tolower(oscommandline->solverName[k]);
2006 oscommandline->solverName = optionValue;
2010 oscommandline->osplInputFile = optionValue;
2011 oscommandline->osplInput
2012 = fileUtil->getFileAsString(
2013 (oscommandline->osplInputFile).c_str());
2017 oscommandline->osplOutputFile = optionValue;
2021 oscommandline->printRowNumberAsString = optionValue;
2031 if (fileprintlevelset)
2034 logfilename = optionValue;
2039 osoutput->SetPrintLevel(logfilename,
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;
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;
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;
2480 if (writeheader) temp << header << std::endl;
2481 temp <<
" GLPK" << std::endl;
2482 writeheader =
false;
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:"
2542 if (oscommandline->configFile !=
"")
2543 cout <<
"Config file = "
2544 << oscommandline->configFile
2546 if (oscommandline->osilFile !=
"")
2547 cout <<
"OSiL file = "
2548 << oscommandline->osilFile
2550 if (oscommandline->osolFile !=
"")
2551 cout <<
"OSoL file = "
2552 << oscommandline->osolFile
2554 if (oscommandline->osrlFile !=
"")
2555 cout <<
"OSrL file = "
2556 << oscommandline->osrlFile
2559 if (oscommandline->osplInputFile !=
"")
2560 cout <<
"OSpL Input file = "
2561 << oscommandline->osplInputFile
2563 if (oscommandline->serviceMethod !=
"")
2564 cout <<
"Service Method = "
2565 << oscommandline->serviceMethod
2567 if (oscommandline->mpsFile !=
"")
2568 cout <<
"MPS File Name = "
2569 << oscommandline->mpsFile
2571 if (oscommandline->nlFile !=
"")
2572 cout <<
"NL File Name = "
2573 << oscommandline->nlFile
2575 if (oscommandline->solverName !=
"")
2576 cout <<
"Selected Solver = "
2577 << oscommandline->solverName
2579 if (oscommandline->serviceLocation !=
"")
2580 cout <<
"Service Location = "
2581 << oscommandline->serviceLocation
2584 if (oscommandline->jobID !=
"")
2586 << oscommandline->jobID