COrderingFacade.h
Go to the documentation of this file.
// -*- c++ -*-
//*****************************************************************************
//*****************************************************************************
#ifndef polybori_orderings_COrderingFacade_h_
#define polybori_orderings_COrderingFacade_h_
// include basic definitions
#include <polybori/pbori_defs.h>
#include <polybori/BoolePolynomial.h>
#include <polybori/BooleMonomial.h>
#include <polybori/BooleExponent.h>
#include "COrderingBase.h"
#include "COrderingTags.h"
#include <polybori/iterators/COrderedIter.h>
// include ordering tags
#include <polybori/common/tags.h>
#include "order_traits.h"
// include polybori functionals
#include <polybori/routines/pbori_func.h>
BEGIN_NAMESPACE_PBORI
template <class OrderType, class OrderTag>
class COrderingFacade:
public COrderingBase,
public COrderingTags<OrderTag>, public order_traits<OrderTag> {
typedef COrderingFacade self;
typedef COrderingBase base_type;
public:
typedef self base;
typedef OrderType order_type;
typedef CCacheTypes::lead_tag<OrderTag> order_lead_tag;
typedef COrderingTags<OrderTag> ordering_tags;
COrderingFacade():
base_type() { }
COrderingFacade(const self& rhs):
base_type(rhs) { }
~COrderingFacade() { }
poly_type leadFirst(const poly_type& poly) const {
if(orderedStandardIteration())
return poly;
else
return lead(poly);
}
bool_type isLexicographical() const {
return is_valid<typename ordering_tags::lex_property>::result;
}
bool_type orderedStandardIteration() const {
return is_valid<typename ordering_tags::ordered_property>::result;
}
bool_type isSymmetric() const {
return is_valid<typename ordering_tags::symmetry_property>::result;
}
bool_type isDegreeOrder() const {
return is_valid<typename ordering_tags::degorder_property>::result;
}
bool_type isBlockOrder() const {
return is_valid<typename ordering_tags::blockorder_property>::result;
}
bool_type isTotalDegreeOrder() const {
return is_valid<typename ordering_tags::totaldegorder_property>::result;
}
bool_type isDegreeReverseLexicographical() const {
return is_valid<typename ordering_tags::degrevlexorder_property>::result;
}
bool_type ascendingVariables() const {
return is_valid<typename ordering_tags::ascending_property>::result;
}
bool_type descendingVariables() const {
return is_valid<typename ordering_tags::descending_property>::result;
}
ordercode_type getOrderCode() const {
return order_traits<OrderTag>::order_code;
}
ordercode_type getBaseOrderCode() const {
return order_traits<OrderTag>::baseorder_code;
}
bool_type lieInSameBlock(idx_type first, idx_type second) const {
return inSameBlockInternal(first, second,
typename ordering_tags::blockorder_property());
}
idx_type lastBlockStart() const {
if (isBlockOrder()) {
return *(blockEnd() - 2);
}
else if (isLexicographical()) {
return CTypes::max_idx;
}
return 0;
}
// Initialize iterator corresponding to leading term
ordered_iterator
leadIteratorBegin(const poly_type& poly) const {
return CGenericOrderedIter<order_type, navigator,
monom_type>(poly.navigation(), poly.ring());
}
ordered_iterator
leadIteratorEnd(const poly_type& poly) const {
return CGenericOrderedIter<order_type, navigator, monom_type>(navigator(), poly.ring());
}
// Initialize iterator corresponding to leading term
ordered_exp_iterator
leadExpIteratorBegin(const poly_type& poly) const {
return CGenericOrderedIter<order_type, navigator, exp_type>(poly.navigation(), poly.ring());
}
ordered_exp_iterator
leadExpIteratorEnd(const poly_type& poly) const {
return CGenericOrderedIter<order_type, navigator, exp_type>(navigator(), poly.ring());
}
protected:
bool_type inSameBlockInternal(idx_type, idx_type,
invalid_tag) const { // not a block order
return true;
}
bool_type inSameBlockInternal(idx_type first, idx_type second,
valid_tag) const { // is block order
// todo: throw here if first,second >=CTypes::max_idx
if(PBORI_UNLIKELY(first > CTypes::max_idx || second > CTypes::max_idx ||
first < 0 || second < 0))
throw std::runtime_error("Variable index out of range.");
if (second < first)
std::swap(first, second);
block_iterator upper(blockBegin());
while (first >= *upper) // Note: convention, last element is max_idx
++upper;
return (second < *upper);
}
};
END_NAMESPACE_PBORI
#endif