forked from nicholasRenninger/dfasat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconflict_graph.cpp
194 lines (167 loc) · 4.29 KB
/
conflict_graph.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include "conflict_graph.h"
void apta_graph::add_conflicts(state_merger &merger){
for(node_set::iterator it = nodes.begin(); it != nodes.end(); ++it){
graph_node* left = *it;
node_set::iterator next_it = it;
next_it++;
for(node_set::iterator it2 = next_it;
it2 != nodes.end();
++it2){
graph_node* right = *it2;
refinement* ref = merger.test_merge(left->anode, right->anode);
if(ref != 0){
left->neighbors.insert(right);
right->neighbors.insert(left);
}
}
}
}
apta_graph::apta_graph(state_set &states){
for(state_set::iterator it = states.begin(); it != states.end(); ++it){
nodes.insert(new graph_node(*it));
}
}
graph_node::graph_node(apta_node* an){
anode = an;
}
void apta_graph::remove_edges(int size){
node_set to_remove;
for(node_set::iterator it = nodes.begin(); it != nodes.end(); ++it){
if((*it)->neighbors.size() < size)
to_remove.insert(*it);
}
for(node_set::iterator it = to_remove.begin(); it != to_remove.end(); ++it){
nodes.erase(*it);
for(node_set::iterator it2 = (*it)->neighbors.begin(); it2 != (*it)->neighbors.end(); ++it2){
(*it2)->neighbors.erase(*it);
}
}
}
node_set *apta_graph::find_clique_converge() {
int size = 0;
while(true){
node_set* result = find_clique();
if(result->size() > size){
remove_edges( result->size() );
size = result->size();
} else {
return result;
}
}
}
node_set *apta_graph::find_clique(){
node_set* result = new node_set();
if( nodes.empty() ) return result;
graph_node* head = NULL;
int max_degree = -1;
for(node_set::iterator it = nodes.begin();
it != nodes.end();
++it){
graph_node* n = *it;
if((int)n->neighbors.size() > max_degree){
max_degree = n->neighbors.size();
head = n;
}
}
result->insert(head);
node_set intersection = (*head).neighbors;
max_degree = -1;
for(node_set::iterator it = nodes.begin();
it != nodes.end();
++it){
graph_node* n = *it;
if((int)n->neighbors.size() > max_degree){
max_degree = n->neighbors.size();
head = n;
}
}
while(!intersection.empty()){
result->insert(head);
intersection.erase(head);
node_set new_intersection = node_set(intersection);
for(node_set::iterator it = intersection.begin();
it != intersection.end();
++it){
graph_node* keep = *it;
if(head->neighbors.find(keep) == head->neighbors.end()){
new_intersection.erase(keep);
}
}
intersection = new_intersection;
int best_match = -1;
for(node_set::iterator it = intersection.begin();
it != intersection.end();
++it){
graph_node* current = *it;
int match = 0;
for(node_set::iterator it2 = intersection.begin();
it2 != intersection.end();
++it2){
if(current->neighbors.find(*it2) != current->neighbors.end()){
match++;
}
}
if(match > best_match){
best_match = match;
head = current;
}
}
}
return result;
}
/*
node_set *apta_graph::find_bipartite(){
node_set* result = new node_set();
if( nodes.empty() ) return result;
graph_node* head = NULL;
int max_degree = -1;
for(node_set::iterator it = nodes.begin(); it != nodes.end(); ++it){
graph_node* n = *it;
if((int)n->neighbors.size() > max_degree){
max_degree = n->neighbors.size();
head = n;
}
}
result->insert(head);
node_set intersection = (*head).neighbors;
max_degree = -1;
for(node_set::iterator it = nodes.begin(); it != nodes.end(); ++it){
graph_node* n = *it;
if((int)n->neighbors.size() > max_degree){
max_degree = n->neighbors.size();
head = n;
}
}
while(!intersection.empty()){
result->insert(head);
intersection.erase(head);
node_set new_intersection = node_set(intersection);
for(node_set::iterator it = intersection.begin(); it != intersection.end(); ++it){
graph_node* keep = *it;
if(head->neighbors.find(keep) == head->neighbors.end()){
new_intersection.erase(keep);
}
}
intersection = new_intersection;
int best_match = -1;
for(node_set::iterator it = intersection.begin();
it != intersection.end();
++it){
graph_node* current = *it;
int match = 0;
for(node_set::iterator it2 = intersection.begin();
it2 != intersection.end();
++it2){
if(current->neighbors.find(*it2) != current->neighbors.end()){
match++;
}
}
if(match > best_match){
best_match = match;
head = current;
}
}
}
return result;
}
*/