forked from TUfischl/newdetkdecomp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuperedge.cpp
92 lines (74 loc) · 2.31 KB
/
Superedge.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <memory>
#include <list>
#include "Superedge.h"
#include "Globals.h"
list<SuperedgeSharedPtr> MySuperedges;
void Superedge::add(const HyperedgeVector &Edges, const VertexSet &Vertices)
{
for (auto e : Edges)
if (!e->isHeavy())
this->Edges.insert(e);
else
writeErrorMsg("Superedges only from normal edges.", "Superedge::add");
for (auto v : Vertices)
Hyperedge::add(v);
}
void Superedge::reduce(const VertexSet &Vertices)
{
for (auto it = this->Vertices.begin(); it != this->Vertices.end(); )
if (Vertices.find(*it) == Vertices.end())
it = this->Vertices.erase(it);
else
it++;
}
SuperedgeSharedPtr Superedge::getSuperedge(const HyperedgeVector &Edges, const VertexSet &VetComp)
{
VertexSet vertices;
SuperedgeSharedPtr sup;
bool found;
for (auto he : Edges) {
for (auto v : he->allVertices()) {
if (VetComp.find(v) != VetComp.end())
vertices.insert(v); //c collect all vertices in Edges that also occur in Vetcomp
}
}
//cout << *Edges << ";" << vertices << endl;
for (auto se : MySuperedges)
if (se->getNbrOfVertices() == vertices.size()) {
found = true;
for (auto it = se->allVertices().begin(); it != se->allVertices().end() && found; it++)
if ((*it)->getLabel() != -1 || VetComp.find(*it) == VetComp.end()) //c QUESTION what's the meaning of label -1 here?
found = false;
if (found) //c Contains right amount of vertices, and only edges in Edges
return se;
}
string name = "SE";
name += to_string(MySuperedges.size() + 1);
sup = std::make_shared<Superedge>(name);
sup->add(Edges,vertices);
MySuperedges.push_back(sup);
return sup;
}
void Superedge::setAllLabels(int label) const
{
Hyperedge::setAllLabels(label);
for (auto e : Edges)
e->setLabel(label);
}
std::ostream & operator<<(std::ostream & stream, const std::shared_ptr<Superedge>& super)
{
stream << "Superedge: ";
for (auto v_it = super->Vertices.begin(); v_it != super->Vertices.end();) {
stream << (*v_it)->getName();
v_it++;
if (v_it != super->Vertices.end()) cout << ",";
}
stream << "(";
for (auto e_it = super->Edges.begin(); e_it != super->Edges.end();) {
stream << (*e_it)->getName();
e_it++;
if (e_it != super->Edges.end()) cout << ",";
}
stream << ")";
return stream;
}