Changeset 1099:91a8ee9d088d in lemon0.x for src/work/marci/lp/lp_solver_wrapper_3.h
 Timestamp:
 01/27/05 18:44:04 (16 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@1498
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/work/marci/lp/lp_solver_wrapper_3.h
r1097 r1099 28 28 //#include <lemon/graph_wrapper.h> 29 29 #include <lemon/invalid.h> 30 #include <expression.h> 30 31 //#include <bfs_dfs.h> 31 32 //#include <stp.h> … … 144 145 /// Invalid constructor. 145 146 ClassIt(const Invalid&) : i(1) { } 147 friend bool operator<(const ClassIt& x, const ClassIt& y); 148 friend std::ostream& operator<<(std::ostream& os, 149 const ClassIt& it); 146 150 }; 151 friend bool operator<(const ClassIt& x, const ClassIt& y) { 152 return (x.i < y.i); 153 } 154 friend std::ostream& operator<<(std::ostream& os, 155 const ClassIt& it) { 156 os << it.i; 157 return os; 158 } 147 159 /// First member of class \c class_id. 148 160 ClassIt& first(ClassIt& it, int class_id) const { … … 159 171 }; 160 172 161 template <typename _Col, typename _Value>162 class Expr;163 164 template <typename _Col, typename _Value>165 class SmallExpr {166 template <typename _C, typename _V>167 friend class Expr;168 protected:169 _Col col;170 _Value value;171 public:172 SmallExpr(_Col _col) : col(_col), value(1) {173 }174 SmallExpr& operator *= (_Value _value) {175 value*=_value;176 return *this;177 }178 // template <typename _C, typename _V>179 // friend SmallExpr<_C, _V> operator* (_V _value,180 // const SmallExpr<_C, _V>& expr);181 template <typename _C, typename _V>182 friend std::ostream& operator<<(std::ostream& os,183 const SmallExpr<_C, _V>& expr);184 };185 186 template <typename _Col, typename _Value>187 SmallExpr<_Col, _Value>188 operator* (_Value value,189 const SmallExpr<_Col, _Value>& expr) {190 SmallExpr<_Col, _Value> tmp;191 tmp=expr;192 tmp*=value;193 return tmp;194 }195 196 template <typename _Col, typename _Value>197 std::ostream& operator<<(std::ostream& os,198 const SmallExpr<_Col, _Value>& expr) {199 os << expr.value << "*" << expr.col;200 return os;201 }202 203 template <typename _Col, typename _Value>204 class Expr {205 protected:206 typedef207 typename std::map<_Col, _Value> Data;208 Data data;209 public:210 Expr() { }211 Expr(SmallExpr<_Col, _Value> expr) {212 data.insert(std::make_pair(expr.col, expr.value));213 }214 // Expr(_Col col) {215 // data.insert(std::make_pair(col, 1));216 // }217 Expr& operator*=(_Value _value) {218 for (typename Data::iterator i=data.begin();219 i!=data.end(); ++i) {220 (*i).second *= _value;221 }222 return *this;223 }224 Expr& operator+=(SmallExpr<_Col, _Value> expr) {225 typename Data::iterator i=data.find(expr.col);226 if (i==data.end()) {227 data.insert(std::make_pair(expr.col, expr.value));228 } else {229 (*i).second+=expr.value;230 }231 return *this;232 }233 // template <typename _C, typename _V>234 // friend Expr<_C, _V> operator*(_V _value, const Expr<_C, _V>& expr);235 template <typename _C, typename _V>236 friend std::ostream& operator<<(std::ostream& os,237 const Expr<_C, _V>& expr);238 };239 240 template <typename _Col, typename _Value>241 Expr<_Col, _Value> operator*(_Value _value,242 const Expr<_Col, _Value>& expr) {243 Expr<_Col, _Value> tmp;244 tmp=expr;245 tmp*=_value;246 return tmp;247 }248 249 template <typename _Col, typename _Value>250 std::ostream& operator<<(std::ostream& os,251 const Expr<_Col, _Value>& expr) {252 for (typename Expr<_Col, _Value>::Data::const_iterator i=253 expr.data.begin();254 i!=expr.data.end(); ++i) {255 os << (*i).second << "*" << (*i).first << " ";256 }257 return os;258 }259 173 260 174 /*! \e … … 425 339 } 426 340 341 //MOST HIGH LEVEL, USER FRIEND FUNCTIONS 342 343 /// \e 344 typedef Expr<ColIt, _Value> Expression; 345 /// \e 346 typedef Expr<RowIt, _Value> DualExpression; 347 /// \e 348 void setRowCoeffs(RowIt row_it, const Expression& expr) { 349 std::vector<std::pair<int, _Value> > row_coeffs; 350 for(typename Expression::Data::const_iterator i=expr.data.begin(); 351 i!=expr.data.end(); ++i) { 352 row_coeffs.push_back(std::make_pair 353 (col_iter_map[(*i).first], (*i).second)); 354 } 355 _setRowCoeffs(row_iter_map[row_it], row_coeffs); 356 } 357 /// \e 358 void setColCoeffs(ColIt col_it, const DualExpression& expr) { 359 std::vector<std::pair<int, _Value> > col_coeffs; 360 for(typename DualExpression::Data::const_iterator i=expr.data.begin(); 361 i!=expr.data.end(); ++i) { 362 col_coeffs.push_back(std::make_pair 363 (row_iter_map[(*i).first], (*i).second)); 364 } 365 _setColCoeffs(col_iter_map[col_it], col_coeffs); 366 } 367 /// \e 368 void setObjCoeffs(const Expression& expr) { 369 for(typename Expression::Data::const_iterator i=expr.data.begin(); 370 i!=expr.data.end(); ++i) { 371 setObjCoef((*i).first, (*i).second); 372 } 373 } 427 374 //SOLVER FUNCTIONS 428 375
Note: See TracChangeset
for help on using the changeset viewer.