21 #ifndef _GRINGO_SAFETYCHECK_HH
22 #define _GRINGO_SAFETYCHECK_HH
25 #include <forward_list>
26 #include <unordered_map>
32 template <
class Var,
class Ent>
51 typedef std::vector<EntNode*>
EntVec;
52 typedef std::vector<VarNode*>
VarVec;
72 template <
class Pred = std::less<Ent>>
84 template <
class Var,
class Ent>
87 : data(std::forward<T>(args)...)
94 template <
class Var,
class Ent>
97 : data(std::forward<T>(args)...)
104 template <
class Var,
class Ent>
107 template <
class Var,
class Ent>
110 template <
class Var,
class Ent>
116 template <
class Var,
class Ent>
121 template <
class Var,
class Ent>
122 template <
class... T>
124 varNodes_.emplace_front(std::forward<T>(args)...);
128 template <
class Var,
class Ent>
129 template <
class... T>
131 entNodes_.emplace_front(std::forward<T>(args)...);
135 template <
class Var,
class Ent>
136 template <
class Pred>
140 std::vector<EntNode*> done;
141 while (!open.empty()) {
142 for (
auto it = open.begin(),
end = open.end() - 1; it !=
end; ++it) {
143 if (
pred((*it)->data, open.back()->data)) {
std::swap(open.back(), *it); }
145 auto x = open.back();
148 done.emplace_back(
x);
153 template <
class Var,
class Ent>
156 if (!
x.depends) { open.emplace_back(&
x); }
160 template <
class Var,
class Ent>
165 if (bound) { bound->emplace_back(y); }
166 for (
auto &z : y->provides) {
167 if (!--z->depends) { open.emplace_back(z); }
173 template <
class Var,
class Ent>
177 if (!
x.bound) { open.emplace_back(&
x); }
186 #endif // _GRINGO_SAFETYCHECK_HH
void init(EntVec &open)
Definition: safetycheck.hh:154
EntVec order(Pred pred=Pred())
EntNode(T &&...args)
Definition: safetycheck.hh:96
std::vector< EntNode * > EntVec
Definition: safetycheck.hh:51
Definition: safetycheck.hh:35
unsigned depends
Definition: safetycheck.hh:47
VarNode & insertVar(T &&...args)
void propagate(EntNode *x, EntVec &open, VarVec *bound=nullptr)
Definition: safetycheck.hh:161
EntNode & insertEnt(T &&...args)
void swap(Literal &l, Literal &r)
Definition: literal.h:188
uint32 Var
A variable is currently nothing more but an integer in the range [0..varMax).
Definition: literal.h:42
std::vector< VarNode * > VarVec
Definition: safetycheck.hh:52
Definition: safetycheck.hh:43
void insertEdge(VarNode &x, EntNode &y)
Definition: safetycheck.hh:111
std::vector< EntNode * > provides
Definition: safetycheck.hh:39
Ent data
Definition: safetycheck.hh:48
std::forward_list< VarNode > varNodes_
Definition: safetycheck.hh:77
bool bound
Definition: safetycheck.hh:38
Bound & bound
Definition: output.cc:122
std::forward_list< EntNode > entNodes_
Definition: safetycheck.hh:76
VarVec open()
Definition: safetycheck.hh:174
VarNode(T &&...args)
Definition: safetycheck.hh:86
int x
Definition: utility.cc:65
std::vector< VarNode * > provides
Definition: safetycheck.hh:46
Definition: safetycheck.hh:33
Var data
Definition: safetycheck.hh:40
int end
Definition: literals.cc:62