GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
#include <stdlib.h>1#include <vector>2#include <fstream>3#ifdef _OPENMP4#include <omp.h>5#endif6using namespace std;78#include "libnormaliz/libnormaliz.h"9#include "libnormaliz/cone.h"10#include "libnormaliz/vector_operations.h"11#include "libnormaliz/cone_property.h"12#include "libnormaliz/integer.h"13using namespace libnormaliz;1415typedef long long Integer;1617Cone<Integer> rand_simplex(size_t dim, long bound){1819vector<vector<Integer> > vertices(dim+1,vector<Integer> (dim));20while(true){ // an eternal loop ...21for(size_t i=0;i<=dim;++i){22for(size_t j=0;j<dim;++j)23vertices[i][j]=rand()%(bound+1);24}25Cone<Integer> Simplex(Type::polytope,vertices);26// we must check the rank and normality27if(Simplex.getRank()==dim+1 && Simplex.isDeg1HilbertBasis())28return Simplex;29}30vector<vector<Integer> > dummy_gen(1,vector<Integer>(1,1)); // to make the compiler happy31return Cone<Integer>(Type::cone,dummy_gen);32}3334bool exists_jump_over(Cone<Integer>& Polytope, const vector<vector<Integer> >& jump_cands){3536vector<vector<Integer> > test_polytope=Polytope.getExtremeRays();37test_polytope.resize(test_polytope.size()+1);38for(size_t i=0;i<jump_cands.size();++i){39test_polytope[test_polytope.size()-1]=jump_cands[i];40Cone<Integer> TestCone(Type::cone,test_polytope);41if(TestCone.getNrDeg1Elements()!=Polytope.getNrDeg1Elements()+1)42continue;43if(TestCone.isDeg1HilbertBasis())44return true;45}46return false;47}4849vector<Integer> lattice_widths(Cone<Integer>& Polytope){5051if(!Polytope.isDeg1ExtremeRays()){52cerr<< "Cone in lattice_widths is not defined by lattice polytope"<< endl;53exit(1);54}55vector<Integer> widths(Polytope.getNrExtremeRays());56for(size_t i=0;i<Polytope.getNrSupportHyperplanes();++i){57widths[i]=0;58for(size_t j=0;j<Polytope.getNrExtremeRays();++j){59// v_scalar_product is a useful function from vector_operations.h60Integer test=v_scalar_product(Polytope.getSupportHyperplanes()[i],Polytope.getExtremeRays()[j]);61if(test>widths[i])62widths[i]=test;63}64}65return widths;66}6768int main(int argc, char* argv[]){6970time_t ticks;71srand(time(&ticks));72cout << "Seed " <<ticks << endl; // we may want to reproduce the run7374size_t polytope_dim=4;75size_t cone_dim=polytope_dim+1;76long bound=6;77vector<Integer> grading(cone_dim,0); // at some points we need the explicit grading78grading[polytope_dim]=1;7980size_t nr_simplex=0; // for the progress report8182while(true){83#ifdef _OPENMP84omp_set_num_threads(1);85#endif86Cone<Integer> Candidate=rand_simplex(polytope_dim,bound);87nr_simplex++;88if(nr_simplex%1000 ==0)89cout << "simplex " << nr_simplex << endl;90vector<vector<Integer> > supp_hyps_moved=Candidate.getSupportHyperplanes();91for(size_t i=0;i<supp_hyps_moved.size();++i)92supp_hyps_moved[i][polytope_dim]+=1;93Cone<Integer> Candidate1(Type::inequalities,supp_hyps_moved, Type::grading,to_matrix(grading));94if(Candidate1.getNrDeg1Elements()>Candidate.getNrDeg1Elements())95continue; // there exists a point of height 196cout << "No ht 1 jump"<< " #latt " << Candidate.getNrDeg1Elements() << endl;97// move the hyperplanes further outward98for(size_t i=0;i<supp_hyps_moved.size();++i)99supp_hyps_moved[i][polytope_dim]+=polytope_dim;100Cone<Integer> Candidate2(Type::inequalities,supp_hyps_moved,Type::grading,to_matrix(grading));101cout << "Testing " << Candidate2.getNrDeg1Elements() << " jump candidates" << endl;102// including the lattice points in P103if(exists_jump_over(Candidate,Candidate2.getDeg1Elements()))104continue;105cout << "No ht <= 1+dim jump" << endl;106vector<Integer> widths=lattice_widths(Candidate);107for(size_t i=0;i<supp_hyps_moved.size();++i)108supp_hyps_moved[i][polytope_dim]+=-polytope_dim+(widths[i])*(polytope_dim-2);109vector<vector<mpz_class> > mpz_supp_hyps;110convert(mpz_supp_hyps,supp_hyps_moved);111vector<mpz_class> mpz_grading=convertTo<vector<mpz_class> >(grading);112#ifdef _OPENMP113omp_set_num_threads(4);114#endif115Cone<mpz_class> Candidate3(Type::inequalities,mpz_supp_hyps,Type::grading,to_matrix(mpz_grading));116Candidate3.compute(ConeProperty::Deg1Elements,ConeProperty::Approximate);117vector<vector<Integer> > jumps_cand; // for conversion from mpz_class118convert(jumps_cand,Candidate3.getDeg1Elements());119cout << "Testing " << jumps_cand.size() << " jump candidates" << endl;120if(exists_jump_over(Candidate, jumps_cand))121continue;122cout << "Maximal simplex found" << endl;123cout << "Vertices" << endl;124Candidate.getExtremeRaysMatrix().pretty_print(cout);125cout << "Number of lattice points = " << Candidate.getNrDeg1Elements();126cout << " Multiplicity = " << Candidate.getMultiplicity() << endl;127} // end while128} //end main129130131