CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

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

Views: 418426
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 "libQnormaliz/libQnormaliz.h"
34
#include "libQnormaliz/Qcone_property.h"
35
#include "libQnormaliz/Qmatrix.h"
36
#include "libQnormaliz/Qcone.h"
37
// #include "libQnormaliz/Qsimplex.h"
38
// #include "libQnormaliz/Qcone_dual_mode.h"
39
// #include "libQnormaliz/QHilbertSeries.h"
40
// #include "libQnormaliz/Qreduction.h"
41
// #include "libQnormaliz/Qsublattice_representation.h"
42
// #include "libQnormaliz/Qoffload_handler.h"
43
44
namespace libQnormaliz {
45
using std::list;
46
using std::vector;
47
using std::map;
48
using std::pair;
49
using boost::dynamic_bitset;
50
51
template<typename Number> class Cone;
52
53
template<typename Number>
54
class Full_Cone {
55
56
friend class Cone<Number>;
57
58
public:
59
size_t dim;
60
size_t level0_dim; // dim of cone in level 0 of the inhomogeneous case
61
size_t module_rank; // rank of solution module over level 0 monoid in the inhomogeneous case
62
size_t nr_gen;
63
// size_t hyp_size; // not used at present
64
Number index; // index of full lattice over lattice of generators
65
66
bool verbose;
67
68
bool pointed;
69
bool is_simplicial;
70
bool deg1_generated_computed;
71
bool deg1_generated;
72
bool deg1_extreme_rays;
73
bool deg1_triangulation;
74
bool deg1_hilbert_basis;
75
bool inhomogeneous;
76
77
// control of what to compute
78
bool do_triangulation;
79
bool explicit_full_triang; // indicates whether full triangulation is asked for without default mode
80
bool explicit_h_vector; // to distinguish it from being set via default mode
81
bool do_partial_triangulation;
82
bool do_determinants;
83
bool do_multiplicity;
84
bool do_integrally_closed;
85
bool do_Hilbert_basis;
86
bool do_deg1_elements;
87
bool do_h_vector;
88
bool keep_triangulation;
89
bool do_Stanley_dec;
90
bool do_excluded_faces;
91
bool do_approximation;
92
bool do_default_mode;
93
bool do_bottom_dec;
94
bool suppress_bottom_dec;
95
bool keep_order;
96
bool do_class_group;
97
bool do_module_gens_intcl;
98
bool do_module_rank;
99
bool do_cone_dec;
100
bool stop_after_cone_dec;
101
bool do_hsop;
102
103
bool do_extreme_rays;
104
bool do_pointed;
105
106
// internal helper control variables
107
bool do_only_multiplicity;
108
bool do_only_mult_and_decomp;
109
bool do_evaluation;
110
bool do_all_hyperplanes; // controls whether all support hyperplanes must be computed
111
bool use_bottom_points;
112
ConeProperties is_Computed;
113
bool triangulation_is_nested;
114
bool triangulation_is_partial;
115
bool has_generator_with_common_divisor;
116
117
// data of the cone (input or output)
118
vector<Number> Truncation; //used in the inhomogeneous case to suppress vectors of level > 1
119
Number TruncLevel; // used for approximation of simplicial cones
120
vector<Number> Grading;
121
vector<Number> Sorting;
122
// mpq_class multiplicity;
123
Matrix<Number> Generators;
124
Matrix<Number> ExtStrahl;
125
vector<key_t> PermGens; // stores the permutation of the generators created by sorting
126
vector<bool> Extreme_Rays_Ind;
127
Matrix<Number> Support_Hyperplanes;
128
size_t nrSupport_Hyperplanes;
129
list<vector<Number> > Hilbert_Basis;
130
vector<Number> Witness; // for not integrally closed
131
Matrix<Number> Basis_Max_Subspace; // a basis of the maximal linear subspace of the cone --- only used in connection with dual mode
132
list<vector<Number> > ModuleGeneratorsOverOriginalMonoid;
133
134
size_t CandidatesSize;
135
list<vector<Number> > Deg1_Elements;
136
// HilbertSeries Hilbert_Series;
137
vector<long> gen_degrees; // will contain the degrees of the generators
138
Number shift; // needed in the inhomogeneous case to make degrees positive
139
vector<Number> gen_levels; // will contain the levels of the generators (in the inhomogeneous case)
140
size_t TriangulationBufferSize; // number of elements in Triangulation, for efficiency
141
list< SHORTSIMPLEX<Number> > Triangulation; // triangulation of cone
142
list< SHORTSIMPLEX<Number> > TriangulationBuffer; // simplices to evaluate
143
// list< SimplexEvaluator<Number> > LargeSimplices; // Simplices for internal parallelization
144
Number detSum; // sum of the determinants of the simplices
145
// list< STANLEYDATA<Number> > StanleyDec; // Stanley decomposition
146
// vector<Number> ClassGroup; // the class group as a vector: ClassGroup[0]=its rank, then the orders of the finite cyclic summands
147
148
Matrix<Number> ProjToLevel0Quot; // projection matrix onto quotient modulo level 0 sublattice
149
150
// privare data controlling the computations
151
vector<size_t> HypCounter; // counters used to give unique number to hyperplane
152
// must be defined thread wise to avoid critical
153
154
vector<bool> in_triang; // intriang[i]==true means that Generators[i] has been actively inserted
155
vector<key_t> GensInCone; // lists the generators completely built in
156
size_t nrGensInCone; // their number
157
158
struct FACETDATA {
159
vector<Number> Hyp; // linear form of the hyperplane
160
boost::dynamic_bitset<> GenInHyp; // incidence hyperplane/generators
161
Number ValNewGen; // value of linear form on the generator to be added
162
size_t BornAt; // number of generator (in order of insertion) at which this hyperplane was added,, counting from 0
163
size_t Ident; // unique number identifying the hyperplane (derived from HypCounter)
164
size_t Mother; // Ident of positive mother if known, 0 if unknown
165
bool simplicial; // indicates whether facet is simplicial
166
};
167
168
list<FACETDATA> Facets; // contains the data for Fourier-Motzkin and extension of triangulation
169
size_t old_nr_supp_hyps; // must be remembered since Facets gets extended before the current generators is finished
170
171
// data relating a pyramid to its ancestores
172
Full_Cone<Number>* Top_Cone; // reference to cone on top level
173
vector<key_t> Top_Key; // indices of generators w.r.t Top_Cone
174
Full_Cone<Number>* Mother; // reference to the mother of the pyramid
175
vector<key_t> Mother_Key; // indices of generators w.r.t Mother
176
size_t apex; // indicates which generator of mother cone is apex of pyramid
177
int pyr_level; // -1 for top cone, increased by 1 for each level of pyramids
178
179
// control of pyramids, recusrion and parallelization
180
bool is_pyramid; // false for top cone
181
long last_to_be_inserted; // good to know in case of do_all_hyperplanes==false
182
bool recursion_allowed; // to allow or block recursive formation of pytamids
183
bool multithreaded_pyramid; // indicates that this cone is computed in parallel threads
184
bool tri_recursion; // true if we have gone to pyramids because of triangulation
185
186
vector<size_t> Comparisons; // at index i we note the total number of comparisons
187
// of positive and negative hyperplanes needed for the first i generators
188
size_t nrTotalComparisons; // counts the comparisons in the current computation
189
190
// storage for subpyramids
191
size_t store_level; // the level on which daughters will be stored
192
deque< list<vector<key_t> > > Pyramids; //storage for pyramids
193
deque<size_t> nrPyramids; // number of pyramids on the various levels
194
195
// data that can be used to go out of build_cone and return later (not done at present)
196
// but also useful at other places
197
long nextGen; // the next generator to be processed
198
long lastGen; // the last generator processed
199
200
// Helpers for triangulation and Fourier-Motzkin
201
vector<typename list < SHORTSIMPLEX<Number> >::iterator> TriSectionFirst; // first simplex with lead vertex i
202
vector<typename list < SHORTSIMPLEX<Number> >::iterator> TriSectionLast; // last simplex with lead vertex i
203
list<FACETDATA> LargeRecPyrs; // storage for large recusive pyramids given by basis of pyramid in mother cone
204
205
list< SHORTSIMPLEX<Number> > FreeSimpl; // list of short simplices already evaluated, kept for recycling
206
vector<list< SHORTSIMPLEX<Number> > > FS; // the same per thread
207
vector< Matrix<Number> > RankTest; // helper matrices for rank test
208
209
// helpers for evaluation
210
// vector< SimplexEvaluator<Number> > SimplexEval; // one per thread
211
// vector< Collector<Number> > Results; // one per thread
212
vector<Number> Order_Vector; // vector for the disjoint decomposition of the cone
213
214
// statistics
215
size_t totalNrSimplices; // total number of simplices evaluated
216
size_t nrSimplicialPyr;
217
size_t totalNrPyr;
218
219
bool use_existing_facets; // in order to avoid duplicate computation of already computed facets
220
size_t start_from;
221
222
size_t AdjustedReductionBound;
223
224
long approx_level;
225
bool is_approximation;
226
227
/* ---------------------------------------------------------------------------
228
* Private routines, used in the public routines
229
* ---------------------------------------------------------------------------
230
*/
231
void number_hyperplane(FACETDATA& hyp, const size_t born_at, const size_t mother);
232
bool is_hyperplane_included(FACETDATA& hyp);
233
void add_hyperplane(const size_t& new_generator, const FACETDATA & positive,const FACETDATA & negative,
234
list<FACETDATA>& NewHyps, bool known_to_be_simplicial);
235
void extend_triangulation(const size_t& new_generator);
236
void find_new_facets(const size_t& new_generator);
237
void process_pyramids(const size_t new_generator,const bool recursive);
238
void process_pyramid(const vector<key_t>& Pyramid_key,
239
const size_t new_generator, const size_t store_level, Number height, const bool recursive,
240
typename list< FACETDATA >::iterator hyp, size_t start_level);
241
void select_supphyps_from(const list<FACETDATA>& NewFacets, const size_t new_generator,
242
const vector<key_t>& Pyramid_key);
243
bool check_pyr_buffer(const size_t level);
244
void evaluate_stored_pyramids(const size_t level);
245
void match_neg_hyp_with_pos_hyps(const FACETDATA& hyp, size_t new_generator,list<FACETDATA*>& PosHyps, boost::dynamic_bitset<>& Zero_P);
246
void collect_pos_supphyps(list<FACETDATA*>& PosHyps, boost::dynamic_bitset<>& Zero_P, size_t& nr_pos);
247
void evaluate_rec_pyramids(const size_t level);
248
void evaluate_large_rec_pyramids(size_t new_generator);
249
250
void find_and_evaluate_start_simplex();
251
// Simplex<Number> find_start_simplex() const;
252
vector<key_t> find_start_simplex() const;
253
void store_key(const vector<key_t>&, const Number& height, const Number& mother_vol,
254
list< SHORTSIMPLEX<Number> >& Triangulation);
255
256
void build_top_cone();
257
void build_cone();
258
void get_supphyps_from_copy(bool from_scratch); // if evealuation starts before support hyperplanes are fully computed
259
260
vector<Number> compute_degree_function() const;
261
262
Matrix<Number> select_matrix_from_list(const list<vector<Number> >& S,vector<size_t>& selection);
263
264
bool contains(const vector<Number>& v);
265
bool contains(const Full_Cone& C);
266
void extreme_rays_and_deg1_check();
267
268
void disable_grading_dep_comp();
269
270
void set_levels(); // for truncation in the inhomogeneous case
271
void find_level0_dim(); // ditto for the level 0 dimension
272
void sort_gens_by_degree(bool triangulate);
273
// void compute_support_hyperplanes(bool do_extreme_rays=false);
274
bool check_evaluation_buffer();
275
bool check_evaluation_buffer_size();
276
277
void evaluate_triangulation();
278
279
void transfer_triangulation_to_top();
280
void primal_algorithm();
281
void primal_algorithm_initialize();
282
void primal_algorithm_finalize();
283
void primal_algorithm_set_computed();
284
285
void compose_perm_gens(const vector<key_t>& perm);
286
287
void minimize_support_hyperplanes();
288
void compute_extreme_rays(bool use_facets=false);
289
void compute_extreme_rays_compare(bool use_facets);
290
void compute_extreme_rays_rank(bool use_facets);
291
292
void check_pointed();
293
294
295
void do_vars_check(bool with_default);
296
void reset_tasks();
297
298
void check_simpliciality_hyperplane(const FACETDATA& hyp) const;
299
void set_simplicial(FACETDATA& hyp);
300
301
void start_message();
302
void end_message();
303
304
void set_zero_cone();
305
306
307
/*---------------------------------------------------------------------------
308
* Constructors
309
*---------------------------------------------------------------------------
310
*/
311
Full_Cone(const Matrix<Number>& M, bool do_make_prime=true); //main constructor
312
313
Full_Cone(Full_Cone<Number>& C, const vector<key_t>& Key); // for pyramids
314
315
/*---------------------------------------------------------------------------
316
* Data access
317
*---------------------------------------------------------------------------
318
*/
319
void print() const; //to be modified, just for tests
320
size_t getDimension() const;
321
size_t getNrGenerators() const;
322
bool isPointed() const;
323
bool isDeg1ExtremeRays() const;
324
bool isDeg1HilbertBasis() const;
325
vector<Number> getGrading() const;
326
// mpq_class getMultiplicity() const;
327
Number getShift()const;
328
size_t getModuleRank()const;
329
const Matrix<Number>& getGenerators() const;
330
vector<bool> getExtremeRays() const;
331
Matrix<Number> getSupportHyperplanes() const;
332
Matrix<Number> getHilbertBasis() const;
333
Matrix<Number> getModuleGeneratorsOverOriginalMonoid()const;
334
Matrix<Number> getDeg1Elements() const;
335
vector<Number> getHVector() const;
336
Matrix<Number> getExcludedFaces()const;
337
338
bool isComputed(ConeProperty::Enum prop) const;
339
340
341
/*---------------------------------------------------------------------------
342
* Computation Methods
343
*---------------------------------------------------------------------------
344
*/
345
void dualize_cone(bool print_message=true);
346
void support_hyperplanes();
347
348
void compute();
349
350
/* adds generators, they have to lie inside the existing cone */
351
void add_generators(const Matrix<Number>& new_points);
352
353
void dual_mode();
354
355
void error_msg(string s) const;
356
};
357
//class end *****************************************************************
358
//---------------------------------------------------------------------------
359
360
}
361
362
//---------------------------------------------------------------------------
363
#endif
364
//---------------------------------------------------------------------------
365
366
367