-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithm4.py
More file actions
52 lines (38 loc) · 1.06 KB
/
algorithm4.py
File metadata and controls
52 lines (38 loc) · 1.06 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
49
50
51
52
from cyclic import is_cyclic
from graphGenerator import graph_generator
from visualization import benchmark
from visualization import nc, diameter
import networkx as nx
from visualization import benchmark
from algorithm import algorithm1
G = nx.MultiDiGraph()
def make_weighted(G):
add = []
for u in G.edges():
try:
k = add.index(u)
a, b, w = add[k]
w += 1
add[k] = (a, b, w)
except:
add.append((u[0], u[1], 1))
G = nx.DiGraph()
G.add_weighted_edges_from(add)
@benchmark
def algorithm4(G):
T = nx.MultiDiGraph()
for u in G.edges():
if not(u[0] in T.nodes() and u[1] in T.nodes()):
T.add_edge(u[0], u[1])
G.remove_edges_from(T.edges())
for u in G.edges():
T.add_edge(u[0], u[1])
if is_cyclic(T) == 'Graph is cyclic':
T.remove_edge(u[0], u[1])
return T
if __name__ == '__main__':
G = graph_generator()
#G = algorithm4(G)
print(G.number_of_edges())
make_weighted(G)
print(G.number_of_edges())