realroot_doc 0.1.1
|
00001 /***************************************************************************** 00002 * M a t h e m a g i x 00003 ***************************************************************************** 00004 * Subdivisor 00005 * 2010-05-16 00006 ***************************************************************************** 00007 * Copyright (C) 2010 INRIA Sophia-Antipolis 00008 ***************************************************************************** 00009 * Comments : 00010 ****************************************************************************/ 00011 # ifndef realroot_solver_subdivisor_hpp 00012 # define realroot_solver_subdivisor_hpp 00013 00014 # include <stack> 00015 # include <realroot/Seq.hpp> 00016 00017 # define TMPL template<class CELL, class V> 00018 # define SELF subdivisor<CELL, V> 00019 # define Stack std::stack<Cell*> 00020 //==================================================================== 00021 namespace mmx { 00022 00023 TMPL 00024 class subdivisor { 00025 00026 public: 00027 typedef CELL Cell; 00028 subdivisor(Cell* c) ; 00029 ~subdivisor(void) ; 00030 00031 void run(void) ; 00032 00033 Seq<Cell*> solutions() {return m_sols;} 00034 private: 00035 Stack* m_stack ; 00036 Seq<Cell*> m_sols; 00037 }; 00038 00039 //-------------------------------------------------------------------- 00040 TMPL 00041 SELF::subdivisor(CELL * object) { 00042 m_stack = new Stack ; 00043 m_stack -> push(object); 00044 } 00045 00046 TMPL 00047 SELF::~subdivisor(void) { 00048 delete m_stack ; 00049 } 00050 00051 TMPL void 00052 SELF::run() { 00053 00054 Cell* cl=NULL; 00055 while( !m_stack->empty() ) { 00056 00057 cl = m_stack->top(); m_stack->pop(); 00058 00059 if(V::reduce(cl)) { 00060 V::subdivide(cl,m_stack) ; 00061 delete cl; 00062 } else if(V::regular(cl)) { 00063 m_sols<<cl; 00064 } else 00065 delete cl; 00066 00067 00068 } 00069 } 00070 //==================================================================== 00071 } // namespace mmx 00072 //==================================================================== 00073 # undef TMPL 00074 # undef SELF 00075 # undef Stack 00076 # endif