shortest path outputs not properly

Bug #490166 reported by masashi hashimoto
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
igraph
Invalid
High
Gábor Csárdi

Bug Description

Hi,

sp function outputs paths of node 3 - 1- 7 with weight of 16
but
path 3 - 4 - 7 has only weight of 5

is there any problem in my code ?

-------------code-------------------------------------------------------------------------------------------------------------

library(igraph)
#edge list
d <- data.frame(matrix(c( "2","1", "1","2", "2","0", "0","2", "3","2", "2","3", "3","1", "1","3", "4","3", "3","4", "4","0", "0","4", "5","0", "0","5", "5","3", "3","5", "6","5", "5","6", "6","1", "1","6", "7","1", "1","7", "7","4", "4","7", "8","7", "7","8", "8","1", "1","8", "9","1", "1","9", "9","2", "2","9", "0","7", "7","0", "0","1", "1","0", "1","5", "5","1"),nc=2,byrow=TRUE),stringsAsFactors=FALSE)
colnames(d) <- c("from","to")
#node list
vers <- data.frame(c("0","1","2","3","4","5","6","7","8","9"),stringsAsFactors=FALSE)
#create graph
g <- graph.data.frame(d,directed=TRUE,vertices=vers)
#weight
w1 <- c(3, 1, 8, 6, 2, 7, 8, 3, 3, 3, 7, 8, 1, 4, 3, 3, 1, 4, 8, 3, 1, 8, 6, 2, 7, 8, 3, 3, 3, 7, 8, 1, 4, 3, 3, 1, 4, 8)
E(g)$weight <- w1
#shortest path
sp <- get.shortest.paths(g,from=3,to=7)
sp
 c(c(d[[1]][7], d[[2]][7]),c(d[[1]][22],c(d[[2]][22])))
 E(g)$weight[[7]]+E(g)$weight[[22]]
 c(c(d[[1]][10], d[[2]][10]),c(d[[1]][24],c(d[[2]][24])))
 E(g)$weight[[10]]+E(g)$weight[[24]]

Revision history for this message
Gábor Csárdi (gabor.csardi) wrote :

You should use mode="out" if you want a directed path.

> get.shortest.paths(g, from=3, to=7, mode="out")
[[1]]
[1] 3 4 7

I agree that
- this is confusing
- it should be the default
- it should work properly, even if one uses mode="all"

So this is a bug.

Changed in igraph:
importance: Undecided → High
status: New → Confirmed
Revision history for this message
Gábor Csárdi (gabor.csardi) wrote :

OK, it turns out that this is actually not really a bug. If you use mode="all", then edge directions are ignored, and there is a path 3-1-7, that has total weight 4. This is why you got that answer.

I have changed the default to mode="out", tought, in revision #1718 (0.6-main branch).

Changed in igraph:
status: Confirmed → Invalid
assignee: nobody → Gábor Csárdi (gabor.csardi)
Revision history for this message
Gábor Csárdi (gabor.csardi) wrote :

And of course thanks for the report!

Revision history for this message
Gábor Csárdi (gabor.csardi) wrote : Continue on github

The development of igraph has moved to github, so please do not comment on this bug here. You are of course welcome to comment on github, here:
https://github.com/igraph/igraph/issues/56

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.