source: branches/Couenne/Couenne/src/util/rootQ.h @ 534

Last change on this file since 534 was 534, checked in by pbelotti, 13 years ago

moved include files to make them doxygenable. Introduced three-way branching, with fixed intervals for now. Added check for small bound interval within all generateCuts()

File size: 1.2 KB
Line 
1/*
2 * Name:    rootQ.h
3 * Author:  Pietro Belotti
4 * Purpose: find roots of polynomial Q^k(x) (see Liberti and Pantelides, 2003)
5 *
6 * (C) Pietro Belotti. This file is licensed under the Common Public License (CPL)
7 */
8
9#include <CouenneTypes.h>
10#include <map>
11
12// Find roots of polynomial $Q^k(x) = \sum_{i=1}^{2k} i x^{i-1}$. Used
13// in convexification of powers with odd exponent
14
15extern "C" {
16  CouNumber rootQ (int k);
17}
18
19/// class that stores result of previous calls to rootQ into a map for
20/// faster access
21
22class Qroot {
23
24 protected:
25
26  // maps an integer k with the root of Q^k(x)
27
28  static std::map <int, CouNumber> Qmap;
29
30 public:
31
32  /// empty constructors (we only need the method to work on the static
33  /// structure)
34 
35  Qroot  () {}
36  ~Qroot () {}
37
38  /// retrieve root of Q with order = k. If no such computation has
39  /// been performed yet, do it here
40
41  inline CouNumber operator () (int k) {
42
43    std::map <int, CouNumber>:: iterator pos;
44    CouNumber root;
45
46    k /= 2; // becomes true index
47
48    if ((pos = Qmap.find (k)) == Qmap.end()) {
49
50      std::pair <int, CouNumber> newpair;
51
52      newpair.first  = k;
53      newpair.second = (root = rootQ (k));
54 
55      Qmap.insert (newpair);
56    }
57    else 
58      root = pos -> second;
59
60    return root;
61  }
62};
Note: See TracBrowser for help on using the repository browser.