src/work/athos/lp_old/expression.h
changeset 1365 c280de819a73
parent 1364 ee5959aa4410
child 1366 d00b85f8be45
     1.1 --- a/src/work/athos/lp_old/expression.h	Sun Apr 17 18:57:22 2005 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,197 +0,0 @@
     1.4 -// -*- c++ -*-
     1.5 -#ifndef LEMON_EXPRESSION_H
     1.6 -#define LEMON_EXPRESSION_H
     1.7 -
     1.8 -#include <iostream>
     1.9 -#include <map>
    1.10 -#include <limits>
    1.11 -
    1.12 -namespace lemon {
    1.13 -
    1.14 -  /*! \brief Linear expression
    1.15 -
    1.16 -    \c Expr<_Col,_Value> implements a class of linear expressions with the 
    1.17 -    operations of addition and multiplication with scalar. 
    1.18 -
    1.19 -    \author Marton Makai
    1.20 -   */
    1.21 -  template <typename _Col, typename _Value>
    1.22 -  class Expr;
    1.23 -
    1.24 -  template <typename _Col, typename _Value>
    1.25 -  class Expr {
    1.26 -//  protected:
    1.27 -  public:
    1.28 -    typedef 
    1.29 -    typename std::map<_Col, _Value> Data; 
    1.30 -    Data data;
    1.31 -  public:
    1.32 -    void simplify() {
    1.33 -      for (typename Data::iterator i=data.begin(); 
    1.34 -	   i!=data.end(); ++i) {
    1.35 -	if ((*i).second==0) data.erase(i);
    1.36 -      }
    1.37 -    }
    1.38 -    Expr() { }
    1.39 -    Expr(_Col _col) { 
    1.40 -      data.insert(std::make_pair(_col, 1));
    1.41 -    }
    1.42 -    Expr& operator*=(_Value _value) {
    1.43 -      for (typename Data::iterator i=data.begin(); 
    1.44 -	   i!=data.end(); ++i) {
    1.45 -	(*i).second *= _value;
    1.46 -      }
    1.47 -      simplify();
    1.48 -      return *this;
    1.49 -    }
    1.50 -    Expr& operator+=(const Expr<_Col, _Value>& expr) {
    1.51 -      for (typename Data::const_iterator j=expr.data.begin(); 
    1.52 -	   j!=expr.data.end(); ++j) {
    1.53 -	typename Data::iterator i=data.find((*j).first);
    1.54 -	if (i==data.end()) {
    1.55 -	  data.insert(std::make_pair((*j).first, (*j).second));
    1.56 -	} else {
    1.57 -	  (*i).second+=(*j).second;
    1.58 -	}
    1.59 -      }
    1.60 -      simplify();
    1.61 -      return *this;
    1.62 -    }
    1.63 -    Expr& operator-=(const Expr<_Col, _Value>& expr) {
    1.64 -      for (typename Data::const_iterator j=expr.data.begin(); 
    1.65 -	   j!=expr.data.end(); ++j) {
    1.66 -	typename Data::iterator i=data.find((*j).first);
    1.67 -	if (i==data.end()) {
    1.68 -	  data.insert(std::make_pair((*j).first, -(*j).second));
    1.69 -	} else {
    1.70 -	  (*i).second+=-(*j).second;
    1.71 -	}
    1.72 -      }
    1.73 -      simplify();
    1.74 -      return *this;
    1.75 -    }
    1.76 -    template <typename _C, typename _V> 
    1.77 -    friend std::ostream& operator<<(std::ostream& os, 
    1.78 -				    const Expr<_C, _V>& expr);
    1.79 -  };
    1.80 -
    1.81 -  template <typename _Col, typename _Value>
    1.82 -  Expr<_Col, _Value> operator*(_Value _value, _Col _col) {
    1.83 -    Expr<_Col, _Value> tmp(_col);
    1.84 -    tmp*=_value;
    1.85 -    tmp.simplify();
    1.86 -    return tmp;
    1.87 -  }
    1.88 -
    1.89 -  template <typename _Col, typename _Value>
    1.90 -  Expr<_Col, _Value> operator*(_Value _value, 
    1.91 -			       const Expr<_Col, _Value>& expr) {
    1.92 -    Expr<_Col, _Value> tmp(expr);
    1.93 -    tmp*=_value;
    1.94 -    tmp.simplify();
    1.95 -    return tmp;
    1.96 -  }
    1.97 -
    1.98 -  template <typename _Col, typename _Value>
    1.99 -  Expr<_Col, _Value> operator+(const Expr<_Col, _Value>& expr1, 
   1.100 -			       const Expr<_Col, _Value>& expr2) {
   1.101 -    Expr<_Col, _Value> tmp(expr1);
   1.102 -    tmp+=expr2;
   1.103 -    tmp.simplify();
   1.104 -    return tmp;
   1.105 -  }
   1.106 -
   1.107 -  template <typename _Col, typename _Value>
   1.108 -  Expr<_Col, _Value> operator-(const Expr<_Col, _Value>& expr1, 
   1.109 -			       const Expr<_Col, _Value>& expr2) {
   1.110 -    Expr<_Col, _Value> tmp(expr1);
   1.111 -    tmp-=expr2;
   1.112 -    tmp.simplify();
   1.113 -    return tmp;
   1.114 -  }
   1.115 -
   1.116 -  template <typename _Col, typename _Value>
   1.117 -  std::ostream& operator<<(std::ostream& os, 
   1.118 -			   const Expr<_Col, _Value>& expr) {
   1.119 -    for (typename Expr<_Col, _Value>::Data::const_iterator i=
   1.120 -	   expr.data.begin(); 
   1.121 -	 i!=expr.data.end(); ++i) {
   1.122 -      os << (*i).second << "*" << (*i).first << " ";
   1.123 -    }
   1.124 -    return os;
   1.125 -  }
   1.126 -
   1.127 -  template <typename _Col, typename _Value>
   1.128 -  class LConstr {
   1.129 -    //  protected:
   1.130 -  public:
   1.131 -    Expr<_Col, _Value> expr;
   1.132 -    _Value lo;
   1.133 -  public:
   1.134 -    LConstr(const Expr<_Col, _Value>& _expr, _Value _lo) : 
   1.135 -      expr(_expr), lo(_lo) { }
   1.136 -  };
   1.137 -  
   1.138 -  template <typename _Col, typename _Value>
   1.139 -  LConstr<_Col, _Value> 
   1.140 -  operator<=(_Value lo, const Expr<_Col, _Value>& expr) {
   1.141 -    return LConstr<_Col, _Value>(expr, lo);
   1.142 -  }
   1.143 -
   1.144 -  template <typename _Col, typename _Value>
   1.145 -  class UConstr {
   1.146 -    //  protected:
   1.147 -  public:
   1.148 -    Expr<_Col, _Value> expr;
   1.149 -    _Value up;
   1.150 -  public:
   1.151 -    UConstr(const Expr<_Col, _Value>& _expr, _Value _up) : 
   1.152 -      expr(_expr), up(_up) { }
   1.153 -  };
   1.154 -
   1.155 -  template <typename _Col, typename _Value>
   1.156 -  UConstr<_Col, _Value> 
   1.157 -  operator<=(const Expr<_Col, _Value>& expr, _Value up) {
   1.158 -    return UConstr<_Col, _Value>(expr, up);
   1.159 -  }
   1.160 -
   1.161 -  template <typename _Col, typename _Value>
   1.162 -  class Constr {
   1.163 -    //  protected:
   1.164 -  public:
   1.165 -    Expr<_Col, _Value> expr;
   1.166 -    _Value lo, up;
   1.167 -  public:
   1.168 -    Constr(const Expr<_Col, _Value>& _expr, _Value _lo, _Value _up) : 
   1.169 -      expr(_expr), lo(_lo), up(_up) { }
   1.170 -    Constr(const LConstr<_Col, _Value>& _lconstr) : 
   1.171 -      expr(_lconstr.expr), 
   1.172 -      lo(_lconstr.lo), 
   1.173 -      up(std::numeric_limits<_Value>::infinity()) { }
   1.174 -    Constr(const UConstr<_Col, _Value>& _uconstr) : 
   1.175 -      expr(_uconstr.expr), 
   1.176 -      lo(-std::numeric_limits<_Value>::infinity()), 
   1.177 -      up(_uconstr.up) { }
   1.178 -  };
   1.179 -
   1.180 -  template <typename _Col, typename _Value>
   1.181 -  Constr<_Col, _Value> 
   1.182 -  operator<=(const LConstr<_Col, _Value>& lconstr, _Value up) {
   1.183 -    return Constr<_Col, _Value>(lconstr.expr, lconstr.lo, up);
   1.184 -  }
   1.185 -
   1.186 -  template <typename _Col, typename _Value>
   1.187 -  Constr<_Col, _Value> 
   1.188 -  operator<=(_Value lo, const UConstr<_Col, _Value>& uconstr) {
   1.189 -    return Constr<_Col, _Value>(uconstr.expr, lo, uconstr.up);
   1.190 -  }
   1.191 -
   1.192 -  template <typename _Col, typename _Value>
   1.193 -  Constr<_Col, _Value> 
   1.194 -  operator==(const Expr<_Col, _Value>& expr, _Value value) {
   1.195 -    return Constr<_Col, _Value>(expr, value, value);
   1.196 -  }
   1.197 -  
   1.198 -} //namespace lemon
   1.199 -
   1.200 -#endif //LEMON_EXPRESSION_H