carl  24.04
Computer ARithmetic Library
GroebnerExample.cpp
Go to the documentation of this file.
1 #include <vector>
2 #include <sstream>
3 
5 #include "groebner/katsura.h"
6 #include "groebner/cyclic.h"
9 
10 using namespace carl;
11 const static int MAX_KATSURA = 5;
12 const static int MAX_CYCLIC = 3;
13 
14 template <typename C, typename O, typename P>
16 {
17  GbBenchmark(const std::string& n, const std::vector<MultivariatePolynomial<C, O, P>>& pols)
18  {
19  name = n;
20  polynomials = pols;
21  }
22 
23  std::string name;
24  std::vector<MultivariatePolynomial<C, O, P>> polynomials;
25 };
26 
27 template<typename C, typename O, typename P>
28 std::ostream& operator<<(std::ostream& os, const GbBenchmark<C, O, P>& b)
29 {
30  return os << b.name << ": " << b.polynomials << ". ";
31 }
32 
33 template<typename C, typename O, typename P>
36 
37  static std::vector<GbBenchmark<C, O, P>> loadBenchmarks()
38  {
39  std::vector<GbBenchmark<C, O, P>> res;
40  bool verbose = true;
41  for(unsigned index = 2; index <= MAX_KATSURA; index++)
42  {
43  std::stringstream name;
44  name << " Katsura " << index;
45  std::cout << "Load benchmark: " << name.str() << std::endl;
46  res.push_back(GbBenchmark<C, O, P>(name.str(), carl::benchmarks::katsura<C, O, P>(index)));
47  if(verbose) {
48  std::cout << res.back() << std::endl;
49  }
50 
51 
52  }
53 
54  for(unsigned index = 2; index <= MAX_CYCLIC; index++)
55  {
56  std::stringstream name;
57  name << " Cyclic " << index;
58  std::cout << "Load benchmark: " << name.str() << std::endl;
59  res.push_back(GbBenchmark<C, O, P>(name.str(), carl::benchmarks::cyclic<C, O, P>(index)));
60  if(verbose) {
61  std::cout << res.back() << std::endl;
62  }
63  }
64  return res;
65 
66  }
67 
68  static std::vector<AbstractGBProcedure<Polynomial>*> loadGbProcedures()
69  {
70  std::vector<AbstractGBProcedure<Polynomial>*> res;
72  return res;
73  }
74 };
75 
76 template<typename C, typename O, typename P>
77 int execute(std::ostream& os = std::cout)
78 {
79  std::vector<GbBenchmark<C, O, P>> benchmarksets = ExecuteBenchmarks<C, O, P>::loadBenchmarks();
80  std::vector<AbstractGBProcedure<MultivariatePolynomial<C, O, P>>*> procedures = ExecuteBenchmarks<C, O, P>::loadGbProcedures();
81 
82  for(const auto& b : benchmarksets)
83  {
84  os << "Running benchmark: " << b.name << std::endl;
85  int pCount = 0;
86  for(auto & p : procedures)
87  {
88  pCount++;
89  os << "\tProcedure: " << pCount << "/" << procedures.size() << std::endl;
90  os << "\t\t Adding .. \n";
91  os.flush();
92  carl::Timer timer;
93  for(const auto& pol : b.polynomials)
94  {
95  std::cout << pol << std::endl;
96  p->addPolynomial(pol);
97  }
98  os << timer << std::endl;
99  os << "\t\t Reducing .. \n";
100  os.flush();
101  timer.reset();
102  p->reduceInput();
103  os << timer << std::endl;
104  os << "\t\t Calculating .. \n";
105  os.flush();
106  timer.reset();
107  p->calculate();
108  os << timer << std::endl;
109  os << "\t\t Done .. \n";
110  }
111  }
112 
113  for(auto & p : procedures)
114  {
115  delete p;
116  }
117  return 0;
118 
119 }
120 
121 int main (int, char** )
122 {
123  #ifdef USE_CLN_NUMBERS
124  execute<cln::cl_RA, GrLexOrdering, StdMultivariatePolynomialPolicies<NoReasons, NoAllocator>>();
125  #else
126  execute<mpq_class, GrLexOrdering, StdMultivariatePolynomialPolicies<NoReasons, NoAllocator>>();
127  #endif
128 
129 }
int main(int, char **)
static const int MAX_KATSURA
static const int MAX_CYCLIC
int execute(std::ostream &os=std::cout)
carl is the main namespace for the library.
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
A general class for Groebner Basis calculation.
Definition: GBProcedure.h:46
The general-purpose multivariate polynomial class.
This classes provides an easy way to obtain the current number of milliseconds that the program has b...
Definition: Timer.h:18
void reset() noexcept
Reset the start point to now.
Definition: Timer.h:40
std::vector< MultivariatePolynomial< C, O, P > > polynomials
GbBenchmark(const std::string &n, const std::vector< MultivariatePolynomial< C, O, P >> &pols)
std::string name
static std::vector< AbstractGBProcedure< Polynomial > * > loadGbProcedures()
static std::vector< GbBenchmark< C, O, P > > loadBenchmarks()
MultivariatePolynomial< C, O, P > Polynomial