-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
47 lines (39 loc) · 1.25 KB
/
Copy pathconfig.py
File metadata and controls
47 lines (39 loc) · 1.25 KB
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
from math import factorial
from itertools import permutations
# n = 2 # number of voters
# v = 3 # number of vertices
# g = 2**(v**2) # number of total directed graphs
# e = v**2 # number of possible directed edges
def compute_r(g,n):
return g**n
class config:
n = 3 # number of voters
v = 3 # number of vertices
g = 2**(v**2) # number of total directed graphs
e = v**2 # number of possible directed edges
r = compute_r(g, v)
graphs = list()
def update_g(g, internal=False):
print(f"Updating config.g := {g}")
if g != len(config.graphs) and not internal:
print(f"Warning: Requested update does not match internal state!")
print(f"\tRequested update: g={g}, number of graphs saved: len(config.graphs=){len(config.graphs)}")
config.g = g
config.r = compute_r(g, config.n)
def update_graphs(graphs):
print("Updating config.graphs")
config.graphs = graphs
config.update_g(len(config.graphs), internal=True)
def __new__(cls, *args, **kw):
if not hasattr(cls, '_instance'):
orig = super(config, cls)
cls._instance = orig.__new__(cls, *args, **kw)
return cls._instance
if __name__ == '__main__':
print(config.g)
print(config.r)
config.update_g(3)
print(config.g)
print(config.r)
graphs = [1,2,3,4]
config.update_graphs(graphs)