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 RANDOMSCHREIERSIMSCONSTRUCTION_H_
00034 #define RANDOMSCHREIERSIMSCONSTRUCTION_H_
00035
00036 #include "construct/base_construction.h"
00037 #include "bsgs.h"
00038
00039 #include <boost/foreach.hpp>
00040
00041 namespace permlib {
00042
00044
00048 template <class PERM, class TRANS>
00049 class RandomSchreierSimsConstruction : public BaseConstruction<PERM, TRANS> {
00050 public:
00052
00057 RandomSchreierSimsConstruction(uint n, RandomGenerator<PERM> *rng, ulong knownOrder = 0);
00058
00060
00062 template <class ForwardIterator>
00063 BSGS<PERM, TRANS> construct(ForwardIterator generatorsBegin, ForwardIterator generatorsEnd, bool& guaranteedBSGS) const;
00064
00066
00076 template <class ForwardIterator, class InputIterator>
00077 BSGS<PERM, TRANS> construct(ForwardIterator generatorsBegin, ForwardIterator generatorsEnd, InputIterator prescribedBaseBegin, InputIterator prescribedBaseEnd, bool& guaranteedBSGS) const;
00078
00080 mutable uint m_statRandomElementsConsidered;
00081
00083 static const uint minimalConsecutiveSiftingElementCount = 20;
00084
00086 static const uint maxIterationFactor = 10000;
00087 private:
00088 RandomGenerator<PERM> *m_rng;
00089 ulong m_knownOrder;
00090 };
00091
00092
00093
00094
00095
00096 template <class PERM, class TRANS>
00097 RandomSchreierSimsConstruction<PERM,TRANS>::RandomSchreierSimsConstruction(uint n, RandomGenerator<PERM> *rng, ulong knownOrder)
00098 : BaseConstruction<PERM, TRANS>(n), m_statRandomElementsConsidered(0), m_rng(rng), m_knownOrder(knownOrder)
00099 { }
00100
00101 template <class PERM, class TRANS>
00102 template <class ForwardIterator>
00103 inline BSGS<PERM, TRANS> RandomSchreierSimsConstruction<PERM,TRANS>::construct(ForwardIterator generatorsBegin, ForwardIterator generatorsEnd, bool& guaranteedBSGS) const {
00104 return construct(generatorsBegin, generatorsEnd, BaseConstruction<PERM,TRANS>::empty, BaseConstruction<PERM,TRANS>::empty, guaranteedBSGS);
00105 }
00106
00107 template <class PERM, class TRANS>
00108 template <class ForwardIterator, class InputIterator>
00109 BSGS<PERM, TRANS> RandomSchreierSimsConstruction<PERM, TRANS>
00110 ::construct(ForwardIterator generatorsBegin, ForwardIterator generatorsEnd, InputIterator prescribedBaseBegin, InputIterator prescribedBaseEnd, bool& guaranteedBSGS) const
00111 {
00112 const uint &n = BaseConstruction<PERM, TRANS>::m_n;
00113 BSGS<PERM, TRANS> ret(n);
00114 std::vector<ulong> &B = ret.B;
00115 std::vector<TRANS> &U = ret.U;
00116 std::vector<PERMlist> S;
00117 setup(generatorsBegin, generatorsEnd, prescribedBaseBegin, prescribedBaseEnd, ret, S);
00118
00119 uint consecutiveSiftingElementCount = minimalConsecutiveSiftingElementCount;
00120 if (m_knownOrder > 0)
00121
00122 consecutiveSiftingElementCount = maxIterationFactor;
00123 const uint maxIterationCount = B.size() * maxIterationFactor;
00124 for (uint it = 0; it < maxIterationCount; ++it) {
00125 bool isProbableBSGS = true;
00126 for (uint i = 0; i < consecutiveSiftingElementCount && ret.order() != m_knownOrder; ++i) {
00127 PERM g = m_rng->next();
00128 ++m_statRandomElementsConsidered;
00129 PERM h(n);
00130 uint j = ret.sift(g, h);
00131 if (j < B.size() || !h.isIdentity()) {
00132
00133 h.flush();
00134
00135 if (j == B.size()) {
00136 ulong gamma = n+1;
00137 if (ret.chooseBaseElement(h, gamma)) {
00138 B.push_back(gamma);
00139 }
00140 BOOST_ASSERT(j < B.size());
00141 S.push_back(PERMlist());
00142 U.push_back(TRANS(n));
00143 }
00144
00145 boost::shared_ptr<PERM> hPtr(new PERM(h));
00146 S[j].insert(S[j].end(), hPtr);
00147
00148 ret.orbitUpdate(j, S[j], hPtr);
00149 isProbableBSGS = false;
00150 break;
00151 }
00152 }
00153 if (isProbableBSGS)
00154 break;
00155 }
00156
00157 mergeGenerators(S, ret);
00158
00159
00160 guaranteedBSGS = ret.order() == m_knownOrder;
00161
00162 return ret;
00163 }
00164
00165 }
00166
00167 #endif // -- RANDOMSCHREIERSIMSCONSTRUCTION_H_