40 static const char* staticGetName() {
41 return Pred::staticGetName();
45 virtual void doOrder(Ideal& ideal)
const {
48 stable_sort(ideal.
begin(), ideal.
end(), pred);
54 static const char* staticGetName() {
return "random";}
57 using result_type = unsigned;
58 static constexpr unsigned min() {
return 0; }
59 static constexpr unsigned max() {
return RAND_MAX; }
60 unsigned operator()()
const {
return std::rand(); }
62 void doOrder(Ideal& ideal)
const {
64 std::shuffle(ideal.
begin(), ideal.
end(), g);
70 static const char* staticGetName() {
return "tdeg";}
72 virtual bool doPredicate(
const Exponent* a,
78 mutable mpz_class _degA;
79 mutable mpz_class _degB;
84 static const char* staticGetName() {
return "median";}
86 virtual bool doPredicate(
const Exponent* a,
88 return median(a, getVarCount()) <
median(b, getVarCount());
94 static const char* staticGetName() {
return "posMedian";}
96 virtual bool doPredicate(
const Exponent* a,
105 static const char* staticGetName() {
return "minPos";}
107 virtual bool doPredicate(
const Exponent* a,
116 static const char* staticGetName() {
return "max";}
118 virtual bool doPredicate(
const Exponent* a,
126 static const char* staticGetName() {
return "support";}
128 virtual bool doPredicate(
const Exponent* a,
137 static const char* staticGetName() {
return "strongGenericity";}
140 void orderGenericity(Ideal& ideal,
bool strong)
const {
150 for (cit a = ideal.
begin(); a != ideal.
end(); ++a) {
151 for (cit b = a + 1; b != ideal.
end(); ++b) {
164 Pred pred(degeneracy);
165 stable_sort(ideal.
begin(), ideal.
end(), pred);
170 typedef map<const Exponent*, size_t> UnGenMap;
172 virtual void doOrder(Ideal& ideal)
const {
173 orderGenericity(ideal,
true);
178 Pred(UnGenMap& degeneracy): _degeneracy(degeneracy) {}
181 return _degeneracy[a] < _degeneracy[b];
185 UnGenMap& _degeneracy;
191 static const char* staticGetName() {
return "null";}
193 virtual void doOrder(Ideal& ideal)
const {}
197 class WeakGenericityOrderer :
public StrongGenericityOrderer {
199 static const char* staticGetName() {
return "weakGenericity";}
201 virtual void doOrder(Ideal& ideal)
const {
202 orderGenericity(ideal,
false);
210 ReverseOrderer(unique_ptr<IdealOrderer> orderer): _orderer(std::move(orderer)) {}
213 virtual void doOrder(Ideal& ideal)
const {
217 reverse(ideal.
begin(), ideal.
end());
218 _orderer->order(ideal);
219 reverse(ideal.
begin(), ideal.
end());
221 unique_ptr<IdealOrderer> _orderer;
226 CompositeOrderer(): _orderersDeleter(_orderers) {}
228 void refineOrderingWith(unique_ptr<IdealOrderer> orderer) {
233 typedef vector<IdealOrderer*> Container;
234 typedef Container::const_reverse_iterator rev_cit;
236 virtual void doOrder(Ideal& ideal)
const {
240 rev_cit rbegin(_orderers.end());
241 rev_cit rend(_orderers.begin());
242 for (rev_cit it = rbegin; it != rend; ++it)
247 ElementDeleter<Container> _orderersDeleter;
251 OrdererFactory getOrdererFactory() {
252 OrdererFactory factory(
"ordering of terms");
270 unique_ptr<IdealOrderer> createNonCompositeOrderer(
const string& prefix) {
271 if (prefix.substr(0, 3) ==
"rev") {
272 unique_ptr<IdealOrderer> orderer =
274 return unique_ptr<IdealOrderer>(
new ReverseOrderer(std::move(orderer)));
281 if (prefix.find(
'_') == string::npos)
282 return createNonCompositeOrderer(prefix);
284 unique_ptr<CompositeOrderer> composite(
new CompositeOrderer());
287 size_t nextUnderscore = prefix.find(
'_', pos);
288 string subPrefix = prefix.substr(pos, nextUnderscore - pos);
289 composite->refineOrderingWith(createNonCompositeOrderer(subPrefix));
291 if (nextUnderscore == string::npos)
293 pos = nextUnderscore + 1;
295 return unique_ptr<IdealOrderer>(composite.release());
void exceptionSafePushBack(Container &container, unique_ptr< Element > pointer)
unique_ptr< IdealOrderer > createIdealOrderer(const string &prefix)
void nameFactoryRegister(NameFactory< AbstractProduct > &factory)
Registers the string returned by ConcreteProduct::getStaticName() to a function that default-construc...
unique_ptr< AbstractProduct > createWithPrefix(const NameFactory< AbstractProduct > &factory, const string &prefix)
Creates the unique product that has the indicated prefix, or create the actual product that has name ...
Cont::const_iterator const_iterator
bool strictlyContains(const Exponent *term) const
const_iterator end() const
const_iterator begin() const
size_t getVarCount() const
A NameFactory takes a name and then creates an instance of a class that has been previously registere...
size_t getSizeOfSupport() const
static bool sharesNonZeroExponent(const Exponent *a, const Exponent *b, size_t varCount)
Returns whether there is some such that .
This header file includes common definitions and is included as the first line of code in every imple...