CouenneRootQ.hpp

Go to the documentation of this file.
00001 /* $Id: CouenneRootQ.hpp 940 2013-01-13 19:49:02Z pbelotti $
00002  *
00003  * Name:    rootQ.hpp
00004  * Author:  Pietro Belotti
00005  * Purpose: find roots of polynomial Q^k(x) (see Liberti and Pantelides, 2003)
00006  *
00007  * (C) Carnegie-Mellon University, 2006-10.
00008  * This file is licensed under the Eclipse Public License (EPL)
00009  */
00010 
00011 #ifndef CouenneRootQ_hpp
00012 #define CouenneRootQ_hpp
00013 
00014 #include "CouenneTypes.hpp"
00015 #include <map>
00016 #include <iostream>
00017 
00018 namespace Couenne
00019 {
00020 
00023 CouNumber rootQ (int k);
00024 
00025 
00028 
00029 class Qroot {
00030 
00031  protected:
00032 
00034 
00035   static std::map <int, CouNumber> Qmap;
00036 
00037  public:
00038 
00041   Qroot  () {}
00042 
00044   ~Qroot () {}
00045 
00048 
00049   inline CouNumber operator () (int k) {
00050 
00051     std::map <int, CouNumber>:: iterator pos;
00052     CouNumber root;
00053 
00054     if( k % 2 == 1 )
00055     {
00056        k /= 2; // becomes true index
00057 
00058        if ((pos = Qmap.find (k)) == Qmap.end()) {
00059 
00060           std::pair <int, CouNumber> newpair;
00061 
00062           newpair.first  = k;
00063           newpair.second = (root = rootQ (k));
00064 
00065           Qmap.insert (newpair);
00066        }
00067        else
00068           root = pos -> second;
00069     }
00070     else
00071     {
00072        switch(k) {
00073           case 2: return -(sqrt(2.0) - 1.0);
00074           case 4: return -0.56042566045031785945;
00075           case 6: return -0.64146546982884663257;
00076           case 8: return -0.69428385661425826738;
00077           case 10: return -0.73192937842370733350;
00078           default:
00079              std::cerr << "Need to implement root finding for even k" << std::endl;
00080              throw -1;
00081        }
00082     }
00083 
00084     return root;
00085   }
00086 };
00087 
00088 }
00089 
00090 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Mar 2015 for Couenne by  doxygen 1.6.1