PolyBoRi
PairManager.h
Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //*****************************************************************************
00014 //*****************************************************************************
00015 
00016 #ifndef polybori_groebner_PairManager_h_
00017 #define polybori_groebner_PairManager_h_
00018 
00019 #include "PairStatusSet.h"
00020 
00021 
00022 // include basic definitions
00023 #include "groebner_defs.h"
00024 #include "pairs.h"
00025 #include "PolyEntry.h"
00026 #include "NextSpoly.h"
00027 #include "CheckChainCriterion.h"
00028 #include <polybori/routines/pbori_algo.h>
00029 #include <utility>
00030 
00031 BEGIN_NAMESPACE_PBORIGB
00032 
00037 class PairManager {
00038   typedef PairManager self;
00039 
00040 public:
00041   typedef std::priority_queue<Pair, std::vector<PairE>, PairECompare>
00042   queue_type;
00043 
00044   PairManager(const BoolePolyRing& ring):
00045     queue(ring)  { }
00046 
00047   void appendHiddenGenerators(std::vector<Polynomial>& vec) {
00048     queue_type temp(queue);
00049     while(!temp.empty()){
00050       appendTo(vec, temp.top());
00051       temp.pop();
00052     }
00053   }
00054 
00055   void introducePair(const Pair& pair, bool isHFE) {  
00056     if (!skip(pair, isHFE)) queue.push(pair);
00057   };  
00058 
00059   Polynomial nextSpoly(ReductionStrategy& gen) {
00060     if (PBORI_UNLIKELY(pairSetEmpty()))
00061       return gen.leadingTerms.ring().zero();
00062 
00063     return NextSpoly(gen, status)(popped());
00064   }
00065 
00066   bool pairSetEmpty() const { return queue.empty(); }
00067 
00068   template <class StrategyType>
00069   void cleanTopByChainCriterion(StrategyType& strat) {
00070     CheckChainCriterion<StrategyType> continuing(strat, status);
00071     while(!pairSetEmpty() && continuing(queue.top()))
00072       queue.pop();   
00073   }
00074 
00075   PairStatusSet status;
00076   queue_type queue;
00077 
00078 protected:
00080   Pair popped() {
00081     Pair result = queue.top();
00082     queue.pop();
00083     return result;
00084   }
00085 
00086 private:
00087   bool skip(const Pair& pair, bool isHFE) {
00088     return isHFE && (pair.getType() == IJ_PAIR) && (pair.sugar > 4);
00089   };
00091    void appendTo(std::vector<Polynomial>& vec, const Pair& current) const {
00092     if (current.getType() == DELAYED_PAIR)
00093       appendTo(vec, current.delayedPair().p);
00094   }
00095 
00097   void appendTo(std::vector<Polynomial>& vec, const Polynomial& poly) const {
00098     if (!poly.isZero())
00099       vec.push_back(poly);
00100   }
00101 };
00102 
00103 END_NAMESPACE_PBORIGB
00104 
00105 #endif /* polybori_groebner_PairManager_h_ */