2 * src/lemon/lin_expr.h - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Combinatorial Optimization Research Group, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
17 #ifndef LEMON_LIN_EXPR_H
18 #define LEMON_LIN_EXPR_H
26 ///\brief Classes to handle linear expressions
29 /// Class to handle sparse linear expressions
30 template <class _V,class _C>
31 class SparseLinExpr : public std::map<_V, _C>
38 typedef typename std::map<_V, _C> Base;
43 SparseLinExpr(const Var &v) : const_comp(v) {
44 Base::insert(std::make_pair(v, 1));
46 SparseLinExpr(const Coeff &v) : const_comp(v) {}
48 void set(const Var &v,const Coeff &c) {
49 return Base::insert(std::make_pair(v, c));
51 // Coeff &operator[](const Var &v) { return data[v]; }
52 // const Coeff &operator[](const Var &v) const { return data[v]; }
54 Coeff &constComp() { return const_comp; }
55 const Coeff &constComp() const { return const_comp; }
57 ///Removes the components with zero coefficient.
59 for (typename Base::iterator i=Base::begin(); i!=Base::end();) {
60 typename Base::iterator j=i;
62 if ((*i).second==0) Base::erase(i);
71 #endif //LEMON_LIN_EXPR_H