cache_manager.h
Go to the documentation of this file.
/* Copyright (c) 2005-2007 by The PolyBoRi Team */
#include <polybori.h>
#include <algorithm>
#include <utility>
#include <iostream>
#include <boost/shared_ptr.hpp>
#include "groebner_defs.h"
#ifndef PBORI_GB_CACHE_H
#define PBORI_GB_CACHE_H
BEGIN_NAMESPACE_PBORIGB
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){
BooleExponent::const_iterator it=used_variables.begin();
BooleExponent::const_iterator end=used_variables.end();
idx_type1 idx_0123=0;
while(it!=end){
ring_2_0123[*it]=idx_0123;
back_2_ring[idx_0123]=*it;
idx_0123++;
it++;
}
}
//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);
Polynomial translate_indices(const Polynomial& p, const std::vector<idx_type>& table);
class CacheManager{
public:
typedef Polynomial::poly_vec_map_type impl_type;
typedef std::vector<Polynomial> poly_vec_type;
typedef boost::shared_ptr<poly_vec_type> res_type;
typedef Polynomial::poly_vec_map_type::const_iterator impl_iterator_type;
protected:
impl_type impl;
public:
CacheManager(){
}
res_type lookup(const Polynomial& p, bool& succ){
int nv=p.ring().nVariables();
BooleExponent used_exp=p.usedVariablesExp();
std::vector<idx_type> back_2_ring(used_exp.size());
std::vector<idx_type> ring_2_0123(nv);
//PBORI_ASSERT(nv<255);
set_up_translation_vectors(ring_2_0123,back_2_ring, used_exp);
Polynomial p_t=translate_indices(p,ring_2_0123);
impl_iterator_type it=impl.find(p_t);
//cache_res_type res;
if (it!=impl.end()){
succ=true;
res_type res(new poly_vec_type(it->second));
for(poly_vec_type::size_type i=0;i<res->size();i++){
(*res)[i]=translate_indices((*res)[i],back_2_ring);
}
return res;
}
else{
succ=false;
return res_type();
}
}
void insert(const Polynomial& key, const poly_vec_type& value){
int nv=key.ring().nVariables();
BooleExponent used_exp=key.usedVariablesExp();
std::vector<idx_type> back_2_ring(used_exp.size());
std::vector<idx_type> ring_2_0123(nv);
set_up_translation_vectors(ring_2_0123,back_2_ring, used_exp);
Polynomial key_t=translate_indices(key,ring_2_0123);
poly_vec_type value_t(value);
for(poly_vec_type::size_type i=0;i<value_t.size();i++){
value_t[i]=translate_indices(value_t[i], ring_2_0123);
}
impl[key_t]=value_t;
}
};
END_NAMESPACE_PBORIGB
#endif
polybori::BooleExponent
This class is just a wrapper for using variables for storing indices as interim data structure for Bo...
Definition: BooleExponent.h:34
polybori::groebner::CacheManager::impl
impl_type impl
Definition: cache_manager.h:36
polybori::BooleExponent::begin
const_iterator begin() const
Start iteration over indices (constant access)
Definition: BooleExponent.h:97
END_NAMESPACE_PBORIGB
#define END_NAMESPACE_PBORIGB
Definition: groebner_defs.h:16
polybori::groebner::CacheManager::res_type
boost::shared_ptr< poly_vec_type > res_type
Definition: cache_manager.h:33
polybori::BoolePolynomial::ring
const ring_type & ring() const
Access ring, where this belongs to.
Definition: BoolePolynomial.h:478
polybori::groebner::set_up_translation_vectors
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
polybori::groebner::CacheManager::impl_type
Polynomial::poly_vec_map_type impl_type
Definition: cache_manager.h:30
polybori::groebner::CacheManager::CacheManager
CacheManager()
Definition: cache_manager.h:38
BEGIN_NAMESPACE_PBORIGB
#define BEGIN_NAMESPACE_PBORIGB
Definition: groebner_defs.h:15
polybori::groebner::translate_indices
Polynomial translate_indices(const Polynomial &p, const std::vector< idx_type > &table)
Definition: groebner_alg.cc:278
polybori::groebner::CacheManager::impl_iterator_type
Polynomial::poly_vec_map_type::const_iterator impl_iterator_type
Definition: cache_manager.h:34
polybori::BoolePolynomial
This class wraps the underlying decicion diagram type and defines the necessary operations.
Definition: BoolePolynomial.h:85
polybori::groebner::CacheManager::insert
void insert(const Polynomial &key, const poly_vec_type &value)
Definition: cache_manager.h:67
groebner_defs.h
polybori::BoolePolynomial::poly_vec_map_type
std::map< self, std::vector< self >, symmetric_composition< std::less< navigator >, navigates< self > > > poly_vec_map_type
Definition: BoolePolynomial.h:199
polybori::groebner::CacheManager
Definition: cache_manager.h:28
polybori::groebner::CacheManager::lookup
res_type lookup(const Polynomial &p, bool &succ)
Definition: cache_manager.h:41
polybori::BoolePolyRing::nVariables
size_type nVariables() const
Get number of ring variables.
Definition: BoolePolyRing.h:126
polybori::BooleExponent::end
const_iterator end() const
Finish iteration over indices (constant access)
Definition: BooleExponent.h:100
polybori::CGenericIter
Definition: BoolePolynomial.h:70
polybori.h
polybori::BooleExponent::const_iterator
data_type::const_iterator const_iterator
Definition: BooleExponent.h:52
polybori::groebner::CacheManager::poly_vec_type
std::vector< Polynomial > poly_vec_type
Definition: cache_manager.h:32
polybori::BooleExponent::size
size_type size() const
Degree of the corresponding monomial.
Definition: BooleExponent.h:109
polybori::BoolePolynomial::usedVariablesExp
exp_type usedVariablesExp() const
Exponent vector of all of variables of the polynomial.
Definition: BoolePolynomial.cc:404