Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

563604 views
1
#include <stdlib.h>
2
#include <vector>
3
#include <fstream>
4
#ifdef _OPENMP
5
#include <omp.h>
6
#endif
7
using namespace std;
8
9
#include "libnormaliz/libnormaliz.h"
10
#include "libnormaliz/cone.h"
11
#include "libnormaliz/vector_operations.h"
12
#include "libnormaliz/cone_property.h"
13
#include "libnormaliz/integer.h"
14
using namespace libnormaliz;
15
16
typedef long long Integer;
17
18
Cone<Integer> rand_simplex(size_t dim, long bound){
19
20
vector<vector<Integer> > vertices(dim+1,vector<Integer> (dim));
21
while(true){ // an eternal loop ...
22
for(size_t i=0;i<=dim;++i){
23
for(size_t j=0;j<dim;++j)
24
vertices[i][j]=rand()%(bound+1);
25
}
26
Cone<Integer> Simplex(Type::polytope,vertices);
27
// we must check the rank and normality
28
if(Simplex.getRank()==dim+1 && Simplex.isDeg1HilbertBasis())
29
return Simplex;
30
}
31
vector<vector<Integer> > dummy_gen(1,vector<Integer>(1,1)); // to make the compiler happy
32
return Cone<Integer>(Type::cone,dummy_gen);
33
}
34
35
bool exists_jump_over(Cone<Integer>& Polytope, const vector<vector<Integer> >& jump_cands){
36
37
vector<vector<Integer> > test_polytope=Polytope.getExtremeRays();
38
test_polytope.resize(test_polytope.size()+1);
39
for(size_t i=0;i<jump_cands.size();++i){
40
test_polytope[test_polytope.size()-1]=jump_cands[i];
41
Cone<Integer> TestCone(Type::cone,test_polytope);
42
if(TestCone.getNrDeg1Elements()!=Polytope.getNrDeg1Elements()+1)
43
continue;
44
if(TestCone.isDeg1HilbertBasis())
45
return true;
46
}
47
return false;
48
}
49
50
vector<Integer> lattice_widths(Cone<Integer>& Polytope){
51
52
if(!Polytope.isDeg1ExtremeRays()){
53
cerr<< "Cone in lattice_widths is not defined by lattice polytope"<< endl;
54
exit(1);
55
}
56
vector<Integer> widths(Polytope.getNrExtremeRays());
57
for(size_t i=0;i<Polytope.getNrSupportHyperplanes();++i){
58
widths[i]=0;
59
for(size_t j=0;j<Polytope.getNrExtremeRays();++j){
60
// v_scalar_product is a useful function from vector_operations.h
61
Integer test=v_scalar_product(Polytope.getSupportHyperplanes()[i],Polytope.getExtremeRays()[j]);
62
if(test>widths[i])
63
widths[i]=test;
64
}
65
}
66
return widths;
67
}
68
69
int main(int argc, char* argv[]){
70
71
time_t ticks;
72
srand(time(&ticks));
73
cout << "Seed " <<ticks << endl; // we may want to reproduce the run
74
75
size_t polytope_dim=4;
76
size_t cone_dim=polytope_dim+1;
77
long bound=6;
78
vector<Integer> grading(cone_dim,0); // at some points we need the explicit grading
79
grading[polytope_dim]=1;
80
81
size_t nr_simplex=0; // for the progress report
82
83
while(true){
84
#ifdef _OPENMP
85
omp_set_num_threads(1);
86
#endif
87
Cone<Integer> Candidate=rand_simplex(polytope_dim,bound);
88
nr_simplex++;
89
if(nr_simplex%1000 ==0)
90
cout << "simplex " << nr_simplex << endl;
91
vector<vector<Integer> > supp_hyps_moved=Candidate.getSupportHyperplanes();
92
for(size_t i=0;i<supp_hyps_moved.size();++i)
93
supp_hyps_moved[i][polytope_dim]+=1;
94
Cone<Integer> Candidate1(Type::inequalities,supp_hyps_moved, Type::grading,to_matrix(grading));
95
if(Candidate1.getNrDeg1Elements()>Candidate.getNrDeg1Elements())
96
continue; // there exists a point of height 1
97
cout << "No ht 1 jump"<< " #latt " << Candidate.getNrDeg1Elements() << endl;
98
// move the hyperplanes further outward
99
for(size_t i=0;i<supp_hyps_moved.size();++i)
100
supp_hyps_moved[i][polytope_dim]+=polytope_dim;
101
Cone<Integer> Candidate2(Type::inequalities,supp_hyps_moved,Type::grading,to_matrix(grading));
102
cout << "Testing " << Candidate2.getNrDeg1Elements() << " jump candidates" << endl;
103
// including the lattice points in P
104
if(exists_jump_over(Candidate,Candidate2.getDeg1Elements()))
105
continue;
106
cout << "No ht <= 1+dim jump" << endl;
107
vector<Integer> widths=lattice_widths(Candidate);
108
for(size_t i=0;i<supp_hyps_moved.size();++i)
109
supp_hyps_moved[i][polytope_dim]+=-polytope_dim+(widths[i])*(polytope_dim-2);
110
vector<vector<mpz_class> > mpz_supp_hyps;
111
convert(mpz_supp_hyps,supp_hyps_moved);
112
vector<mpz_class> mpz_grading=convertTo<vector<mpz_class> >(grading);
113
#ifdef _OPENMP
114
omp_set_num_threads(4);
115
#endif
116
Cone<mpz_class> Candidate3(Type::inequalities,mpz_supp_hyps,Type::grading,to_matrix(mpz_grading));
117
Candidate3.compute(ConeProperty::Deg1Elements,ConeProperty::Approximate);
118
vector<vector<Integer> > jumps_cand; // for conversion from mpz_class
119
convert(jumps_cand,Candidate3.getDeg1Elements());
120
cout << "Testing " << jumps_cand.size() << " jump candidates" << endl;
121
if(exists_jump_over(Candidate, jumps_cand))
122
continue;
123
cout << "Maximal simplex found" << endl;
124
cout << "Vertices" << endl;
125
Candidate.getExtremeRaysMatrix().pretty_print(cout);
126
cout << "Number of lattice points = " << Candidate.getNrDeg1Elements();
127
cout << " Multiplicity = " << Candidate.getMultiplicity() << endl;
128
} // end while
129
} //end main
130
131