SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
ForwardHyperGraph.tpp
Go to the documentation of this file.
1 namespace smtrat {
2 
3  template<typename VertexProperty, typename EdgeProperty, bool UniqueVertices>
4  void ForwardHyperGraph<VertexProperty,EdgeProperty,UniqueVertices>::toDot(const std::string& filename) const {
5  std::ofstream out(filename);
6  out << "digraph G {" << std::endl;
7  for (Vertex v = 0; v < mVertexProperties.size(); v++) {
8  out << "\t" << v << " [label=\"" << mVertexProperties[v] << "\"];" << std::endl;
9  }
10  std::size_t edgeid = 0;
11  for (Vertex src = 0; src < mEdges.size(); src++) {
12  for (const auto& e: mEdges[src]) {
13  out << "\tedge_" << edgeid << " [label=\"" << *e << "\", shape=box];" << std::endl;
14  out << "\t" << src << " -> edge_" << edgeid << ";" << std::endl;
15  for (const auto& dest: e.out()) {
16  out << "\t" << "edge_" << edgeid << " -> " << dest << ";" << std::endl;
17  }
18  edgeid++;
19  }
20  }
21  out << "}" << std::endl;
22  out.close();
23  }
24 
25  template<typename VP, typename EP, bool UV>
26  std::ostream& operator<<(std::ostream& os, const ForwardHyperGraph<VP,EP,UV>& fhg) {
27  os << "ForwardHyperGraph:" << std::endl;
28  for (typename ForwardHyperGraph<VP,EP>::Vertex v = 0; v < fhg.mEdges.size(); v++) {
29  os << "\t" << v << " (" << fhg.mVertexProperties[v] << ")" << std::endl;
30  for (const auto& e: fhg.mEdges[v]) {
31  os << "\t\t(" << *e << ") ->";
32  for (const auto& out: e.out()) os << " " << out;
33  os << std::endl;
34  }
35  }
36  return os;
37  }
38 
39 /* ***** Pseudo-Code for the algorithm implemented below *****
40 block[v]: is vertex v blocked?
41 B[b]: list of vertices that are blocked due to vertex v
42 stack: vertices on the current path
43 
44 function unblock(v):
45  block[v] = false
46  for u in B[v]: unblock(u)
47 
48 function enumerate(src, v):
49  found = false
50  stack.push(v)
51  block[v] = true
52  for u in out(v):
53  if u = src: output stack, found = true
54  else if not block[u]:
55  if enumerate(src, u): found = true
56  if found: unblock(v)
57  else:
58  for u in out(v):
59  add v to B[u]
60  stack.pop()
61  return found
62 
63 
64 function main:
65  s = 1
66  while s < n do
67  look at subgraph induced by vertices s, ..., n
68  unblock all vertices in subgraph
69  find circuits starting from s: enumerate(s, s)
70  s++
71 */
72  template<typename FHG, typename Collector>
73  bool CycleEnumerator<FHG,Collector>::enumerate(CycleEnumerator<FHG,Collector>::Vertex src, CycleEnumerator<FHG,Collector>::Vertex v) {
74  bool found = false;
75  mVertexStack.push_back(v);
76  mBlocked[v] = true;
77  for (const auto& edge: mGraph.out(v)) {
78  for (Vertex u: edge.out()) {
79  if (u == src) {
80  mEdgeStack.push_back(edge);
81  mAborted = mCollector(mGraph, mVertexStack, mEdgeStack);
82  if (mAborted) return false;
83  found = true;
84  mEdgeStack.pop_back();
85  } else if (!mBlocked[u]) {
86  mEdgeStack.push_back(edge);
87  found = found || enumerate(src, u);
88  if (mAborted) return false;
89  mEdgeStack.pop_back();
90  }
91  }
92  }
93  if (found) unblock(v);
94  else {
95  for (const auto& edge: mGraph.out(v)) {
96  for (Vertex u: edge.out()) {
97  mBlockDependencies[u].push_back(v);
98  }
99  }
100  }
101  mVertexStack.pop_back();
102  return found;
103  }
104 
105  template<typename FHG, typename Collector>
106  bool CycleEnumerator<FHG,Collector>::findAll() {
107  mAborted = false;
108  auto n = mGraph.begin();
109  while (!mAborted && (n < mGraph.end())) {
110  for (auto m = n; m < mGraph.end(); m++) unblock(m);
111  for (auto m = mGraph.begin(); m < n; m++) mBlocked[m] = true;
112  enumerate(n, n);
113  n++;
114  }
115  return mAborted;
116  }
117 
118 }