23 #ifndef OBJECT_SYMMETRY_H_INCLUDED 24 #define OBJECT_SYMMETRY_H_INCLUDED 43 #define Id_Perm(T) csl::ObjectPermutation<T>() 44 #define Id_Sym(T) csl::ObjectSymmetry<T>(Id_Perm(T)) 61 bool symmetric =
true);
74 return permutation.size();
78 return permutation.empty();
81 typename std::map<T, T>::iterator begin() {
82 return permutation.begin();
85 typename std::map<T, T>::iterator end() {
86 return permutation.end();
89 typename std::map<T, T>::const_iterator begin()
const {
90 return permutation.begin();
93 typename std::map<T, T>::const_iterator end()
const {
94 return permutation.end();
102 bool getRightForm()
const {
106 std::map<T, T> getPermutation()
const {
125 T operator[](
const T& key)
const;
127 std::vector<T> operator[](
const std::vector<T>& keys)
const;
129 static void toggleDisplayMode();
133 std::ostream& operator<<(std::ostream& fout,
138 void checkRightForm();
142 bool rightForm =
true;
144 std::map<T, T> permutation;
146 static bool displayMode;
186 bool symmetric =
true);
190 std::vector<std::vector<T>> operator[](
const std::vector<T>& keys)
const;
202 std::ostream& operator<<(std::ostream& fout,
234 :permutation(otherMap)
241 :permutation(otherMap)
255 for (
const auto& pair : permutation)
256 if (permutation.count(pair.second) != 1) {
274 return (rightForm == other.rightForm
275 and permutation == other.permutation);
289 return other + *
this;
296 std::map<T, T> newMap;
297 for (
const auto& pair : other.permutation)
298 newMap[pair.first] = (*this)[pair.second];
299 for (
const auto& pair : permutation)
300 if (other.permutation.find(pair.first) == other.permutation.end())
301 newMap[pair.first] = pair.second;
311 for (
auto& perm : other)
319 newPerm.rightForm = rightForm;
320 newPerm.displayMode = displayMode;
321 for (
const auto& pair : *
this)
322 newPerm[pair.second] = pair.first;
328 auto pos = permutation.find(key);
329 if (pos != permutation.end())
336 const std::vector<T>& keys)
const 339 std::cerr <<
"Warning: applying a non-cyclic permutation.";
341 for (
const auto& key : keys)
342 res.push_back((*
this)[key]);
350 displayMode = not displayMode;
354 std::ostream& operator<<(std::ostream& fout,
357 if (ObjectPermutation<T>::displayMode) {
358 fout <<
"Permutation of " << perm.size() <<
" elements.\n";
359 for (
const auto& pair : perm.permutation)
360 fout << pair.first <<
" --> " << pair.second << std::endl;
363 for (
const auto& pair : perm.permutation)
364 fout <<
": ( " << pair.first <<
", " << pair.second <<
" ) ";
424 const std::vector<T>& keys)
const 426 std::vector<std::vector<T>> res;
428 res.push_back(perm[keys]);
438 newSym.push_back(other);
448 newSym.insert(newSym.end(), other.begin(), other.end());
458 for (
auto& perm : newSym)
469 for (
const auto& permSelf : *
this)
470 for (
const auto& permOther : other)
471 newSym.push_back(permSelf * permOther);
477 std::ostream& operator<<(std::ostream& fout,
481 fout <<
"Symmetry of " << sym.size() <<
" elements.\n";
482 for (
const auto& perm : sym)
483 fout <<
" " << perm << std::endl;
Namespace for csl library.
Definition: abreviation.h:34
Expr operator+(const Expr &a, const Expr &b)
Shortcut function that allows to use arithmetic operator + with Expr (== shared_ptr<Abstract>).
Definition: abstract.cpp:1298
Definition: objectSymmetry.h:41
Expr operator*(const Expr &a, const Expr &b)
Shortcut function that allows to use arithmetic operator * with Expr (== shared_ptr<Abstract>).
Definition: abstract.cpp:1351
std::vector< std::vector< int > > permutations(std::vector< int > init)
Gets all permutations (int the form of vectors of integers) of n elements, n beeing the size of init...
Definition: objectSymmetry.h:47