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 SETSTABILIZEREFINEMENT_H_
00034 #define SETSTABILIZEREFINEMENT_H_
00035
00036 #include "predicate/pointwise_stabilizer_predicate.h"
00037
00038 #include "search/partition/partition.h"
00039 #include "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
00049 template<class PERM>
00050 class SetStabilizeRefinement : public Refinement<PERM> {
00051 public:
00053 template<class InputIterator>
00054 SetStabilizeRefinement(ulong n, InputIterator begin, InputIterator end);
00055
00056 virtual uint apply(Partition& pi) const;
00057
00058 virtual bool init(Partition& pi);
00059 private:
00060 std::vector<ulong> toStab;
00061 };
00062
00063 template<class PERM>
00064 template<class InputIterator>
00065 SetStabilizeRefinement<PERM>::SetStabilizeRefinement(ulong n, InputIterator begin, InputIterator end)
00066 : Refinement<PERM>(n, Default), toStab(begin, end)
00067 {
00068 std::sort(toStab.begin(), toStab.end());
00069 }
00070
00071 template<class PERM>
00072 uint SetStabilizeRefinement<PERM>::apply(Partition& pi) const {
00073 BOOST_ASSERT( this->initialized() );
00074 uint ret = 0;
00075 BOOST_FOREACH(uint cell, Refinement<PERM>::m_cellPairs) {
00076 DEBUG(std::cout << "apply set stab " << cell << std::endl;)
00077 if (pi.intersect(toStab.begin(), toStab.end(), cell))
00078 ++ret;
00079 }
00080 return ret;
00081 }
00082
00083 template<class PERM>
00084 bool SetStabilizeRefinement<PERM>::init(Partition& pi) {
00085 for (uint c = 0; c < pi.cells(); ++c) {
00086 if (pi.intersect(toStab.begin(), toStab.end(), c))
00087 Refinement<PERM>::m_cellPairs.push_back(c);
00088 }
00089 if (!Refinement<PERM>::m_cellPairs.empty()) {
00090 typename Refinement<PERM>::RefinementPtr ref(new SetStabilizeRefinement<PERM>(*this));
00091 Refinement<PERM>::m_backtrackRefinements.push_back(ref);
00092 return true;
00093 }
00094 return false;
00095 }
00096
00097 }
00098 }
00099
00100 #endif // -- SETSTABILIZEREFINEMENT_H_