Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
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
Project: cocalc-sagemath-dev-slelievre
Views: 418426/*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#ifndef FULL_CONE_H24#define FULL_CONE_H2526#include <list>27#include <vector>28#include <deque>29//#include <set>30#include <boost/dynamic_bitset.hpp>3132#include "libQnormaliz/libQnormaliz.h"33#include "libQnormaliz/Qcone_property.h"34#include "libQnormaliz/Qmatrix.h"35#include "libQnormaliz/Qcone.h"36// #include "libQnormaliz/Qsimplex.h"37// #include "libQnormaliz/Qcone_dual_mode.h"38// #include "libQnormaliz/QHilbertSeries.h"39// #include "libQnormaliz/Qreduction.h"40// #include "libQnormaliz/Qsublattice_representation.h"41// #include "libQnormaliz/Qoffload_handler.h"4243namespace libQnormaliz {44using std::list;45using std::vector;46using std::map;47using std::pair;48using boost::dynamic_bitset;4950template<typename Number> class Cone;5152template<typename Number>53class Full_Cone {5455friend class Cone<Number>;5657public:58size_t dim;59size_t level0_dim; // dim of cone in level 0 of the inhomogeneous case60size_t module_rank; // rank of solution module over level 0 monoid in the inhomogeneous case61size_t nr_gen;62// size_t hyp_size; // not used at present63Number index; // index of full lattice over lattice of generators6465bool verbose;6667bool pointed;68bool is_simplicial;69bool deg1_generated_computed;70bool deg1_generated;71bool deg1_extreme_rays;72bool deg1_triangulation;73bool deg1_hilbert_basis;74bool inhomogeneous;7576// control of what to compute77bool do_triangulation;78bool explicit_full_triang; // indicates whether full triangulation is asked for without default mode79bool explicit_h_vector; // to distinguish it from being set via default mode80bool do_partial_triangulation;81bool do_determinants;82bool do_multiplicity;83bool do_integrally_closed;84bool do_Hilbert_basis;85bool do_deg1_elements;86bool do_h_vector;87bool keep_triangulation;88bool do_Stanley_dec;89bool do_excluded_faces;90bool do_approximation;91bool do_default_mode;92bool do_bottom_dec;93bool suppress_bottom_dec;94bool keep_order;95bool do_class_group;96bool do_module_gens_intcl;97bool do_module_rank;98bool do_cone_dec;99bool stop_after_cone_dec;100bool do_hsop;101102bool do_extreme_rays;103bool do_pointed;104105// internal helper control variables106bool do_only_multiplicity;107bool do_only_mult_and_decomp;108bool do_evaluation;109bool do_all_hyperplanes; // controls whether all support hyperplanes must be computed110bool use_bottom_points;111ConeProperties is_Computed;112bool triangulation_is_nested;113bool triangulation_is_partial;114bool has_generator_with_common_divisor;115116// data of the cone (input or output)117vector<Number> Truncation; //used in the inhomogeneous case to suppress vectors of level > 1118Number TruncLevel; // used for approximation of simplicial cones119vector<Number> Grading;120vector<Number> Sorting;121// mpq_class multiplicity;122Matrix<Number> Generators;123Matrix<Number> ExtStrahl;124vector<key_t> PermGens; // stores the permutation of the generators created by sorting125vector<bool> Extreme_Rays_Ind;126Matrix<Number> Support_Hyperplanes;127size_t nrSupport_Hyperplanes;128list<vector<Number> > Hilbert_Basis;129vector<Number> Witness; // for not integrally closed130Matrix<Number> Basis_Max_Subspace; // a basis of the maximal linear subspace of the cone --- only used in connection with dual mode131list<vector<Number> > ModuleGeneratorsOverOriginalMonoid;132133size_t CandidatesSize;134list<vector<Number> > Deg1_Elements;135// HilbertSeries Hilbert_Series;136vector<long> gen_degrees; // will contain the degrees of the generators137Number shift; // needed in the inhomogeneous case to make degrees positive138vector<Number> gen_levels; // will contain the levels of the generators (in the inhomogeneous case)139size_t TriangulationBufferSize; // number of elements in Triangulation, for efficiency140list< SHORTSIMPLEX<Number> > Triangulation; // triangulation of cone141list< SHORTSIMPLEX<Number> > TriangulationBuffer; // simplices to evaluate142// list< SimplexEvaluator<Number> > LargeSimplices; // Simplices for internal parallelization143Number detSum; // sum of the determinants of the simplices144// list< STANLEYDATA<Number> > StanleyDec; // Stanley decomposition145// vector<Number> ClassGroup; // the class group as a vector: ClassGroup[0]=its rank, then the orders of the finite cyclic summands146147Matrix<Number> ProjToLevel0Quot; // projection matrix onto quotient modulo level 0 sublattice148149// privare data controlling the computations150vector<size_t> HypCounter; // counters used to give unique number to hyperplane151// must be defined thread wise to avoid critical152153vector<bool> in_triang; // intriang[i]==true means that Generators[i] has been actively inserted154vector<key_t> GensInCone; // lists the generators completely built in155size_t nrGensInCone; // their number156157struct FACETDATA {158vector<Number> Hyp; // linear form of the hyperplane159boost::dynamic_bitset<> GenInHyp; // incidence hyperplane/generators160Number ValNewGen; // value of linear form on the generator to be added161size_t BornAt; // number of generator (in order of insertion) at which this hyperplane was added,, counting from 0162size_t Ident; // unique number identifying the hyperplane (derived from HypCounter)163size_t Mother; // Ident of positive mother if known, 0 if unknown164bool simplicial; // indicates whether facet is simplicial165};166167list<FACETDATA> Facets; // contains the data for Fourier-Motzkin and extension of triangulation168size_t old_nr_supp_hyps; // must be remembered since Facets gets extended before the current generators is finished169170// data relating a pyramid to its ancestores171Full_Cone<Number>* Top_Cone; // reference to cone on top level172vector<key_t> Top_Key; // indices of generators w.r.t Top_Cone173Full_Cone<Number>* Mother; // reference to the mother of the pyramid174vector<key_t> Mother_Key; // indices of generators w.r.t Mother175size_t apex; // indicates which generator of mother cone is apex of pyramid176int pyr_level; // -1 for top cone, increased by 1 for each level of pyramids177178// control of pyramids, recusrion and parallelization179bool is_pyramid; // false for top cone180long last_to_be_inserted; // good to know in case of do_all_hyperplanes==false181bool recursion_allowed; // to allow or block recursive formation of pytamids182bool multithreaded_pyramid; // indicates that this cone is computed in parallel threads183bool tri_recursion; // true if we have gone to pyramids because of triangulation184185vector<size_t> Comparisons; // at index i we note the total number of comparisons186// of positive and negative hyperplanes needed for the first i generators187size_t nrTotalComparisons; // counts the comparisons in the current computation188189// storage for subpyramids190size_t store_level; // the level on which daughters will be stored191deque< list<vector<key_t> > > Pyramids; //storage for pyramids192deque<size_t> nrPyramids; // number of pyramids on the various levels193194// data that can be used to go out of build_cone and return later (not done at present)195// but also useful at other places196long nextGen; // the next generator to be processed197long lastGen; // the last generator processed198199// Helpers for triangulation and Fourier-Motzkin200vector<typename list < SHORTSIMPLEX<Number> >::iterator> TriSectionFirst; // first simplex with lead vertex i201vector<typename list < SHORTSIMPLEX<Number> >::iterator> TriSectionLast; // last simplex with lead vertex i202list<FACETDATA> LargeRecPyrs; // storage for large recusive pyramids given by basis of pyramid in mother cone203204list< SHORTSIMPLEX<Number> > FreeSimpl; // list of short simplices already evaluated, kept for recycling205vector<list< SHORTSIMPLEX<Number> > > FS; // the same per thread206vector< Matrix<Number> > RankTest; // helper matrices for rank test207208// helpers for evaluation209// vector< SimplexEvaluator<Number> > SimplexEval; // one per thread210// vector< Collector<Number> > Results; // one per thread211vector<Number> Order_Vector; // vector for the disjoint decomposition of the cone212213// statistics214size_t totalNrSimplices; // total number of simplices evaluated215size_t nrSimplicialPyr;216size_t totalNrPyr;217218bool use_existing_facets; // in order to avoid duplicate computation of already computed facets219size_t start_from;220221size_t AdjustedReductionBound;222223long approx_level;224bool is_approximation;225226/* ---------------------------------------------------------------------------227* Private routines, used in the public routines228* ---------------------------------------------------------------------------229*/230void number_hyperplane(FACETDATA& hyp, const size_t born_at, const size_t mother);231bool is_hyperplane_included(FACETDATA& hyp);232void add_hyperplane(const size_t& new_generator, const FACETDATA & positive,const FACETDATA & negative,233list<FACETDATA>& NewHyps, bool known_to_be_simplicial);234void extend_triangulation(const size_t& new_generator);235void find_new_facets(const size_t& new_generator);236void process_pyramids(const size_t new_generator,const bool recursive);237void process_pyramid(const vector<key_t>& Pyramid_key,238const size_t new_generator, const size_t store_level, Number height, const bool recursive,239typename list< FACETDATA >::iterator hyp, size_t start_level);240void select_supphyps_from(const list<FACETDATA>& NewFacets, const size_t new_generator,241const vector<key_t>& Pyramid_key);242bool check_pyr_buffer(const size_t level);243void evaluate_stored_pyramids(const size_t level);244void match_neg_hyp_with_pos_hyps(const FACETDATA& hyp, size_t new_generator,list<FACETDATA*>& PosHyps, boost::dynamic_bitset<>& Zero_P);245void collect_pos_supphyps(list<FACETDATA*>& PosHyps, boost::dynamic_bitset<>& Zero_P, size_t& nr_pos);246void evaluate_rec_pyramids(const size_t level);247void evaluate_large_rec_pyramids(size_t new_generator);248249void find_and_evaluate_start_simplex();250// Simplex<Number> find_start_simplex() const;251vector<key_t> find_start_simplex() const;252void store_key(const vector<key_t>&, const Number& height, const Number& mother_vol,253list< SHORTSIMPLEX<Number> >& Triangulation);254255void build_top_cone();256void build_cone();257void get_supphyps_from_copy(bool from_scratch); // if evealuation starts before support hyperplanes are fully computed258259vector<Number> compute_degree_function() const;260261Matrix<Number> select_matrix_from_list(const list<vector<Number> >& S,vector<size_t>& selection);262263bool contains(const vector<Number>& v);264bool contains(const Full_Cone& C);265void extreme_rays_and_deg1_check();266267void disable_grading_dep_comp();268269void set_levels(); // for truncation in the inhomogeneous case270void find_level0_dim(); // ditto for the level 0 dimension271void sort_gens_by_degree(bool triangulate);272// void compute_support_hyperplanes(bool do_extreme_rays=false);273bool check_evaluation_buffer();274bool check_evaluation_buffer_size();275276void evaluate_triangulation();277278void transfer_triangulation_to_top();279void primal_algorithm();280void primal_algorithm_initialize();281void primal_algorithm_finalize();282void primal_algorithm_set_computed();283284void compose_perm_gens(const vector<key_t>& perm);285286void minimize_support_hyperplanes();287void compute_extreme_rays(bool use_facets=false);288void compute_extreme_rays_compare(bool use_facets);289void compute_extreme_rays_rank(bool use_facets);290291void check_pointed();292293294void do_vars_check(bool with_default);295void reset_tasks();296297void check_simpliciality_hyperplane(const FACETDATA& hyp) const;298void set_simplicial(FACETDATA& hyp);299300void start_message();301void end_message();302303void set_zero_cone();304305306/*---------------------------------------------------------------------------307* Constructors308*---------------------------------------------------------------------------309*/310Full_Cone(const Matrix<Number>& M, bool do_make_prime=true); //main constructor311312Full_Cone(Full_Cone<Number>& C, const vector<key_t>& Key); // for pyramids313314/*---------------------------------------------------------------------------315* Data access316*---------------------------------------------------------------------------317*/318void print() const; //to be modified, just for tests319size_t getDimension() const;320size_t getNrGenerators() const;321bool isPointed() const;322bool isDeg1ExtremeRays() const;323bool isDeg1HilbertBasis() const;324vector<Number> getGrading() const;325// mpq_class getMultiplicity() const;326Number getShift()const;327size_t getModuleRank()const;328const Matrix<Number>& getGenerators() const;329vector<bool> getExtremeRays() const;330Matrix<Number> getSupportHyperplanes() const;331Matrix<Number> getHilbertBasis() const;332Matrix<Number> getModuleGeneratorsOverOriginalMonoid()const;333Matrix<Number> getDeg1Elements() const;334vector<Number> getHVector() const;335Matrix<Number> getExcludedFaces()const;336337bool isComputed(ConeProperty::Enum prop) const;338339340/*---------------------------------------------------------------------------341* Computation Methods342*---------------------------------------------------------------------------343*/344void dualize_cone(bool print_message=true);345void support_hyperplanes();346347void compute();348349/* adds generators, they have to lie inside the existing cone */350void add_generators(const Matrix<Number>& new_points);351352void dual_mode();353354void error_msg(string s) const;355};356//class end *****************************************************************357//---------------------------------------------------------------------------358359}360361//---------------------------------------------------------------------------362#endif363//---------------------------------------------------------------------------364365366367