-
Notifications
You must be signed in to change notification settings - Fork 2
/
p5editing.cc
130 lines (121 loc) · 3.5 KB
/
p5editing.cc
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
/* tinygraph -- exploring graph conjectures on small graphs
Copyright (C) 2015 Falk Hüffner
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
#include "Graph.hh"
Set findP5(const Graph& g) {
int n = g.n();
for (int u = 0; u < n; ++u) {
for (int v : g.neighbors(u)) {
for (int w : g.neighbors(v)) {
if (w == u || g.hasEdge(w, u))
continue;
for (int x : g.neighbors(w)) {
if (g.hasEdge(x, v) || g.hasEdge(x, u))
continue;
for (int y : g.neighbors(x)) {
if (y < u || g.hasEdge(y, w) || g.hasEdge(y, v) || g.hasEdge(y, u))
continue;
return {u, v, w, x, y};
}
}
}
}
}
return {};
}
Set verticesInP5s(const Graph& g) {
Set r;
int n = g.n();
for (int u = 0; u < n; ++u) {
for (int v : g.neighbors(u)) {
for (int w : g.neighbors(v)) {
if (w == u || g.hasEdge(w, u))
continue;
for (int x : g.neighbors(w)) {
if (g.hasEdge(x, v) || g.hasEdge(x, u))
continue;
for (int y : g.neighbors(x)) {
if (y < u || g.hasEdge(y, w) || g.hasEdge(y, v) || g.hasEdge(y, u))
continue;
r |= {u, v, w, x, y};
}
}
}
}
}
return r;
}
std::vector<std::pair<int, int>>* p5EditingBranch(Graph& g, int k) {
if (k < 0)
return nullptr;
Set p5 = findP5(g);
if (p5.isEmpty())
return new std::vector<std::pair<int, int>>();
for (Set e : p5.combinations(2)) {
int u = e.pop();
int v = e.pop();
g.toggleEdge(u, v);
auto s = p5EditingBranch(g, k - 1);
if (s) {
s->push_back({u, v});
return s;
}
g.toggleEdge(u, v);
}
return nullptr;
}
std::vector<std::pair<int, int>> p5Editing(const Graph& g0) {
Graph g = g0;
for (int k = 0; ; ++k) {
auto ps = p5EditingBranch(g, k);
if (ps) {
auto s = *ps;
delete ps;
return s;
}
}
}
int main() {
double max_f = 0;
for (int n = 1; n <= MAXN; ++n) {
double max_f_n = 0;
std::cerr << "--- n = " << n << std::endl;
Graph::enumerate(n, [&max_f, &max_f_n](const Graph& g) {
Set vs = g.vertices() - verticesInP5s(g);
if (!vs.isEmpty()) {
auto s = p5Editing(g);
for (int u : vs) {
Graph g2 = g;
g2.deleteVertex(u);
auto s2 = p5Editing(g2);
if (s.size() != s2.size()) {
std::cout << "Found counterexample:" << std::endl
<< g << std::endl
<< "Optimal solution of size " << s.size() << ':' << std::endl;
for (auto p : s)
std::cout << p.first << '\t' << p.second << std::endl;
std::cout << std::endl << "Vertex " << u << " is not contained in any P5." << std::endl
<< "After deleting " << u << ", optimal solution has size "
<< s2.size() << ':' << std::endl;
for (auto p : s2) {
auto v2 = [u](int v) { return v < u ? v : v + 1; };
std::cout << v2(p.first) << '\t' << v2(p.second) << std::endl;
}
exit(0);
}
}
}
}, Graph::CONNECTED);
}
return 0;
}