File: PermlibPermutationGroup.hh

package info (click to toggle)
topcom 1.2.0~beta%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 148,596 kB
  • sloc: cpp: 40,956; sh: 4,663; makefile: 679; ansic: 55
file content (269 lines) | stat: -rw-r--r-- 9,741 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
//////////////////////////////////////////////////////////////////////////
// PermlibPermutationGroup.hh
// produced: 05/06/2022 jr
// (based on "Permlib" by Thomas Rehn [Diploma Thesis 2010])
/////////////////////////////////////////////////////////////////////////
#ifndef PERMLIBPERMUTATIONGROUP_HH
#define PERMLIBPERMUTATIONGROUP_HH

#ifdef HAVE_LIBPERMLIB

#include "Global.hh"
#include "ContainerIO.hh"
#include "LabelSet.hh"
#include "Symmetry.hh"

#include <permlib/permlib_api.h>

namespace topcom {

  template <comparison_mode_type mode>
  class PermlibPermutationGroup {
  public:
    typedef comparison_mode_type                 mode_type;
  private:
    boost::shared_ptr<permlib::PermutationGroup> _groupptr;
  private:
    PermlibPermutationGroup() = delete;
  public:
    
    // constructors:
    inline PermlibPermutationGroup(const PermlibPermutationGroup&); // copied
    inline PermlibPermutationGroup(const boost::shared_ptr<permlib::PermutationGroup>&); // from data
    PermlibPermutationGroup(const parameter_type); // contains only the identity
    PermlibPermutationGroup(const parameter_type,
			    const symmetry_collectordata&); // built from generators
    PermlibPermutationGroup(const SymmetryGroup&); // built from symmetry group
  
    // destructor:
    inline ~PermlibPermutationGroup();
  
    // copy assignment:
    inline PermlibPermutationGroup& operator=(const PermlibPermutationGroup&);

    // accessors:
    inline parameter_type               n              () const;
    inline size_type                    order          () const;

    // standard functions:
    bool                                empty          () const;
    bool                                is_in_group    (const Symmetry&) const;
    PermlibPermutationGroup             stabilizer     (const LabelSet&) const;
    size_type                           stabilizer_card(const LabelSet&) const;
    size_type                           orbit_size     (const LabelSet&) const;

    bool                                lex_decreases  (const LabelSet&) const;
    bool                                colex_increases(const LabelSet&) const;
   
    // stream input/output:
    inline std::istream& read(std::istream& ist);
    template <comparison_mode_type streammode>
    friend inline std::istream& operator>>(std::istream& ist, PermlibPermutationGroup<streammode>& st);
    inline std::ostream& write(std::ostream& ost) const;
    template <comparison_mode_type streammode>
    friend inline std::ostream& operator<<(std::ostream& ost, const PermlibPermutationGroup<streammode>& st);
  private:
    
    // internal methods:
    inline parameter_type _elem(const parameter_type) const;
    inline bool _compare_subsets(const LabelSet&, const LabelSet&) const;
  };
  
  // forward template specializations:
  template <>
  inline parameter_type PermlibPermutationGroup<lexmin_mode>::_elem(const parameter_type) const;
  
  template <>
  inline parameter_type PermlibPermutationGroup<colexmax_mode>::_elem(const parameter_type) const;

  template <>
  inline bool PermlibPermutationGroup<lexmin_mode>::_compare_subsets(const LabelSet&, const LabelSet&) const;
  
  template <>
  inline bool PermlibPermutationGroup<colexmax_mode>::_compare_subsets(const LabelSet&, const LabelSet&) const;

  // constructors:
  template <comparison_mode_type mode>
  inline PermlibPermutationGroup<mode>::PermlibPermutationGroup(const PermlibPermutationGroup& ppg) :
    _groupptr(ppg._groupptr) {
  }

  template <comparison_mode_type mode>
  inline PermlibPermutationGroup<mode>::PermlibPermutationGroup(const boost::shared_ptr<permlib::PermutationGroup>& groupptr) :
    _groupptr(groupptr) {
  }

  template <comparison_mode_type mode>
  PermlibPermutationGroup<mode>::PermlibPermutationGroup(const parameter_type n) :
    _groupptr(new permlib::PermutationGroup(n)) {
  }
     
  template <comparison_mode_type mode>
  PermlibPermutationGroup<mode>::PermlibPermutationGroup(const parameter_type n,
							 const symmetry_collectordata& generators) {
    std::vector<permlib::Permutation::ptr> genptr_collector;
    for (symmetry_collectordata::const_iterator geniter = generators.begin();
	 geniter != generators.end();
	 ++geniter) {
      genptr_collector.push_back(permlib::Permutation::ptr(new permlib::Permutation(Permutation(*geniter))));
    }
    _groupptr = permlib::construct(n, genptr_collector.begin(), genptr_collector.end());
  }
   
  template <comparison_mode_type mode>
  PermlibPermutationGroup<mode>::PermlibPermutationGroup(const SymmetryGroup& sg) {
    std::vector<permlib::Permutation::ptr> symptr_collector;
    for (SymmetryGroup::const_iterator symiter = sg.begin();
	 symiter != sg.end();
	 ++symiter) {
      symptr_collector.push_back(permlib::Permutation::ptr(new permlib::Permutation(Permutation(*symiter))));
    }
    _groupptr = permlib::construct(sg.n(), symptr_collector.begin(), symptr_collector.end());    
  }

  // destructor:
  template <comparison_mode_type mode>
  inline PermlibPermutationGroup<mode>::~PermlibPermutationGroup() {
  }

  // assignment:
  template <comparison_mode_type mode>
  inline PermlibPermutationGroup<mode>& PermlibPermutationGroup<mode>::operator=(const PermlibPermutationGroup& st) {
    if (&st == this) {
      return *this;
    }
    _groupptr.reset();
    _groupptr = new permlib::Permutation::ptr(*st._groupptr); // deep copy
    return *this;
  }

  // accessors:
  template <comparison_mode_type mode>
  inline parameter_type PermlibPermutationGroup<mode>::n() const {
    return _groupptr->n;
  }

  template <comparison_mode_type mode>
  inline size_type PermlibPermutationGroup<mode>::order() const {
    return _groupptr->order();
  }

  // standard functions:
  template <comparison_mode_type mode>
  bool PermlibPermutationGroup<mode>::empty() const {
    return (order() == 1);
  }


  template <comparison_mode_type mode>
  bool PermlibPermutationGroup<mode>::is_in_group(const Symmetry& s) const {
    return _groupptr->sifts(permlib::Permutation(Permutation(s)));
  }

  template <comparison_mode_type mode>
  PermlibPermutationGroup<mode> PermlibPermutationGroup<mode>::stabilizer(const LabelSet& is) const {
    std::vector<parameter_type> is_vec(is.convert_to_vector_of_parameter_types());
    return PermlibPermutationGroup<mode>(permlib::setStabilizer(*_groupptr, is_vec.begin(), is_vec.end()));
  }
  
  template <comparison_mode_type mode>
  size_type PermlibPermutationGroup<mode>::stabilizer_card(const LabelSet& is) const {
    return permlib::setStabilizer(*_groupptr, is.begin(), is.end()).order();
  }
  
  template <comparison_mode_type mode>
  size_type PermlibPermutationGroup<mode>::orbit_size(const LabelSet& is) const {
    return order() / stabilizer_card(is);
  }

  template <comparison_mode_type mode>
  bool PermlibPermutationGroup<mode>::lex_decreases(const LabelSet& ls) const {
    if (mode != lexmin_mode) {
      MessageStreams::forced() << message::lock
			       << "PermlibPermutationGroup::lex_decreases(...): wrong mode - exiting." << std::endl
			       << message::unlock;
      exit(1);
    }
    permlib::dset bitset_rep(_groupptr->n);
    for (LabelSet::const_iterator lsiter = ls.begin();
	 lsiter != ls.end();
	 ++lsiter) {
      bitset_rep.set(*lsiter);
    }
    permlib::dset lexminset = permlib::smallestSetImage(*_groupptr, bitset_rep);
    return (lexminset != bitset_rep);
  }

  template <comparison_mode_type mode>
  bool PermlibPermutationGroup<mode>::colex_increases(const LabelSet& ls) const {
    if (mode != colexmax_mode) {
      MessageStreams::forced() << message::lock
			       << "PermlibPermutationGroup::colex_increases(...): wrong mode - exiting." << std::endl
			       << message::unlock;
      exit(1);
    }
    permlib::dset bitset_rep(_groupptr->n);
    for (LabelSet::const_iterator lsiter = ls.begin();
    	 lsiter != ls.end();
    	 ++lsiter) {
      bitset_rep.set(_elem(*lsiter));
    }
    permlib::dset colexmaxset = permlib::smallestSetImage(*_groupptr, bitset_rep);
    return (colexmaxset != bitset_rep);
  }
  
  // stream input/output:
  template <comparison_mode_type mode>
  inline std::istream& PermlibPermutationGroup<mode>::read(std::istream& ist) {
    MessageStreams::forced() << message::lock
			     << "PermlibPermutationGroup::read(std::istream&): reading into PermlibPermutationGroup not supported - exiting" << std::endl
			     << message::unlock;
    exit(1);
  }
  
  template <comparison_mode_type streammode>
  inline std::istream& operator>>(std::istream& ist, PermlibPermutationGroup<streammode>& st) {
    return st.read(ist);
  }
  
  template <comparison_mode_type mode>
  inline std::ostream& PermlibPermutationGroup<mode>::write(std::ostream& ost) const {
    ost << *_groupptr;
    return ost;
  }
  
  template <comparison_mode_type streammode>
  inline std::ostream& operator<<(std::ostream& ost, const PermlibPermutationGroup<streammode>& st) {
    return st.write(ost);
  }
  
  // internal methods:
  template <>
  inline parameter_type PermlibPermutationGroup<lexmin_mode>::_elem(const parameter_type i) const {
    return i;
  }

  template <>
  inline parameter_type PermlibPermutationGroup<colexmax_mode>::_elem(const parameter_type i) const {
    return _groupptr->n - i - 1;
  }

  template <>
  inline bool PermlibPermutationGroup<lexmin_mode>::_compare_subsets(const LabelSet& ls1,
								     const LabelSet& ls2) const {
    return ls1.lexsmaller(ls2);
  }

  template <>
  inline bool PermlibPermutationGroup<colexmax_mode>::_compare_subsets(const LabelSet& ls1,
								       const LabelSet& ls2) const {
    return ls1.colexgreater(ls2);
  }
  
}; // namespace topcom

#endif

#endif

// eof PermlibPermutationGroup.hh