Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path Information #9

Open
srkankdr opened this issue Oct 16, 2019 · 2 comments
Open

Path Information #9

srkankdr opened this issue Oct 16, 2019 · 2 comments

Comments

@srkankdr
Copy link

srkankdr commented Oct 16, 2019

Hello,

I have created a simple graph by using a distance matrix.
Below you can find the code.

from dijkstar import Graph, find_path
matrix = ...... (distance matrix is created here)
graph = Graph()
for i in range(size):
    for j in range(size):
        graph.add_edge(i, j, {'cost': matrix[i][j]})        
cost_func = lambda u, v, e, prev_e: e['cost']
path = find_path(graph, 0, 6, cost_func=cost_func)
path

My question is, how am I able to learn the details of the founded path. There is a total cost, but I want to learn with which order of nodes I will get this cost. I want to learn the optimal order of nodes.

Thank you.

@srkankdr
Copy link
Author

I suppose the problem may be related to the cost function that I used. I directly coppied from the documentation and I couldn't understand the usage of it.

@wylee
Copy link
Owner

wylee commented Oct 16, 2019

find_path() returns a PathInfo object that has nodes, edges, costs, total_cost attributes, so you can access the ordered nodes with path.nodes.

Regarding the cost function, you don't need it if you're not dynamically computing costs. You could change your code to the following:

from dijkstar import Graph, find_path
matrix = ...... (distance matrix is created here)
graph = Graph()
for i in range(size):
    for j in range(size):
        graph.add_edge(i, j, matrix[i][j])
path = find_path(graph, 0, 6)
path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants