00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef SETIMAGEREFINEMENT_H_
00034 #define SETIMAGEREFINEMENT_H_
00035
00036 #include <permlib/predicate/pointwise_stabilizer_predicate.h>
00037
00038 #include <permlib/search/partition/partition.h>
00039 #include <permlib/search/partition/refinement.h>
00040
00041 #include <algorithm>
00042 #include <boost/dynamic_bitset.hpp>
00043 #include <boost/foreach.hpp>
00044
00045 namespace permlib {
00046 namespace partition {
00047
00050 template<class PERM>
00051 class SetImageRefinement : public Refinement<PERM> {
00052 public:
00054
00061 template<class InputIterator>
00062 SetImageRefinement(ulong n, InputIterator begin, InputIterator end, InputIterator beginImg, InputIterator endImg);
00063
00064 virtual uint apply(Partition& pi) const;
00065 virtual uint apply2(Partition& pi, const PERM& t) const;
00066
00067 virtual bool init(Partition& pi);
00068 private:
00069 std::vector<ulong> delta;
00070 std::vector<ulong> gamma;
00071 };
00072
00073 template<class PERM>
00074 template<class InputIterator>
00075 SetImageRefinement<PERM>::SetImageRefinement(ulong n, InputIterator begin, InputIterator end, InputIterator beginImg, InputIterator endImg)
00076 : Refinement<PERM>(n, Default), delta(begin, end), gamma(beginImg, endImg)
00077 {
00078 std::sort(delta.begin(), delta.end());
00079 std::sort(gamma.begin(), gamma.end());
00080 }
00081
00082 template<class PERM>
00083 uint SetImageRefinement<PERM>::apply(Partition& pi) const {
00084 BOOST_ASSERT( this->initialized() );
00085 uint ret = 0;
00086 BOOST_FOREACH(uint cell, Refinement<PERM>::m_cellPairs) {
00087 DEBUG(std::cout << "apply set image1 " << cell << std::endl;)
00088 if (pi.intersect(delta.begin(), delta.end(), cell))
00089 ++ret;
00090 }
00091 return ret;
00092 }
00093
00094 template<class PERM>
00095 uint SetImageRefinement<PERM>::apply2(Partition& pi, const PERM& t) const {
00096 BOOST_ASSERT( this->initialized() );
00097 uint ret = 0;
00098 BOOST_FOREACH(uint cell, Refinement<PERM>::m_cellPairs) {
00099 DEBUG(std::cout << "apply set image2 " << cell << std::endl;)
00100 if (pi.intersect(gamma.begin(), gamma.end(), cell))
00101 ++ret;
00102 }
00103 return ret;
00104 }
00105
00106 template<class PERM>
00107 bool SetImageRefinement<PERM>::init(Partition& pi) {
00108 for (uint c = 0; c < pi.cells(); ++c) {
00109 if (pi.intersect(delta.begin(), delta.end(), c))
00110 Refinement<PERM>::m_cellPairs.push_back(c);
00111 }
00112 if (!Refinement<PERM>::m_cellPairs.empty()) {
00113 typename Refinement<PERM>::RefinementPtr ref(new SetImageRefinement<PERM>(*this));
00114 Refinement<PERM>::m_backtrackRefinements.push_back(ref);
00115 return true;
00116 }
00117 return false;
00118 }
00119
00120 }
00121 }
00122
00123 #endif // -- SETIMAGEREFINEMENT_H_