Giter Club home page Giter Club logo

shortestpaths's People

Contributors

thanasismattas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mavisval

shortestpaths's Issues

list index out of range exception on Eppstein's graph

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.
rendered_graph
Is it a bug or am I doing something wrong?

incorrect number of paths found?

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.