Gröbner basis project
Codebase for research into Gröbner basis computation
dynamic_engine.hpp
1 #ifndef __DYNAMIC_ENGINE_H__
2 #define __DYNAMIC_ENGINE_H__
3 
4 /*****************************************************************************\
5 * This file is part of DynGB. *
6 * *
7 * DynGB is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * Foobar is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with DynGB. If not, see <http://www.gnu.org/licenses/>. *
19 \*****************************************************************************/
20 
21 #include <cstddef>
22 
23 #include "monomial.hpp"
24 #include "monomial_ideal.hpp"
25 #include "hilbert_functions.hpp"
26 #include "polynomial.hpp"
27 #include "critical_pair.hpp"
28 #include "lp_solver.hpp"
29 #include "skeleton.hpp"
30 #include "glpk_solver.hpp"
31 #include "ppl_solver.hpp"
32 
33 #include <map>
34 #include <vector>
35 #include <iostream>
36 
37 using std::map; using std::vector; using std::cout; using std::endl;
38 
69 enum class DynamicHeuristic
70 {
71  MIN_HEURISTIC = 0,
72  ORD_HILBERT_THEN_LEX, ORD_HILBERT_THEN_DEG, GRAD_HILB_THEN_DEG,
73  MIN_CRIT_PAIRS, GRAD_MIN_CRIT_PAIRS,
74  BETTI_HILBERT_DEG, BIG_BETTI_HILBERT_DEG, GRAD_BETTI_HILBERT_DEG,
75  SMOOTHEST_DEGREES, LARGEST_MAX_COMPONENT,
76  DEG_THEN_GRAD_HILB, DEG_THEN_ORD_HILBERT,
77  MAX_HEURISTIC
78 };
79 
94 int hilbertCmp(
99 );
100 
109 class PPWithIdeal {
110  public:
112 
122  Monomial u, const list<Monomial> & F, ::ray & w,
123  const list<Critical_Pair_Dynamic *> & P,
124  const Dense_Univariate_Integer_Polynomial * h = nullptr
125  ) : t(u), ordering(w), num_new_pairs(-1), min_deg(-1), max_deg(-1),
126  I(u.num_vars(), F, h), pairs(P)
127  {
128  I.add_generator(u);
129  };
132  : t(PI.t), ordering(PI.ordering), num_new_pairs(PI.num_new_pairs),
133  min_deg(PI.min_deg), max_deg(PI.max_deg), I(PI.I), pairs(PI.pairs)
134  { }
136 
137 
141 
142 
144  inline const Monomial & getPP() const { return t; };
146  inline const Monomial_Ideal & getIdeal() const { return I; };
148  inline ::ray getOrdering() { return ordering; };
153  inline const map<DEG_TYPE, unsigned long> & getIncBetti(bool graded = false)
154  {
155  if (graded)
156  return I.inc_betti(ordering.weights());
157  else
158  return I.inc_betti();
159  }
165  bool graded = false
166  ) {
167  if (graded)
168  return I.hilbert_numerator(ordering.weights());
169  else
170  return I.hilbert_numerator();
171  }
177  bool graded = false
178  ) {
179  if (graded)
180  return I.reduced_hilbert_numerator(ordering.weights());
181  else
182  return I.reduced_hilbert_numerator();
183  }
188  return I.hilbert_poly();
189  };
194  inline int howManyNewPairs() const { return num_new_pairs; }
199  inline int degOfNewPairs() const { return min_deg; }
205  {
206  if (min_deg < 0)
207  {
208  const list<Monomial> & G = I.generators();
209  min_deg = max_deg = G.front().weighted_degree(ordering.weights());
210  for (const Monomial & g : G) {
211  int d = g.weighted_degree(ordering.weights());
212  if (d < min_deg) min_deg = d;
213  if (d > max_deg) max_deg = d;
214  }
215  }
216  return max_deg - min_deg;
217  }
219 
220 
222  void computeNumberNewPairs();
224  protected:
232  const list<Critical_Pair_Dynamic *> & pairs;
238  int min_deg;
240  int max_deg;
241 };
242 
255 void compatiblePP(
256  Monomial currentLPP, // the current LPP
257  const set<Monomial> &allPPs, // the monomials to consider;
258  // some will be removed
259  const set<::ray> &bndrys, // known boundary vectors
260  set<Monomial> &result, // returned as PPs for Hilbert function
261  // ("easy" (& efficient?) to extract exps
262  set<Monomial> &boundary_mons, // boundary monomials
263  LP_Solver *skel // used for alternate refinement
264 );
265 
279  LP_Solver *skel,
280  const list<Abstract_Polynomial *> &currentPolys
281 );
282 
293  const PPWithIdeal &pp_I,
294  const set<Monomial> &monomialsForComparison,
295  vector<constraint> &result
296 );
297 
316 void SelectMonomial(
317  Abstract_Polynomial * r, // changes
318  list<Monomial> &CurrentLPPs, // changes
319  Dense_Univariate_Integer_Polynomial ** current_hilbert_numerator,
320  const list<Abstract_Polynomial *> &CurrentPolys,
321  const list<Critical_Pair_Dynamic *> & critpairs,
322  LP_Solver * currSkel, // possibly changes
323  bool &ordering_changed,
324  DynamicHeuristic method = DynamicHeuristic::ORD_HILBERT_THEN_DEG
325 );
326 
327 #endif
The general class of a polynomial.
Definition: polynomial.hpp:101
PPWithIdeal(Monomial u, const list< Monomial > &F, ::ray &w, const list< Critical_Pair_Dynamic *> &P, const Dense_Univariate_Integer_Polynomial *h=nullptr)
Construct a monomial/ideal pair.
void SelectMonomial(Abstract_Polynomial *r, list< Monomial > &CurrentLPPs, Dense_Univariate_Integer_Polynomial **current_hilbert_numerator, const list< Abstract_Polynomial *> &CurrentPolys, const list< Critical_Pair_Dynamic *> &critpairs, LP_Solver *currSkel, bool &ordering_changed, DynamicHeuristic method=DynamicHeuristic::ORD_HILBERT_THEN_DEG)
Selects a leading power product for a polynomial.
const Monomial_Ideal & getIdeal() const
the old ideal of leading monomials
Dense_Univariate_Integer_Polynomial * getHilbertReducedNumerator(bool graded=false)
the Hilbert numerator obtained by adding the monomial to the ideal (numerator is reduced) ...
int howManyNewPairs() const
estimate of the number of new critical pairs generated by adding the monomial to the ideal ...
A class for monomial ideals.
int getDifferenceInDegree()
computes the difference in degree between the first and last monomials of the ideal ...
int num_new_pairs
estimate of number of new pairs
const list< Critical_Pair_Dynamic * > & pairs
the list of critical pairs of at this point in the algorithm
const map< DEG_TYPE, unsigned long > & getIncBetti(bool graded=false)
the incremental Betti numbers obtained by adding the monomial to the ideal
Dense_Univariate_Rational_Polynomial * getHilbertPolynomial()
the Hilbert polynomial obtained by adding the monomial to the ideal
PPWithIdeal(const PPWithIdeal &PI)
copy constructor
Monomial_Ideal I
the ideal of leading terms
quick-’n-dirty Dense_Univariate integer polynomial class
inline ::ray getOrdering()
the current monomial ordering
int min_deg
minimum weighted degree of monomials in ideal
void compatiblePP(Monomial currentLPP, const set< Monomial > &allPPs, const set<::ray > &bndrys, set< Monomial > &result, set< Monomial > &boundary_mons, LP_Solver *skel)
DynamicHeuristic
exact or approximate polyhedral cone solution, with methods allowing definition and refinement ...
Definition: lp_solver.hpp:504
Dense_Univariate_Integer_Polynomial * getHilbertNumerator(bool graded=false)
the Hilbert numerator obtained by adding the monomial to the ideal (numerator is not reduced) ...
~PPWithIdeal()
does nothing the default wouldn&#39;t do
Implementation of monomials.
Definition: monomial.hpp:69
bool verifyAndModifyIfNecessary(LP_Solver *skel, const list< Abstract_Polynomial *> &currentPolys)
int hilbertCmp(const Dense_Univariate_Integer_Polynomial &hn1, const Dense_Univariate_Rational_Polynomial &hp1, const Dense_Univariate_Integer_Polynomial &hn2, const Dense_Univariate_Rational_Polynomial &hp2)
const Monomial & getPP() const
the leading monomial being added to the ideal
void ConstraintsForNewPP(const PPWithIdeal &pp_I, const set< Monomial > &monomialsForComparison, vector< constraint > &result)
quick-’n-dirty Dense_Univariate rational polynomial class
Monomial t
the last monomial added to
int degOfNewPairs() const
the degree of the new critical pairs generated by adding the monomial to the ideal ...
int max_deg
minimum weighted degree of monomials in ideal
::ray ordering
the current ordering of the Gröbner basis computation
a ray defined by nonnegative coordinates
Definition: lp_solver.hpp:190