/** * This file is part of Gomu. * * Copyright 2016 by Jean Fromentin * * Gomu is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Gomu is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Gomu. If not, see . */ #include "permutations.hpp" PermutationEnumerator::PermutationEnumerator(uint64 r):n(r),sigma(r){ } void PermutationEnumerator::reset(){ sigma=Permutation(n); } const Permutation& PermutationEnumerator::get() const{ return sigma; } bool PermutationEnumerator::next(){ for(int first=n-1;first>0;--first){ if(sigma.win[first]::PermutationEnumerator(uint64 r):PermutationEnumerator(r),sigmaB(r),sign(0){ } void PermutationEnumerator::reset(){ PermutationEnumerator::reset(); sigmaB=Permutation(n); sign=0; } const Permutation& PermutationEnumerator::get() const{ return sigmaB; } bool PermutationEnumerator::next(){ ++sign; if(sign==(1<::next()) return false; sigmaB.m128=sigma.m128; } else{ uint64 mask=(1<<(n-1)); for(uint64 i=1;i<=n;++i){ sigmaB.win[i]=(mask&sign)?-sigma.win[i]:sigma.win[i]; mask>>=1; } } return true; }; PermutationEnumerator::PermutationEnumerator(uint64 r):PermutationEnumerator(r),sigmaD(r),sign(0){ } void PermutationEnumerator::reset(){ PermutationEnumerator::reset(); sigmaD=Permutation(n); sign=0; } const Permutation& PermutationEnumerator::get() const{ return sigmaD; } bool PermutationEnumerator::next(){ ++sign; if(sign==(1<::next()) return false; sigmaD.m128=sigma.m128; } else{ if(__builtin_popcountll(sign)%2==0){ uint64 mask=1; for(uint64 i=1;i<=n;++i){ sigmaD.win[i]=(mask&sign)?-sigma.win[i]:sigma.win[i]; mask<<=1; } } else return next(); } return true; }; int PermutationEnumerator::cmp(const PermutationEnumerator& E) const{ if(n==E.n) return 0; if(n::cmp(const PermutationEnumerator& E) const{ if(n==E.n) return 0; if(n::cmp(const PermutationEnumerator& E) const{ if(n==E.n) return 0; if(n