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 MIPGEN_HH 00023 #define MIPGEN_HH 00024 00025 /** 00026 * @file 00027 * Interface of class mipgen. 00028 */ 00029 00030 class driver; 00031 00032 /** 00033 * The mipgen class generates a Mixed Integer Program. 00034 * It is the base class for other output format drivers. 00035 * 00036 * @section order Order of problem data 00037 * 00038 * @subsection rows Order of Rows 00039 * In the final form, the problem description will contain these rows: 00040 * -# one row @c _MaxOrder restricting the number of fields which are 00041 * part of any solution 00042 * -# two rows for gamma selection if driver::gamma_constraint is set 00043 * -# one row for each constraint specified in the input file 00044 * -# rows for difference vectors from mipgen::collect_fields() 00045 * 00046 * These rows are all represented in mipgen::row_names, 00047 * mipgen::row_bounds and mipgen::matrix, but not in 00048 * mipgen::constraints which contains only the input sonstraints. 00049 * 00050 * @subsection cols Order of Columns 00051 * In the final form, the problem description will contain these 00052 * columns: 00053 * -# one column for gamma selection from mipgen::append_gamma() 00054 * if driver::gamma_constraint is set, otherwise omitted 00055 * -# modulo arithmetic columns from mipgen::modfields() 00056 * -# difference vectors from mipgen::collect_fields() 00057 * -# original input fields from driver::fields 00058 * 00059 * These columns are all represented in mipgen::col_names, 00060 * mipgen::col_bounds and mipgen::matrix as well as mipgen::fields. 00061 * 00062 */ 00063 class mipgen { 00064 public: 00065 mipgen(const driver& d); 00066 virtual ~mipgen(); 00067 void formulate(); 00068 virtual void write(const char* filename); 00069 00070 protected: 00071 00072 /** 00073 * Reference to the driver. 00074 * This allows access to command line options and input data. 00075 */ 00076 const driver& drv; 00077 00078 /** 00079 * Number of generated columns. 00080 * 00081 * Columns used to express modulo arithmetic, but also some other 00082 * generated columns, preceed the actual %field descriptions in the 00083 * matrix. This number gives an indication as to how many generated 00084 * columns there are, and thus allows different handling of the 00085 * different types of columns without relying on the special naming 00086 * convention that a generated column starts with an underscore. 00087 */ 00088 size_t modcount; 00089 00090 /** 00091 * Column data. 00092 * 00093 * As the description of class field explains, a field is a colum 00094 * description, including a name, the matrix elements of this 00095 * column, and a pair of bounds on the variable associated with this 00096 * column. This list contains original field descriptions from the 00097 * input file, but preceding them there are generated columns. 00098 * 00099 * @see @ref cols 00100 */ 00101 std::vector<field> fields; 00102 00103 /** 00104 * Row descriptions. 00105 * 00106 * This is a direct copy of driver::constraints at first and 00107 * restricts most operations to the field components which are 00108 * actually constrained in some way. In the final output, only these 00109 * components will be included as rows, along with some special 00110 * rows. 00111 * 00112 * Preceding the equality constrained rows corresponding to these 00113 * constraints, there will be one generated row for the maximum 00114 * order, and—if enabled—two rows for gamma selection. These are not 00115 * represented as constraint objects and thus not part of this 00116 * list. 00117 * 00118 * @see @ref rows 00119 */ 00120 std::vector<constraint> constraints; 00121 00122 /** 00123 * A list of column names. 00124 * This is copied from the names of the mipgen::constraints by 00125 * mipgen::copy_col_names. They are intended for easy output 00126 * generation in derived classes. 00127 */ 00128 std::vector<std::string> col_names; 00129 00130 /** 00131 * A list of row names. 00132 * This is copied from the names of the mipgen::fields by 00133 * mipgen::copy_row_names, except for some special rows. 00134 * They are intended for easy output generation in derived classes. 00135 */ 00136 std::vector<std::string> row_names; 00137 00138 /** 00139 * A list of column bounds. 00140 * These bounds on the variables are set by mipgen::set_bounds. 00141 * They are intended for easy output generation in derived classes. 00142 */ 00143 std::vector<bounds> col_bounds; 00144 00145 /** 00146 * A list of row bounds. 00147 * These bounds on the row values are set by mipgen::set_bounds. 00148 * They are intended for easy output generation in derived classes. 00149 */ 00150 std::vector<bounds> row_bounds; 00151 00152 /** 00153 * The final matrix elements. 00154 * A list of list is used to represent the final integral 00155 * two-dimensional matrix of coefficients of the integer program. 00156 * They are intended for easy output generation in derived classes. 00157 */ 00158 std::vector< std::vector<int> > matrix; 00159 00160 virtual void make_matrix(size_t rows, size_t cols); 00161 virtual void set_element(size_t row, size_t col, int val); 00162 virtual void fill_matrix(); 00163 virtual void write(std::ostream& out); 00164 static int realmod(int a, int b); 00165 00166 private: 00167 00168 /** 00169 * Map row number to field component index. 00170 * The rows in the output mostly correspond to mipgen::constraints, 00171 * which identify the corresponding quantum number by name. 00172 * The order of elements in the field::values might therefore be 00173 * different from the output order. This vector gives the 00174 * corresponding indices into field::values in order of output 00175 * rows. 00176 */ 00177 std::vector<int> indices; 00178 00179 void modfields(); 00180 void multiply_k(); 00181 void append_gamma(); 00182 void comdenom(); 00183 void get_indices(); 00184 void set_bounds(); 00185 void copy_row_names(); 00186 void collect_fields(); 00187 void copy_col_names(); 00188 void unique_names(std::vector<std::string>& names); 00189 }; 00190 00191 #endif // ifndef MIPGEN_HH
1.6.0