-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_example.py
More file actions
48 lines (34 loc) · 1.47 KB
/
Copy pathsample_example.py
File metadata and controls
48 lines (34 loc) · 1.47 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
48
from src.certifier import strongly_separates
def unify_edges(edges: list[tuple[int, int]]):
"""
Ensures that there are no duplicated or reversed duplicated edges in the edge list.
Given a list of edges, this function removes duplicates by treating an edge (u, v)
as identical to (v, u). The resulting list contains only one representative of each
undirected edge.
"""
edges_set = set()
for (vertex1, vertex2) in edges:
if (vertex1, vertex2) in edges_set or (vertex2, vertex1) in edges_set:
continue
edges_set.add((vertex1, vertex2))
return list(map(list, edges_set))
def build_system(edges: list[tuple[int, int]]):
"""
Builds a separator system where each path is a single edge.
For each edge in the input list, this function creates a trivial path consisting
of the two endpoints of that edge. The resulting system uses the set of edges
itself as the separator system.
"""
paths = []
for (a, b) in edges:
paths.append([a, b])
return paths
if __name__ == "__main__":
raw_edges = [(a, b) for a in range(4) for b in range (4) if a != b]
K_4 = unify_edges(raw_edges)
separating_path_system = build_system(K_4)
# “Checks whether the edge set of K_4 itself separates it.”
is_separated = strongly_separates(K_4, separating_path_system)
print("Correctly separates!\n")
print(f"{'Separating System:':<20}{separating_path_system}")
print(f"{'Graph:':<20}{K_4}")