-
Notifications
You must be signed in to change notification settings - Fork 0
/
redmonds2.py
52 lines (39 loc) · 987 Bytes
/
redmonds2.py
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
import networkx as nx
import matplotlib.pyplot as plt
from utils import obtener_digrafo_parcial_minimo, contraer
nodes = [0, 1, 2, 3, 4, 5, 6, 7]
edges = [
(0, 1, 3),
(1, 3, 1),
(2, 1, 1),
(3, 2, 1),
(3, 4, 1),
(4, 5, 2),
(5, 6, 1),
(7, 5, 1),
(6, 7, 1),
(6, 1, 2),
]
# Creamos grafo
G = nx.DiGraph()
G.add_nodes_from(nodes)
G.add_weighted_edges_from(edges)
Gs = [G]
Hs = []
s = 0
while True:
H = obtener_digrafo_parcial_minimo(Gs[-1])
Hs.append(H)
ciclos = list(nx.simple_cycles(H))
if ciclos:
Gss = contraer(Gs[-1], H, ciclos[0], s)
Gs.append(Gss)
s += 1
continue
print('NO MORE CICLOS BITCH')
break
pos = nx.spring_layout(Gs[-1])
nx.draw_networkx_edge_labels(Gs[-1], pos, edge_labels=nx.get_edge_attributes(Gs[-1], 'weight'))
nx.draw(Gs[-1], pos, with_labels=True, node_color='skyblue', node_size=700, edge_color='k', linewidths=1, font_size=15)
plt.tight_layout()
plt.show()