igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] shortest paths in a undirected weighted graph


From: Gábor Csárdi
Subject: Re: [igraph] shortest paths in a undirected weighted graph
Date: Thu, 7 Oct 2010 10:54:16 +0200

Federico,

this is implemented in the coming 0.6 version of igraph, you can
download a snapshot of the R package, that has it from here:
http://code.google.com/p/igraph/downloads/detail?name=igraph_nightly_0.6-2030-20100726.tar.gz

Best Regards,
Gabor

On Wed, Oct 6, 2010 at 11:42 PM, federico vaglio
<address@hidden> wrote:
> Hi to all,
> is there a way to get all shortest paths, not just lengths, between two
> vertices in a undirected weighted graph?
>
> get.shortest.paths function has "weights" argument but gives only one
> shortest path, even if more than one shortest path exist between given
> vertices.
>
> get.all.shortest.paths function returns all possible shortest paths but
> ignores edge weights, even if passed graph has a weight attribute.
>
> How to get the best of both ?
>
>
> Thank you in advance
>
> Example code.
>
> require(igraph)
>
> # create a graph with 5 vertices
> g <- graph.empty(5, dir=FALSE)
>
> # add edges
> g <- add.edges(g, c(0, 1, 0, 2, 0, 3, 1, 4, 2, 4, 3, 4))
>
> # edge weigths
> E(g)$weight <- c(1, 1, 2, 1, 1, 1)
>
> # use weights but return only one path
> get.shortest.paths(g, from=0, to=4)
>
> #
> # my result
> #[[1]]
> #[1] 0 2 4
>
>
> # return all shortes paths but ignore weights
> get.all.shortest.paths(g, from=0, to=4)
>
> #
> # my result
> #[[1]]
> #[1] 0 3 4
> #
> #[[2]]
> #[1] 0 2 4
> #
> #[[3]]
> #[1] 0 1 4
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>
>



-- 
Gabor Csardi <address@hidden>     UNIL DGM



reply via email to

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