00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <cassert>
00023 #include <vector>
00024 #include <iostream>
00025 #include <fstream>
00026 #include <limits>
00027
00028 #include "driver.hh"
00029 #include "bounds.hh"
00030 #include "mipgen.hh"
00031 #include "opbgen.hh"
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 opbgen::opbgen(const driver& d) : mipgen(d) {
00048 }
00049
00050
00051
00052
00053
00054
00055
00056
00057 void opbgen::write(std::ostream& out) {
00058 size_t rows = row_names.size(), cols = col_names.size();
00059 int bits;
00060 for (bits = 1; drv.max_order >= (1 << bits); ++bits) ;
00061 out << "min:";
00062 for (size_t col = modcount; col < cols; ++col) {
00063 for (int bit = bits - 1; bit >= 0; --bit) {
00064 out << " " << std::showpos << (1 << bit) << std::noshowpos
00065 << "*" << col_names[col] << "_" << bit;
00066 }
00067 }
00068 out << ";" << std::endl;
00069 for (size_t row = 0; row < rows; ++row) {
00070 int mod = 0, modcol = -1;
00071 for (size_t col = 0; col < modcount; ++col) {
00072 if (matrix[row][col]) {
00073 assert(mod == 0);
00074 modcol = col;
00075 mod = matrix[row][col];
00076 }
00077 }
00078 if (mod) {
00079 for (size_t col = modcount; col < cols; ++col) {
00080 matrix[row][col] = realmod(matrix[row][col], mod);
00081 }
00082 if (row_bounds[row].lower_type != bounds::infinite)
00083 row_bounds[row].lower_value =
00084 realmod(row_bounds[row].lower_value, mod) + drv.max_order * mod;
00085 if (row_bounds[row].upper_type != bounds::infinite)
00086 row_bounds[row].upper_value =
00087 realmod(row_bounds[row].upper_value, mod) + drv.max_order * mod;
00088 }
00089 for (int side = 0; side < 2; ++side) {
00090 out << row_names[row] << ":";
00091 for (size_t col = 0; col < cols; ++col) {
00092 int c1 = matrix[row][col];
00093
00094 for (int bit = (col == 0 && drv.gamma_constraint) ? 0 : bits - 1;
00095 bit >= 0; --bit) {
00096 int c2 = c1 << bit;
00097 if (mod && col >= modcount) c2 %= mod;
00098 if (!c2) continue;
00099 out << " " << std::showpos << c2 << std::noshowpos
00100 << "*" << col_names[col] << "_" << bit;
00101 }
00102 }
00103 if (row_bounds[row].lower_value == row_bounds[row].upper_value) {
00104 out << " = " << row_bounds[row].lower_value << ";" << std::endl;
00105 break;
00106 }
00107 if (side == 0)
00108 out << " >= " << row_bounds[row].lower_value << ";" << std::endl;
00109 else
00110 out << " <= " << row_bounds[row].upper_value << ";" << std::endl;
00111 }
00112 }
00113 }