00001 /* 00002 * Copyright 2007 Martin von Gagern 00003 * 00004 * 00005 * This file is part of mqn2mps. 00006 * 00007 * mqn2mps is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * mqn2mps is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 00022 #ifndef DRIVER_HH 00023 #define DRIVER_HH 00024 00025 #include <string> 00026 #include <vector> 00027 #include <map> 00028 #include <iostream> 00029 00030 #include "rational.hh" 00031 #include "parser.hh" 00032 #include "lexer.hh" 00033 00034 /** 00035 * @file 00036 * Interface of class driver. 00037 */ 00038 00039 /** 00040 * The driver class is the central component of the program. 00041 * It manages the command line arguments and current settings, and 00042 * uses ofther classes for input parsing, problem formulation and file 00043 * output. 00044 */ 00045 class driver { 00046 00047 public: 00048 driver(); 00049 virtual ~driver(); 00050 00051 void usage(const char* cmd, std::ostream& out); 00052 void parse_opts(int argc, char** argv); 00053 void parse_file(const char *file); 00054 void parse_stdin(); 00055 00056 void set_names(const yy::location& location, 00057 std::vector<std::string>* qns); 00058 void set_constraints(const yy::location& location, 00059 std::vector<constraint>* css); 00060 field* checked_field(const yy::location& location, 00061 std::string* name, 00062 std::vector<rational>* rationals); 00063 void set_fields(const yy::location& location, 00064 std::vector<field>* vcs); 00065 void result(const yy::location& location, 00066 std::string* name); 00067 00068 int scan(yy::parser::semantic_type* yylval, 00069 yy::parser::location_type* yylloc); 00070 00071 void parse(const std::string& file); 00072 00073 /** 00074 * The file name of the file currently being processed. 00075 */ 00076 std::string file; 00077 00078 void error(const yy::location& location, const std::string& message); 00079 void error(const std::string& message); 00080 00081 /** 00082 * Command line option @c --multiply-k. 00083 * 00084 * When this option is specified, all columns with a name starting 00085 * with @c n_ will be multiplied with the value of the column named 00086 * @c k. 00087 * 00088 * @see mipgen::multiply_k, usage 00089 */ 00090 bool multiply_k; 00091 00092 /** 00093 * Command line option @c --gamma. 00094 * 00095 * When this option is specified, a pair of inequalities is added to 00096 * ensure that no single fractional value is the only nonzero value 00097 * of a solution. 00098 * 00099 * @see mipgen::append_gamma, usage 00100 */ 00101 bool gamma_constraint; 00102 00103 /** 00104 * Command line option @c --max-order. 00105 * 00106 * This specifies the maximum number of vectors any solution may 00107 * have. 00108 * 00109 * @see mipgen::set_bounds, usage 00110 */ 00111 int max_order; 00112 00113 /** 00114 * Command line option @c --min-order. 00115 * 00116 * This specifies the minimum number of vectors any solution must 00117 * have. 00118 * 00119 * @see mipgen::set_bounds, usage 00120 */ 00121 int min_order; 00122 00123 /** 00124 * Command line option @c --format. 00125 * 00126 * This gives the name of the output format that should be used. 00127 * Each format is implemented by its own class, derived from 00128 * mipgen. Currently supported formats are: 00129 * - @c mps implemented by mpsgen 00130 * - @c opb implemented by opbgen 00131 * - @c csv implemented by mipgen itself 00132 * 00133 * @see process, usage 00134 */ 00135 std::string format; 00136 00137 /** 00138 * Instance name, as specified in the input file. 00139 * 00140 * The input format may start by giving an arbitrary name for the 00141 * instance. If a name is given, it will be stored here, otherwise a 00142 * default will be used. 00143 */ 00144 std::string name; 00145 00146 /** 00147 * Row names. 00148 * 00149 * The names of the rows (i.e. quantum numbers) will be stored in 00150 * this vector in the order in which they are given in the input 00151 * file. 00152 */ 00153 std::vector<std::string> names; 00154 00155 /** 00156 * Row numbers. 00157 * 00158 * This table maps row names to the corresponding row numbers. It 00159 * can be used to look up a component by name. 00160 */ 00161 std::map<std::string, int> indices; 00162 00163 /** 00164 * Row constraints. 00165 * 00166 * These give the constraints that a row must fulfill, like a given 00167 * target value, and maybe the modulo arithmetic to be used. Rows 00168 * are identified using their name. The order of the components is 00169 * given by the order of the names attribute, which might be 00170 * different from the order of the constraints. 00171 */ 00172 std::vector<constraint> constraints; 00173 00174 /** 00175 * Columns. 00176 * 00177 * The columns are represented through field objects, which contain 00178 * a column name along with the values, in the order specified by 00179 * the names vector. 00180 */ 00181 std::vector<field> fields; 00182 00183 private: 00184 00185 /** 00186 * The lexer used to scan input files. 00187 */ 00188 yy::lexer* theLexer; 00189 00190 /** 00191 * Internal flag to enable lexer debug output. 00192 */ 00193 bool trace_scanning; 00194 00195 /** 00196 * Internal flag to enable parser debug output. 00197 */ 00198 bool trace_parsing; 00199 00200 /** 00201 * Counter of errors during input parsing. 00202 * 00203 * When the parser completes and there have been any errors along 00204 * the way, the file will not be processed. 00205 */ 00206 int errorCount; 00207 00208 protected: 00209 void parse(const char *file, std::istream &in); 00210 virtual void process(const char* file); 00211 }; 00212 00213 /** 00214 * Wrapper around the lexer. 00215 * By using this method, the driver doesn't have to know anything at 00216 * all about the actual lexer implementation. 00217 * 00218 * @param[out] yylval the value of the token. 00219 * @param[out] yylloc the location of the token. 00220 * @return the type code of the token. 00221 */ 00222 inline int driver::scan(yy::parser::semantic_type* yylval, 00223 yy::parser::location_type* yylloc) { 00224 return theLexer->yylex(yylval, yylloc); 00225 } 00226 00227 #endif // ifndef DRIVER_HH
1.6.0