igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] Longest path calculation complains about negative edge weights


From: Ananya Muddukrishna
Subject: [igraph] Longest path calculation complains about negative edge weights
Date: Tue, 19 Nov 2013 19:52:44 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0

Hi,

I am trying to get the longest path between nodes "S" and "E" as shown below. The get.shortest.paths function fails complaining about negative edge weights.
Please help me sort the problem.

> rm(list=ls())
>
> g <- graph.empty(directed=TRUE) + vertices(c("S", "A", "B", "C", "E"))
>
> g[from="S", to="A", attr="weight"] <- 0
> g[from="S", to="B", attr="weight"] <- 0
> g[from="S", to="C", attr="weight"] <- 0
> g[from="A", to="E", attr="weight"] <- -300
> g[from="B", to="E", attr="weight"] <- -200
> g[from="C", to="E", attr="weight"] <- -100
>
> plot(g)
>
> V(g)
Vertex sequence:
[1] "S" "A" "B" "C" "E"
> E(g)
Edge sequence:

[1] S -> A
[2] S -> B
[3] S -> C
[4] A -> E
[5] B -> E
[6] C -> E
> cbind(E(g), E(g)$weight)
     [,1] [,2]
[1,]    1    0
[2,]    2    0
[3,]    3    0
[4,]    4 -300
[5,]    5 -200
[6,]    6 -100
>
> s_index <- which(V(g)$name == "S")
> e_index <- which(V(g)$name == "E")
> p <- get.shortest.paths(g, from=s_index, to=e_index, mode="out", output="both") Error in get.shortest.paths(g, from = s_index, to = e_index, mode = "out", : At structural_properties.c:5220 : Weight vector must be non-negative, Invalid value
>
> print("Longest path")
[1] "Longest path"
> V(g)[unlist(p$vpath)]
Error in unlist(p$vpath) : object 'p' not found
> E(g)[unlist(p$epath)]
Error in unlist(p$epath) : object 'p' not found
>
> warnings()
Warning messages:
1: In max(nchar(el)) : no non-missing arguments to max; returning -Inf
2: In format.default(el[, 1], width = w) : NAs introduced by coercion
> version
               _
platform       x86_64-unknown-linux-gnu
arch           x86_64
os             linux-gnu
system         x86_64, linux-gnu
status
major          3
minor          0.2
year           2013
month          09
day            25
svn rev        63987
language       R
version.string R version 3.0.2 (2013-09-25)
nickname       Frisbee Sailing

Best regards,
Ananya

--
Ananya Muddukrishna
Ph.D. student
KTH Royal Institute of Technology
http://www.kth.se/profile/ananya/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]