permlib 0.2.9
Library for permutation computations
Loading...
Searching...
No Matches
orbit_set.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 ORBIT_SET_H_
34#define ORBIT_SET_H_
35
36#include <permlib/transversal/orbit.h>
37
38namespace permlib {
39
41template<class PERM,class PDOMAIN>
42class OrbitSet : public Orbit<PERM,PDOMAIN> {
43public:
44 virtual bool contains(const PDOMAIN& val) const;
45
47 bool empty() const { return m_orbitSet.empty(); }
48
50
56 template<class Action>
57 void orbit(const PDOMAIN& beta, const std::list<typename PERM::ptr> &generators, Action a);
58
60 size_t size() const {return m_orbitSet.size(); }
61
62 virtual const PDOMAIN& element() const;
63
64 typedef typename std::set<PDOMAIN>::const_iterator const_iterator;
66 const_iterator begin() const { return m_orbitSet.begin(); }
68 const_iterator end() const { return m_orbitSet.end(); }
69protected:
71 std::set<PDOMAIN> m_orbitSet;
72
73 virtual bool foundOrbitElement(const PDOMAIN& alpha, const PDOMAIN& alpha_p, const typename PERM::ptr& p);
74};
75
76template <class PERM,class PDOMAIN>
77inline bool OrbitSet<PERM,PDOMAIN>::foundOrbitElement(const PDOMAIN& alpha, const PDOMAIN& alpha_p, const typename PERM::ptr& p) {
78 if (m_orbitSet.insert(alpha_p).second) {
79 PERMLIB_DEBUG(std::cout << " o " << alpha_p << " @ " << (*p) << std::endl;)
80 return true;
81 }
82 return false;
83}
84
85template <class PERM,class PDOMAIN>
86inline bool OrbitSet<PERM,PDOMAIN>::contains(const PDOMAIN& val) const {
87 return m_orbitSet.find(val) != m_orbitSet.end();
88}
89
90template <class PERM,class PDOMAIN>
91template<class Action>
92inline void OrbitSet<PERM,PDOMAIN>::orbit(const PDOMAIN& beta, const std::list<typename PERM::ptr> &generators, Action a) {
93 std::list<PDOMAIN> orbitList;
94 Orbit<PERM,PDOMAIN>::orbit(beta, generators, a, orbitList);
95}
96
97template <class PERM,class PDOMAIN>
98inline const PDOMAIN& OrbitSet<PERM,PDOMAIN>::element() const {
99 return *(m_orbitSet.begin());
100}
101
102}
103
104#endif // -- ORBIT_SET_H_
stores an orbit in a set for fast contains() operation
Definition: orbit_set.h:42
size_t size() const
number of orbit elements
Definition: orbit_set.h:60
void orbit(const PDOMAIN &beta, const std::list< typename PERM::ptr > &generators, Action a)
computes orbit of beta under generators
Definition: orbit_set.h:92
virtual bool contains(const PDOMAIN &val) const
true iff there exists a transversal element mapping to val
Definition: orbit_set.h:86
std::set< PDOMAIN > m_orbitSet
orbit elements as set
Definition: orbit_set.h:71
virtual bool foundOrbitElement(const PDOMAIN &alpha, const PDOMAIN &alpha_p, const typename PERM::ptr &p)
callback when the orbit algorithm constructs an element alpha_p from alpha and p
Definition: orbit_set.h:77
bool empty() const
true iff orbit is empty (i.e. contains no element at all)
Definition: orbit_set.h:47
const_iterator end() const
end-iterator to orbit elements
Definition: orbit_set.h:68
const_iterator begin() const
begin-iterator to orbit elements
Definition: orbit_set.h:66
virtual const PDOMAIN & element() const
returns one element of the orbit
Definition: orbit_set.h:98
abstract base class for orbit computation
Definition: orbit.h:44
void orbit(const PDOMAIN &beta, const std::list< typename PERM::ptr > &generators, Action a, std::list< PDOMAIN > &orbitList)
computes orbit of beta under generators
Definition: orbit.h:89