permlib 0.2.9
Library for permutation computations
Loading...
Searching...
No Matches
vector_stabilizer_search.h
1// ---------------------------------------------------------------------------
2//
3// This file is part of PermLib.
4//
5// Copyright (c) 2009-2011 Thomas Rehn <thomas@carmen76.de>
6// All rights reserved.
7//
8// Redistribution and use in source and binary forms, with or without
9// modification, are permitted provided that the following conditions
10// are met:
11// 1. Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// 2. Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// 3. The name of the author may not be used to endorse or promote products
17// derived from this software without specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29//
30// ---------------------------------------------------------------------------
31
32
33#ifndef PARTITION_VECTOR_STABILIZER_SEARCH_H_
34#define PARTITION_VECTOR_STABILIZER_SEARCH_H_
35
36#include <permlib/search/partition/r_base.h>
37#include <permlib/predicate/vector_stabilizer_predicate.h>
38#include <permlib/search/partition/set_stabilize_refinement.h>
39#include <permlib/search/partition/refinement_family.h>
40
41namespace permlib {
42namespace partition {
43
45template<class BSGSIN,class TRANSRET>
46class VectorStabilizerSearch : public RBase<BSGSIN,TRANSRET> {
47public:
48 typedef typename RBase<BSGSIN,TRANSRET>::PERM PERM;
49
51
55 VectorStabilizerSearch(const BSGSIN& bsgs, unsigned int pruningLevelDCM);
56
58
64 template<class InputIterator>
65 void construct(InputIterator begin, InputIterator end, unsigned int maxEntries);
66protected:
67 virtual unsigned int processNewFixPoints(const Partition& pi, unsigned int backtrackCount);
68private:
69 std::vector<unsigned int> toStab;
70 unsigned int m_maxEntries;
71};
72
73template<class BSGSIN,class TRANSRET>
74VectorStabilizerSearch<BSGSIN,TRANSRET>::VectorStabilizerSearch(const BSGSIN& bsgs, unsigned int pruningLevelDCM)
75 : RBase<BSGSIN,TRANSRET>(bsgs, pruningLevelDCM)
76{ }
77
78template<class BSGSIN,class TRANSRET>
79template<class InputIterator>
80void VectorStabilizerSearch<BSGSIN,TRANSRET>::construct(InputIterator begin, InputIterator end, unsigned int maxEntries) {
82 m_maxEntries = maxEntries;
83 toStab.insert(toStab.begin(), begin, end);
84 std::vector<unsigned int> stabC(toStab.size());
85
86#ifdef PERMLIB_DEBUGMODE
87 BOOST_FOREACH(const unsigned int v, stabC) {
88 BOOST_ASSERT( v < maxEntries );
89 }
90#endif
91
92 // we can ignore the highest entries because these are automatically stabilized
93 // if all other entries are stabilized
94 for (unsigned int c = 0; c < maxEntries - 1; ++c) {
95 unsigned int i = 0;
96 std::vector<unsigned int>::iterator stabIt = toStab.begin(), cIt = stabC.begin();
97 for (; stabIt != toStab.end(); ++stabIt) {
98 BOOST_ASSERT( cIt != stabC.end() );
99 if (*stabIt == c)
100 *cIt++ = i;
101 ++i;
102 }
103 SetStabilizeRefinement<PERM> ssr(this->m_bsgs.n, stabC.begin(), cIt);
104 ssr.initializeAndApply(this->m_partition);
105 PERM empty(this->m_bsgs.n);
106 ssr.apply2(this->m_partition2, empty);
107 }
109}
110
111template<class BSGSIN,class TRANSRET>
113 const unsigned int basePos = RBase<BSGSIN,TRANSRET>::processNewFixPoints(pi, level);
114 if (!this->m_limitInitialized) {
115 bool allFound = true;
116 int pos = -1;
117 BOOST_FOREACH(unsigned int alpha, toStab) {
118 ++pos;
119 if (alpha == m_maxEntries - 1)
120 continue;
121 if (std::find(pi.fixPointsBegin(), pi.fixPointsEnd(), static_cast<unsigned int>(pos)) == pi.fixPointsEnd()) {
122 allFound = false;
123 break;
124 }
125 }
126 if (allFound) {
127 this->m_limitLevel = level;
128 this->m_limitBase = basePos;
129 this->m_limitInitialized = true;
130 }
131 }
132 return basePos;
133}
134
135}
136}
137
138#endif // -- PARTITION_VECTOR_STABILIZER_SEARCH_H_
predicate for the subgroup that stabilizes a given integer vector
Definition: vector_stabilizer_predicate.h:44
partition
Definition: partition.h:48
vector_t::const_iterator fixPointsBegin() const
iterator to the begin of fix points
Definition: partition.h:164
vector_t::const_iterator fixPointsEnd() const
iterator to the end of fix points
Definition: partition.h:167
R-base for partition backtracking.
Definition: r_base.h:56
void construct(SubgroupPredicate< PERM > *pred, RefinementFamily< PERM > *predRefinement)
constructs an R-base for given predicate and refinement family
Definition: r_base.h:115
virtual unsigned int processNewFixPoints(const Partition &pi, unsigned int level)
callback when a new fix point appears during R-base construction
Definition: r_base.h:197
virtual unsigned int apply2(Partition &pi, const PERM &t) const
applies (right-)refinement to pi which is the image of the original partition this refinement was ini...
Definition: refinement.h:156
bool initializeAndApply(Partition &pi)
applies (left-)refinement to partition and initializes refinement for future use in R-base
Definition: refinement.h:136
concrete -refinements for set stabilization
Definition: set_stabilize_refinement.h:50
subgroup search for a stabilizer of an integer vector based on partition backtracking
Definition: vector_stabilizer_search.h:46
virtual unsigned int processNewFixPoints(const Partition &pi, unsigned int backtrackCount)
callback when a new fix point appears during R-base construction
Definition: vector_stabilizer_search.h:112
VectorStabilizerSearch(const BSGSIN &bsgs, unsigned int pruningLevelDCM)
constructor
Definition: vector_stabilizer_search.h:74
void construct(InputIterator begin, InputIterator end, unsigned int maxEntries)
initializes search
Definition: vector_stabilizer_search.h:80