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

distances() ignores 'mode' when algorithm='johnson' #571

Closed
szhorvat opened this issue Sep 10, 2022 · 2 comments · Fixed by #628
Closed

distances() ignores 'mode' when algorithm='johnson' #571

szhorvat opened this issue Sep 10, 2022 · 2 comments · Fixed by #628
Milestone

Comments

@szhorvat
Copy link
Member

Describe the bug

The distances() function ignores the mode parameter when algorithm='johnson' because igraph_distances_johnson() does not support setting the mode: igraph/igraph#2193

This can lead to confusion and invalid results.

I suggest that when algorithm='johnson' and mode != 'all' for undirected or mode != 'out' for directed an error should be thrown.

To reproduce

> g<-make_graph(c(1,2,2,1,2,3))
> distances(g)
     [,1] [,2] [,3]
[1,]    0    1    2
[2,]    1    0    1
[3,]    2    1    0
> distances(g, algorithm='dijkstra')
     [,1] [,2] [,3]
[1,]    0    1    2
[2,]    1    0    1
[3,]    2    1    0
> distances(g, algorithm='johnson')
     [,1] [,2] [,3]
[1,]    0    1    2
[2,]    1    0    1
[3,]  Inf  Inf    0

Notice that since the default mode is 'all', the graph is treated as undirected by both the default algorithm and Dijkstra. But with Johnson it is unexpectedly treated as directed.

Version information

  • R/igraph version: 1.3.4
@szhorvat szhorvat added this to the 1.3.6 milestone Sep 10, 2022
@szhorvat
Copy link
Member Author

BTW I find it very strange that the default mode is all and not out. I would expect the function to respect the directedness of the graph by default. But this is not something we can change unfortunately.

@ntamas
Copy link
Member

ntamas commented Sep 12, 2022

7a34b43 now throws an error when Johnson's algorithm would be invoked with mode="in" or mode="all" (and forces the mode to be "out" for the undirected case).

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

Successfully merging a pull request may close this issue.

2 participants