-
Notifications
You must be signed in to change notification settings - Fork 2
/
count-table.cc
114 lines (101 loc) · 3.48 KB
/
count-table.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
/* tinygraph -- exploring graph conjectures on small graphs
Copyright (C) 2019 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 <ctime>
#include <map>
#include <set>
#include <iostream>
#include "Classes.hh"
#include "Invariants.hh"
#include "EulerTransform.hh"
using PropertyTest = std::function<bool(const Graph&)>;
const auto invariant = [](const Graph& g) { return Invariants::coloringNumber(g); };
const bool connectedOnly = true;
int n0 = 1;
int k0 = 2;
template<typename T>
std::vector<std::vector<T>> cumulativeCounts(const std::vector<std::vector<T>>& counts) {
std::vector<std::vector<T>> cumulativeCounts(counts.size());
for (std::size_t n = 0; n < counts.size(); ++n) {
T sum = 0;
for (const auto& count : counts[n]) {
sum += count;
cumulativeCounts[n].push_back(sum);
}
}
return cumulativeCounts;
}
template<typename T>
void output(const std::vector<std::vector<T>>& counts) {
int maxk = 0;
for (const auto& ks : counts)
maxk = std::max(maxk, int(ks.size() + 1));
if (counts.empty())
return;
for (int k = k0; k <= maxk; ++k) {
for (int n = n0; n < int(counts.size()); ++n) {
if (n > n0)
std::cout << ", ";
const auto x = k < int(counts[n].size()) ? counts[n][k] : 0;
std::cout << x;
}
std::cout << std::endl;
}
bool first = true;
for (int n = n0; n < int(counts.size()); ++n) {
for (int k = k0 + (n - n0) - 1; k >= k0; --k) {
if (!first)
std::cout << ", ";
first = false;
const auto x = k < int(counts[n].size()) ? counts[n][k] : 0;
std::cout << x;
}
}
std::cout << std::endl;
}
int main() {
std::vector<std::vector<uint64_t>> counts;
std::vector<double> times;
for (int n = n0; ; ++n) {
auto tStart = double(std::clock()) / CLOCKS_PER_SEC;
std::cerr << "\n\n--- n = " << n;
if (times.size() >= 2) {
auto tn = times.back();
auto tn1 = times[times.size() - 2];
auto est = tn * (tn / tn1);
std::cerr << " estimated time: " << est << 's' << std::endl;
if (est > 1e6)
return 0;
} else {
std::cerr << std::endl;
}
counts.resize(n + 1);
auto counter = [&counts, n](const Graph& g) {
const auto k = invariant(g);
if (k >= int(counts[n].size()))
counts[n].resize(k + 1);
++counts[n][k];
};
Graph::enumerate(n, counter, connectedOnly ? Graph::CONNECTED : 0);
auto tEnd = double(std::clock()) / CLOCKS_PER_SEC;
auto t = tEnd - tStart;
times.push_back(t);
std::cerr << "time: " << t << 's' << std::endl;
std::cout << (connectedOnly ? "connected " : "") << "graphs, counts starting at n = " << n0 << ", k = " << k0 << std::endl;
output(counts);
std::cout << "\n" << (connectedOnly ? "connected " : "")
<< "graphs, cumulative counts starting at n = " << n0 << ", k = " << k0 << std::endl;
output(cumulativeCounts(counts));
}
return 0;
}