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 ORBIT_H_
00034 #define ORBIT_H_
00035
00036 #include <list>
00037
00038 #include <boost/foreach.hpp>
00039
00040 namespace permlib {
00041
00043 template<class PERM,class DOMAIN>
00044 class Orbit {
00045 public:
00046 virtual ~Orbit() {}
00047
00049 virtual bool contains(const DOMAIN& val) const = 0;
00050
00052 virtual const DOMAIN& element() const = 0;
00053 protected:
00055
00061 template<class Action>
00062 void orbit(const DOMAIN& beta, const PERMlist &generators, Action a, std::list<DOMAIN>& orbitList);
00063
00065
00074 template<class Action>
00075 void orbitUpdate(const DOMAIN& beta, const PERMlist &generators, const PERMptr &g, Action a, std::list<DOMAIN>& orbitList);
00076
00078
00081 virtual bool foundOrbitElement(const DOMAIN& alpha, const DOMAIN& alpha_p, const PERMptr& p) = 0;
00082 };
00083
00084 template <class PERM,class DOMAIN>
00085 template<class Action>
00086 inline void Orbit<PERM,DOMAIN>::orbit(const DOMAIN& beta, const PERMlist &generators, Action a, std::list<DOMAIN>& orbitList) {
00087 if (orbitList.empty()) {
00088 orbitList.push_back(beta);
00089 foundOrbitElement(beta, beta, PERMptr());
00090 }
00091 BOOST_ASSERT( orbitList.size() >= 1 );
00092
00093 DEBUG(std::cout << "orbit of " << beta << std::endl;)
00094 typename std::list<DOMAIN>::const_iterator it;
00095 for (it = orbitList.begin(); it != orbitList.end(); ++it) {
00096 const DOMAIN &alpha = *it;
00097 BOOST_FOREACH(const PERMptr& p, generators) {
00098 DOMAIN alpha_p = a(*p, alpha);
00099 if (foundOrbitElement(alpha, alpha_p, p))
00100 orbitList.push_back(alpha_p);
00101 }
00102 }
00103 }
00104
00105 template <class PERM,class DOMAIN>
00106 template<class Action>
00107 inline void Orbit<PERM,DOMAIN>::orbitUpdate(const DOMAIN& beta, const PERMlist &generators, const PERMptr &g, Action a, std::list<DOMAIN>& orbitList) {
00108 if (orbitList.empty()) {
00109 orbitList.push_back(beta);
00110 foundOrbitElement(beta, beta, PERMptr());
00111 }
00112 BOOST_ASSERT( orbitList.size() >= 1 );
00113
00114 DEBUG(std::cout << "orbiUpdate of " << beta << " and " << *g << std::endl;)
00115 const uint oldSize = orbitList.size();
00116
00117 typename std::list<DOMAIN>::const_iterator it;
00118 for (it = orbitList.begin(); it != orbitList.end(); ++it) {
00119 const DOMAIN &alpha = *it;
00120 DOMAIN alpha_g = a(*g, alpha);
00121 if (foundOrbitElement(alpha, alpha_g, g))
00122 orbitList.push_back(alpha_g);
00123 }
00124
00125 if (oldSize == orbitList.size())
00126 return;
00127
00128 orbit(beta, generators, a, orbitList);
00129 }
00130
00131 }
00132
00133 #endif // -- ORBIT_H_