You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Draft: connecting components without taking the same path
import random
import matplotlib.pyplot as plt
import networkx as nx
import tqdm
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]
if __name__ == '__main__':
G = nx.grid_2d_graph(100, 100)
H = G.copy()
I = nx.Graph()
paths = {}
for i in tqdm.tnrange(10):
node_list = [n for n in G.nodes()]
chuncks = [c for c in chunks(node_list, int(len(node_list) / 4))]
u = random.choice(chuncks[0])
v = random.choice(chuncks[3])
paths[i] = nx.shortest_path(G, u, v)
edges = list(zip(paths[i], paths[i][1:] + paths[i][:1]))
# G.remove_edges_from(edges)
G.remove_nodes_from(paths[i])
I.add_edges_from(edges[:-1])
pos_h = {n: n for n in H.nodes}
pso_i = {n: n for n in I.nodes}
fig, ax = plt.subplots(1, 1, figsize=(20, 20))
nx.draw_networkx_nodes(H, pos_h, arrows=False, with_labels=False,
node_size=1)
nx.draw_networkx_edges(I, pso_i, edge_color='r')
plt.show()
Imagine that at the end of those lines is a TRNSYS component. The point grid is there to show the available paths.:
Draft: connecting components without taking the same path
Imagine that at the end of those lines is a TRNSYS component. The point grid is there to show the available paths.:
Originally posted by @samuelduchesne in #11 (comment)
The text was updated successfully, but these errors were encountered: