diff options
Diffstat (limited to 'common.py')
-rwxr-xr-x | common.py | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/common.py b/common.py new file mode 100755 index 0000000..411867b --- /dev/null +++ b/common.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +from itertools import combinations + +def increment(dictionary, key): + dictionary[key] = dictionary.get(key, 0) + 1 + +def print_dict(dictionary): + keys = sorted(list(dictionary.keys())) + for key in keys: + print(key, dictionary[key]) + +def distribution(counts, capset, num): + combs = tuple(combinations(range(counts["dim"]), num)) + num_i = len(combs) + num_j = 3**num + dists = [[0 for j in range(num_j)] + for i in range(num_i)] + for card in capset: + for i, indices in enumerate(combs): + substr = "".join(card[indices[n]] for n in range(num)) + j = int(substr, 3) + dists[i][j] += 1 + metadist = {} + for i in range(num_i): + dists[i] = "".join(map(str, sorted(dists[i]))) + name = "dist" + str(num) + ":" + dists[i] + increment(counts, name) + increment(metadist, name) + if counts["premeta" + str(num)]: + z = tuple(zip(*counts["premeta" + str(num)].items())) + else: + z = ([],[]) + if metadist in z[1]: + key = z[0][z[1].index(metadist)] + else: + key = len(z[0]) + counts["premeta" + str(num)][key] = metadist + name = "premeta" + str(num) + ":" + str(key) + increment(counts, name) + +def metadistribution(counts, num): + dists = tuple(sorted(key for key in counts.keys() + if key.startswith("dist" + str(num)))) + for key in counts["premeta" + str(num)]: + count = counts["premeta" + str(num) + ":" + str(key)] + metadist = counts["premeta" + str(num)][key] + newstr = "".join(str(metadist.get(dist, 0)) for dist in dists) + counts["meta" + str(num) + ":" + newstr] = count + for key in counts.copy(): + if key.startswith("premeta" + str(num)): + del counts[key] + +def main(): + capsets = [] + capset_file = open("capset.out", "r") + for line in capset_file: + capsets.append(line[1:-2].split(" ")) + capset_file.close() + + counts = {"count" : 0, + "dim" : len(capsets[0][0])} + nums = range(1, counts["dim"]) + for num in nums: + counts["premeta" + str(num)] = {} + for capset in capsets: + counts["count"] += 1 + for num in nums: + distribution(counts, capset, num) + for num in nums: + metadistribution(counts, num) + print_dict(counts) + +if __name__ == "__main__": main() |