Blog Archives

Calculating all paths between any two nodes in a graph

[sourcecode language="python"] /usr/bin/python import networkx as nx from collections import deque import matplotlib.pyplot as plt g=nx.MultiGraph() g.add_edge(1,2) g.add_edge(1,3) g.add_edge(1,5) g.add_edge(2,1) g.add_edge(2,3) g.add_edge(2,4) g.add_edge(3,4) g.add_edge(4,3) g.add_edge(5,6) g.add_edge(5,4) g.add_edge(6,3) g.add_edge(8,9) path_queue=deque() def BFS(graph,start,end,q): temp_path = [start] q.append(temp_path) while len(q)>0: tmp_path = q.popleft()

Tagged with:
Posted in Uncategorized