Couenne  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CouenneLQelems.hpp
Go to the documentation of this file.
1 /* $Id: CouenneLQelems.hpp 490 2011-01-14 16:07:12Z pbelotti $
2  *
3  * Name: lqelems.hpp
4  * Author: Pietro Belotti
5  * Purpose: definition of elemental elements of linear and bilinear expressions
6  *
7  * (C) Carnegie-Mellon University, 2007.
8  * This file is licensed under the Eclipse Public License (EPL)
9  */
10 
11 #ifndef COUENNE_LQELEMS_H
12 #define COUENNE_LQELEMS_H
13 
14 #include <map>
15 
16 #include "CouenneTypes.hpp"
17 
18 namespace Couenne {
19 
20 class quadElem {
21 
22 private:
26 
27 public:
28 
30  varI_ (i),
31  varJ_ (j),
32  coeff_ (c) {}
33 
34  quadElem (const quadElem &src):
35  varI_ (src.varI_),
36  varJ_ (src.varJ_),
37  coeff_ (src.coeff_) {}
38 
40  {return new quadElem (*this);}
41 
42  inline exprVar *varI () {return varI_;}
43  inline exprVar *varJ () {return varJ_;}
44  inline CouNumber coeff () {return coeff_;}
45 };
46 
47 
48 class LinMap {
49 
50 private:
51  std::map <int, CouNumber> lmap_;
52 
53 public:
54 
56  std::map <int, CouNumber> &Map ()
57  {return lmap_;}
58 
60  void insert (int index, CouNumber coe) {
61 
62  std::map <int, CouNumber>::iterator i = lmap_.find (index);
63 
64  if (i != lmap_.end()) {
65  if (fabs (i -> second += coe) < COUENNE_EPS)
66  lmap_.erase (i);
67  } else {
68  std::pair <int, CouNumber> npair (index, coe);
69  lmap_.insert (npair);
70  }
71  }
72 };
73 
74 
75 class QuadMap {
76 
77 private:
78  std::map <std::pair <int, int>, CouNumber> qmap_;
79 
80 public:
81 
83  std::map <std::pair <int, int>, CouNumber> &Map ()
84  {return qmap_;}
85 
87  void insert (int indI, int indJ, CouNumber coe) {
88 
89  std::pair <int, int> nind (indI, indJ);
90  std::map <std::pair <int, int>, CouNumber>::iterator i = qmap_.find (nind);
91 
92  if (i != qmap_.end()) {
93  if (fabs (i -> second += coe) < COUENNE_EPS)
94  qmap_.erase (i);
95  } else {
96  std::pair <std::pair <int, int>, CouNumber> npair (nind, coe);
97  qmap_.insert (npair);
98  }
99  }
100 };
101 
102 }
103 
104 #endif
quadElem(const quadElem &src)
quadElem * clone()
void insert(int indI, int indJ, CouNumber coe)
insert a pair &lt;&lt;int,int&gt;,CouNumber&gt; into a map for quadratic terms
void insert(int index, CouNumber coe)
insert a pair &lt;int,CouNumber&gt; into a map for linear terms
quadElem(exprVar *i, exprVar *j, CouNumber c)
#define COUENNE_EPS
std::map< int, CouNumber > & Map()
public access
double CouNumber
main number type in Couenne
std::map< int, CouNumber > lmap_
std::map< std::pair< int, int >, CouNumber > & Map()
public access
variable-type operator
std::map< std::pair< int, int >, CouNumber > qmap_