PolyBoRi
cache_manager.h
Go to the documentation of this file.
1 /* Copyright (c) 2005-2007 by The PolyBoRi Team */
2 
3 #include <polybori.h>
4 #include <algorithm>
5 #include <utility>
6 #include <iostream>
7 #include <boost/shared_ptr.hpp>
8 #include "groebner_defs.h"
9 #ifndef PBORI_GB_CACHE_H
10 #define PBORI_GB_CACHE_H
11 
12 
14 template<class idx_type1, class idx_type2> void set_up_translation_vectors(std::vector<idx_type1>& ring_2_0123, std::vector<idx_type2>& back_2_ring, const Exponent& used_variables){
15  BooleExponent::const_iterator it=used_variables.begin();
16  BooleExponent::const_iterator end=used_variables.end();
17  idx_type1 idx_0123=0;
18  while(it!=end){
19  ring_2_0123[*it]=idx_0123;
20  back_2_ring[idx_0123]=*it;
21  idx_0123++;
22  it++;
23  }
24 }
25 
26 //template<class idx_type1, class idx_type2> void set_up_translation_vectors(std::vector<idx_type1>& ring_2_0123, std::vector<idx_type>& back_2_ring, const Exponent& used_variables);
27 Polynomial translate_indices(const Polynomial& p, const std::vector<idx_type>& table);
29  public:
31 
32  typedef std::vector<Polynomial> poly_vec_type;
33  typedef boost::shared_ptr<poly_vec_type> res_type;
35  protected:
36  impl_type impl;
37  public:
39 
40  }
41  res_type lookup(const Polynomial& p, bool& succ){
42  int nv=p.ring().nVariables();
43  BooleExponent used_exp=p.usedVariablesExp();
44  std::vector<idx_type> back_2_ring(used_exp.size());
45  std::vector<idx_type> ring_2_0123(nv);
46 
47  //PBORI_ASSERT(nv<255);
48  set_up_translation_vectors(ring_2_0123,back_2_ring, used_exp);
49  Polynomial p_t=translate_indices(p,ring_2_0123);
50  impl_iterator_type it=impl.find(p_t);
51  //cache_res_type res;
52  if (it!=impl.end()){
53  succ=true;
54  res_type res(new poly_vec_type(it->second));
55 
56 
57  for(poly_vec_type::size_type i=0;i<res->size();i++){
58  (*res)[i]=translate_indices((*res)[i],back_2_ring);
59  }
60  return res;
61  }
62  else{
63  succ=false;
64  return res_type();
65  }
66  }
67  void insert(const Polynomial& key, const poly_vec_type& value){
68  int nv=key.ring().nVariables();
69  BooleExponent used_exp=key.usedVariablesExp();
70  std::vector<idx_type> back_2_ring(used_exp.size());
71  std::vector<idx_type> ring_2_0123(nv);
72  set_up_translation_vectors(ring_2_0123,back_2_ring, used_exp);
73  Polynomial key_t=translate_indices(key,ring_2_0123);
74  poly_vec_type value_t(value);
75 
76  for(poly_vec_type::size_type i=0;i<value_t.size();i++){
77  value_t[i]=translate_indices(value_t[i], ring_2_0123);
78  }
79  impl[key_t]=value_t;
80  }
81 
82 
83 };
85 #endif
This class is just a wrapper for using variables for storing indices as interim data structure for Bo...
Definition: BooleExponent.h:34
impl_type impl
Definition: cache_manager.h:36
const_iterator begin() const
Start iteration over indices (constant access)
Definition: BooleExponent.h:97
#define END_NAMESPACE_PBORIGB
Definition: groebner_defs.h:16
boost::shared_ptr< poly_vec_type > res_type
Definition: cache_manager.h:33
const ring_type & ring() const
Access ring, where this belongs to.
Definition: BoolePolynomial.h:478
void set_up_translation_vectors(std::vector< idx_type1 > &ring_2_0123, std::vector< idx_type2 > &back_2_ring, const Exponent &used_variables)
Definition: cache_manager.h:14
Polynomial::poly_vec_map_type impl_type
Definition: cache_manager.h:30
CacheManager()
Definition: cache_manager.h:38
#define BEGIN_NAMESPACE_PBORIGB
Definition: groebner_defs.h:15
Polynomial translate_indices(const Polynomial &p, const std::vector< idx_type > &table)
Definition: groebner_alg.cc:278
Polynomial::poly_vec_map_type::const_iterator impl_iterator_type
Definition: cache_manager.h:34
This class wraps the underlying decicion diagram type and defines the necessary operations.
Definition: BoolePolynomial.h:85
void insert(const Polynomial &key, const poly_vec_type &value)
Definition: cache_manager.h:67
std::map< self, std::vector< self >, symmetric_composition< std::less< navigator >, navigates< self > > > poly_vec_map_type
Definition: BoolePolynomial.h:199
Definition: cache_manager.h:28
res_type lookup(const Polynomial &p, bool &succ)
Definition: cache_manager.h:41
size_type nVariables() const
Get number of ring variables.
Definition: BoolePolyRing.h:126
const_iterator end() const
Finish iteration over indices (constant access)
Definition: BooleExponent.h:100
Definition: BoolePolynomial.h:70
data_type::const_iterator const_iterator
Definition: BooleExponent.h:52
std::vector< Polynomial > poly_vec_type
Definition: cache_manager.h:32
size_type size() const
Degree of the corresponding monomial.
Definition: BooleExponent.h:109
exp_type usedVariablesExp() const
Exponent vector of all of variables of the polynomial.
Definition: BoolePolynomial.cc:404