[R] Subgraph isomorphism using vertex labels

Gábor Csárdi csardi at rmki.kfki.hu
Thu Aug 2 05:58:30 CEST 2012


I am sorry, but I don't know what exactly is the problem. What's wrong
with this:

library(igraph)
kar <- nexus.get("karate")
star3 <- graph.formula(A -- B:C:D)
subiso <- graph.get.subisomorphisms.vf2(kar, star3)

Then you can query the symbolic ids:

V(kar)$name[ subiso[[1]]+1 ]   # This is actually a bug and the +1
should not be needed

Or for all isomorphic subgraphs:

subiso2 <- lapply(subiso, function(x) V(kar)$name[x+1])

Gabor

On Wed, Aug 1, 2012 at 11:27 PM, HIMANSHU MITTAL <hm3286 at gmail.com> wrote:
> Thanks,
> but the problem is that igraph doesn't even give the correct id mappings. it
> only gives the mapping of the structure(without labels)
>
> For above eg:
> igraph only sees the one edge structure(of graph 2) without labels or names
> and gives all possible edges in the main graph(1) to be isomorphic to the
> query graph(2)
>
>
> On Wed, Aug 1, 2012 at 9:20 PM, Gábor Csárdi <csardi at rmki.kfki.hu> wrote:
>>
>> Hi,
>>
>> igraph will give you the mappings via vertex ids. If you want to use
>> symbolic vertex names, then attach a vertex attribute called 'name'.
>> Then any vector of numeric vertex ids (v, from graph g) can be
>> converted to vertex names via
>>
>> V(g)$name[v]
>>
>> or the more readable equivalent
>>
>> get.vertex.attribute(g, "name", v)
>>
>> Best,
>> Gabor
>>
>> On Tue, Jul 31, 2012 at 3:12 PM, HIMANSHU MITTAL <hm3286 at gmail.com> wrote:
>> > Hi all,
>> > I want to find all the mappings of one graph in another graph, based on
>> > their vertex labels
>> > Is there any way to do this in igraph based on vertex labels.
>> > (as far as i know Igraph allows the subgraph isomorphism based only on
>> > vertex and edge colors)
>> >
>> > Eg:
>> > graph 1:
>> > x(1) x(2)
>> > x(2) y(3)
>> > y(4) x(1)
>> > z(5) x(2)
>> >
>> > graph 2:
>> > x(1) y(2)
>> >
>> > # the brackets contain the corresponding vertex ids
>> >
>> > i would like my output to contain the two mappings from graph 1
>> > i.e
>> > x(2) y(3) &
>> > x(1) y(4)
>> >
>> > Regards,
>> > Himanshu Mittal
>> >
>> >         [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-help at r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>> --
>> Gabor Csardi <csardi at rmki.kfki.hu>     MTA KFKI RMKI
>
>



-- 
Gabor Csardi <csardi at rmki.kfki.hu>     MTA KFKI RMKI



More information about the R-help mailing list