src/work/marci/lp/lp_solver_wrapper_3.h
changeset 1111 88ade201ffc6
parent 1110 ba28dfbea5f2
child 1112 b258584569f2
     1.1 --- a/src/work/marci/lp/lp_solver_wrapper_3.h	Mon Jan 31 17:00:12 2005 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,822 +0,0 @@
     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 <iostream>
    1.15 -#include <map>
    1.16 -#include <limits>
    1.17 -// #include <stdio>
    1.18 -//#include <stdlib>
    1.19 -extern "C" {
    1.20 -#include "glpk.h"
    1.21 -}
    1.22 -
    1.23 -#include <iostream>
    1.24 -#include <vector>
    1.25 -#include <string>
    1.26 -#include <list>
    1.27 -#include <memory>
    1.28 -#include <utility>
    1.29 -
    1.30 -//#include <sage_graph.h>
    1.31 -//#include <lemon/list_graph.h>
    1.32 -//#include <lemon/graph_wrapper.h>
    1.33 -#include <lemon/invalid.h>
    1.34 -#include <expression.h>
    1.35 -//#include <bfs_dfs.h>
    1.36 -//#include <stp.h>
    1.37 -//#include <lemon/max_flow.h>
    1.38 -//#include <augmenting_flow.h>
    1.39 -//#include <iter_map.h>
    1.40 -
    1.41 -using std::cout;
    1.42 -using std::cin;
    1.43 -using std::endl;
    1.44 -
    1.45 -namespace lemon {
    1.46 -  
    1.47 -  /// \addtogroup misc
    1.48 -  /// @{
    1.49 -
    1.50 -  /// \brief A partitioned vector with iterable classes.
    1.51 -  ///
    1.52 -  /// This class implements a container in which the data is stored in an 
    1.53 -  /// stl vector, the range is partitioned into sets and each set is 
    1.54 -  /// doubly linked in a list. 
    1.55 -  /// That is, each class is iterable by lemon iterators, and any member of 
    1.56 -  /// the vector can bo moved to an other class.
    1.57 -  template <typename T>
    1.58 -  class IterablePartition {
    1.59 -  protected:
    1.60 -    struct Node {
    1.61 -      T data;
    1.62 -      int prev; //invalid az -1
    1.63 -      int next; 
    1.64 -    };
    1.65 -    std::vector<Node> nodes;
    1.66 -    struct Tip {
    1.67 -      int first;
    1.68 -      int last;
    1.69 -    };
    1.70 -    std::vector<Tip> tips;
    1.71 -  public:
    1.72 -    /// The classes are indexed by integers from \c 0 to \c classNum()-1.
    1.73 -    int classNum() const { return tips.size(); }
    1.74 -    /// This lemon style iterator iterates through a class. 
    1.75 -    class ClassIt;
    1.76 -    /// Constructor. The number of classes is to be given which is fixed 
    1.77 -    /// over the life of the container. 
    1.78 -    /// The partition classes are indexed from 0 to class_num-1. 
    1.79 -    IterablePartition(int class_num) { 
    1.80 -      for (int i=0; i<class_num; ++i) {
    1.81 -	Tip t;
    1.82 -	t.first=t.last=-1;
    1.83 -	tips.push_back(t);
    1.84 -      }
    1.85 -    }
    1.86 -  protected:
    1.87 -    void befuz(ClassIt it, int class_id) {
    1.88 -      if (tips[class_id].first==-1) {
    1.89 -	if (tips[class_id].last==-1) {
    1.90 -	  nodes[it.i].prev=nodes[it.i].next=-1;
    1.91 -	  tips[class_id].first=tips[class_id].last=it.i;
    1.92 -	}
    1.93 -      } else {
    1.94 -	nodes[it.i].prev=tips[class_id].last;
    1.95 -	nodes[it.i].next=-1;
    1.96 -	nodes[tips[class_id].last].next=it.i;
    1.97 -	tips[class_id].last=it.i;
    1.98 -      }
    1.99 -    }
   1.100 -    void kifuz(ClassIt it, int class_id) {
   1.101 -      if (tips[class_id].first==it.i) {
   1.102 -	if (tips[class_id].last==it.i) {
   1.103 -	  tips[class_id].first=tips[class_id].last=-1;
   1.104 -	} else {
   1.105 -	  tips[class_id].first=nodes[it.i].next;
   1.106 -	  nodes[nodes[it.i].next].prev=-1;
   1.107 -	}
   1.108 -      } else {
   1.109 -	if (tips[class_id].last==it.i) {
   1.110 -	  tips[class_id].last=nodes[it.i].prev;
   1.111 -	  nodes[nodes[it.i].prev].next=-1;
   1.112 -	} else {
   1.113 -	  nodes[nodes[it.i].next].prev=nodes[it.i].prev;
   1.114 -	  nodes[nodes[it.i].prev].next=nodes[it.i].next;
   1.115 -	}
   1.116 -      }
   1.117 -    }
   1.118 -  public:
   1.119 -    /// A new element with data \c t is pushed into the vector and into class 
   1.120 -    /// \c class_id.
   1.121 -    ClassIt push_back(const T& t, int class_id) { 
   1.122 -      Node n;
   1.123 -      n.data=t;
   1.124 -      nodes.push_back(n);
   1.125 -      int i=nodes.size()-1;
   1.126 -      befuz(i, class_id);
   1.127 -      return i;
   1.128 -    }
   1.129 -    /// A member is moved to an other class.
   1.130 -    void set(ClassIt it, int old_class_id, int new_class_id) {
   1.131 -      kifuz(it.i, old_class_id);
   1.132 -      befuz(it.i, new_class_id);
   1.133 -    }
   1.134 -    /// Returns the data pointed by \c it.
   1.135 -    T& operator[](ClassIt it) { return nodes[it.i].data; }
   1.136 -    /// Returns the data pointed by \c it.
   1.137 -    const T& operator[](ClassIt it) const { return nodes[it.i].data; }
   1.138 -    ///.
   1.139 -    class ClassIt {
   1.140 -      friend class IterablePartition;
   1.141 -    protected:
   1.142 -      int i;
   1.143 -    public:
   1.144 -      /// Default constructor.
   1.145 -      ClassIt() { }
   1.146 -      /// This constructor constructs an iterator which points
   1.147 -      /// to the member of th container indexed by the integer _i.
   1.148 -      ClassIt(const int& _i) : i(_i) { }
   1.149 -      /// Invalid constructor.
   1.150 -      ClassIt(const Invalid&) : i(-1) { }
   1.151 -      friend bool operator<(const ClassIt& x, const ClassIt& y);
   1.152 -      friend std::ostream& operator<<(std::ostream& os, 
   1.153 -				      const ClassIt& it);
   1.154 -    };
   1.155 -    friend bool operator<(const ClassIt& x, const ClassIt& y) {
   1.156 -      return (x.i < y.i);
   1.157 -    }
   1.158 -    friend std::ostream& operator<<(std::ostream& os, 
   1.159 -				    const ClassIt& it) {
   1.160 -      os << it.i;
   1.161 -      return os;
   1.162 -    }
   1.163 -    /// First member of class \c class_id.
   1.164 -    ClassIt& first(ClassIt& it, int class_id) const {
   1.165 -      it.i=tips[class_id].first;
   1.166 -      return it;
   1.167 -    }
   1.168 -    /// Next member.
   1.169 -    ClassIt& next(ClassIt& it) const {
   1.170 -      it.i=nodes[it.i].next;
   1.171 -      return it;
   1.172 -    }
   1.173 -    /// True iff the iterator is valid.
   1.174 -    bool valid(const ClassIt& it) const { return it.i!=-1; }
   1.175 -  };
   1.176 -
   1.177 -
   1.178 -  /*! \e
   1.179 -
   1.180 -  \todo A[x,y]-t cserel. Jobboldal, baloldal csere.
   1.181 -  \todo LEKERDEZESEK!!!
   1.182 -  \todo DOKSI!!!! Doxygen group!!!
   1.183 -
   1.184 -   */
   1.185 -  template <typename _Value>
   1.186 -  class LPSolverBase {
   1.187 -  public:
   1.188 -    /// \e
   1.189 -    typedef _Value Value;
   1.190 -    /// \e
   1.191 -    typedef IterablePartition<int>::ClassIt RowIt;
   1.192 -    /// \e
   1.193 -    typedef IterablePartition<int>::ClassIt ColIt;
   1.194 -  public:
   1.195 -    /// \e
   1.196 -    IterablePartition<int> row_iter_map;
   1.197 -    /// \e
   1.198 -    IterablePartition<int> col_iter_map;
   1.199 -    /// \e
   1.200 -    const int VALID_CLASS;
   1.201 -    /// \e
   1.202 -    const int INVALID_CLASS;
   1.203 -    /// \e 
   1.204 -    static const _Value INF;
   1.205 -  public:
   1.206 -    /// \e
   1.207 -    LPSolverBase() : row_iter_map(2), 
   1.208 -		     col_iter_map(2), 
   1.209 -		     VALID_CLASS(0), INVALID_CLASS(1) { }
   1.210 -    /// \e
   1.211 -    virtual ~LPSolverBase() { }
   1.212 -
   1.213 -    //MATRIX INDEPEDENT MANIPULATING FUNCTIONS
   1.214 -
   1.215 -  public:
   1.216 -    /// \e
   1.217 -    virtual void setMinimize() = 0;
   1.218 -    /// \e
   1.219 -    virtual void setMaximize() = 0;
   1.220 -
   1.221 -    //LOW LEVEL INTERFACE, MATRIX MANIPULATING FUNCTIONS
   1.222 -
   1.223 -  protected:
   1.224 -    /// \e
   1.225 -    virtual int _addRow() = 0;
   1.226 -    /// \e
   1.227 -    virtual int _addCol() = 0;
   1.228 -    /// \e
   1.229 -    virtual void _setRowCoeffs(int i, 
   1.230 -			       const std::vector<std::pair<int, _Value> >& coeffs) = 0;
   1.231 -    /// \e
   1.232 -    virtual void _setColCoeffs(int i, 
   1.233 -			       const std::vector<std::pair<int, _Value> >& coeffs) = 0;
   1.234 -    /// \e
   1.235 -    virtual void _eraseCol(int i) = 0;
   1.236 -    /// \e
   1.237 -    virtual void _eraseRow(int i) = 0;
   1.238 -  public:
   1.239 -    /// \e
   1.240 -    enum Bound { FREE, LOWER, UPPER, DOUBLE, FIXED };
   1.241 -  protected:
   1.242 -    /// \e
   1.243 -    /// The lower bound of a variable (column) have to be given by an 
   1.244 -    /// extended number of type _Value, i.e. a finite number of type 
   1.245 -    /// _Value or -INF.
   1.246 -    virtual void _setColLowerBound(int i, _Value value) = 0;
   1.247 -    /// \e
   1.248 -    /// The upper bound of a variable (column) have to be given by an 
   1.249 -    /// extended number of type _Value, i.e. a finite number of type 
   1.250 -    /// _Value or INF.
   1.251 -    virtual void _setColUpperBound(int i, _Value value) = 0;
   1.252 -    /// \e
   1.253 -    /// The lower bound of a variable (column) is an 
   1.254 -    /// extended number of type _Value, i.e. a finite number of type 
   1.255 -    /// _Value or -INF.
   1.256 -    virtual _Value _getColLowerBound(int i) = 0;
   1.257 -    /// \e
   1.258 -    /// The upper bound of a variable (column) is an 
   1.259 -    /// extended number of type _Value, i.e. a finite number of type 
   1.260 -    /// _Value or INF.
   1.261 -    virtual _Value _getColUpperBound(int i) = 0;
   1.262 -    /// \e
   1.263 -    virtual void _setColBounds(int i, Bound bound, 
   1.264 -			       _Value lo, _Value up) = 0; 
   1.265 -    /// \e
   1.266 -    virtual void _setRowBounds(int i, Bound bound, 
   1.267 -			       _Value lo, _Value up) = 0; 
   1.268 -    /// \e
   1.269 -    virtual void _setObjCoef(int i, _Value obj_coef) = 0;
   1.270 -    /// \e
   1.271 -    virtual _Value _getObjCoef(int i) = 0;
   1.272 -
   1.273 -    //LOW LEVEL, SOLUTION RETRIEVING FUNCTIONS
   1.274 -
   1.275 -  protected:
   1.276 -    virtual _Value _getPrimal(int i) = 0;
   1.277 -
   1.278 -    //HIGH LEVEL INTERFACE, MATRIX MANIPULATING FUNTIONS
   1.279 -
   1.280 -  public:
   1.281 -    /// \e
   1.282 -    RowIt addRow() {
   1.283 -      int i=_addRow();
   1.284 -      RowIt row_it;
   1.285 -      row_iter_map.first(row_it, INVALID_CLASS);
   1.286 -      if (row_iter_map.valid(row_it)) { //van hasznalhato hely
   1.287 -	row_iter_map.set(row_it, INVALID_CLASS, VALID_CLASS);
   1.288 -	row_iter_map[row_it]=i;
   1.289 -      } else { //a cucc vegere kell inzertalni mert nincs szabad hely
   1.290 -	row_it=row_iter_map.push_back(i, VALID_CLASS);
   1.291 -      }
   1.292 -      return row_it;
   1.293 -    }
   1.294 -    /// \e
   1.295 -    ColIt addCol() {
   1.296 -      int i=_addCol();  
   1.297 -      ColIt col_it;
   1.298 -      col_iter_map.first(col_it, INVALID_CLASS);
   1.299 -      if (col_iter_map.valid(col_it)) { //van hasznalhato hely
   1.300 -	col_iter_map.set(col_it, INVALID_CLASS, VALID_CLASS);
   1.301 -	col_iter_map[col_it]=i;
   1.302 -      } else { //a cucc vegere kell inzertalni mert nincs szabad hely
   1.303 -	col_it=col_iter_map.push_back(i, VALID_CLASS);
   1.304 -      }
   1.305 -      return col_it;
   1.306 -    }
   1.307 -    /// \e
   1.308 -    template <typename Begin, typename End>
   1.309 -    void setRowCoeffs(RowIt row_it, Begin begin, End end) {
   1.310 -      std::vector<std::pair<int, double> > coeffs;
   1.311 -      for ( ; begin!=end; ++begin) {
   1.312 -	coeffs.push_back(std::
   1.313 -			 make_pair(col_iter_map[begin->first], begin->second));
   1.314 -      }
   1.315 -      _setRowCoeffs(row_iter_map[row_it], coeffs);
   1.316 -    }
   1.317 -    /// \e
   1.318 -    template <typename Begin, typename End>
   1.319 -    void setColCoeffs(ColIt col_it, Begin begin, End end) {
   1.320 -      std::vector<std::pair<int, double> > coeffs;
   1.321 -      for ( ; begin!=end; ++begin) {
   1.322 -	coeffs.push_back(std::
   1.323 -			 make_pair(row_iter_map[begin->first], begin->second));
   1.324 -      }
   1.325 -      _setColCoeffs(col_iter_map[col_it], coeffs);
   1.326 -    }
   1.327 -    /// \e
   1.328 -    void eraseCol(const ColIt& col_it) {
   1.329 -      col_iter_map.set(col_it, VALID_CLASS, INVALID_CLASS);
   1.330 -      int cols[2];
   1.331 -      cols[1]=col_iter_map[col_it];
   1.332 -      _eraseCol(cols[1]);
   1.333 -      col_iter_map[col_it]=0; //glpk specifikus, de kell ez??
   1.334 -      ColIt it;
   1.335 -      for (col_iter_map.first(it, VALID_CLASS); 
   1.336 -	   col_iter_map.valid(it); col_iter_map.next(it)) {
   1.337 -	if (col_iter_map[it]>cols[1]) --col_iter_map[it];
   1.338 -      }
   1.339 -    }
   1.340 -    /// \e
   1.341 -    void eraseRow(const RowIt& row_it) {
   1.342 -      row_iter_map.set(row_it, VALID_CLASS, INVALID_CLASS);
   1.343 -      int rows[2];
   1.344 -      rows[1]=row_iter_map[row_it];
   1.345 -      _eraseRow(rows[1]);
   1.346 -      row_iter_map[row_it]=0; //glpk specifikus, de kell ez??
   1.347 -      RowIt it;
   1.348 -      for (row_iter_map.first(it, VALID_CLASS); 
   1.349 -	   row_iter_map.valid(it); row_iter_map.next(it)) {
   1.350 -	if (row_iter_map[it]>rows[1]) --row_iter_map[it];
   1.351 -      }
   1.352 -    }
   1.353 -    /// \e
   1.354 -    void setColLowerBound(ColIt col_it, _Value lo) {
   1.355 -      _setColLowerBound(col_iter_map[col_it], lo);
   1.356 -    }
   1.357 -    /// \e
   1.358 -    void setColUpperBound(ColIt col_it, _Value up) {
   1.359 -      _setColUpperBound(col_iter_map[col_it], up);
   1.360 -    }
   1.361 -    /// \e
   1.362 -    _Value getColLowerBound(ColIt col_it) {
   1.363 -      return _getColLowerBound(col_iter_map[col_it]);
   1.364 -    }
   1.365 -    /// \e
   1.366 -    _Value getColUpperBound(ColIt col_it) {      
   1.367 -      return _getColUpperBound(col_iter_map[col_it]);
   1.368 -    }
   1.369 -    /// \e
   1.370 -    void setColBounds(const ColIt& col_it, Bound bound, 
   1.371 -		      _Value lo, _Value up) {
   1.372 -      _setColBounds(col_iter_map[col_it], bound, lo, up);
   1.373 -    }
   1.374 -    /// \e
   1.375 -    void setRowBounds(const RowIt& row_it, Bound bound, 
   1.376 -		      _Value lo, _Value up) {
   1.377 -      _setRowBounds(row_iter_map[row_it], bound, lo, up);
   1.378 -    }
   1.379 -    /// \e
   1.380 -    void setObjCoef(const ColIt& col_it, _Value obj_coef) {
   1.381 -      _setObjCoef(col_iter_map[col_it], obj_coef);
   1.382 -    }
   1.383 -    /// \e
   1.384 -    _Value getObjCoef(const ColIt& col_it) {
   1.385 -      return _getObjCoef(col_iter_map[col_it]);
   1.386 -    }
   1.387 -
   1.388 -    //MOST HIGH LEVEL, USER FRIEND FUNCTIONS
   1.389 -
   1.390 -    /// \e
   1.391 -    typedef Expr<ColIt, _Value> Expression;
   1.392 -    /// \e
   1.393 -    typedef Expr<RowIt, _Value> DualExpression;
   1.394 -    /// \e
   1.395 -    void setRowCoeffs(RowIt row_it, const Expression& expr) {
   1.396 -      std::vector<std::pair<int, _Value> > row_coeffs;
   1.397 -      for(typename Expression::Data::const_iterator i=expr.data.begin(); 
   1.398 -	  i!=expr.data.end(); ++i) {
   1.399 -	row_coeffs.push_back(std::make_pair
   1.400 -			     (col_iter_map[(*i).first], (*i).second));
   1.401 -      }
   1.402 -      _setRowCoeffs(row_iter_map[row_it], row_coeffs);
   1.403 -    }
   1.404 -    /// \e
   1.405 -    void setColCoeffs(ColIt col_it, const DualExpression& expr) {
   1.406 -      std::vector<std::pair<int, _Value> > col_coeffs;
   1.407 -      for(typename DualExpression::Data::const_iterator i=expr.data.begin(); 
   1.408 -	  i!=expr.data.end(); ++i) {
   1.409 -	col_coeffs.push_back(std::make_pair
   1.410 -			     (row_iter_map[(*i).first], (*i).second));
   1.411 -      }
   1.412 -      _setColCoeffs(col_iter_map[col_it], col_coeffs);
   1.413 -    }
   1.414 -    /// \e
   1.415 -    void setObjCoeffs(const Expression& expr) {
   1.416 -      for(typename Expression::Data::const_iterator i=expr.data.begin(); 
   1.417 -	  i!=expr.data.end(); ++i) {
   1.418 -	setObjCoef((*i).first, (*i).second);
   1.419 -      }
   1.420 -    }
   1.421 -    //SOLVER FUNCTIONS
   1.422 -
   1.423 -    /// \e
   1.424 -    virtual void solveSimplex() = 0;
   1.425 -    /// \e
   1.426 -    virtual void solvePrimalSimplex() = 0;
   1.427 -    /// \e
   1.428 -    virtual void solveDualSimplex() = 0;
   1.429 -    /// \e
   1.430 -
   1.431 -    //HIGH LEVEL, SOLUTION RETRIEVING FUNCTIONS
   1.432 -
   1.433 -  public:
   1.434 -    _Value getPrimal(const ColIt& col_it) {
   1.435 -      return _getPrimal(col_iter_map[col_it]);
   1.436 -    }
   1.437 -    /// \e
   1.438 -    virtual _Value getObjVal() = 0;
   1.439 -
   1.440 -    //OTHER FUNCTIONS
   1.441 -
   1.442 -    /// \e
   1.443 -    virtual int rowNum() const = 0;
   1.444 -    /// \e
   1.445 -    virtual int colNum() const = 0;
   1.446 -    /// \e
   1.447 -    virtual int warmUp() = 0;
   1.448 -    /// \e
   1.449 -    virtual void printWarmUpStatus(int i) = 0;
   1.450 -    /// \e
   1.451 -    virtual int getPrimalStatus() = 0;
   1.452 -    /// \e
   1.453 -    virtual void printPrimalStatus(int i) = 0;
   1.454 -    /// \e
   1.455 -    virtual int getDualStatus() = 0;
   1.456 -    /// \e
   1.457 -    virtual void printDualStatus(int i) = 0;
   1.458 -    /// Returns the status of the slack variable assigned to row \c row_it.
   1.459 -    virtual int getRowStat(const RowIt& row_it) = 0;
   1.460 -    /// \e
   1.461 -    virtual void printRowStatus(int i) = 0;
   1.462 -    /// Returns the status of the variable assigned to column \c col_it.
   1.463 -    virtual int getColStat(const ColIt& col_it) = 0;
   1.464 -    /// \e
   1.465 -    virtual void printColStatus(int i) = 0;
   1.466 -  };
   1.467 -  
   1.468 -  template <typename _Value>
   1.469 -  const _Value LPSolverBase<_Value>::INF=std::numeric_limits<_Value>::infinity();
   1.470 -
   1.471 -
   1.472 -  /// \brief Wrappers for LP solvers
   1.473 -  /// 
   1.474 -  /// This class implements a lemon wrapper for glpk.
   1.475 -  /// Later other LP-solvers will be wrapped into lemon.
   1.476 -  /// The aim of this class is to give a general surface to different 
   1.477 -  /// solvers, i.e. it makes possible to write algorithms using LP's, 
   1.478 -  /// in which the solver can be changed to an other one easily.
   1.479 -  class LPGLPK : public LPSolverBase<double> {
   1.480 -  public:
   1.481 -    typedef LPSolverBase<double> Parent;
   1.482 -
   1.483 -  public:
   1.484 -    /// \e
   1.485 -    LPX* lp;
   1.486 -
   1.487 -  public:
   1.488 -    /// \e
   1.489 -    LPGLPK() : Parent(), 
   1.490 -			lp(lpx_create_prob()) {
   1.491 -      lpx_set_int_parm(lp, LPX_K_DUAL, 1);
   1.492 -    }
   1.493 -    /// \e
   1.494 -    ~LPGLPK() {
   1.495 -      lpx_delete_prob(lp);
   1.496 -    }
   1.497 -
   1.498 -    //MATRIX INDEPEDENT MANIPULATING FUNCTIONS
   1.499 -
   1.500 -    /// \e
   1.501 -    void setMinimize() { 
   1.502 -      lpx_set_obj_dir(lp, LPX_MIN);
   1.503 -    }
   1.504 -    /// \e
   1.505 -    void setMaximize() { 
   1.506 -      lpx_set_obj_dir(lp, LPX_MAX);
   1.507 -    }
   1.508 -
   1.509 -    //LOW LEVEL INTERFACE, MATRIX MANIPULATING FUNCTIONS
   1.510 -
   1.511 -  protected:
   1.512 -    /// \e
   1.513 -    int _addCol() { 
   1.514 -      int i=lpx_add_cols(lp, 1);
   1.515 -      _setColLowerBound(i, -INF);
   1.516 -      _setColUpperBound(i, INF);
   1.517 -      return i;
   1.518 -    }
   1.519 -    /// \e
   1.520 -    int _addRow() { 
   1.521 -      int i=lpx_add_rows(lp, 1);
   1.522 -      return i;
   1.523 -    }
   1.524 -    /// \e
   1.525 -    virtual void _setRowCoeffs(int i, 
   1.526 -			       const std::vector<std::pair<int, double> >& coeffs) {
   1.527 -      int mem_length=1+colNum();
   1.528 -      int* indices = new int[mem_length];
   1.529 -      double* doubles = new double[mem_length];
   1.530 -      int length=0;
   1.531 -      for (std::vector<std::pair<int, double> >::
   1.532 -	     const_iterator it=coeffs.begin(); it!=coeffs.end(); ++it) {
   1.533 -	++length;
   1.534 -	indices[length]=it->first;
   1.535 -	doubles[length]=it->second;
   1.536 -// 	std::cout << "  " << indices[length] << " " 
   1.537 -// 		  << doubles[length] << std::endl;
   1.538 -      }
   1.539 -//      std::cout << i << " " << length << std::endl;
   1.540 -      lpx_set_mat_row(lp, i, length, indices, doubles);
   1.541 -      delete [] indices;
   1.542 -      delete [] doubles;
   1.543 -    }
   1.544 -    /// \e
   1.545 -    virtual void _setColCoeffs(int i, 
   1.546 -			       const std::vector<std::pair<int, double> >& coeffs) {
   1.547 -      int mem_length=1+rowNum();
   1.548 -      int* indices = new int[mem_length];
   1.549 -      double* doubles = new double[mem_length];
   1.550 -      int length=0;
   1.551 -      for (std::vector<std::pair<int, double> >::
   1.552 -	     const_iterator it=coeffs.begin(); it!=coeffs.end(); ++it) {
   1.553 -	++length;
   1.554 -	indices[length]=it->first;
   1.555 -	doubles[length]=it->second;
   1.556 -      }
   1.557 -      lpx_set_mat_col(lp, i, length, indices, doubles);
   1.558 -      delete [] indices;
   1.559 -      delete [] doubles;
   1.560 -    }
   1.561 -    /// \e
   1.562 -    virtual void _eraseCol(int i) {
   1.563 -      int cols[2];
   1.564 -      cols[1]=i;
   1.565 -      lpx_del_cols(lp, 1, cols);
   1.566 -    }
   1.567 -    virtual void _eraseRow(int i) {
   1.568 -      int rows[2];
   1.569 -      rows[1]=i;
   1.570 -      lpx_del_rows(lp, 1, rows);
   1.571 -    }
   1.572 -    virtual void _setColLowerBound(int i, double lo) {
   1.573 -      if (lo==INF) {
   1.574 -	//FIXME error
   1.575 -      }
   1.576 -      int b=lpx_get_col_type(lp, i);
   1.577 -      double up=lpx_get_col_ub(lp, i);	
   1.578 -      if (lo==-INF) {
   1.579 -	switch (b) {
   1.580 -	case LPX_FR:
   1.581 -	case LPX_LO:
   1.582 -	  lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
   1.583 -	  break;
   1.584 -	case LPX_UP:
   1.585 -	  break;
   1.586 -	case LPX_DB:
   1.587 -	case LPX_FX:
   1.588 -	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
   1.589 -	  break;
   1.590 -	default: ;
   1.591 -	  //FIXME error
   1.592 -	}
   1.593 -      } else {
   1.594 -	switch (b) {
   1.595 -	case LPX_FR:
   1.596 -	case LPX_LO:
   1.597 -	  lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
   1.598 -	  break;
   1.599 -	case LPX_UP:	  
   1.600 -	case LPX_DB:
   1.601 -	case LPX_FX:
   1.602 -	  if (lo==up) 
   1.603 -	    lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
   1.604 -	  else 
   1.605 -	    lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
   1.606 -	  break;
   1.607 -	default: ;
   1.608 -	  //FIXME error
   1.609 -	}
   1.610 -      }
   1.611 -    }
   1.612 -    virtual void _setColUpperBound(int i, double up) {
   1.613 -      if (up==-INF) {
   1.614 -	//FIXME error
   1.615 -      }
   1.616 -      int b=lpx_get_col_type(lp, i);
   1.617 -      double lo=lpx_get_col_lb(lp, i);
   1.618 -      if (up==INF) {
   1.619 -	switch (b) {
   1.620 -	case LPX_FR:
   1.621 -	case LPX_LO:
   1.622 -	  break;
   1.623 -	case LPX_UP:
   1.624 -	  lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
   1.625 -	  break;
   1.626 -	case LPX_DB:
   1.627 -	case LPX_FX:
   1.628 -	  lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
   1.629 -	  break;
   1.630 -	default: ;
   1.631 -	  //FIXME error
   1.632 -	}
   1.633 -      } else {
   1.634 -	switch (b) {
   1.635 -	case LPX_FR:
   1.636 -	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
   1.637 -	case LPX_LO:
   1.638 -	  if (lo==up) 
   1.639 -	    lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
   1.640 -	  else
   1.641 -	    lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
   1.642 -	  break;
   1.643 -	case LPX_UP:
   1.644 -	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
   1.645 -	  break;
   1.646 -	case LPX_DB:
   1.647 -	case LPX_FX:
   1.648 -	  if (lo==up) 
   1.649 -	    lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
   1.650 -	  else 
   1.651 -	    lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
   1.652 -	  break;
   1.653 -	default: ;
   1.654 -	  //FIXME error
   1.655 -	}
   1.656 -      }
   1.657 -    }
   1.658 -    virtual double _getColLowerBound(int i) {
   1.659 -      int b=lpx_get_col_type(lp, i);
   1.660 -      switch (b) {
   1.661 -      case LPX_FR:
   1.662 -	return -INF;
   1.663 -      case LPX_LO:
   1.664 -	return lpx_get_col_lb(lp, i);
   1.665 -      case LPX_UP:
   1.666 -	return -INF;
   1.667 -      case LPX_DB:
   1.668 -      case LPX_FX:
   1.669 -	return lpx_get_col_lb(lp, i);
   1.670 -      default: ;
   1.671 -	//FIXME error
   1.672 -	return 0.0;
   1.673 -      }
   1.674 -    }
   1.675 -    virtual double _getColUpperBound(int i) {
   1.676 -      int b=lpx_get_col_type(lp, i);
   1.677 -      switch (b) {
   1.678 -      case LPX_FR:
   1.679 -      case LPX_LO:
   1.680 -	return INF;
   1.681 -      case LPX_UP:
   1.682 -      case LPX_DB:
   1.683 -      case LPX_FX:
   1.684 -	return lpx_get_col_ub(lp, i);
   1.685 -      default: ;
   1.686 -	//FIXME error
   1.687 -	return 0.0;
   1.688 -      }
   1.689 -    }
   1.690 -    virtual void _setColBounds(int i, Bound bound, 
   1.691 -			       double lo, double up) {
   1.692 -      switch (bound) {
   1.693 -      case FREE:
   1.694 -	lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
   1.695 -	break;
   1.696 -      case LOWER:
   1.697 -	lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
   1.698 -	break;
   1.699 -      case UPPER:
   1.700 -	lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
   1.701 -	break;
   1.702 -      case DOUBLE:
   1.703 -	lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
   1.704 -	break;
   1.705 -      case FIXED:
   1.706 -	lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
   1.707 -	break;
   1.708 -      }
   1.709 -    } 
   1.710 -    virtual void _setRowBounds(int i, Bound bound, 
   1.711 -			       double lo, double up) {
   1.712 -      switch (bound) {
   1.713 -      case FREE:
   1.714 -	lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
   1.715 -	break;
   1.716 -      case LOWER:
   1.717 -	lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
   1.718 -	break;
   1.719 -      case UPPER:
   1.720 -	lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
   1.721 -	break;
   1.722 -      case DOUBLE:
   1.723 -	lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
   1.724 -	break;
   1.725 -      case FIXED:
   1.726 -	lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
   1.727 -	break;
   1.728 -      }
   1.729 -    } 
   1.730 -  protected:
   1.731 -    /// \e
   1.732 -    virtual double _getObjCoef(int i) { 
   1.733 -      return lpx_get_obj_coef(lp, i);
   1.734 -    }
   1.735 -    /// \e
   1.736 -    virtual void _setObjCoef(int i, double obj_coef) { 
   1.737 -      lpx_set_obj_coef(lp, i, obj_coef);
   1.738 -    }
   1.739 -  public:
   1.740 -    /// \e
   1.741 -    void solveSimplex() { lpx_simplex(lp); }
   1.742 -    /// \e
   1.743 -    void solvePrimalSimplex() { lpx_simplex(lp); }
   1.744 -    /// \e
   1.745 -    void solveDualSimplex() { lpx_simplex(lp); }
   1.746 -    /// \e
   1.747 -  protected:
   1.748 -    virtual double _getPrimal(int i) {
   1.749 -      return lpx_get_col_prim(lp, i);
   1.750 -    }
   1.751 -  public:
   1.752 -    /// \e
   1.753 -    double getObjVal() { return lpx_get_obj_val(lp); }
   1.754 -    /// \e
   1.755 -    int rowNum() const { return lpx_get_num_rows(lp); }
   1.756 -    /// \e
   1.757 -    int colNum() const { return lpx_get_num_cols(lp); }
   1.758 -    /// \e
   1.759 -    int warmUp() { return lpx_warm_up(lp); }
   1.760 -    /// \e
   1.761 -    void printWarmUpStatus(int i) {
   1.762 -      switch (i) {
   1.763 -      case LPX_E_OK: cout << "LPX_E_OK" << endl; break;
   1.764 -      case LPX_E_EMPTY: cout << "LPX_E_EMPTY" << endl; break;	
   1.765 -      case LPX_E_BADB: cout << "LPX_E_BADB" << endl; break;
   1.766 -      case LPX_E_SING: cout << "LPX_E_SING" << endl; break;
   1.767 -      }
   1.768 -    }
   1.769 -    /// \e
   1.770 -    int getPrimalStatus() { return lpx_get_prim_stat(lp); }
   1.771 -    /// \e
   1.772 -    void printPrimalStatus(int i) {
   1.773 -      switch (i) {
   1.774 -      case LPX_P_UNDEF: cout << "LPX_P_UNDEF" << endl; break;
   1.775 -      case LPX_P_FEAS: cout << "LPX_P_FEAS" << endl; break;	
   1.776 -      case LPX_P_INFEAS: cout << "LPX_P_INFEAS" << endl; break;
   1.777 -      case LPX_P_NOFEAS: cout << "LPX_P_NOFEAS" << endl; break;
   1.778 -      }
   1.779 -    }
   1.780 -    /// \e
   1.781 -    int getDualStatus() { return lpx_get_dual_stat(lp); }
   1.782 -    /// \e
   1.783 -    void printDualStatus(int i) {
   1.784 -      switch (i) {
   1.785 -      case LPX_D_UNDEF: cout << "LPX_D_UNDEF" << endl; break;
   1.786 -      case LPX_D_FEAS: cout << "LPX_D_FEAS" << endl; break;	
   1.787 -      case LPX_D_INFEAS: cout << "LPX_D_INFEAS" << endl; break;
   1.788 -      case LPX_D_NOFEAS: cout << "LPX_D_NOFEAS" << endl; break;
   1.789 -      }
   1.790 -    }
   1.791 -    /// Returns the status of the slack variable assigned to row \c row_it.
   1.792 -    int getRowStat(const RowIt& row_it) { 
   1.793 -      return lpx_get_row_stat(lp, row_iter_map[row_it]); 
   1.794 -    }
   1.795 -    /// \e
   1.796 -    void printRowStatus(int i) {
   1.797 -      switch (i) {
   1.798 -      case LPX_BS: cout << "LPX_BS" << endl; break;
   1.799 -      case LPX_NL: cout << "LPX_NL" << endl; break;	
   1.800 -      case LPX_NU: cout << "LPX_NU" << endl; break;
   1.801 -      case LPX_NF: cout << "LPX_NF" << endl; break;
   1.802 -      case LPX_NS: cout << "LPX_NS" << endl; break;
   1.803 -      }
   1.804 -    }
   1.805 -    /// Returns the status of the variable assigned to column \c col_it.
   1.806 -    int getColStat(const ColIt& col_it) { 
   1.807 -      return lpx_get_col_stat(lp, col_iter_map[col_it]); 
   1.808 -    }
   1.809 -    /// \e
   1.810 -    void printColStatus(int i) {
   1.811 -      switch (i) {
   1.812 -      case LPX_BS: cout << "LPX_BS" << endl; break;
   1.813 -      case LPX_NL: cout << "LPX_NL" << endl; break;	
   1.814 -      case LPX_NU: cout << "LPX_NU" << endl; break;
   1.815 -      case LPX_NF: cout << "LPX_NF" << endl; break;
   1.816 -      case LPX_NS: cout << "LPX_NS" << endl; break;
   1.817 -      }
   1.818 -    }
   1.819 -  };
   1.820 -  
   1.821 -  /// @}
   1.822 -
   1.823 -} //namespace lemon
   1.824 -
   1.825 -#endif //LEMON_LP_SOLVER_WRAPPER_H