The driver class is the central component of the program. More...
#include <driver.hh>

Public Member Functions | |
| driver () | |
| Constructor. | |
| virtual | ~driver () |
| Destructor. | |
| void | usage (const char *cmd, std::ostream &out) |
| Print usage information. | |
| void | parse_opts (int argc, char **argv) |
| Parse and execute command line options. | |
| void | parse_file (const char *file) |
| Handle a single input file. | |
| void | parse_stdin () |
| Handle input from the standard input stream. | |
| void | set_names (const yy::location &location, std::vector< std::string > *qns) |
| Accept the vector of quantum number names from the parser. | |
| void | set_constraints (const yy::location &location, std::vector< constraint > *css) |
| Accept the vector of constraint (row) specifications from the parser. | |
| field * | checked_field (const yy::location &location, std::string *name, std::vector< rational > *rationals) |
| Check a field (column) specification while parsing. | |
| void | set_fields (const yy::location &location, std::vector< field > *vcs) |
| Accept the vector of field (column) specifications from the parser. | |
| void | result (const yy::location &location, std::string *name) |
| Accept instance name from parser. | |
| int | scan (yy::parser::semantic_type *yylval, yy::parser::location_type *yylloc) |
| Wrapper around the lexer. | |
| void | parse (const std::string &file) |
| void | error (const yy::location &location, const std::string &message) |
| Print a localized parser error message. | |
| void | error (const std::string &message) |
| Print an unlocalized parser error message. | |
Public Attributes | |
| std::string | file |
| The file name of the file currently being processed. | |
| bool | multiply_k |
Command line option --multiply-k. | |
| bool | gamma_constraint |
Command line option --gamma. | |
| int | max_order |
Command line option --max-order. | |
| int | min_order |
Command line option --min-order. | |
| std::string | format |
Command line option --format. | |
| std::string | name |
| Instance name, as specified in the input file. | |
| std::vector< std::string > | names |
| Row names. | |
| std::map< std::string, int > | indices |
| Row numbers. | |
| std::vector< constraint > | constraints |
| Row constraints. | |
| std::vector< field > | fields |
| Columns. | |
Protected Member Functions | |
| void | parse (const char *file, std::istream &in) |
| Parse an input stream. | |
| virtual void | process (const char *file) |
| Process one parsed file. | |
Private Attributes | |
| yy::lexer * | theLexer |
| The lexer used to scan input files. | |
| bool | trace_scanning |
| Internal flag to enable lexer debug output. | |
| bool | trace_parsing |
| Internal flag to enable parser debug output. | |
| int | errorCount |
| Counter of errors during input parsing. | |
The driver class is the central component of the program.
It manages the command line arguments and current settings, and uses ofther classes for input parsing, problem formulation and file output.
Definition at line 45 of file driver.hh.
| driver::driver | ( | ) |
| driver::~driver | ( | ) | [virtual] |
| field * driver::checked_field | ( | const yy::location & | location, | |
| std::string * | name, | |||
| std::vector< rational > * | rationals | |||
| ) |
Check a field (column) specification while parsing.
The method ensures that there are no invalid names, and that the number of values matches the number of quantum number names passed to set_names() before. If anything is wrong, an error is printed.
| location | the position in the source file where the field specification started, to be used in error messages. | |
| name | the name of the new field, this function will take care of releasing the memory for this object. | |
| rationals | the component values of the field, this function will take care of releasing the memory for this object. |
Definition at line 346 of file driver.cc.
References error(), and names.
Referenced by yy::parser::parse().
| void driver::error | ( | const std::string & | message | ) |
Print an unlocalized parser error message.
The error counter is incremented as well, so that the file won't be processed afterwards.
| message | a textual description of the error. |
Definition at line 246 of file driver.cc.
References errorCount.
| void driver::error | ( | const yy::location & | location, | |
| const std::string & | message | |||
| ) |
Print a localized parser error message.
The error counter is incremented as well, so that the file won't be processed afterwards.
| location | the position in the input file where the error occurred. | |
| message | a textual description of the error. |
Definition at line 234 of file driver.cc.
References errorCount.
Referenced by checked_field(), yy::parser::error(), yy::lexer::LexerError(), set_constraints(), and set_names().
| void driver::parse | ( | const char * | file, | |
| std::istream & | in | |||
| ) | [protected] |
Parse an input stream.
Combines the common parsing process of parse_file and parse_stdin.
| file | the file name, as it should appear in parser error messages. | |
| in | the input stream from which the scanner will read its tokens. |
Definition at line 209 of file driver.cc.
References errorCount, yy::parser::parse(), yy::parser::set_debug_level(), theLexer, trace_parsing, and trace_scanning.
| void driver::parse_file | ( | const char * | infile | ) |
Handle a single input file.
This includes parsing the file and processing its content.
| infile | the file to be read. |
Definition at line 175 of file driver.cc.
References errorCount, format, and process().
Referenced by parse_opts().
| void driver::parse_opts | ( | int | argc, | |
| char ** | argv | |||
| ) |
Parse and execute command line options.
The list of command line options that the program recognizes is given here. It should be kept in sync with what usage prints. Most arguments can be given using either a short or a long name.
| argc | the number of command line arguments. | |
| argv | an array of command line arguments. |
Definition at line 103 of file driver.cc.
References format, gamma_constraint, max_order, min_order, multiply_k, parse_file(), parse_stdin(), trace_parsing, trace_scanning, and usage().
Referenced by main().
| void driver::parse_stdin | ( | ) |
Handle input from the standard input stream.
This includes parsing the stream and processing its content.
Definition at line 194 of file driver.cc.
References errorCount, and process().
Referenced by parse_opts().
| void driver::process | ( | const char * | file | ) | [protected, virtual] |
Process one parsed file.
The file has already been parsed and will be processed to the matching output format.
| file | the input file that should be processed |
Definition at line 397 of file driver.cc.
References format, mipgen::formulate(), and mipgen::write().
Referenced by parse_file(), and parse_stdin().
| void driver::result | ( | const yy::location & | location, | |
| std::string * | name | |||
| ) |
Accept instance name from parser.
This method is invoked by the parser just as a complete input stream has been parsed.
| location | the location where the instance started, not used. | |
| name | the name of the problem instance, this function will take care of releasing the memory for this object. |
Definition at line 382 of file driver.cc.
References std::swap().
Referenced by yy::parser::parse().
| int driver::scan | ( | yy::parser::semantic_type * | yylval, | |
| yy::parser::location_type * | yylloc | |||
| ) | [inline] |
Wrapper around the lexer.
By using this method, the driver doesn't have to know anything at all about the actual lexer implementation.
| [out] | yylval | the value of the token. |
| [out] | yylloc | the location of the token. |
Definition at line 222 of file driver.hh.
References theLexer, and yy::lexer::yylex().
| void driver::set_constraints | ( | const yy::location & | location, | |
| std::vector< constraint > * | css | |||
| ) |
Accept the vector of constraint (row) specifications from the parser.
The method will check to ensure that each name given in one of these constraints is present in the list of quantum number names as well.
| location | the position in the source file where the list of constraints started, to be used in error messages. | |
| css | a pointer to the new list of constraints, this function will take care of releasing the memory for this object. |
Definition at line 300 of file driver.cc.
References constraints, error(), indices, and std::swap().
Referenced by yy::parser::parse().
| void driver::set_fields | ( | const yy::location & | location, | |
| std::vector< field > * | vcs | |||
| ) |
Accept the vector of field (column) specifications from the parser.
There is no error checking, as each field is checked individually using the checked_field() method.
| location | the position in the source file where the list of constraints started, to be used in error messages. | |
| vcs | a pointer to the new list of vectors, this function will take care of releasing the memory for this object. |
Definition at line 323 of file driver.cc.
References fields, and std::swap().
Referenced by yy::parser::parse().
| void driver::set_names | ( | const yy::location & | location, | |
| std::vector< std::string > * | qns | |||
| ) |
Accept the vector of quantum number names from the parser.
The names will be checked to ensure that all special names required by certain command line options are indeed present, and that no duplicate names occur. Names beginning with an underscore are reserved for generated columns and may not be used in input. The indices map will be updated here as well.
| location | the position in the source file where the list of names started, to be used in error messages. | |
| qns | a pointer to the new list of names, this function will take care of releasing the memory for this object. |
Definition at line 264 of file driver.cc.
References error(), gamma_constraint, indices, multiply_k, names, and std::swap().
Referenced by yy::parser::parse().
| void driver::usage | ( | const char * | cmd, | |
| std::ostream & | out | |||
| ) |
Print usage information.
Whenever a new option is introduced, it should be added here, along with a description. The usage information can be displayed by passing the argumen --help on the command line.
| cmd | the name of the executable as given on the command line. | |
| out | the output stream to which the information will be printed. |
Definition at line 77 of file driver.cc.
Referenced by parse_opts().
| std::vector<constraint> driver::constraints |
Row constraints.
These give the constraints that a row must fulfill, like a given target value, and maybe the modulo arithmetic to be used. Rows are identified using their name. The order of the components is given by the order of the names attribute, which might be different from the order of the constraints.
Definition at line 172 of file driver.hh.
Referenced by mipgen::formulate(), mipgen::get_indices(), mipgen::modfields(), set_constraints(), and mipgen::write().
int driver::errorCount [private] |
Counter of errors during input parsing.
When the parser completes and there have been any errors along the way, the file will not be processed.
Definition at line 206 of file driver.hh.
Referenced by error(), parse(), parse_file(), and parse_stdin().
| std::vector<field> driver::fields |
Columns.
The columns are represented through field objects, which contain a column name along with the values, in the order specified by the names vector.
Definition at line 181 of file driver.hh.
Referenced by mipgen::modfields(), set_fields(), and mipgen::write().
| std::string driver::format |
Command line option --format.
This gives the name of the output format that should be used. Each format is implemented by its own class, derived from mipgen. Currently supported formats are:
Definition at line 135 of file driver.hh.
Referenced by parse_file(), parse_opts(), and process().
Command line option --gamma.
When this option is specified, a pair of inequalities is added to ensure that no single fractional value is the only nonzero value of a solution.
Definition at line 101 of file driver.hh.
Referenced by mipgen::copy_row_names(), mipgen::formulate(), mipgen::get_indices(), parse_opts(), mipgen::set_bounds(), set_names(), and opbgen::write().
| std::map<std::string, int> driver::indices |
Row numbers.
This table maps row names to the corresponding row numbers. It can be used to look up a component by name.
Definition at line 161 of file driver.hh.
Referenced by mipgen::append_gamma(), mipgen::comdenom(), mipgen::get_indices(), mipgen::modfields(), mipgen::multiply_k(), set_constraints(), and set_names().
Command line option --max-order.
This specifies the maximum number of vectors any solution may have.
Definition at line 111 of file driver.hh.
Referenced by mipgen::append_gamma(), mipgen::collect_fields(), parse_opts(), mipgen::set_bounds(), and opbgen::write().
Command line option --min-order.
This specifies the minimum number of vectors any solution must have.
Definition at line 121 of file driver.hh.
Referenced by parse_opts(), and mipgen::set_bounds().
Command line option --multiply-k.
When this option is specified, all columns with a name starting with n_ will be multiplied with the value of the column named k.
Definition at line 90 of file driver.hh.
Referenced by mipgen::formulate(), parse_opts(), and set_names().
| std::string driver::name |
Instance name, as specified in the input file.
The input format may start by giving an arbitrary name for the instance. If a name is given, it will be stored here, otherwise a default will be used.
Definition at line 144 of file driver.hh.
Referenced by mpsgen::write().
| std::vector<std::string> driver::names |
Row names.
The names of the rows (i.e. quantum numbers) will be stored in this vector in the order in which they are given in the input file.
Definition at line 153 of file driver.hh.
Referenced by mipgen::append_gamma(), checked_field(), mipgen::get_indices(), mipgen::modfields(), mipgen::multiply_k(), set_names(), and mipgen::write().
1.6.0