1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/work/marci/lp/lp_solver_wrapper_3.h Tue Jan 11 17:15:46 2005 +0000
1.3 @@ -0,0 +1,632 @@
1.4 +// -*- c++ -*-
1.5 +#ifndef LEMON_LP_SOLVER_WRAPPER_H
1.6 +#define LEMON_LP_SOLVER_WRAPPER_H
1.7 +
1.8 +///\ingroup misc
1.9 +///\file
1.10 +///\brief Dijkstra algorithm.
1.11 +
1.12 +// #include <stdio.h>
1.13 +#include <stdlib.h>
1.14 +// #include <stdio>
1.15 +//#include <stdlib>
1.16 +extern "C" {
1.17 +#include "glpk.h"
1.18 +}
1.19 +
1.20 +#include <iostream>
1.21 +#include <vector>
1.22 +#include <string>
1.23 +#include <list>
1.24 +#include <memory>
1.25 +#include <utility>
1.26 +
1.27 +//#include <sage_graph.h>
1.28 +//#include <lemon/list_graph.h>
1.29 +//#include <lemon/graph_wrapper.h>
1.30 +#include <lemon/invalid.h>
1.31 +//#include <bfs_dfs.h>
1.32 +//#include <stp.h>
1.33 +//#include <lemon/max_flow.h>
1.34 +//#include <augmenting_flow.h>
1.35 +//#include <iter_map.h>
1.36 +
1.37 +using std::cout;
1.38 +using std::cin;
1.39 +using std::endl;
1.40 +
1.41 +namespace lemon {
1.42 +
1.43 +
1.44 + /// \addtogroup misc
1.45 + /// @{
1.46 +
1.47 + /// \brief A partitioned vector with iterable classes.
1.48 + ///
1.49 + /// This class implements a container in which the data is stored in an
1.50 + /// stl vector, the range is partitioned into sets and each set is
1.51 + /// doubly linked in a list.
1.52 + /// That is, each class is iterable by lemon iterators, and any member of
1.53 + /// the vector can bo moved to an other class.
1.54 + template <typename T>
1.55 + class IterablePartition {
1.56 + protected:
1.57 + struct Node {
1.58 + T data;
1.59 + int prev; //invalid az -1
1.60 + int next;
1.61 + };
1.62 + std::vector<Node> nodes;
1.63 + struct Tip {
1.64 + int first;
1.65 + int last;
1.66 + };
1.67 + std::vector<Tip> tips;
1.68 + public:
1.69 + /// The classes are indexed by integers from \c 0 to \c classNum()-1.
1.70 + int classNum() const { return tips.size(); }
1.71 + /// This lemon style iterator iterates through a class.
1.72 + class ClassIt;
1.73 + /// Constructor. The number of classes is to be given which is fixed
1.74 + /// over the life of the container.
1.75 + /// The partition classes are indexed from 0 to class_num-1.
1.76 + IterablePartition(int class_num) {
1.77 + for (int i=0; i<class_num; ++i) {
1.78 + Tip t;
1.79 + t.first=t.last=-1;
1.80 + tips.push_back(t);
1.81 + }
1.82 + }
1.83 + protected:
1.84 + void befuz(ClassIt it, int class_id) {
1.85 + if (tips[class_id].first==-1) {
1.86 + if (tips[class_id].last==-1) {
1.87 + nodes[it.i].prev=nodes[it.i].next=-1;
1.88 + tips[class_id].first=tips[class_id].last=it.i;
1.89 + }
1.90 + } else {
1.91 + nodes[it.i].prev=tips[class_id].last;
1.92 + nodes[it.i].next=-1;
1.93 + nodes[tips[class_id].last].next=it.i;
1.94 + tips[class_id].last=it.i;
1.95 + }
1.96 + }
1.97 + void kifuz(ClassIt it, int class_id) {
1.98 + if (tips[class_id].first==it.i) {
1.99 + if (tips[class_id].last==it.i) {
1.100 + tips[class_id].first=tips[class_id].last=-1;
1.101 + } else {
1.102 + tips[class_id].first=nodes[it.i].next;
1.103 + nodes[nodes[it.i].next].prev=-1;
1.104 + }
1.105 + } else {
1.106 + if (tips[class_id].last==it.i) {
1.107 + tips[class_id].last=nodes[it.i].prev;
1.108 + nodes[nodes[it.i].prev].next=-1;
1.109 + } else {
1.110 + nodes[nodes[it.i].next].prev=nodes[it.i].prev;
1.111 + nodes[nodes[it.i].prev].next=nodes[it.i].next;
1.112 + }
1.113 + }
1.114 + }
1.115 + public:
1.116 + /// A new element with data \c t is pushed into the vector and into class
1.117 + /// \c class_id.
1.118 + ClassIt push_back(const T& t, int class_id) {
1.119 + Node n;
1.120 + n.data=t;
1.121 + nodes.push_back(n);
1.122 + int i=nodes.size()-1;
1.123 + befuz(i, class_id);
1.124 + return i;
1.125 + }
1.126 + /// A member is moved to an other class.
1.127 + void set(ClassIt it, int old_class_id, int new_class_id) {
1.128 + kifuz(it.i, old_class_id);
1.129 + befuz(it.i, new_class_id);
1.130 + }
1.131 + /// Returns the data pointed by \c it.
1.132 + T& operator[](ClassIt it) { return nodes[it.i].data; }
1.133 + /// Returns the data pointed by \c it.
1.134 + const T& operator[](ClassIt it) const { return nodes[it.i].data; }
1.135 + ///.
1.136 + class ClassIt {
1.137 + friend class IterablePartition;
1.138 + protected:
1.139 + int i;
1.140 + public:
1.141 + /// Default constructor.
1.142 + ClassIt() { }
1.143 + /// This constructor constructs an iterator which points
1.144 + /// to the member of th container indexed by the integer _i.
1.145 + ClassIt(const int& _i) : i(_i) { }
1.146 + /// Invalid constructor.
1.147 + ClassIt(const Invalid&) : i(-1) { }
1.148 + };
1.149 + /// First member of class \c class_id.
1.150 + ClassIt& first(ClassIt& it, int class_id) const {
1.151 + it.i=tips[class_id].first;
1.152 + return it;
1.153 + }
1.154 + /// Next member.
1.155 + ClassIt& next(ClassIt& it) const {
1.156 + it.i=nodes[it.i].next;
1.157 + return it;
1.158 + }
1.159 + /// True iff the iterator is valid.
1.160 + bool valid(const ClassIt& it) const { return it.i!=-1; }
1.161 + };
1.162 +
1.163 + /*! \e
1.164 + */
1.165 + template <typename _Value>
1.166 + class LPSolverBase {
1.167 + public:
1.168 + /// \e
1.169 + typedef _Value Value;
1.170 + /// \e
1.171 + typedef IterablePartition<int>::ClassIt RowIt;
1.172 + /// \e
1.173 + typedef IterablePartition<int>::ClassIt ColIt;
1.174 + public:
1.175 + /// \e
1.176 + IterablePartition<int> row_iter_map;
1.177 + /// \e
1.178 + IterablePartition<int> col_iter_map;
1.179 + /// \e
1.180 + const int VALID_CLASS;
1.181 + /// \e
1.182 + const int INVALID_CLASS;
1.183 + public:
1.184 + /// \e
1.185 + LPSolverBase() : row_iter_map(2),
1.186 + col_iter_map(2),
1.187 + VALID_CLASS(0), INVALID_CLASS(1) { }
1.188 + /// \e
1.189 + virtual ~LPSolverBase() { }
1.190 + /// \e
1.191 + virtual void setMinimize() = 0;
1.192 + /// \e
1.193 + virtual void setMaximize() = 0;
1.194 + protected:
1.195 + /// \e
1.196 + virtual int _addRow() = 0;
1.197 + /// \e
1.198 + virtual int _addCol() = 0;
1.199 + public:
1.200 + /// \e
1.201 + RowIt addRow() {
1.202 + int i=_addRow();
1.203 + RowIt row_it;
1.204 + row_iter_map.first(row_it, INVALID_CLASS);
1.205 + if (row_iter_map.valid(row_it)) { //van hasznalhato hely
1.206 + row_iter_map.set(row_it, INVALID_CLASS, VALID_CLASS);
1.207 + row_iter_map[row_it]=i;
1.208 + } else { //a cucc vegere kell inzertalni mert nincs szabad hely
1.209 + row_it=row_iter_map.push_back(i, VALID_CLASS);
1.210 + }
1.211 + return row_it;
1.212 + }
1.213 + /// \e
1.214 + ColIt addCol() {
1.215 + int i=_addCol();
1.216 + ColIt col_it;
1.217 + col_iter_map.first(col_it, INVALID_CLASS);
1.218 + if (col_iter_map.valid(col_it)) { //van hasznalhato hely
1.219 + col_iter_map.set(col_it, INVALID_CLASS, VALID_CLASS);
1.220 + col_iter_map[col_it]=i;
1.221 + } else { //a cucc vegere kell inzertalni mert nincs szabad hely
1.222 + col_it=col_iter_map.push_back(i, VALID_CLASS);
1.223 + }
1.224 + return col_it;
1.225 + }
1.226 + /// \e
1.227 + virtual void setRowCoeffs(int i,
1.228 + std::vector<std::pair<int, double> > coeffs) = 0;
1.229 + /// \e
1.230 + virtual void setColCoeffs(int i,
1.231 + std::vector<std::pair<int, double> > coeffs) = 0;
1.232 + /// \e
1.233 + template <typename Begin, typename End>
1.234 + void setRowCoeffs(RowIt row_it, Begin begin, End end) {
1.235 + std::vector<std::pair<int, double> > coeffs;
1.236 + for ( ; begin!=end; ++begin) {
1.237 + coeffs.push_back(std::
1.238 + make_pair(col_iter_map[begin->first], begin->second));
1.239 + }
1.240 + setRowCoeffs(row_iter_map[row_it], coeffs);
1.241 + }
1.242 + /// \e
1.243 + template <typename Begin, typename End>
1.244 + void setColCoeffs(ColIt col_it, Begin begin, End end) {
1.245 + std::vector<std::pair<int, double> > coeffs;
1.246 + for ( ; begin!=end; ++begin) {
1.247 + coeffs.push_back(std::
1.248 + make_pair(row_iter_map[begin->first], begin->second));
1.249 + }
1.250 + setColCoeffs(col_iter_map[col_it], coeffs);
1.251 + }
1.252 + /// temporally, glpk style indexing
1.253 + //virtual void setRowCoeffs(RowIt row_it, int num,
1.254 + // int* indices, _Value* doubles) = 0;
1.255 + //pair<RowIt, _Value>-bol kell megadni egy std range-et
1.256 + /// \e
1.257 + // virtual void seColCoeffs(int i,
1.258 + // std::vector<std::pair<int, double> > coeffs) = 0;
1.259 + /// \e
1.260 +// template <typename Begin, typename End>
1.261 +// void setRowCoeffs(RowIt row_it, Begin begin, End end) {
1.262 +// int mem_length=1+colNum();
1.263 +// int* indices = new int[mem_length];
1.264 +// _Value* doubles = new _Value[mem_length];
1.265 +// int length=0;
1.266 +// for ( ; begin!=end; ++begin) {
1.267 +// ++length;
1.268 +// indices[length]=col_iter_map[begin->first];
1.269 +// doubles[length]=begin->second;
1.270 +// }
1.271 +// setRowCoeffs(row_it, length, indices, doubles);
1.272 +// delete [] indices;
1.273 +// delete [] doubles;
1.274 +// }
1.275 + /// temporally, glpk style indexing
1.276 + //virtual void setColCoeffs(ColIt col_it, int num,
1.277 + // int* indices, _Value* doubles) = 0;
1.278 + //pair<ColIt, _Value>-bol kell megadni egy std range-et
1.279 + /// \e
1.280 +// template <typename Begin, typename End>
1.281 +// void setColCoeffs(ColIt col_it, Begin begin, End end) {
1.282 +// int mem_length=1+rowNum();
1.283 +// int* indices = new int[mem_length];
1.284 +// _Value* doubles = new _Value[mem_length];
1.285 +// int length=0;
1.286 +// for ( ; begin!=end; ++begin) {
1.287 +// ++length;
1.288 +// indices[length]=row_iter_map[begin->first];
1.289 +// doubles[length]=begin->second;
1.290 +// }
1.291 +// setColCoeffs(col_it, length, indices, doubles);
1.292 +// delete [] indices;
1.293 +// delete [] doubles;
1.294 +// }
1.295 + protected:
1.296 + /// \e
1.297 + virtual void _eraseCol(int i) = 0;
1.298 + /// \e
1.299 + virtual void _eraseRow(int i) = 0;
1.300 + public:
1.301 + /// \e
1.302 + void eraseCol(const ColIt& col_it) {
1.303 + col_iter_map.set(col_it, VALID_CLASS, INVALID_CLASS);
1.304 + int cols[2];
1.305 + cols[1]=col_iter_map[col_it];
1.306 + _eraseCol(cols[1]);
1.307 + col_iter_map[col_it]=0; //glpk specifikus, de kell ez??
1.308 + ColIt it;
1.309 + for (col_iter_map.first(it, VALID_CLASS);
1.310 + col_iter_map.valid(it); col_iter_map.next(it)) {
1.311 + if (col_iter_map[it]>cols[1]) --col_iter_map[it];
1.312 + }
1.313 + }
1.314 + /// \e
1.315 + void eraseRow(const RowIt& row_it) {
1.316 + row_iter_map.set(row_it, VALID_CLASS, INVALID_CLASS);
1.317 + int rows[2];
1.318 + rows[1]=row_iter_map[row_it];
1.319 + _eraseRow(rows[1]);
1.320 + row_iter_map[row_it]=0; //glpk specifikus, de kell ez??
1.321 + RowIt it;
1.322 + for (row_iter_map.first(it, VALID_CLASS);
1.323 + row_iter_map.valid(it); row_iter_map.next(it)) {
1.324 + if (row_iter_map[it]>rows[1]) --row_iter_map[it];
1.325 + }
1.326 + }
1.327 + /// \e
1.328 + virtual void setColBounds(const ColIt& col_it, int bound_type,
1.329 + _Value lo, _Value up) =0;
1.330 + /// \e
1.331 + virtual _Value getObjCoef(const ColIt& col_it) = 0;
1.332 + /// \e
1.333 + virtual void setRowBounds(const RowIt& row_it, int bound_type,
1.334 + _Value lo, _Value up) = 0;
1.335 + /// \e
1.336 + virtual void setObjCoef(const ColIt& col_it, _Value obj_coef) = 0;
1.337 + /// \e
1.338 + virtual void solveSimplex() = 0;
1.339 + /// \e
1.340 + virtual void solvePrimalSimplex() = 0;
1.341 + /// \e
1.342 + virtual void solveDualSimplex() = 0;
1.343 + /// \e
1.344 + virtual _Value getPrimal(const ColIt& col_it) = 0;
1.345 + /// \e
1.346 + virtual _Value getObjVal() = 0;
1.347 + /// \e
1.348 + virtual int rowNum() const = 0;
1.349 + /// \e
1.350 + virtual int colNum() const = 0;
1.351 + /// \e
1.352 + virtual int warmUp() = 0;
1.353 + /// \e
1.354 + virtual void printWarmUpStatus(int i) = 0;
1.355 + /// \e
1.356 + virtual int getPrimalStatus() = 0;
1.357 + /// \e
1.358 + virtual void printPrimalStatus(int i) = 0;
1.359 + /// \e
1.360 + virtual int getDualStatus() = 0;
1.361 + /// \e
1.362 + virtual void printDualStatus(int i) = 0;
1.363 + /// Returns the status of the slack variable assigned to row \c row_it.
1.364 + virtual int getRowStat(const RowIt& row_it) = 0;
1.365 + /// \e
1.366 + virtual void printRowStatus(int i) = 0;
1.367 + /// Returns the status of the variable assigned to column \c col_it.
1.368 + virtual int getColStat(const ColIt& col_it) = 0;
1.369 + /// \e
1.370 + virtual void printColStatus(int i) = 0;
1.371 + };
1.372 +
1.373 +
1.374 + /// \brief Wrappers for LP solvers
1.375 + ///
1.376 + /// This class implements a lemon wrapper for glpk.
1.377 + /// Later other LP-solvers will be wrapped into lemon.
1.378 + /// The aim of this class is to give a general surface to different
1.379 + /// solvers, i.e. it makes possible to write algorithms using LP's,
1.380 + /// in which the solver can be changed to an other one easily.
1.381 + class LPSolverWrapper : public LPSolverBase<double> {
1.382 + public:
1.383 + typedef LPSolverBase<double> Parent;
1.384 +
1.385 + public:
1.386 + /// \e
1.387 + LPX* lp;
1.388 +
1.389 + public:
1.390 + /// \e
1.391 + LPSolverWrapper() : Parent(),
1.392 + lp(lpx_create_prob()) {
1.393 + lpx_set_int_parm(lp, LPX_K_DUAL, 1);
1.394 + }
1.395 + /// \e
1.396 + ~LPSolverWrapper() {
1.397 + lpx_delete_prob(lp);
1.398 + }
1.399 + /// \e
1.400 + void setMinimize() {
1.401 + lpx_set_obj_dir(lp, LPX_MIN);
1.402 + }
1.403 + /// \e
1.404 + void setMaximize() {
1.405 + lpx_set_obj_dir(lp, LPX_MAX);
1.406 + }
1.407 + protected:
1.408 + /// \e
1.409 + int _addCol() {
1.410 + return lpx_add_cols(lp, 1);
1.411 + }
1.412 + /// \e
1.413 + int _addRow() {
1.414 + return lpx_add_rows(lp, 1);
1.415 + }
1.416 + public:
1.417 + using Parent::setRowCoeffs;
1.418 + /// \e
1.419 + virtual void setRowCoeffs(int i,
1.420 + std::vector<std::pair<int, double> > coeffs) {
1.421 + int mem_length=1+colNum();
1.422 + int* indices = new int[mem_length];
1.423 + double* doubles = new double[mem_length];
1.424 + int length=0;
1.425 + for (std::vector<std::pair<int, double> >::
1.426 + const_iterator it=coeffs.begin(); it!=coeffs.end(); ++it) {
1.427 + ++length;
1.428 + indices[length]=it->first;
1.429 + doubles[length]=it->second;
1.430 + std::cout << " " << indices[length] << " "
1.431 + << doubles[length] << std::endl;
1.432 + }
1.433 + std::cout << i << " " << length << std::endl;
1.434 + lpx_set_mat_row(lp, i, length, indices, doubles);
1.435 + delete [] indices;
1.436 + delete [] doubles;
1.437 + }
1.438 + /// \e
1.439 + virtual void setColCoeffs(int i,
1.440 + std::vector<std::pair<int, double> > coeffs) {
1.441 + int mem_length=1+rowNum();
1.442 + int* indices = new int[mem_length];
1.443 + double* doubles = new double[mem_length];
1.444 + int length=0;
1.445 + for (std::vector<std::pair<int, double> >::
1.446 + const_iterator it=coeffs.begin(); it!=coeffs.end(); ++it) {
1.447 + ++length;
1.448 + indices[length]=it->first;
1.449 + doubles[length]=it->second;
1.450 + }
1.451 + lpx_set_mat_col(lp, i, length, indices, doubles);
1.452 + delete [] indices;
1.453 + delete [] doubles;
1.454 + }
1.455 +// /// \e
1.456 +// /// temporally, glpk style indexing
1.457 +// virtual void setRowCoeffs(RowIt row_it, int num,
1.458 +// int* indices, _Value* doubles) = 0;
1.459 +// //pair<RowIt, _Value>-bol kell megadni egy std range-et
1.460 +// /// \e
1.461 +// template <typename Begin, typename End>
1.462 +// void setRowCoeffs(RowIt row_it, Begin begin, End end) {
1.463 +// int mem_length=1+colNum();
1.464 +// int* indices = new int[mem_length];
1.465 +// _Value* doubles = new _Value[mem_length];
1.466 +// int length=0;
1.467 +// for ( ; begin!=end; ++begin) {
1.468 +// ++length;
1.469 +// indices[length]=col_iter_map[begin->first];
1.470 +// doubles[length]=begin->second;
1.471 +// }
1.472 +// setRowCoeffs(row_it, length, indices, doubles);
1.473 +// delete [] indices;
1.474 +// delete [] doubles;
1.475 +// }
1.476 +// void setRowCoeffs(RowIt row_it, int length,
1.477 +// int* indices, double* doubles) {
1.478 +// lpx_set_mat_row(lp, row_iter_map[row_it], length, indices, doubles);
1.479 +// }
1.480 +// using Parent::setColCoeffs;
1.481 +// void setColCoeffs(ColIt col_it, int length,
1.482 +// int* indices, double* doubles) {
1.483 +// lpx_set_mat_col(lp, col_iter_map[col_it], length, indices, doubles);
1.484 +// }
1.485 + // //pair<RowIt, double>-bol kell megadni egy std range-et
1.486 + // /// \e
1.487 + // template <typename Begin, typename End>
1.488 + // void setColCoeffs(const ColIt& col_it,
1.489 + // Begin begin, End end) {
1.490 + // int mem_length=1+lpx_get_num_rows(lp);
1.491 + // int* indices = new int[mem_length];
1.492 + // double* doubles = new double[mem_length];
1.493 + // int length=0;
1.494 + // for ( ; begin!=end; ++begin) {
1.495 + // ++length;
1.496 + // indices[length]=row_iter_map[begin->first];
1.497 + // doubles[length]=begin->second;
1.498 + // }
1.499 + // lpx_set_mat_col(lp, col_iter_map[col_it], length, indices, doubles);
1.500 + // delete [] indices;
1.501 + // delete [] doubles;
1.502 + // }
1.503 + // //pair<ColIt, double>-bol kell megadni egy std range-et
1.504 + // /// \e
1.505 + // template <typename Begin, typename End>
1.506 + // void setRowCoeffs(const RowIt& row_it,
1.507 + // Begin begin, End end) {
1.508 + // int mem_length=1+lpx_get_num_cols(lp);
1.509 + // int* indices = new int[mem_length];
1.510 + // double* doubles = new double[mem_length];
1.511 + // int length=0;
1.512 + // for ( ; begin!=end; ++begin) {
1.513 + // ++length;
1.514 + // indices[length]=col_iter_map[begin->first];
1.515 + // doubles[length]=begin->second;
1.516 + // }
1.517 + // lpx_set_mat_row(lp, row_iter_map[row_it], length, indices, doubles);
1.518 + // delete [] indices;
1.519 + // delete [] doubles;
1.520 + // }
1.521 + /// \e
1.522 + protected:
1.523 + virtual void _eraseCol(int i) {
1.524 + int cols[2];
1.525 + cols[1]=i;
1.526 + lpx_del_cols(lp, 1, cols);
1.527 + }
1.528 + virtual void _eraseRow(int i) {
1.529 + int rows[2];
1.530 + rows[1]=i;
1.531 + lpx_del_rows(lp, 1, rows);
1.532 + }
1.533 + public:
1.534 + /// \e
1.535 + void setColBounds(const ColIt& col_it, int bound_type,
1.536 + double lo, double up) {
1.537 + lpx_set_col_bnds(lp, col_iter_map[col_it], bound_type, lo, up);
1.538 + }
1.539 + /// \e
1.540 + double getObjCoef(const ColIt& col_it) {
1.541 + return lpx_get_obj_coef(lp, col_iter_map[col_it]);
1.542 + }
1.543 + /// \e
1.544 + void setRowBounds(const RowIt& row_it, int bound_type,
1.545 + double lo, double up) {
1.546 + lpx_set_row_bnds(lp, row_iter_map[row_it], bound_type, lo, up);
1.547 + }
1.548 + /// \e
1.549 + void setObjCoef(const ColIt& col_it, double obj_coef) {
1.550 + lpx_set_obj_coef(lp, col_iter_map[col_it], obj_coef);
1.551 + }
1.552 + /// \e
1.553 + void solveSimplex() { lpx_simplex(lp); }
1.554 + /// \e
1.555 + void solvePrimalSimplex() { lpx_simplex(lp); }
1.556 + /// \e
1.557 + void solveDualSimplex() { lpx_simplex(lp); }
1.558 + /// \e
1.559 + double getPrimal(const ColIt& col_it) {
1.560 + return lpx_get_col_prim(lp, col_iter_map[col_it]);
1.561 + }
1.562 + /// \e
1.563 + double getObjVal() { return lpx_get_obj_val(lp); }
1.564 + /// \e
1.565 + int rowNum() const { return lpx_get_num_rows(lp); }
1.566 + /// \e
1.567 + int colNum() const { return lpx_get_num_cols(lp); }
1.568 + /// \e
1.569 + int warmUp() { return lpx_warm_up(lp); }
1.570 + /// \e
1.571 + void printWarmUpStatus(int i) {
1.572 + switch (i) {
1.573 + case LPX_E_OK: cout << "LPX_E_OK" << endl; break;
1.574 + case LPX_E_EMPTY: cout << "LPX_E_EMPTY" << endl; break;
1.575 + case LPX_E_BADB: cout << "LPX_E_BADB" << endl; break;
1.576 + case LPX_E_SING: cout << "LPX_E_SING" << endl; break;
1.577 + }
1.578 + }
1.579 + /// \e
1.580 + int getPrimalStatus() { return lpx_get_prim_stat(lp); }
1.581 + /// \e
1.582 + void printPrimalStatus(int i) {
1.583 + switch (i) {
1.584 + case LPX_P_UNDEF: cout << "LPX_P_UNDEF" << endl; break;
1.585 + case LPX_P_FEAS: cout << "LPX_P_FEAS" << endl; break;
1.586 + case LPX_P_INFEAS: cout << "LPX_P_INFEAS" << endl; break;
1.587 + case LPX_P_NOFEAS: cout << "LPX_P_NOFEAS" << endl; break;
1.588 + }
1.589 + }
1.590 + /// \e
1.591 + int getDualStatus() { return lpx_get_dual_stat(lp); }
1.592 + /// \e
1.593 + void printDualStatus(int i) {
1.594 + switch (i) {
1.595 + case LPX_D_UNDEF: cout << "LPX_D_UNDEF" << endl; break;
1.596 + case LPX_D_FEAS: cout << "LPX_D_FEAS" << endl; break;
1.597 + case LPX_D_INFEAS: cout << "LPX_D_INFEAS" << endl; break;
1.598 + case LPX_D_NOFEAS: cout << "LPX_D_NOFEAS" << endl; break;
1.599 + }
1.600 + }
1.601 + /// Returns the status of the slack variable assigned to row \c row_it.
1.602 + int getRowStat(const RowIt& row_it) {
1.603 + return lpx_get_row_stat(lp, row_iter_map[row_it]);
1.604 + }
1.605 + /// \e
1.606 + void printRowStatus(int i) {
1.607 + switch (i) {
1.608 + case LPX_BS: cout << "LPX_BS" << endl; break;
1.609 + case LPX_NL: cout << "LPX_NL" << endl; break;
1.610 + case LPX_NU: cout << "LPX_NU" << endl; break;
1.611 + case LPX_NF: cout << "LPX_NF" << endl; break;
1.612 + case LPX_NS: cout << "LPX_NS" << endl; break;
1.613 + }
1.614 + }
1.615 + /// Returns the status of the variable assigned to column \c col_it.
1.616 + int getColStat(const ColIt& col_it) {
1.617 + return lpx_get_col_stat(lp, col_iter_map[col_it]);
1.618 + }
1.619 + /// \e
1.620 + void printColStatus(int i) {
1.621 + switch (i) {
1.622 + case LPX_BS: cout << "LPX_BS" << endl; break;
1.623 + case LPX_NL: cout << "LPX_NL" << endl; break;
1.624 + case LPX_NU: cout << "LPX_NU" << endl; break;
1.625 + case LPX_NF: cout << "LPX_NF" << endl; break;
1.626 + case LPX_NS: cout << "LPX_NS" << endl; break;
1.627 + }
1.628 + }
1.629 + };
1.630 +
1.631 + /// @}
1.632 +
1.633 +} //namespace lemon
1.634 +
1.635 +#endif //LEMON_LP_SOLVER_WRAPPER_H
2.1 --- a/src/work/marci/lp/min_cost_gen_flow.h Tue Jan 11 09:15:25 2005 +0000
2.2 +++ b/src/work/marci/lp/min_cost_gen_flow.h Tue Jan 11 17:15:46 2005 +0000
2.3 @@ -14,7 +14,7 @@
2.4 //#include <augmenting_flow.h>
2.5 //#include <preflow_res.h>
2.6 #include <work/marci/merge_node_graph_wrapper.h>
2.7 -#include <work/marci/lp/lp_solver_wrapper_2.h>
2.8 +#include <work/marci/lp/lp_solver_wrapper_3.h>
2.9
2.10 namespace lemon {
2.11
2.12 @@ -228,6 +228,12 @@
2.13 lp.setColBounds(col_it, LPX_DB, lcapacity[e], capacity[e]);
2.14 lp.setObjCoef(col_it, cost[e]);
2.15 }
2.16 + LPSolver::ColIt col_it;
2.17 + for (lp.col_iter_map.first(col_it, lp.VALID_CLASS);
2.18 + lp.col_iter_map.valid(col_it);
2.19 + lp.col_iter_map.next(col_it)) {
2.20 + std::cout << "ize " << lp.col_iter_map[col_it] << std::endl;
2.21 + }
2.22 for (typename Graph::NodeIt n(g); n!=INVALID; ++n) {
2.23 typename Graph::template EdgeMap<Num> coeffs(g, 0);
2.24 for (typename Graph::InEdgeIt e(g, n); e!=INVALID; ++e)
2.25 @@ -244,6 +250,7 @@
2.26 }
2.27 }
2.28 //std::cout << std::endl;
2.29 + std::cout << " " << g.id(n) << " " << row.size() << std::endl;
2.30 lp.setRowCoeffs(row_it, row.begin(), row.end());
2.31 lp.setRowBounds(row_it, LPX_FX, 0.0, 0.0);
2.32 }