permlib 0.2.9
Library for permutation computations
orbit_list.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_LIST_H_
34#define ORBIT_LIST_H_
35
36#include <permlib/transversal/orbit.h>
37
38namespace permlib {
39
41template<class PERM,class PDOMAIN>
42class OrbitList : public Orbit<PERM,PDOMAIN> {
43public:
44 virtual bool contains(const PDOMAIN& val) const;
45
47 bool empty() const { return m_orbitList.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_orbitList.size(); }
61
62 virtual const PDOMAIN& element() const;
63protected:
65 std::list<PDOMAIN> m_orbitList;
66
67 virtual bool foundOrbitElement(const PDOMAIN& alpha, const PDOMAIN& alpha_p, const typename PERM::ptr& p);
68};
69
70template <class PERM,class PDOMAIN>
71inline bool OrbitList<PERM,PDOMAIN>::foundOrbitElement(const PDOMAIN& alpha, const PDOMAIN& alpha_p, const typename PERM::ptr& p) {
72 typename std::list<PDOMAIN>::iterator it = std::lower_bound(m_orbitList.begin(), m_orbitList.end(), alpha_p);
73 if (*it != alpha_p) {
74 m_orbitList.insert(it, alpha_p);
75 return true;
76 }
77 return false;
78}
79
80template <class PERM,class PDOMAIN>
81inline bool OrbitList<PERM,PDOMAIN>::contains(const PDOMAIN& val) const {
82 return std::binary_search(m_orbitList.begin(), m_orbitList.end(), val);
83}
84
85template <class PERM,class PDOMAIN>
86template<class Action>
87inline void OrbitList<PERM,PDOMAIN>::orbit(const PDOMAIN& beta, const std::list<typename PERM::ptr> &generators, Action a) {
88 // use separate list here because m_orbitList is sorted
89 std::list<PDOMAIN> orbitList;
90 Orbit<PERM,PDOMAIN>::orbit(beta, generators, a, orbitList);
91}
92
93template <class PERM,class PDOMAIN>
94inline const PDOMAIN& OrbitList<PERM,PDOMAIN>::element() const {
95 return *(m_orbitList.begin());
96}
97
98}
99
100#endif // -- ORBIT_LIST_H_
stores an orbit in a sorted list
Definition: orbit_list.h:42
virtual bool contains(const PDOMAIN &val) const
true iff there exists a transversal element mapping to val
Definition: orbit_list.h:81
std::list< PDOMAIN > m_orbitList
orbit elements as set
Definition: orbit_list.h:65
void orbit(const PDOMAIN &beta, const std::list< typename PERM::ptr > &generators, Action a)
computes orbit of beta under generators
Definition: orbit_list.h:87
bool empty() const
true iff orbit is empty (i.e. contains no element at all)
Definition: orbit_list.h:47
virtual const PDOMAIN & element() const
returns one element of the orbit
Definition: orbit_list.h:94
size_t size() const
number of orbit elements
Definition: orbit_list.h:60
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_list.h:71
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