souffle  2.0.2-371-g6315b36
Public Member Functions | Static Public Member Functions | Protected Member Functions
souffle::ast::SipsMetric Class Referenceabstract

Class for SIPS cost-metric functions Each subclass represents a different heuristic used for evaluating the cost of choosing an atom next in the schedule. More...

#include <SipsMetric.h>

Inheritance diagram for souffle::ast::SipsMetric:
Inheritance graph
Collaboration diagram for souffle::ast::SipsMetric:
Collaboration graph

Public Member Functions

std::vector< unsigned int > getReordering (const Clause *clause) const
 Determines the new ordering of a clause after the SIPS is applied. More...
 
virtual ~SipsMetric ()=default
 

Static Public Member Functions

static std::unique_ptr< SipsMetriccreate (const std::string &heuristic, const TranslationUnit &tu)
 Create a SIPS metric based on a given heuristic. More...
 

Protected Member Functions

virtual std::vector< double > evaluateCosts (const std::vector< Atom * > atoms, const BindingStore &bindingStore) const =0
 Evaluates the cost of choosing each atom next in the current schedule. More...
 

Detailed Description

Class for SIPS cost-metric functions Each subclass represents a different heuristic used for evaluating the cost of choosing an atom next in the schedule.

Definition at line 39 of file SipsMetric.h.

Constructor & Destructor Documentation

◆ ~SipsMetric()

virtual souffle::ast::SipsMetric::~SipsMetric ( )
virtualdefault

Member Function Documentation

◆ create()

std::unique_ptr< SipsMetric > souffle::ast::SipsMetric::create ( const std::string &  heuristic,
const TranslationUnit tu 
)
static

Create a SIPS metric based on a given heuristic.

Definition at line 68 of file SipsMetric.cpp.

93  {
94  // Goal: Always choose the left-most atom
95  std::vector<double> cost;
96  for (const auto* atom : atoms) {

◆ evaluateCosts()

virtual std::vector<double> souffle::ast::SipsMetric::evaluateCosts ( const std::vector< Atom * >  atoms,
const BindingStore bindingStore 
) const
protectedpure virtual

Evaluates the cost of choosing each atom next in the current schedule.

Parameters
atomsatoms to choose from; may be nullptr
bindingStorethe variables already bound to a value

Implemented in souffle::ast::DeltaInputSips, souffle::ast::InputSips, souffle::ast::DeltaSips, souffle::ast::ProfileUseSips, souffle::ast::LeastFreeVarsSips, souffle::ast::LeastFreeSips, souffle::ast::MaxRatioSips, souffle::ast::MaxBoundSips, souffle::ast::NaiveSips, souffle::ast::AllBoundSips, and souffle::ast::StrictSips.

Referenced by getReordering().

◆ getReordering()

std::vector< unsigned int > souffle::ast::SipsMetric::getReordering ( const Clause clause) const

Determines the new ordering of a clause after the SIPS is applied.

Parameters
clauseclause to reorder
Returns
the vector of new positions; v[i] = j iff atom j moves to pos i

Definition at line 39 of file SipsMetric.cpp.

39  {
40  // grab the index of the next atom, based on the SIPS function
41  const auto& costs = evaluateCosts(atoms, bindingStore);
42  auto minIdx = std::distance(costs.begin(), std::min_element(costs.begin(), costs.end()));
43  const auto* nextAtom = atoms[minIdx];
44  assert(nextAtom != nullptr && "nullptr atoms should have maximal cost");
45 
46  // set all arguments that are variables as bound
47  for (const auto* arg : nextAtom->getArguments()) {
48  if (const auto* var = dynamic_cast<const Variable*>(arg)) {
49  bindingStore.bindVariableStrongly(var->getName());
50  }
51  }
52 
53  newOrder[numAdded] = minIdx; // add to the ordering
54  atoms[minIdx] = nullptr; // mark as done
55  numAdded++; // move on
56  }
57 
58  return newOrder;
59 }
60 
61 /** Create a SIPS metric based on a given heuristic. */
62 std::unique_ptr<SipsMetric> SipsMetric::create(const std::string& heuristic, const TranslationUnit& tu) {
63  if (heuristic == "strict")
64  return std::make_unique<StrictSips>();
65  else if (heuristic == "all-bound")

References evaluateCosts().

Here is the call graph for this function:

The documentation for this class was generated from the following files:
souffle::ast::SipsMetric::create
static std::unique_ptr< SipsMetric > create(const std::string &heuristic, const TranslationUnit &tu)
Create a SIPS metric based on a given heuristic.
Definition: SipsMetric.cpp:68
souffle::ast::SipsMetric::evaluateCosts
virtual std::vector< double > evaluateCosts(const std::vector< Atom * > atoms, const BindingStore &bindingStore) const =0
Evaluates the cost of choosing each atom next in the current schedule.