permlib
0.2.9
Library for permutation computations
Toggle main menu visibility
Loading...
Searching...
No Matches
include
permlib
generator
bsgs_generator.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 BSGSGENERATOR_H_
34
#define BSGSGENERATOR_H_
35
36
#include <permlib/common.h>
37
#include <permlib/generator/generator.h>
38
39
#include <boost/scoped_ptr.hpp>
40
41
namespace
permlib {
42
44
47
template
<
class
TRANS>
48
class
BSGSGenerator
:
public
Generator
<typename TRANS::PERMtype> {
49
private
:
50
typedef
typename
TRANS::PERMtype PERM;
51
public
:
53
56
BSGSGenerator
(
const
std::vector<TRANS>& U);
57
virtual
~BSGSGenerator
() {}
58
59
virtual
PERM
next
();
60
virtual
bool
hasNext
();
61
private
:
62
const
std::vector<TRANS>& m_U;
63
std::vector<std::list<unsigned long>::const_iterator > m_Upositions;
64
bool
m_hasNext;
65
};
66
67
//
68
// ---- IMPLEMENTATION
69
//
70
71
template
<
class
TRANS>
72
BSGSGenerator<TRANS>::BSGSGenerator
(
const
std::vector<TRANS>& U)
73
: m_U(U), m_Upositions(U.size()), m_hasNext(true)
74
{
75
for
(
unsigned
int
i = 0; i < m_U.size(); ++i) {
76
m_Upositions[i] = m_U[i].begin();
77
}
78
}
79
80
81
template
<
class
TRANS>
82
bool
BSGSGenerator<TRANS>::hasNext
() {
83
return
m_hasNext;
84
}
85
86
87
template
<
class
TRANS>
88
typename
BSGSGenerator<TRANS>::PERM
BSGSGenerator<TRANS>::next
() {
89
BOOST_ASSERT( m_hasNext );
90
PERM g(m_U[0].n());
91
for
(
int
i = m_Upositions.size() - 1; i >= 0; --i) {
92
boost::scoped_ptr<PERM> u_beta( m_U[i].at( *m_Upositions[i] ) );
93
BOOST_ASSERT( u_beta );
94
g *= *u_beta;
95
}
96
97
// advance position
98
int
i;
99
for
(i = m_Upositions.size() - 1; i >= 0; --i) {
100
m_Upositions[i]++;
101
if
(m_Upositions[i] == m_U[i].end())
102
m_Upositions[i] = m_U[i].begin();
103
else
104
break
;
105
}
106
if
( i < 0 )
107
m_hasNext =
false
;
108
109
return
g;
110
}
111
112
}
113
114
#endif
// -- BSGSGENERATOR_H_
permlib::BSGSGenerator::next
virtual PERM next()
generates an element
Definition
bsgs_generator.h:88
permlib::BSGSGenerator::hasNext
virtual bool hasNext()
true, iff more elements can be generated
Definition
bsgs_generator.h:82
permlib::BSGSGenerator::BSGSGenerator
BSGSGenerator(const std::vector< TRANS > &U)
constructor
Definition
bsgs_generator.h:72
permlib::Generator
interface for group element generators
Definition
generator.h:40
Generated on
for permlib by
1.17.0