9 #include <boost/random/uniform_int.hpp>
31 virtual const char*
what()
const throw ()
33 return "Cannot shrink permutation";
76 template <
typename RandomNumberGenerator>
113 _data.resize(new_size);
135 template <
typename RandomNumberGenerator>
138 for (
size_t i = 0; i <
_data.size(); ++i)
140 boost::uniform_int <int> dist(i,
_data.size() - 1);
141 size_t j = dist(rng);
175 assert (index <
_data.size());
202 while ((tmp =
get(pa)) != a)
204 while ((tmp =
get(pb)) != b)
283 for (
size_type i = new_size; i < old_size; ++i)
285 if (
_data[i] < new_size)
289 _data.resize(new_size);
290 for (
size_type i = old_size; i < new_size; i++)
324 template <
class Less>
336 _data[index] = value;
384 memberlist->resize(size);
386 (*memberlist)[i] = i;
401 _permutation(groups.size())
403 _size = groups.
size();
404 for (
size_t i = 0; i < groups.size(); ++i)
406 state_type::iterator iter = _state.find(groups[i]);
407 if (iter == _state.end())
410 _state[groups[i]].first->push_back(i);
414 iter->second.first->push_back(i);
417 for (state_type::iterator iter = _state.begin(); iter != _state.end(); ++iter)
430 for (state_type::iterator iter = _state.begin(); iter != _state.end(); ++iter)
432 delete iter->second.first;
433 delete iter->second.second;
458 return enumerate_group(_state.begin(), 0);
486 if (state == _state.end())
488 for (state = _state.begin(); state != _state.end(); ++state)
494 _permutation.
_set(memberlist[i], memberlist[perm(i)]);
502 if (index >= state->second.first->size())
504 return enumerate_group(++state, 0);
523 if (!enumerate_group(state, index + 1))
545 for (
size_t i = 0; i < p.
size(); ++i)
566 for (
size_t i = 1; i < p.size(); i++)
567 stream <<
' ' << p(i);
582 template <
class Less>
586 std::sort(data.begin() + first, data.begin() + beyond, less);
597 template <
class Less>
Definition: permutations.hpp:357
virtual ~permutation_enumerator()
Definition: permutations.hpp:428
size_t size_type
Definition: permutations.hpp:359
virtual bool visitor(const permutation &perm)=0
std::map< int, groupinfo_type > state_type
Definition: permutations.hpp:362
std::pair< memberlist_type *, permutation * > groupinfo_type
Definition: permutations.hpp:361
permutation_enumerator(const std::vector< permutation::value_type > &groups)
Definition: permutations.hpp:400
bool empty()
Definition: permutations.hpp:441
permutation_enumerator(permutation::size_type size)
Definition: permutations.hpp:378
virtual bool enumerate()
Definition: permutations.hpp:453
std::vector< permutation::value_type > memberlist_type
Definition: permutations.hpp:360
Definition: permutations.hpp:19
permutation_shrink_exception()
Definition: permutations.hpp:21
virtual ~permutation_shrink_exception()
Definition: permutations.hpp:26
virtual const char * what() const
Definition: permutations.hpp:31
Definition: permutations.hpp:44
void swap(value_type a, value_type b)
Definition: permutations.hpp:187
void revert()
Definition: permutations.hpp:213
data_type _data
Definition: permutations.hpp:52
void _set(value_type index, value_type value)
Definition: permutations.hpp:334
permutation(size_type size=0)
Definition: permutations.hpp:63
size_t size_type
Definition: permutations.hpp:46
data_type & get_data()
Definition: permutations.hpp:343
void reset(size_t new_size)
Definition: permutations.hpp:111
permutation(size_type size, RandomNumberGenerator &rng)
Definition: permutations.hpp:77
void shuffle(RandomNumberGenerator &rng)
Definition: permutations.hpp:136
permutation operator*(const permutation &rhs) const
Definition: permutations.hpp:261
void shrink(difference_type by)
Definition: permutations.hpp:311
permutation & operator=(const permutation &other)
Definition: permutations.hpp:244
value_type get(value_type index) const
Definition: permutations.hpp:173
value_type operator()(value_type index) const
Definition: permutations.hpp:162
size_t value_type
Definition: permutations.hpp:48
std::vector< value_type > data_type
Definition: permutations.hpp:49
void grow(difference_type by)
Definition: permutations.hpp:300
permutation(const permutation &other)
Definition: permutations.hpp:89
virtual ~permutation()
Definition: permutations.hpp:100
ptrdiff_t difference_type
Definition: permutations.hpp:47
permutation reverse() const
Definition: permutations.hpp:229
size_type size() const
Definition: permutations.hpp:150
friend void sort(permutation &permutation, size_t first, size_t beyond, Less &less)
Class to setup a permutation which can be put before a vector.
Definition: permutations.hpp:583
void resize(size_type new_size)
Definition: permutations.hpp:280
void rswap(value_type a, value_type b)
Definition: permutations.hpp:199
void reset()
Definition: permutations.hpp:124
Definition: algorithm.hpp:14
void sort(permutation &permutation, size_t first, size_t beyond, Less &less)
Definition: permutations.hpp:583
bool operator==(const permutation &p, const permutation &q)
Definition: permutations.hpp:540
std::ostream & operator<<(std::ostream &stream, const binary_linear_space &space)
Definition: binary_linear_space.hpp:205
void sort(permutation &permutation, Less &less)
Definition: permutations.hpp:598