igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] shortest path calculation


From: Thiago M. Venancio
Subject: Re: [igraph] shortest path calculation
Date: Fri, 30 Jan 2009 12:02:32 -0500

Please find the file b.txt attached.

No spaces after the edges. File edited using emacs.

Below is the code to reproduce my observation. If you do not use the weights=FALSE, it assumes zero, as it is in the documentation.  As you said, the other functions do not support weights and automatically assume 1, even if the ncol loads the weights as zero. My problem is that I got a bit confused with this. Now it is pretty clear.

Thanks for your help in this matter.

Thiago

> t = read.graph("b.txt", format="ncol", weights=FALSE)
> t
Vertices: 4
Edges: 3
Directed: FALSE
Edges:

[0] a -- b
[1] b -- c
[2] c -- d
> shortest.paths(t)
     [,1] [,2] [,3] [,4]
[1,]    0    1    2    3
[2,]    1    0    1    2
[3,]    2    1    0    1
[4,]    3    2    1    0

> t = read.graph("b.txt", format="ncol")

> shortest.paths(t)
     [,1] [,2] [,3] [,4]
[1,]    0    0    0    0
[2,]    0    0    0    0
[3,]    0    0    0    0
[4,]    0    0    0    0


On Fri, Jan 30, 2009 at 11:52 AM, Gábor Csárdi <address@hidden> wrote:
On Fri, Jan 30, 2009 at 5:45 PM, Thiago M. Venancio
<address@hidden> wrote:
> Thanks Gabor !
> It worked.
> My toy file is simple:
>
> #=======
> a b
> b c
> c d
> #=======

Sorry, but that is still not good enough, there might be spaces after
the edges and the 'ncol' reader might interpret these as weights
(which would be a bug). Anyway, I will check this, but it is a lot
easier if you provide ALL information to reproduce the error.

> The interesting point is that the shortest.paths function does not work
> without assigning the weights=FALSE, but the average.path.length and
> path.length.hist work without any problems. Since they are related, I was
> just wondering what is different in how they handle the data.

The latter two don't support edge weights.

G.

> Best,
>
> Thiago
>
> On Fri, Jan 30, 2009 at 11:40 AM, Gábor Csárdi <address@hidden> wrote:
>>
>> Hmmm, again I cannot be sure what happens, because I haven't seen your
>> file. Anyway, giving 'weights=FALSE' to read.graph should solve the
>> problem.
>>
>> G.
>>
>> On Fri, Jan 30, 2009 at 5:37 PM, Thiago M. Venancio
>> <address@hidden> wrote:
>> > Hi Gabor,
>> > You got it right. There is no weight in the file. Assigning one does the
>> > trick.
>> > My graph is unweighted, is there any way to assign 1 during the file
>> > reading
>> > or do I have to change the file to include an useless column with ones ?
>> > Thank you very much.
>> > Thiago
>> >
>> > On Fri, Jan 30, 2009 at 11:33 AM, Gábor Csárdi <address@hidden>
>> > wrote:
>> >>
>> >> Impossible to tell for sure without knowing what is in the file "b".
>> >> My guess is that all edges have weight zero, but can be something
>> >> else.
>> >>
>> >> G.
>> >>
>> >> On Fri, Jan 30, 2009 at 5:30 PM, Thiago M. Venancio
>> >> <address@hidden> wrote:
>> >> > Hi,
>> >> >
>> >> > I am experiencing some problems in calculating the shortest path
>> >> > length
>> >> > matrix. Note that it is giving zeroes for all the cells, even when
>> >> > vertices
>> >> > are connected.
>> >> > I noticed the V() function return indexes in the indexes and in my
>> >> > graph
>> >> > return quoted numbers. Explicitly telling the indexes also does not
>> >> > solve
>> >> > the problem.
>> >> > The example in the documentation is working. I do not know what is
>> >> > the
>> >> > problem in my code.
>> >> > Below is a toy example.
>> >> >
>> >> > Thanks.
>> >> >
>> >> > Thiago
>> >> >
>> >> > test = read.graph("b", format="ncol", names=T)
>> >> >> test
>> >> > Vertices: 4
>> >> > Edges: 3
>> >> > Directed: FALSE
>> >> > Edges:
>> >> >
>> >> > [0] a -- b
>> >> > [1] b -- c
>> >> > [2] c -- d
>> >> >
>> >> >> shortest.paths(test)
>> >> >      [,1] [,2] [,3] [,4]
>> >> > [1,]    0    0    0    0
>> >> > [2,]    0    0    0    0
>> >> > [3,]    0    0    0    0
>> >> > [4,]    0    0    0    0
>> >> >
>> >> >> shortest.paths(test,v=1:2)
>> >> >      [,1] [,2] [,3] [,4]
>> >> > [1,]    0    0    0    0
>> >> > [2,]    0    0    0    0
>> >> >
>> >> >
>> >> >
>> >> > _______________________________________________
>> >> > igraph-help mailing list
>> >> > address@hidden
>> >> > http://lists.nongnu.org/mailman/listinfo/igraph-help
>> >> >
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> Gabor Csardi <address@hidden>     UNIL DGM
>> >>
>> >>
>> >> _______________________________________________
>> >> igraph-help mailing list
>> >> address@hidden
>> >> http://lists.nongnu.org/mailman/listinfo/igraph-help
>> >
>> >
>> >
>> >
>> > _______________________________________________
>> > igraph-help mailing list
>> > address@hidden
>> > http://lists.nongnu.org/mailman/listinfo/igraph-help
>> >
>> >
>>
>>
>>
>> --
>> Gabor Csardi <address@hidden>     UNIL DGM
>>
>>
>> _______________________________________________
>> igraph-help mailing list
>> address@hidden
>> http://lists.nongnu.org/mailman/listinfo/igraph-help
>
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>
>



--
Gabor Csardi <address@hidden>     UNIL DGM


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


Attachment: b.txt
Description: Text document


reply via email to

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