thanasismattas / shortestpaths Goto Github PK
View Code? Open in Web Editor NEWBidirectional k-shortest paths with DP
License: GNU General Public License v3.0
Bidirectional k-shortest paths with DP
License: GNU General Public License v3.0
Hi, thank you for your code. I get a list index out of range exception (prio peek on empty queue) in the following code:
import networkx as nx
import shortestpaths as sp
def create_pos_weighted_graph():
'''this is the graph from Eppstein's paper Figure 1 (a)'''
graph = nx.DiGraph() # Directed Graph
for i in range(3):
for j in range(4):
graph.add_node((i, j), index=(i, j), name=(i, j))
edges = []
edges.append(((0, 0), (0, 1), 2))
edges.append(((0, 0), (1, 0), 13))
edges.append(((0, 1), (0, 2), 20))
edges.append(((0, 1), (1, 1), 27))
edges.append(((0, 2), (0, 3), 14))
edges.append(((0, 2), (1, 2), 14))
edges.append(((0, 3), (1, 3), 15))
edges.append(((1, 0), (1, 1), 9))
edges.append(((1, 0), (2, 0), 15))
edges.append(((1, 1), (1, 2), 10))
edges.append(((1, 1), (2, 1), 20))
edges.append(((1, 2), (1, 3), 25))
edges.append(((1, 2), (2, 2), 12))
edges.append(((1, 3), (2, 3), 7))
edges.append(((2, 0), (2, 1), 18))
edges.append(((2, 1), (2, 2), 8))
edges.append(((2, 2), (2, 3), 11))
# edges.append(((2,3), (0,0),50)) # this egde makes a cycle
graph.add_weighted_edges_from(edges)
return graph, (0, 0), (2, 3)
G, s, t = create_pos_weighted_graph()
k_paths = sp.k_shortest_paths(G, s, t, 5)
print("k_paths:")
sp.print_paths(k_paths)
sp.plot_paths(k_paths, G)
G is a DAG and should have 10 paths from (0,0) to (2,3).
Exception ocurs after 1st path found.
Is it a bug or am I doing something wrong?
I want to input my own data generate from networkx, maybe you can add an parameter for the options
Sorry to bother you again.
Using the Eppstein graph of #3 and sp.__version__='1.1.3'
with a call like
G, s, t = create_pos_weighted_graph()
k_paths = sp.k_shortest_paths(G, s, t, 20)
print("k_paths:")
sp.print_paths(k_paths)
I get 7 paths printed:
path 1: [(0, 0), (1, 0), (1, 1), (1, 2), (2, 2), (2, 3)] cost: 55
path 2: [(0, 0), (0, 1), (0, 2), (0, 3), (1, 3), (2, 3)] cost: 58
path 3: [(0, 0), (0, 1), (0, 2), (1, 2), (2, 2), (2, 3)] cost: 59
path 4: [(0, 0), (1, 0), (1, 1), (2, 1), (2, 2), (2, 3)] cost: 61
path 5: [(0, 0), (0, 1), (1, 1), (1, 2), (2, 2), (2, 3)] cost: 62
path 6: [(0, 0), (1, 0), (2, 0), (2, 1), (2, 2), (2, 3)] cost: 65
path 7: [(0, 0), (0, 1), (1, 1), (2, 1), (2, 2), (2, 3)] cost: 68
But, there are 10 paths in the DAG:
found path #1 of length 55: [(0, 0), (1, 0), (1, 1), (1, 2), (2, 2), (2, 3)]
found path #2 of length 58: [(0, 0), (0, 1), (0, 2), (0, 3), (1, 3), (2, 3)]
found path #3 of length 59: [(0, 0), (0, 1), (0, 2), (1, 2), (2, 2), (2, 3)]
found path #4 of length 61: [(0, 0), (1, 0), (1, 1), (2, 1), (2, 2), (2, 3)]
found path #5 of length 62: [(0, 0), (0, 1), (1, 1), (1, 2), (2, 2), (2, 3)]
found path #6 of length 64: [(0, 0), (1, 0), (1, 1), (1, 2), (1, 3), (2, 3)]
found path #7 of length 65: [(0, 0), (1, 0), (2, 0), (2, 1), (2, 2), (2, 3)]
found path #8 of length 68: [(0, 0), (0, 1), (0, 2), (1, 2), (1, 3), (2, 3)]
found path #9 of length 68: [(0, 0), (0, 1), (1, 1), (2, 1), (2, 2), (2, 3)]
found path #10 of length 71: [(0, 0), (0, 1), (1, 1), (1, 2), (1, 3), (2, 3)]
Why are some paths missing?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.