GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
/*1* Normaliz2* Copyright (C) 2007-2014 Winfried Bruns, Bogdan Ichim, Christof Soeger3* This program is free software: you can redistribute it and/or modify4* it under the terms of the GNU General Public License as published by5* the Free Software Foundation, either version 3 of the License, or6* (at your option) any later version.7*8* This program is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11* GNU General Public License for more details.12*13* You should have received a copy of the GNU General Public License14* along with this program. If not, see <http://www.gnu.org/licenses/>.15*16* As an exception, when this program is distributed through (i) the App Store17* by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or (iii) Google Play18* by Google Inc., then that store may impose any digital rights management,19* device limits and/or redistribution restrictions that are required by its20* terms of service.21*/2223//---------------------------------------------------------------------------2425#include <boost/dynamic_bitset.hpp>2627#include "libnormaliz/integer.h"28#include "libnormaliz/matrix.h"29#include "libnormaliz/nmz_nauty.h"30#include "libnormaliz/vector_operations.h"3132#ifdef NMZ_NAUTY3334// #define MAXN 5000 /* Define this before including nauty.h */35// we use dynamic allocation3637#include <nauty/nauty.h>3839namespace libnormaliz {40using namespace std;4142vector<vector<long> > CollectedAutoms;4344void getmyautoms(int count, int *perm, int *orbits,45int numorbits, int stabvertex, int n){46int i;47vector<long> this_perm(n);48for (i = 0; i < n; ++i) this_perm[i] = perm[i];49CollectedAutoms.push_back(this_perm);50}5152template<typename Integer>53vector<vector<long> > compute_automs_by_nauty(const vector<vector<Integer> >& Generators, size_t nr_special_gens,54const vector<vector<Integer> >& LinForms,55const size_t nr_special_linforms, mpz_class& group_order,56BinaryMatrix<Integer>& CanType){57CollectedAutoms.clear();5859DYNALLSTAT(graph,g,g_sz);60DYNALLSTAT(graph,cg,cg_sz);61DYNALLSTAT(int,lab,lab_sz);62DYNALLSTAT(int,ptn,ptn_sz);63DYNALLSTAT(int,orbits,orbits_sz);64static DEFAULTOPTIONS_GRAPH(options);65statsblk stats;6667options.userautomproc = getmyautoms;68options.getcanon = TRUE;6970int n,m;7172options.writeautoms = FALSE;73options.defaultptn = FALSE;7475size_t mm=Generators.size();76size_t nn=LinForms.size();7778BinaryMatrix<Integer> MM(mm,nn);79Matrix<Integer> MVal(mm,nn);8081key_t i,j,k;8283bool first=true;84Integer mini=0;85for(i=0;i<mm; ++i){86for(j=0;j<nn;++j){87MVal[i][j]=v_scalar_product(Generators[i],LinForms[j]);88if(MVal[i][j]<mini || first){89mini=MVal[i][j];90first=false;91}92}93}9495MM.set_offset(mini);96for(i=0;i<mm; ++i){97for(j=0;j<nn;++j)98MM.insert(MVal[i][j]-mini,i,j);99}100101size_t ll=MM.nr_layers();102103size_t layer_size=mm+nn;104n=ll*layer_size;105m = SETWORDSNEEDED(n);106107nauty_check(WORDSIZE,m,n,NAUTYVERSIONID);108109DYNALLOC2(graph,g,g_sz,m,n,"malloc");110DYNALLOC2(graph,cg,cg_sz,n,m,"malloc");111DYNALLOC1(int,lab,lab_sz,n,"malloc");112DYNALLOC1(int,ptn,ptn_sz,n,"malloc");113DYNALLOC1(int,orbits,orbits_sz,n,"malloc");114115EMPTYGRAPH(g,m,n);116117for(i=0;i<layer_size;++i){ // make vertical edges over all layers118for(k=1;k<ll;++k)119ADDONEEDGE(g,(k-1)*layer_size+i,k*layer_size+i,m);120}121122for(i=0;i<mm;++i){ // make horizontal edges layer by layer123for(j=0;j<nn;++j){124for(k=0;k<ll;++k){125if(MM.test(i,j,k)) // k is the number of layers below the current one126ADDONEEDGE(g,k*layer_size+i,k*layer_size+mm+j,m);127}128}129}130131for(int ii=0;ii<n;++ii){ // prepare partitions132lab[ii]=ii;133ptn[ii]=1;134}135136for(k=0;k<ll;++k){ // make partitions layer by layer137ptn[k*layer_size+ mm-1]=0; // row vertices in one partition138for(size_t s=0; s< nr_special_gens;++s) // speciall generators in extra partitions (makes them fixed points)139ptn[k*layer_size+s]=0;140ptn[(k+1)*layer_size-1]=0; // column indices in the next141for(size_t s=0; s< nr_special_linforms;++s) // special linear forms in extra partitions142ptn[(k+1)*layer_size-2-s]=0;143}144145densenauty(g,lab,ptn,orbits,&options,&stats,m,n,cg);146147vector<vector<long> > AutomsAndOrbits(2*CollectedAutoms.size());148AutomsAndOrbits.reserve(2*CollectedAutoms.size()+3);149150for(k=0;k<CollectedAutoms.size();++k){151vector<long> GenPerm(mm);152for(i=0;i<mm;++i)153GenPerm[i]=CollectedAutoms[k][i];154AutomsAndOrbits[k]=GenPerm;155vector<long> LFPerm(nn-nr_special_linforms); // we remove the special linear forms here156for(i=mm;i<mm+nn-nr_special_linforms;++i)157LFPerm[i-mm]=CollectedAutoms[k][i]-mm;158AutomsAndOrbits[k+CollectedAutoms.size()]=LFPerm;159AutomsAndOrbits[k+CollectedAutoms.size()];160161}162163vector<long> GenOrbits(mm);164for(i=0;i<mm;++i)165GenOrbits[i]=orbits[i];166AutomsAndOrbits.push_back(GenOrbits);167168vector<long> LFOrbits(nn-nr_special_linforms); // we remove the special linear forms here169for(i=0;i<nn-nr_special_linforms;++i)170LFOrbits[i]=orbits[i+mm]-mm;171AutomsAndOrbits.push_back(LFOrbits);172173group_order=mpz_class(stats.grpsize1);174175vector<long> row_order(mm), col_order(nn);176for(key_t i=0;i<mm;++i)177row_order[i]=lab[i];178for(key_t i=0;i<nn;++i)179col_order[i]=lab[mm+i]-mm;180181AutomsAndOrbits.push_back(row_order);182183nauty_freedyn();184185CanType=MM.reordered(row_order,col_order);186187return AutomsAndOrbits;188189}190191#ifndef NMZ_MIC_OFFLOAD //offload with long is not supported192template vector<vector<long> > compute_automs_by_nauty(const vector<vector<long> >& Generators, size_t nr_special_gens,193const vector<vector<long> >& LinForms,const size_t nr_special_linforms,194mpz_class& group_order, BinaryMatrix<long>& CanType);195#endif // NMZ_MIC_OFFLOAD196template vector<vector<long> > compute_automs_by_nauty(const vector<vector<long long> >& Generators, size_t nr_special_gens,197const vector<vector<long long> >& LinForms,const size_t nr_special_linforms,198mpz_class& group_order, BinaryMatrix<long long>& CanType);199template vector<vector<long> > compute_automs_by_nauty(const vector<vector<mpz_class> >& Generators, size_t nr_special_gens,200const vector<vector<mpz_class> >& LinForms,const size_t nr_special_linforms,201mpz_class& group_order,BinaryMatrix<mpz_class>& CanType);202203} // namespace204205#endif // NMZ_NAUTY206207208209