igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Bug in get.shortest.paths?


From: Gábor Csárdi
Subject: Re: [igraph] Bug in get.shortest.paths?
Date: Wed, 23 Jan 2013 09:33:17 -0500

Thanks, this is a known bug, it was fixed in our development tree. Here is a workaround function:

get.shortest.paths <- function(graph, from, to=V(graph),
                               mode=c("out", "all", "in"),
                               weights=NULL,
                               output=c("vpath", "epath", "both")) {

  if (!is.igraph(graph)) {
    stop("Not a graph object")
  }
  mode <- igraph:::igraph.match.arg(mode)
  mode <- switch(mode, "out"=1, "in"=2, "all"=3)
  ooutput <- igraph:::igraph.match.arg(output)
  output <- switch(ooutput, "vpath"=0, "epath"=2, "both"=2)

  if (is.null(weights)) {
    if ("weight" %in% list.edge.attributes(graph)) {
      weights <- as.numeric(E(graph)$weight)
    }
  } else {
    if (length(weights)==1 && is.na(weights)) {
      weights <- NULL
    } else {
      weights <- as.numeric(weights)
    }
  }
  
  to <- igraph:::as.igraph.vs(graph, to)-1
  on.exit( .Call("R_igraph_finalizer", PACKAGE="igraph") )
  res <- .Call("R_igraph_get_shortest_paths", graph,
               igraph:::as.igraph.vs(graph, from)-1, to, as.numeric(mode),
               as.numeric(length(to)),
               weights, as.numeric(output), PACKAGE="igraph")

  if (output !=2 ) {
    res <- lapply(res, function(x) x+1)
  } else {
    res <- list(vpath=lapply(res$vpath, function(x) x+1),
                epath=lapply(res$epath, function(x) x+1))
  }
  if (ooutput == "epath") { res$epath } else { res }
}

Thanks, Best,
Gabor


On Wed, Jan 23, 2013 at 3:45 AM, David Edwards <address@hidden> wrote:

I cant get get.shortest.paths() to work when I set output=”epath”:

 

g <- graph.tree(25, children = 2, mode="out")

get.shortest.paths(g, 1, output="vpath") # works ok

get.shortest.paths(g, 1, output="epath") # gives error

 

 

Best regards

David

 


_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help




--
Gabor Csardi <address@hidden>     MTA KFKI RMKI

reply via email to

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