00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <vector>
00023 #include <limits>
00024 #include <coin/CoinPackedMatrix.hpp>
00025 #include <coin/CoinMpsIO.hpp>
00026
00027 #include "driver.hh"
00028 #include "bounds.hh"
00029 #include "mipgen.hh"
00030 #include "mpsgen.hh"
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 mpsgen::mpsgen(const driver& d) : mipgen(d), matrix(0) {
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052 mpsgen::~mpsgen() {
00053 if (matrix) delete matrix;
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 void mpsgen::write(const char* filename) {
00069 CoinMpsIO io;
00070 size_t rows = row_names.size(), cols = col_names.size();
00071 double infinity = io.getInfinity();
00072 double *collb = new double[cols], *colub = new double[cols];
00073 double *obj = new double[cols];
00074 char *integrality = new char[cols];
00075 double *rowlb = new double[rows], *rowub = new double[rows];
00076
00077 for (size_t col = 0; col < cols; ++col) {
00078 collb[col] = col_bounds[col].lower(false, -infinity);
00079 colub[col] = col_bounds[col].upper(false, infinity);
00080 obj[col] = col < modcount ? 0 : 1;
00081 integrality[col] = 1;
00082 }
00083 for (size_t row = 0; row < rows; ++row) {
00084 rowlb[row] = row_bounds[row].lower(false, -infinity);
00085 rowub[row] = row_bounds[row].upper(false, infinity);
00086 }
00087
00088 io.setMpsData(*matrix,
00089 infinity, collb, colub, obj, integrality, rowlb, rowub,
00090 col_names, row_names);
00091 io.setProblemName(drv.name.c_str());
00092 io.writeMps(filename ? filename : "/dev/stdout");
00093
00094 delete[] collb;
00095 delete[] colub;
00096 delete[] obj;
00097 delete[] integrality;
00098 delete[] rowlb;
00099 delete[] rowub;
00100 }
00101
00102
00103
00104
00105
00106
00107
00108 void mpsgen::make_matrix(size_t rows, size_t cols) {
00109 if (matrix) delete matrix;
00110 matrix = new CoinPackedMatrix();
00111 matrix->setDimensions(rows, cols);
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 void mpsgen::set_element(size_t row, size_t col, int val) {
00125 if (val) matrix->modifyCoefficient(row, col, val);
00126 }