torressa / cspy

A collection of algorithms for the (Resource) Constrained Shortest Path problem in Python / C++ / C#
https://torressa.github.io/cspy/
MIT License
77 stars 24 forks source link

BiDirectional: Example doesn't work as intended #25

Closed cabje15 closed 4 years ago

cabje15 commented 4 years ago

In the example:

from cspy import BiDirectional from networkx import DiGraph from numpy import array G = DiGraph(directed=True, n_res=2) G.add_edge("Source", "A", res_cost=array([1, 2]), weight=0) G.add_edge("A", "B", res_cost=array([1, 0.3]), weight=0) G.add_edge("A", "C", res_cost=array([1, 0.1]), weight=0) G.add_edge("B", "C", res_cost=array([1, 3]), weight=-10) G.add_edge("B", "Sink", res_cost=array([1, 2]), weight=10) G.add_edge("C", "Sink", res_cost=array([1, 10]), weight=0) max_res, min_res = [4, 20], [1, 0] bidirec = BiDirectional(G, max_res, min_res, direction="both") bidirec.run() print(bidirec.path)

The result should be:

["Source", "A", "B", "C", "Sink"]

But it is: ['Source', 'A', 'C', 'Sink']

cabje15 commented 4 years ago

When I run the code many times in I got both:

['Source', 'A', 'B', 'C', 'Sink'] ['Source', 'A', 'C', 'Sink'] ['Source', 'A', 'B', 'Sink']

Apparently it does not consequently return ['Source', 'A', 'B', 'C', 'Sink']

torressa commented 4 years ago

Cheers for the bug @cabje15 ! I'll look into it!

torressa commented 4 years ago

I've been digging into it. Depending on the sequence directions in which the algorithm moves the algorithm ends up providing different final paths. I've implemented a path joining algorithm and performed a more robust test against this. It seems to work, unfortunately there's a conflict with the examples with cycles (tests_issue17.py). I'll finish up and commit changes tomorrow most likely

torressa commented 4 years ago

Didn't manage unfortunately, I'll commit onto a new branch

torressa commented 4 years ago

I think it's fixed. Closing for now.