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

563619 views
1
/*
2
* Normaliz
3
* Copyright (C) 2007-2014 Winfried Bruns, Bogdan Ichim, Christof Soeger
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*
17
* As an exception, when this program is distributed through (i) the App Store
18
* by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or (iii) Google Play
19
* by Google Inc., then that store may impose any digital rights management,
20
* device limits and/or redistribution restrictions that are required by its
21
* terms of service.
22
*/
23
24
#ifndef FULL_CONE_H
25
#define FULL_CONE_H
26
27
#include <list>
28
#include <vector>
29
#include <deque>
30
//#include <set>
31
#include <boost/dynamic_bitset.hpp>
32
33
#include "libnormaliz/libnormaliz.h"
34
#include "libnormaliz/cone_property.h"
35
#include "libnormaliz/matrix.h"
36
#include "libnormaliz/simplex.h"
37
#include "libnormaliz/cone_dual_mode.h"
38
#include "libnormaliz/HilbertSeries.h"
39
#include "libnormaliz/reduction.h"
40
// #include "libnormaliz/sublattice_representation.h"
41
#include "libnormaliz/offload_handler.h"
42
43
namespace libnormaliz {
44
using std::list;
45
using std::vector;
46
using std::map;
47
using std::pair;
48
using boost::dynamic_bitset;
49
50
template<typename Integer> class Cone;
51
template<typename Integer> class SimplexEvaluator;
52
template<typename Integer> class CandidateList;
53
template<typename Integer> class Candidate;
54
template<typename Integer> class Simplex;
55
template<typename Integer> class Collector;
56
57
template<typename Integer>
58
class Full_Cone {
59
60
friend class Cone<Integer>;
61
friend class SimplexEvaluator<Integer>;
62
friend class CandidateList<Integer>;
63
friend class Candidate<Integer>;
64
friend class Collector<Integer>;
65
66
public:
67
68
int omp_start_level; // records the omp_get_level() when the computation is started
69
// recorded at the start of the top cone constructor and the compute functions
70
// compute and dualize_cone
71
size_t dim;
72
size_t level0_dim; // dim of cone in level 0 of the inhomogeneous case
73
size_t module_rank; // rank of solution module over level 0 monoid in the inhomogeneous case
74
size_t nr_gen;
75
// size_t hyp_size; // not used at present
76
Integer index; // index of full lattice over lattice of generators
77
78
bool verbose;
79
80
bool pointed;
81
bool is_simplicial;
82
bool deg1_generated_computed;
83
bool deg1_generated;
84
bool deg1_extreme_rays;
85
bool deg1_triangulation;
86
bool deg1_hilbert_basis;
87
bool inhomogeneous;
88
89
// control of what to compute
90
bool do_triangulation;
91
bool explicit_full_triang; // indicates whether full triangulation is asked for without default mode
92
bool explicit_h_vector; // to distinguish it from being set via default mode
93
bool do_partial_triangulation;
94
bool do_determinants;
95
bool do_multiplicity;
96
bool do_integrally_closed;
97
bool do_Hilbert_basis;
98
bool do_deg1_elements;
99
bool do_h_vector;
100
bool keep_triangulation;
101
bool do_Stanley_dec;
102
bool do_excluded_faces;
103
bool do_approximation;
104
bool do_default_mode;
105
bool do_bottom_dec;
106
bool suppress_bottom_dec;
107
bool keep_order;
108
bool do_class_group;
109
bool do_module_gens_intcl;
110
bool do_module_rank;
111
bool do_cone_dec;
112
bool stop_after_cone_dec;
113
bool do_hsop;
114
115
bool do_extreme_rays;
116
bool do_pointed;
117
118
// internal helper control variables
119
bool do_only_multiplicity;
120
bool do_only_mult_and_decomp;
121
bool do_evaluation;
122
bool do_all_hyperplanes; // controls whether all support hyperplanes must be computed
123
bool use_bottom_points;
124
ConeProperties is_Computed;
125
bool triangulation_is_nested;
126
bool triangulation_is_partial;
127
bool has_generator_with_common_divisor;
128
129
// data of the cone (input or output)
130
vector<Integer> Truncation; //used in the inhomogeneous case to suppress vectors of level > 1
131
Integer TruncLevel; // used for approximation of simplicial cones
132
vector<Integer> Grading;
133
vector<Integer> Sorting;
134
mpq_class multiplicity;
135
Matrix<Integer> Generators;
136
Matrix<Integer> ExtStrahl;
137
vector<key_t> PermGens; // stores the permutation of the generators created by sorting
138
vector<bool> Extreme_Rays_Ind;
139
Matrix<Integer> Support_Hyperplanes;
140
Matrix<Integer> Subcone_Support_Hyperplanes; // used if *this computes elements in a subcone, for example in approximation
141
Matrix<Integer> Subcone_Equations;
142
vector<Integer> Subcone_Grading;
143
size_t nrSupport_Hyperplanes;
144
list<vector<Integer> > Hilbert_Basis;
145
vector<Integer> Witness; // for not integrally closed
146
Matrix<Integer> Basis_Max_Subspace; // a basis of the maximal linear subspace of the cone --- only used in connection with dual mode
147
list<vector<Integer> > ModuleGeneratorsOverOriginalMonoid;
148
CandidateList<Integer> OldCandidates,NewCandidates; // for the Hilbert basis
149
size_t CandidatesSize;
150
list<vector<Integer> > Deg1_Elements;
151
HilbertSeries Hilbert_Series;
152
vector<Integer> gen_degrees; // will contain the degrees of the generators
153
Integer shift; // needed in the inhomogeneous case to make degrees positive
154
vector<Integer> gen_levels; // will contain the levels of the generators (in the inhomogeneous case)
155
size_t TriangulationBufferSize; // number of elements in Triangulation, for efficiency
156
list< SHORTSIMPLEX<Integer> > Triangulation; // triangulation of cone
157
list< SHORTSIMPLEX<Integer> > TriangulationBuffer; // simplices to evaluate
158
list< SimplexEvaluator<Integer> > LargeSimplices; // Simplices for internal parallelization
159
Integer detSum; // sum of the determinants of the simplices
160
list< STANLEYDATA_int> StanleyDec; // Stanley decomposition
161
vector<Integer> ClassGroup; // the class group as a vector: ClassGroup[0]=its rank, then the orders of the finite cyclic summands
162
163
Matrix<Integer> ProjToLevel0Quot; // projection matrix onto quotient modulo level 0 sublattice
164
165
// privare data controlling the computations
166
vector<size_t> HypCounter; // counters used to give unique number to hyperplane
167
// must be defined thread wise to avoid critical
168
169
vector<bool> in_triang; // intriang[i]==true means that Generators[i] has been actively inserted
170
vector<key_t> GensInCone; // lists the generators completely built in
171
size_t nrGensInCone; // their number
172
173
struct FACETDATA {
174
vector<Integer> Hyp; // linear form of the hyperplane
175
boost::dynamic_bitset<> GenInHyp; // incidence hyperplane/generators
176
Integer ValNewGen; // value of linear form on the generator to be added
177
size_t BornAt; // number of generator (in order of insertion) at which this hyperplane was added,, counting from 0
178
size_t Ident; // unique number identifying the hyperplane (derived from HypCounter)
179
size_t Mother; // Ident of positive mother if known, 0 if unknown
180
bool is_positive_on_all_original_gens;
181
bool is_negative_on_some_original_gen;
182
bool simplicial; // indicates whether facet is simplicial
183
};
184
185
list<FACETDATA> Facets; // contains the data for Fourier-Motzkin and extension of triangulation
186
size_t old_nr_supp_hyps; // must be remembered since Facets gets extended before the current generators is finished
187
188
// data relating a pyramid to its ancestores
189
Full_Cone<Integer>* Top_Cone; // reference to cone on top level
190
vector<key_t> Top_Key; // indices of generators w.r.t Top_Cone
191
Full_Cone<Integer>* Mother; // reference to the mother of the pyramid
192
vector<key_t> Mother_Key; // indices of generators w.r.t Mother
193
size_t apex; // indicates which generator of mother cone is apex of pyramid
194
int pyr_level; // -1 for top cone, increased by 1 for each level of pyramids
195
196
// control of pyramids, recusrion and parallelization
197
bool is_pyramid; // false for top cone
198
long last_to_be_inserted; // good to know in case of do_all_hyperplanes==false
199
bool recursion_allowed; // to allow or block recursive formation of pytamids
200
bool multithreaded_pyramid; // indicates that this cone is computed in parallel threads
201
bool tri_recursion; // true if we have gone to pyramids because of triangulation
202
203
vector<size_t> Comparisons; // at index i we note the total number of comparisons
204
// of positive and negative hyperplanes needed for the first i generators
205
size_t nrTotalComparisons; // counts the comparisons in the current computation
206
207
// storage for subpyramids
208
size_t store_level; // the level on which daughters will be stored
209
deque< list<vector<key_t> > > Pyramids; //storage for pyramids
210
deque<size_t> nrPyramids; // number of pyramids on the various levels
211
deque<bool> Pyramids_scrambled; // only used for mic
212
213
// data that can be used to go out of build_cone and return later (not done at present)
214
// but also useful at other places
215
long nextGen; // the next generator to be processed
216
long lastGen; // the last generator processed
217
218
// Helpers for triangulation and Fourier-Motzkin
219
vector<typename list < SHORTSIMPLEX<Integer> >::iterator> TriSectionFirst; // first simplex with lead vertex i
220
vector<typename list < SHORTSIMPLEX<Integer> >::iterator> TriSectionLast; // last simplex with lead vertex i
221
list<FACETDATA> LargeRecPyrs; // storage for large recusive pyramids given by basis of pyramid in mother cone
222
223
list< SHORTSIMPLEX<Integer> > FreeSimpl; // list of short simplices already evaluated, kept for recycling
224
vector<list< SHORTSIMPLEX<Integer> > > FS; // the same per thread
225
vector< Matrix<Integer> > RankTest; // helper matrices for rank test
226
227
// helpers for evaluation
228
vector< SimplexEvaluator<Integer> > SimplexEval; // one per thread
229
vector< Collector<Integer> > Results; // one per thread
230
vector<Integer> Order_Vector; // vector for the disjoint decomposition of the cone
231
#ifdef NMZ_MIC_OFFLOAD
232
MicOffloader<long long> mic_offloader;
233
#endif
234
void try_offload_loc(long place,size_t max_level);
235
236
237
// defining semiopen cones
238
Matrix<Integer> ExcludedFaces;
239
map<boost::dynamic_bitset<>, long> InExCollect;
240
241
// statistics
242
size_t totalNrSimplices; // total number of simplices evaluated
243
size_t nrSimplicialPyr;
244
size_t totalNrPyr;
245
246
bool use_existing_facets; // in order to avoid duplicate computation of already computed facets
247
size_t start_from;
248
249
size_t AdjustedReductionBound;
250
251
bool is_approximation;
252
bool is_global_approximation; // true if approximation is defined in Cone
253
254
vector<vector<key_t>> approx_points_keys;
255
Matrix<Integer> OriginalGenerators;
256
257
Integer VolumeBound; //used to stop computation of approximation if simplex of this has larger volume
258
259
/* ---------------------------------------------------------------------------
260
* Private routines, used in the public routines
261
* ---------------------------------------------------------------------------
262
*/
263
void number_hyperplane(FACETDATA& hyp, const size_t born_at, const size_t mother);
264
bool is_hyperplane_included(FACETDATA& hyp);
265
void add_hyperplane(const size_t& new_generator, const FACETDATA & positive,const FACETDATA & negative,
266
list<FACETDATA>& NewHyps, bool known_to_be_simplicial);
267
void extend_triangulation(const size_t& new_generator);
268
void find_new_facets(const size_t& new_generator);
269
void process_pyramids(const size_t new_generator,const bool recursive);
270
void process_pyramid(const vector<key_t>& Pyramid_key,
271
const size_t new_generator, const size_t store_level, Integer height, const bool recursive,
272
typename list< FACETDATA >::iterator hyp, size_t start_level);
273
void select_supphyps_from(const list<FACETDATA>& NewFacets, const size_t new_generator,
274
const vector<key_t>& Pyramid_key);
275
bool check_pyr_buffer(const size_t level);
276
void evaluate_stored_pyramids(const size_t level);
277
void match_neg_hyp_with_pos_hyps(const FACETDATA& hyp, size_t new_generator,list<FACETDATA*>& PosHyps, boost::dynamic_bitset<>& Zero_P);
278
void collect_pos_supphyps(list<FACETDATA*>& PosHyps, boost::dynamic_bitset<>& Zero_P, size_t& nr_pos);
279
void evaluate_rec_pyramids(const size_t level);
280
void evaluate_large_rec_pyramids(size_t new_generator);
281
282
void find_and_evaluate_start_simplex();
283
// Simplex<Integer> find_start_simplex() const;
284
vector<key_t> find_start_simplex() const;
285
void store_key(const vector<key_t>&, const Integer& height, const Integer& mother_vol,
286
list< SHORTSIMPLEX<Integer> >& Triangulation);
287
void find_bottom_facets();
288
vector<list<vector<Integer>>> latt_approx(); // makes a cone over a lattice polytope approximating "this"
289
void convert_polyhedron_to_polytope();
290
void compute_elements_via_approx(list<vector<Integer> >& elements_from_approx); // uses the approximation
291
void compute_deg1_elements_via_approx_global(); // deg 1 elements from the approximation
292
void compute_deg1_elements_via_projection_simplicial(const vector<key_t>& key); // for a simplicial subcone by projecion
293
void compute_sub_div_elements(const Matrix<Integer>& gens,list<vector<Integer> >& sub_div_elements,
294
bool best_point=false); //computes subdividing elements via approximation
295
void select_deg1_elements(const Full_Cone& C);
296
// void select_Hilbert_Basis(const Full_Cone& C); //experimental, unused
297
298
void build_top_cone();
299
void build_cone();
300
void get_supphyps_from_copy(bool from_scratch); // if evealuation starts before support hyperplanes are fully computed
301
void update_reducers(bool forced=false); // update list of reducers after evaluation of simplices
302
303
304
bool is_reducible(list<vector<Integer> *> & Irred, const vector<Integer> & new_element);
305
void global_reduction();
306
307
vector<Integer> compute_degree_function() const;
308
309
Matrix<Integer> select_matrix_from_list(const list<vector<Integer> >& S,vector<size_t>& selection);
310
311
bool contains(const vector<Integer>& v);
312
bool subcone_contains(const vector<Integer>& v);
313
bool contains(const Full_Cone& C);
314
void extreme_rays_and_deg1_check();
315
void find_grading();
316
void find_grading_inhom();
317
void check_given_grading();
318
void disable_grading_dep_comp();
319
void set_degrees();
320
void set_levels(); // for truncation in the inhomogeneous case
321
void find_module_rank(); // finds the module rank in the inhom case
322
void find_module_rank_from_HB();
323
void find_module_rank_from_proj(); // used if Hilbert basis is not computed
324
void find_level0_dim(); // ditto for the level 0 dimension
325
void sort_gens_by_degree(bool triangulate);
326
// void compute_support_hyperplanes(bool do_extreme_rays=false);
327
bool check_evaluation_buffer();
328
bool check_evaluation_buffer_size();
329
void prepare_old_candidates_and_support_hyperplanes();
330
void evaluate_triangulation();
331
void evaluate_large_simplices();
332
void evaluate_large_simplex(size_t j, size_t lss);
333
void transfer_triangulation_to_top();
334
void primal_algorithm();
335
void primal_algorithm_initialize();
336
void primal_algorithm_finalize();
337
void primal_algorithm_set_computed();
338
void make_module_gens();
339
void make_module_gens_and_extract_HB();
340
void remove_duplicate_ori_gens_from_HB();
341
void compute_class_group();
342
void compose_perm_gens(const vector<key_t>& perm);
343
void check_grading_after_dual_mode();
344
345
void minimize_support_hyperplanes();
346
void compute_extreme_rays(bool use_facets=false);
347
void compute_extreme_rays_compare(bool use_facets);
348
void compute_extreme_rays_rank(bool use_facets);
349
void select_deg1_elements();
350
351
void check_pointed();
352
void deg1_check();
353
void check_deg1_extreme_rays();
354
void check_deg1_hilbert_basis();
355
356
void compute_multiplicity();
357
358
void minimize_excluded_faces();
359
void prepare_inclusion_exclusion();
360
361
void do_vars_check(bool with_default);
362
void reset_tasks();
363
void addMult(Integer& volume, const vector<key_t>& key, const int& tn); // multiplicity sum over thread tn
364
365
void check_simpliciality_hyperplane(const FACETDATA& hyp) const;
366
void set_simplicial(FACETDATA& hyp);
367
368
369
void compute_hsop();
370
void heights(list<vector<key_t>>& facet_keys,list<pair<boost::dynamic_bitset<>,size_t>> faces, size_t index,vector<size_t>& ideal_heights, size_t max_dim);
371
372
void start_message();
373
void end_message();
374
375
void set_zero_cone();
376
377
378
#ifdef NMZ_MIC_OFFLOAD
379
void try_offload(size_t max_level);
380
#else
381
void try_offload(size_t max_level) {};
382
#endif
383
384
385
/*---------------------------------------------------------------------------
386
* Constructors
387
*---------------------------------------------------------------------------
388
*/
389
Full_Cone(const Matrix<Integer>& M, bool do_make_prime=true); //main constructor
390
Full_Cone(Cone_Dual_Mode<Integer> &C); // removes data from the argument!
391
Full_Cone(Full_Cone<Integer>& C, const vector<key_t>& Key); // for pyramids
392
393
/*---------------------------------------------------------------------------
394
* Data access
395
*---------------------------------------------------------------------------
396
*/
397
void print() const; //to be modified, just for tests
398
size_t getDimension() const;
399
size_t getNrGenerators() const;
400
bool isPointed() const;
401
bool isDeg1ExtremeRays() const;
402
bool isDeg1HilbertBasis() const;
403
vector<Integer> getGrading() const;
404
mpq_class getMultiplicity() const;
405
Integer getShift()const;
406
size_t getModuleRank()const;
407
const Matrix<Integer>& getGenerators() const;
408
vector<bool> getExtremeRays() const;
409
Matrix<Integer> getSupportHyperplanes() const;
410
Matrix<Integer> getHilbertBasis() const;
411
Matrix<Integer> getModuleGeneratorsOverOriginalMonoid()const;
412
Matrix<Integer> getDeg1Elements() const;
413
vector<Integer> getHVector() const;
414
Matrix<Integer> getExcludedFaces()const;
415
416
bool isComputed(ConeProperty::Enum prop) const;
417
418
419
/*---------------------------------------------------------------------------
420
* Computation Methods
421
*---------------------------------------------------------------------------
422
*/
423
void dualize_cone(bool print_message=true);
424
void support_hyperplanes();
425
426
void compute();
427
428
/* adds generators, they have to lie inside the existing cone */
429
void add_generators(const Matrix<Integer>& new_points);
430
431
void dual_mode();
432
433
void error_msg(string s) const;
434
};
435
//class end *****************************************************************
436
//---------------------------------------------------------------------------
437
438
}
439
440
//---------------------------------------------------------------------------
441
#endif
442
//---------------------------------------------------------------------------
443
444
445