OSCommandLine.cpp
Go to the documentation of this file.
1 /* $Id: OSCommandLine.cpp 4340 2011-10-15 20:08:33Z Gassmann $ */
21 #include <cstdio>
22 #include <sstream>
23 
24 #include "OSConfig.h"
25 #include "OSInstance.h"
26 #include "OSOption.h"
27 #include "OSOutput.h"
28 #include "OSCommandLine.h"
29 
30 using std::string;
31 
32 extern const OSSmartPtr<OSOutput> osoutput;
33 
35 {
36 #ifndef NDEBUG
37  osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_trace, "Reset command line options\n");
38 #endif
39  if (osinstance != NULL) delete osinstance;
40  osinstance = NULL;
41  if (osoption != NULL) delete osoption;
42  osoption = NULL;
43  serviceLocation = "";
44  serviceMethod = "";
45  solverName = "";
46  configFile = "";
47  osilFile = "";
48  osil = "";
49  osilOutputFile = "";
50  osolFile = "";
51  osol = "";
52  osolOutputFile = "";
53  osrlFile = "";
54  insListFile = "";
55  insList = "";
56  osplInputFile = "";
57  osplInput = "";
58  osplOutputFile = "";
59  mpsFile = "";
60  mps = "";
61  nlFile = "";
62  nl = "";
63  datFile = "";
64  dat = "";
65  gamsControlFile = "";
66  browser = "";
68  logFile = "";
70  jobID = "";
71  invokeHelp = false;
72  listOptions = false;
73  writeVersion = false;
74  printModel = false;
76  quit = false;
77 #ifndef NDEBUG
78  osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_trace, "Done resetting command line options\n");
79 #endif
80 }// reset_options
81 
83  osinstance(NULL),
84  osoption(NULL)
85 {
86 #ifndef NDEBUG
87  osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_trace, "Inside command line constructor\n");
88 #endif
89  reset_options();
90 }
91 
93 {
94 #ifndef NDEBUG
95  osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_trace, "Inside command line destructor\n");
96 #endif
97  if (osinstance != NULL) delete osinstance;
98  osinstance = NULL;
99  if (osoption != NULL) delete osoption;
100  osoption = NULL;
101 }
102 
104 {
105  unsigned int k;
106  for (k = 0; k < solverName.length(); k++)
107  {
108  solverName[k] = (char)tolower(solverName[k]);
109  }
110 }
111 
113 {
114  unsigned int k;
115  for (k = 0; k < solverName.length(); k++)
116  {
117  solverName[k] = (char)toupper(solverName[k]);
118  }
119 }
120 
122 {
123  std::ostringstream outStr;
124  outStr << "The following command line options and values have been read:"
125  << std::endl;
126  if (serviceLocation != "")
127  outStr << "Service Location = "
128  << serviceLocation
129  << std::endl;
130  if (serviceMethod != "")
131  outStr << "Service Method = "
132  << serviceMethod
133  << std::endl;
134  if ( solverName != "")
135  outStr << "Selected Solver = "
136  << solverName
137  << std::endl;
138 
139  if (configFile != "")
140  outStr << "Config file = "
141  << configFile
142  << std::endl;
143  if (osilFile != "")
144  outStr << "OSiL file = "
145  << osilFile
146  << std::endl;
147  if (osilOutputFile != "")
148  outStr << "OSiL output file = "
149  << osilOutputFile
150  << std::endl;
151  if (osolFile != "")
152  outStr << "OSoL file = "
153  << osolFile
154  << std::endl;
155  if (osolOutputFile != "")
156  outStr << "OSoL output file = "
157  << osolOutputFile
158  << std::endl;
159  if (osrlFile != "")
160  outStr << "OSrL file = "
161  << osrlFile
162  << std::endl;
163  if (insListFile != "")
164  outStr << "Instruction List file = "
165  << insListFile
166  << std::endl;
167  if (osplInputFile != "")
168  outStr << "OSpL Input file = "
169  << osplInputFile
170  << std::endl;
171  if (osplOutputFile != "")
172  outStr << "OSpL Output file = "
173  << osplOutputFile
174  << std::endl;
175  if (mpsFile != "")
176  outStr << "MPS File Name = "
177  << mpsFile
178  << std::endl;
179  if (nlFile != "")
180  outStr << "NL File Name = "
181  << nlFile
182  << std::endl;
183  if (datFile != "")
184  outStr << "GAMS dat file = "
185  << mpsFile
186  << std::endl;
187  if (gamsControlFile != "")
188  outStr << "GAMS control file = "
189  << gamsControlFile
190  << std::endl;
191 
192  if (browser != "")
193  outStr << "Result browser = "
194  << browser
195  << std::endl;
196  outStr << "Print level for stdout: "
197  << printLevel
198  << std::endl;
199 
200  if (logFile != "")
201  outStr << "Secondary log to "
202  << logFile
203  << std::endl;
204  outStr << "Print level for " << logFile << ": "
205  << printLevel
206  << std::endl;
207 
208  if (jobID != "")
209  outStr << "job ID = "
210  << jobID
211  << std::endl;
212 
213  if (printModel)
214  outStr << "Print model = true"
215  << std::endl;
216  if (printRowNumberAsString != "")
217  outStr << "Print row "
219  << std::endl;
220  return outStr.str();
221 }// list_options
std::string datFile
the name of the file that holds an instance in GAMS dat format
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
std::string insList
insList is the content of the insListFile – this is not implemented
#define DEFAULT_OUTPUT_LEVEL
Definition: OSParameters.h:121
const OSSmartPtr< OSOutput > osoutput
Definition: OSOutput.cpp:39
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
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
Definition: OSCommandLine.h:52
std::string osilOutputFile
osilOutputFile is the name of the file to which the instance can be written in OSiL format...
Definition: OSCommandLine.h:84
std::string jobID
the JobID
std::string osil
osil is the content of the osilFile
Definition: OSCommandLine.h:77
std::string nlFile
the name of the file that holds an instance in AMPL nl format
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 ...
Definition: OSOutput.cpp:178
OSOption * osoption
Template class for Smart Pointers.
Definition: OSSmartPtr.hpp:156
std::string nl
the string that holds an instance in AMPL nl format
bool listOptions
if this parameter is true we echo the values of the options found on the command line ...
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...
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...
OSInstance * osinstance
osinstance is a representation of the instance in OSInstance format
Definition: OSCommandLine.h:42
std::string mps
the string that holds an instance in MPS format
std::string osilFile
osilFile is the name of the file that holds the model instance in OSiL format
Definition: OSCommandLine.h:73
std::string osplOutputFile
name of an output file where the solver should write the result of a knock or kill service request ...
bool printModel
if this parameter is true we print the current instance as read from an osil, nl or mps file ...
std::string osolOutputFile
osolOutputFile is the name of the file to which the solver options can be written in OSoL 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 ...
Definition: OSCommandLine.h:68
std::string mpsFile
the name of the file that holds an instance in MPS format
void fint fint * k
int filePrintLevel
this parameter controls the amount of output to send to the log file (if used) the higher the number...
std::string serviceMethod
the service method the OSSolverService should execute, i.e.
Definition: OSCommandLine.h:57
std::string osol
osol is the content of the osolFile
Definition: OSCommandLine.h:93
OSCommandLine()
constructor method
std::string insListFile
name of the file containing the instance in LINDO instruction list format
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
Definition: OSCommandLine.h:89
void convertSolverNameToLowerCase()
to avoid ambiguity it might be necessary to convert the solver name to lower case ...
~OSCommandLine()
destructor method
OSInstance * osinstance
std::string list_options()
a function to print the current command line option values
std::string solverName
the name of the solver to be invoked locally, e.g -solver Ipopt
Definition: OSCommandLine.h:62
OSOption * osoption
osoption is a representation of the solver options in OSOption format
Definition: OSCommandLine.h:47
void convertSolverNameToUpperCase()
...
void reset_options()
a function to reset the command line to default values useful especially in the interactive shell ...