Skip to content

Integrating igraph_get_k_shortest_paths with python-igraph#577

Merged
ntamas merged 20 commits intoigraph:masterfrom
sombreslames:master
Oct 11, 2022
Merged

Integrating igraph_get_k_shortest_paths with python-igraph#577
ntamas merged 20 commits intoigraph:masterfrom
sombreslames:master

Conversation

@sombreslames
Copy link
Copy Markdown
Contributor

Hello,
This merge request aims to render available within python-igraph the C function igraph_get_k_shortest_paths with python-igraph.

@iosonofabio
Copy link
Copy Markdown
Member

There you go!

Let's see if it passes CI. Il give you a few suggestions after that, but it generally looks pretty good 😊

@sombreslames
Copy link
Copy Markdown
Contributor Author

I did some last update for correct typing should be a bit better.
Where do I write the python doc however ?

@iosonofabio
Copy link
Copy Markdown
Member

We're getting there. Two suggestions:

  1. CI currently segfaults, take a look and let me know if you want me to check your code
  2. Line 14202 and following are the Python docstring. We can polish it once CI passes and the code itself is polished. The lines above the function declaration are internal documentation, that is useful for future us when we will forget what that function does 😋

Correcting call to get_k_shortest_paths
@szhorvat
Copy link
Copy Markdown
Member

We should set up AddressSanitizer runs for py-igraph so it's easier to track down these crashes.

@sombreslames
Copy link
Copy Markdown
Contributor Author

Shall I split the test to better identify the error ?
I could also try to install the testing framework. However I have windows, I could try it on docker.

@ntamas
Copy link
Copy Markdown
Member

ntamas commented Sep 30, 2022

I think the reason for the CI failures is the call to igraph_vs_destroy(&to), where to is an igraph_integer_t and not an igraph_vs_t. I guess this was accidentally copied from a function that supported using multiple target vertices (and hence used an igraph_vs_t as the type of to and not an igraph_integer_t).

@ntamas ntamas marked this pull request as ready for review September 30, 2022 11:00
@ntamas ntamas marked this pull request as draft September 30, 2022 11:00
@ntamas
Copy link
Copy Markdown
Member

ntamas commented Sep 30, 2022

Sorry, I did not mean to mark it as ready for review without your approval, I just accidentally clicked on it.
CI is running again.

@ntamas
Copy link
Copy Markdown
Member

ntamas commented Sep 30, 2022

Now this seems interesting:

>>> g = Graph.Lattice([5, 5], circular=False)
>>> sps = sorted(g.get_k_shortest_paths(6, 0, 12))
igraph._igraph.InternalError: Error at src/misc/other.c:368: Edge IDs do not form a continuous path. -- Invalid value

igraph_get_k_shortest_paths() priamrily works with edge IDs; if you ask for a path consisting of vertex IDs, it attempts to convert the sequence of edge IDs in the obtained path to vertex IDs. The error indicates that there could be a bug in the C core; we'll need to investigate this separately.

@sombreslames
Copy link
Copy Markdown
Contributor Author

Ok, no more segfault, just a test that does not work. I will investigate but it seems curious.

@sombreslames
Copy link
Copy Markdown
Contributor Author

Now this seems interesting:

>>> g = Graph.Lattice([5, 5], circular=False)
>>> sps = sorted(g.get_k_shortest_paths(6, 0, 12))
igraph._igraph.InternalError: Error at src/misc/other.c:368: Edge IDs do not form a continuous path. -- Invalid value

igraph_get_k_shortest_paths() priamrily works with edge IDs; if you ask for a path consisting of vertex IDs, it attempts to convert the sequence of edge IDs in the obtained path to vertex IDs. The error indicates that there could be a bug in the C core; we'll need to investigate this separately.

Ok, do you need anything from me now?
I am afraid that investing the issue in the C core is a bit out of my abilities.
Thanks for the help anyway and have a good day.

@ntamas
Copy link
Copy Markdown
Member

ntamas commented Sep 30, 2022

I will take a look at this issue to see if it's reproducible in the C core (without going through Python), and then report back here.

@szhorvat
Copy link
Copy Markdown
Member

It may be a good test in the C core to compare this function with igraph_get_all_simple_paths(), and make sure they give the same result. This is only possible in the unweighted case.

@szhorvat
Copy link
Copy Markdown
Member

We should set up AddressSanitizer runs for py-igraph so it's easier to track down these crashes.

This is in fact set up already. In fact I contributed to setting it up, but I forgot ...

@ntamas
Copy link
Copy Markdown
Member

ntamas commented Oct 7, 2022

The bug that triggered the igraph._igraph.InternalError in the tests should now be fixed in the latest version of the C core. I have brought the PR up-to-date with master; let's see if the tests pass now.

@ntamas
Copy link
Copy Markdown
Member

ntamas commented Oct 8, 2022

Getting close now! :) A few minor comments from my end:

  • I'd rather prefer the order of arguments to be v, to, k, weights and mode. This is because a reasonable default value for k is 1, and you cannot put arguments with default values in front of arguments without default arguments, so k has to come after to.
  • I'd like to have an output parameter for get_k_shortest_paths, similarly to how it works for get_shortest_paths, for sake of consistency. output must be "vpath" if the user wants vertex IDs in the result and "epath" if the user wants edge IDs. The default is "vpath". I have refactored the handling of this argument from igraphmodule_Graph_get_shortest_paths() into a separate function so you only need to call the same function from igraphmodule_Graph_get_k_shortest_paths() to achieve the same thing.

Let me know if you don't have time to fix these in the next few days; I'm aiming for a new release early next week and it would be nice to get this into the next release, so if you are busy with other things, I will take care of it on my own.

@ntamas ntamas linked an issue Oct 8, 2022 that may be closed by this pull request
lferrari added 2 commits October 10, 2022 08:56
Changing order of arg of get_k_shortest_path(v,to,k,weights,mode,output)
@sombreslames
Copy link
Copy Markdown
Contributor Author

I changed the order ofthe arg, set K by default to 1 and added the output arg

@sombreslames sombreslames marked this pull request as ready for review October 10, 2022 08:16
@ntamas
Copy link
Copy Markdown
Member

ntamas commented Oct 10, 2022

Made a few changes here and there; I'll merge this tomorrow if the CI tests pass.

@ntamas ntamas merged commit cf8370b into igraph:master Oct 11, 2022
@ntamas
Copy link
Copy Markdown
Member

ntamas commented Oct 11, 2022

Thanks a lot for your contribution!

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

Successfully merging this pull request may close these issues.

get_k_shortest_paths availability in python-graph

4 participants