1.1 --- a/src/work/marci/lp/lp_solver_wrapper_3.h Sat Jan 29 23:22:56 2005 +0000
1.2 +++ b/src/work/marci/lp/lp_solver_wrapper_3.h Mon Jan 31 17:00:12 2005 +0000
1.3 @@ -237,6 +237,26 @@
1.4 enum Bound { FREE, LOWER, UPPER, DOUBLE, FIXED };
1.5 protected:
1.6 /// \e
1.7 + /// The lower bound of a variable (column) have to be given by an
1.8 + /// extended number of type _Value, i.e. a finite number of type
1.9 + /// _Value or -INF.
1.10 + virtual void _setColLowerBound(int i, _Value value) = 0;
1.11 + /// \e
1.12 + /// The upper bound of a variable (column) have to be given by an
1.13 + /// extended number of type _Value, i.e. a finite number of type
1.14 + /// _Value or INF.
1.15 + virtual void _setColUpperBound(int i, _Value value) = 0;
1.16 + /// \e
1.17 + /// The lower bound of a variable (column) is an
1.18 + /// extended number of type _Value, i.e. a finite number of type
1.19 + /// _Value or -INF.
1.20 + virtual _Value _getColLowerBound(int i) = 0;
1.21 + /// \e
1.22 + /// The upper bound of a variable (column) is an
1.23 + /// extended number of type _Value, i.e. a finite number of type
1.24 + /// _Value or INF.
1.25 + virtual _Value _getColUpperBound(int i) = 0;
1.26 + /// \e
1.27 virtual void _setColBounds(int i, Bound bound,
1.28 _Value lo, _Value up) = 0;
1.29 /// \e
1.30 @@ -257,7 +277,7 @@
1.31 public:
1.32 /// \e
1.33 RowIt addRow() {
1.34 - int i=_addRow();
1.35 + int i=_addRow();
1.36 RowIt row_it;
1.37 row_iter_map.first(row_it, INVALID_CLASS);
1.38 if (row_iter_map.valid(row_it)) { //van hasznalhato hely
1.39 @@ -328,6 +348,22 @@
1.40 }
1.41 }
1.42 /// \e
1.43 + void setColLowerBound(ColIt col_it, _Value lo) {
1.44 + _setColLowerBound(col_iter_map[col_it], lo);
1.45 + }
1.46 + /// \e
1.47 + void setColUpperBound(ColIt col_it, _Value up) {
1.48 + _setColUpperBound(col_iter_map[col_it], up);
1.49 + }
1.50 + /// \e
1.51 + _Value getColLowerBound(ColIt col_it) {
1.52 + return _getColLowerBound(col_iter_map[col_it]);
1.53 + }
1.54 + /// \e
1.55 + _Value getColUpperBound(ColIt col_it) {
1.56 + return _getColUpperBound(col_iter_map[col_it]);
1.57 + }
1.58 + /// \e
1.59 void setColBounds(const ColIt& col_it, Bound bound,
1.60 _Value lo, _Value up) {
1.61 _setColBounds(col_iter_map[col_it], bound, lo, up);
1.62 @@ -472,11 +508,15 @@
1.63 protected:
1.64 /// \e
1.65 int _addCol() {
1.66 - return lpx_add_cols(lp, 1);
1.67 + int i=lpx_add_cols(lp, 1);
1.68 + _setColLowerBound(i, -INF);
1.69 + _setColUpperBound(i, INF);
1.70 + return i;
1.71 }
1.72 /// \e
1.73 int _addRow() {
1.74 - return lpx_add_rows(lp, 1);
1.75 + int i=lpx_add_rows(lp, 1);
1.76 + return i;
1.77 }
1.78 /// \e
1.79 virtual void _setRowCoeffs(int i,
1.80 @@ -526,6 +566,124 @@
1.81 rows[1]=i;
1.82 lpx_del_rows(lp, 1, rows);
1.83 }
1.84 + virtual void _setColLowerBound(int i, double lo) {
1.85 + if (lo==INF) {
1.86 + //FIXME error
1.87 + }
1.88 + int b=lpx_get_col_type(lp, i);
1.89 + double up=lpx_get_col_ub(lp, i);
1.90 + if (lo==-INF) {
1.91 + switch (b) {
1.92 + case LPX_FR:
1.93 + case LPX_LO:
1.94 + lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
1.95 + break;
1.96 + case LPX_UP:
1.97 + break;
1.98 + case LPX_DB:
1.99 + case LPX_FX:
1.100 + lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
1.101 + break;
1.102 + default: ;
1.103 + //FIXME error
1.104 + }
1.105 + } else {
1.106 + switch (b) {
1.107 + case LPX_FR:
1.108 + case LPX_LO:
1.109 + lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
1.110 + break;
1.111 + case LPX_UP:
1.112 + case LPX_DB:
1.113 + case LPX_FX:
1.114 + if (lo==up)
1.115 + lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
1.116 + else
1.117 + lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
1.118 + break;
1.119 + default: ;
1.120 + //FIXME error
1.121 + }
1.122 + }
1.123 + }
1.124 + virtual void _setColUpperBound(int i, double up) {
1.125 + if (up==-INF) {
1.126 + //FIXME error
1.127 + }
1.128 + int b=lpx_get_col_type(lp, i);
1.129 + double lo=lpx_get_col_lb(lp, i);
1.130 + if (up==INF) {
1.131 + switch (b) {
1.132 + case LPX_FR:
1.133 + case LPX_LO:
1.134 + break;
1.135 + case LPX_UP:
1.136 + lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
1.137 + break;
1.138 + case LPX_DB:
1.139 + case LPX_FX:
1.140 + lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
1.141 + break;
1.142 + default: ;
1.143 + //FIXME error
1.144 + }
1.145 + } else {
1.146 + switch (b) {
1.147 + case LPX_FR:
1.148 + lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
1.149 + case LPX_LO:
1.150 + if (lo==up)
1.151 + lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
1.152 + else
1.153 + lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
1.154 + break;
1.155 + case LPX_UP:
1.156 + lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
1.157 + break;
1.158 + case LPX_DB:
1.159 + case LPX_FX:
1.160 + if (lo==up)
1.161 + lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
1.162 + else
1.163 + lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
1.164 + break;
1.165 + default: ;
1.166 + //FIXME error
1.167 + }
1.168 + }
1.169 + }
1.170 + virtual double _getColLowerBound(int i) {
1.171 + int b=lpx_get_col_type(lp, i);
1.172 + switch (b) {
1.173 + case LPX_FR:
1.174 + return -INF;
1.175 + case LPX_LO:
1.176 + return lpx_get_col_lb(lp, i);
1.177 + case LPX_UP:
1.178 + return -INF;
1.179 + case LPX_DB:
1.180 + case LPX_FX:
1.181 + return lpx_get_col_lb(lp, i);
1.182 + default: ;
1.183 + //FIXME error
1.184 + return 0.0;
1.185 + }
1.186 + }
1.187 + virtual double _getColUpperBound(int i) {
1.188 + int b=lpx_get_col_type(lp, i);
1.189 + switch (b) {
1.190 + case LPX_FR:
1.191 + case LPX_LO:
1.192 + return INF;
1.193 + case LPX_UP:
1.194 + case LPX_DB:
1.195 + case LPX_FX:
1.196 + return lpx_get_col_ub(lp, i);
1.197 + default: ;
1.198 + //FIXME error
1.199 + return 0.0;
1.200 + }
1.201 + }
1.202 virtual void _setColBounds(int i, Bound bound,
1.203 double lo, double up) {
1.204 switch (bound) {
2.1 --- a/src/work/marci/lp/max_flow_expression.cc Sat Jan 29 23:22:56 2005 +0000
2.2 +++ b/src/work/marci/lp/max_flow_expression.cc Mon Jan 31 17:00:12 2005 +0000
2.3 @@ -49,16 +49,17 @@
2.4 typedef LPSolver::RowIt RowIt;
2.5 typedef Graph::EdgeMap<ColIt> EdgeIndexMap;
2.6 EdgeIndexMap edge_index_map(g);
2.7 - PrimalMap<Edge, EdgeIndexMap> lp_flow(lp, edge_index_map);
2.8 + PrimalMap<Edge, EdgeIndexMap> flow(lp, edge_index_map);
2.9
2.10 // capacity function
2.11 for (Graph::EdgeIt e(g); e!=INVALID; ++e) {
2.12 ColIt col_it=lp.addCol();
2.13 edge_index_map.set(e, col_it);
2.14 - if (cap[e]==0)
2.15 - lp.setColBounds(col_it, LPSolver::FIXED, 0, cap[e]);
2.16 - else
2.17 - lp.setColBounds(col_it, LPSolver::DOUBLE, 0, cap[e]);
2.18 + // interesting property in GLPK:
2.19 + // if you change the order of the following two lines, the
2.20 + // two runs of GLPK are extremely different
2.21 + lp.setColUpperBound(col_it, cap[e]);
2.22 + lp.setColLowerBound(col_it, 0);
2.23 }
2.24
2.25 for (Graph::NodeIt n(g); n!=INVALID; ++n) {
2.26 @@ -79,9 +80,5 @@
2.27 }
2.28 }
2.29 lp.solveSimplex();
2.30 - //std::cout << lp.colNum() << std::endl;
2.31 - //std::cout << lp.rowNum() << std::endl;
2.32 - //std::cout << "flow value: "<< lp.getObjVal() << std::endl;
2.33 - for (Graph::EdgeIt e(g); e!=INVALID; ++e)
2.34 - flow.set(e, lp_flow[e]);
2.35 + cout << "elapsed time: " << ts << endl;
2.36 }