Couenne  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CouenneRootQ.hpp
Go to the documentation of this file.
1 /* $Id: CouenneRootQ.hpp 940 2013-01-13 19:49:02Z pbelotti $
2  *
3  * Name: rootQ.hpp
4  * Author: Pietro Belotti
5  * Purpose: find roots of polynomial Q^k(x) (see Liberti and Pantelides, 2003)
6  *
7  * (C) Carnegie-Mellon University, 2006-10.
8  * This file is licensed under the Eclipse Public License (EPL)
9  */
10 
11 #ifndef CouenneRootQ_hpp
12 #define CouenneRootQ_hpp
13 
14 #include "CouenneTypes.hpp"
15 #include <map>
16 #include <iostream>
17 
18 namespace Couenne
19 {
20 
23 CouNumber rootQ (int k);
24 
25 
28 
29 class Qroot {
30 
31  protected:
32 
34 
35  static std::map <int, CouNumber> Qmap;
36 
37  public:
38 
41  Qroot () {}
42 
44  ~Qroot () {}
45 
48 
49  inline CouNumber operator () (int k) {
50 
51  std::map <int, CouNumber>:: iterator pos;
52  CouNumber root;
53 
54  if( k % 2 == 1 )
55  {
56  k /= 2; // becomes true index
57 
58  if ((pos = Qmap.find (k)) == Qmap.end()) {
59 
60  std::pair <int, CouNumber> newpair;
61 
62  newpair.first = k;
63  newpair.second = (root = rootQ (k));
64 
65  Qmap.insert (newpair);
66  }
67  else
68  root = pos -> second;
69  }
70  else
71  {
72  switch(k) {
73  case 2: return -(sqrt(2.0) - 1.0);
74  case 4: return -0.56042566045031785945;
75  case 6: return -0.64146546982884663257;
76  case 8: return -0.69428385661425826738;
77  case 10: return -0.73192937842370733350;
78  default:
79  std::cerr << "Need to implement root finding for even k" << std::endl;
80  throw -1;
81  }
82  }
83 
84  return root;
85  }
86 };
87 
88 }
89 
90 #endif
CouNumber rootQ(int k)
Find roots of polynomial $Q^k(x) = .
static std::map< int, CouNumber > Qmap
Maps an integer k with the root of .
pos
position where the operator should be printed when printing the expression
Qroot()
Empty constructor – we only need the method to work on the static structure.
~Qroot()
Empty destructor.
double CouNumber
main number type in Couenne
class that stores result of previous calls to rootQ into a map for faster access
CouNumber operator()(int k)
Retrieve root of Q with order = k.