[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Re: working with weighted networks (from pajek .net)
From: |
Gábor Csárdi |
Subject: |
Re: [igraph] Re: working with weighted networks (from pajek .net) |
Date: |
Thu, 2 Sep 2010 12:20:36 +0200 |
On Thu, Sep 2, 2010 at 12:17 PM, Martin Tomko <address@hidden> wrote:
> Hi Gabor,
> thanks for the answer. I have in the meantime focused on the first sollution
> you proposed (but am afraid that that will nto scale well for my problem,
> with EXTREMELY large graphs... )
For those you cannot calculate all shortest paths anyway.
> anyway, the secoond solution look appealing, but I cannot get it to work.
>
> I did this:
>>sp<-get.shortest.paths(g,nodes[1],nodes[2])
>> E(g,path=sp)
> Error in E(g, path = sp) :
> (list) object cannot be coerced to type 'double'
>
> That does not make sense, why would path expect a "double", the docs point
> to a path object.
There is no such thing as a path object. The 'path' argument of 'E'
should be a numeric vector. You need to call 'E' for each path
separately, and then add the weights of the selected edges.
Gabor
> Cheers
> Martin
>
> but that fails: Error in E(sp1) : Not a graph object (as expected)
> How should I sue the function?
>
> On 9/2/2010 11:57 AM, Gábor Csárdi wrote:
>>
>> You're right, I forgot that you have weighted graphs. One solution is
>> to run 'shortest.paths()' as well, and that gives you the lengths.
>>
>> Or you can use the E() function for each path, with the 'path'
>> argument, but this does not work properly if you have multiple edges.
>>
>> Gabor
>>
>> On Thu, Sep 2, 2010 at 11:40 AM, Martin Tomko<address@hidden>
>> wrote:
>>
>>>
>>> Hi Gabor,
>>> I am afraid that this solutions is not right:
>>>
>>> sapply(get.shortest.paths(g, 5), length)-1
>>>
>>> so let's assume we have the follwong network:
>>> vertices
>>> 1
>>> 2
>>> 3
>>> 4
>>> Edges:
>>> 1 - 2 0.5
>>> 2 - 3 0.2
>>> 3 - 4 0.1
>>>
>>> And a resulting shortest path between 1 and 4 as c(1,2,3,4), your
>>> solution
>>> would yield 3 as the length - which is fine for an unweighted graph.
>>> But I need to get the value 0.5+0.2+0.1 = 0.8.
>>>
>>> Is this possible?
>>>
>>> Thanks,
>>> Martin
>>>
>>>
>>>
>>> this is only true in an unweighted network. In a weighted network, where
>>> let's assume we have
>>>
>>> On 9/2/2010 11:32 AM, Gábor Csárdi wrote:
>>>
>>>>
>>>> On Thu, Sep 2, 2010 at 11:25 AM, Martin Tomko<address@hidden>
>>>> wrote:
>>>>
>>>>
>>>>>
>>>>> Thank you Gabor,
>>>>> that helps heaps.
>>>>> One last question - I guess the answer must be trivial. Once I get a
>>>>> path
>>>>> (get.shortest.paths(...)) between two vertices in a weighted graph, I
>>>>> would
>>>>> like to know the length of this path (similar to a vlaue I would get if
>>>>> I
>>>>> counted them all using shortes.paths(..., algorithm="dijkstra")). I
>>>>> only
>>>>> get
>>>>> a list of visited vertices, as documented.
>>>>>
>>>>> Is there a way to get this value?
>>>>>
>>>>>
>>>>
>>>> It is the length of the path vector minus one:
>>>>
>>>> sapply(get.shortest.paths(g, 5), length)-1
>>>>
>>>>
>>>>
>>>>>
>>>>> And is there a way to dientify edges based on input vertices? I read
>>>>> through
>>>>> the documentation and can not find the answer.
>>>>>
>>>>>
>>>>
>>>> What is an input vertex? Adjacent vertex?
>>>>
>>>> E(g)[ adj(v) ]
>>>>
>>>> gives the edges adjacent to vertex v. 'from' and 'to' are similar to
>>>> 'adj', but consider edge direction as well. There are more examples in
>>>> the manual page of 'E' and also here:
>>>> http://igraph.sourceforge.net/igraphbook/igraphbook-iterators.html
>>>>
>>>> Gabor
>>>>
>>>>
>>>>
>>>>>
>>>>> Thanks
>>>>> Martin
>>>>>
>>>>> On 9/2/2010 11:11 AM, Gábor Csárdi wrote:
>>>>>
>>>>>
>>>>>>
>>>>>> On Thu, Sep 2, 2010 at 11:07 AM, Martin Tomko<address@hidden>
>>>>>> wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> Thank you guys, that solved my problem.
>>>>>>> I suspected that $weight should work, but simple listing of an edge
>>>>>>> did
>>>>>>> not
>>>>>>> reveal the attribute. Need to find out how to get the full
>>>>>>> information
>>>>>>> about
>>>>>>> the object...
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> You mean printing everything on the screen? Attributes are not printed
>>>>>> by default, but you can print them by giving extra arguments to the
>>>>>> print.igraph() function. You can also make printing them the default:
>>>>>>
>>>>>> igraph.par("print.edge.attributes", TRUE)
>>>>>> igraph.par("print.graph.attributes", TRUE)
>>>>>> igraph.par("print.vertex.attributes", TRUE)
>>>>>>
>>>>>> Best,
>>>>>> Gabor
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> Cheers
>>>>>>> Martin
>>>>>>>
>>>>>>> On 9/2/2010 10:52 AM, Tamas Nepusz wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>> Sorry, got it working with weights, the appraoch mentionned worked,
>>>>>>>>> but
>>>>>>>>> what confused me is that there is no access to a g$weights vector.
>>>>>>>>> I
>>>>>>>>> am
>>>>>>>>> still not sure how to get the information for any individual edge.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>> E(g)[edgeindex]$weight seems to work for me in igraph 0.5.3. The
>>>>>>>> only
>>>>>>>> thing to watch out for is that edges are indexed from zero, not 1,
>>>>>>>> so
>>>>>>>> E(g)[1]$weight gives the weight of the second edge.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>> --
>>> Martin Tomko
>>> Postdoctoral Research Assistant
>>>
>>> Geographic Information Systems Division
>>> Department of Geography
>>> University of Zurich - Irchel
>>> Winterthurerstr. 190
>>> CH-8057 Zurich, Switzerland
>>>
>>> email: address@hidden
>>> site: http://www.geo.uzh.ch/~mtomko
>>> mob: +41-788 629 558
>>> tel: +41-44-6355256
>>> fax: +41-44-6356848
>>>
>>>
>>>
>>
>>
>>
>
>
> --
> Martin Tomko
> Postdoctoral Research Assistant
>
> Geographic Information Systems Division
> Department of Geography
> University of Zurich - Irchel
> Winterthurerstr. 190
> CH-8057 Zurich, Switzerland
>
> email: address@hidden
> site: http://www.geo.uzh.ch/~mtomko
> mob: +41-788 629 558
> tel: +41-44-6355256
> fax: +41-44-6356848
>
>
--
Gabor Csardi <address@hidden> UNIL DGM
- [igraph] Re: working with weighted networks (from pajek .net), (continued)
- [igraph] Re: working with weighted networks (from pajek .net), Martin Tomko, 2010/09/02
- Re: [igraph] Re: working with weighted networks (from pajek .net), Gábor Csárdi, 2010/09/02
- Re: [igraph] Re: working with weighted networks (from pajek .net), Tamas Nepusz, 2010/09/02
- Re: [igraph] Re: working with weighted networks (from pajek .net), Martin Tomko, 2010/09/02
- Re: [igraph] Re: working with weighted networks (from pajek .net), Gábor Csárdi, 2010/09/02
- Re: [igraph] Re: working with weighted networks (from pajek .net), Martin Tomko, 2010/09/02
- Re: [igraph] Re: working with weighted networks (from pajek .net), Gábor Csárdi, 2010/09/02
- Re: [igraph] Re: working with weighted networks (from pajek .net), Martin Tomko, 2010/09/02
- Re: [igraph] Re: working with weighted networks (from pajek .net), Gábor Csárdi, 2010/09/02
- Re: [igraph] Re: working with weighted networks (from pajek .net), Martin Tomko, 2010/09/02
- Re: [igraph] Re: working with weighted networks (from pajek .net),
Gábor Csárdi <=
- Re: [igraph] Re: working with weighted networks (from pajek .net), Martin Tomko, 2010/09/02
- Re: [igraph] Re: working with weighted networks (from pajek .net), Gábor Csárdi, 2010/09/02