igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Turn a directed network into a weighted undirected network


From: Tamas Nepusz
Subject: Re: [igraph] Turn a directed network into a weighted undirected network
Date: Tue, 7 Jun 2016 12:04:24 +0200

Hi,

I'm not sure if I completely understand your problem. After step #3,
you get a list consisting of four other lists; subisom[[1]] contains
all the triangles that are isomorphic to template graph #1,
subisom[[2]] contains all the triangles that are isomorphic to
template graph #2 and so on. So, in your example, since the triangle
appears in subisom[[2]], therefore it must be isomoprhic to template
graph #2.

T.

> library(igraph)
> set.seed(42)
>
> d <- matrix(c(0,1,0, 0,0,1, 1,1,0),nrow=3,ncol=3)
> G <- graph.adjacency(d)
> V(G)$name <- letters[1:dim(d)[1]]
> V(G)$shape = "none"
> plot(G, edge.arrow.size=0.5, edge.curved=TRUE)
>
>
> # Here are the adjacency matrices for each of the four subgraphs
>
>
> d0<-matrix(c(0,1,0,0,0,1,1,0,0),nrow=3,ncol=3)
> d1<-matrix(c(0,1,0,0,0,1,1,1,0),nrow=3,ncol=3)
> d2<-matrix(c(0,1,0,1,0,1,1,1,0),nrow=3,ncol=3)
> d3<-matrix(c(0,1,1,1,0,1,1,1,0),nrow=3,ncol=3)
>
>
>
> # Turn them into a convenient list
>
> sbgCycle.mat<-list(d0,d1,d2,d3)
> n <- length(list(d0,d1,d2,d3))
>
> # And then into a list of graph objects
>
> pattern <- lapply(sbgCycle.mat, graph.adjacency)
>
>
> # 1. Convert the directed graph to undirected one
>
> UG <- simplify(G)
> UG <- as.undirected(UG)
>
> # 2. Search for triangles in the undirected graph
>
>
> triangle <- graph.full(3)
> # names of incident vertices of triangle in the undirected graph
> sbg.triangle <- unique(graph.get.subisomorphisms.vf2(UG, triangle))
> k <- length(sbg.triangle)
>
> vertices_of_triangle <- function (x) { c(x[1], x[2], x[2], x[3], x[3], x[1]) }
> vlist <- lapply(1:k, function(x) vertices_of_triangle(sbg.triangle[[x]]) )
>
> # edge IDs triangle in the undirected graph
> eids <- lapply(1:k, function(x) get.edge.ids(graph = UG, vp =
> as.numeric(unlist(vlist[x])) ))
>
> # 3. Search for subisomorphisms in the directed graph to all of the
> four templates
>
> subisom <- lapply(1:n, function(x) subgraph_isomorphisms(pattern[[x]],
> G, method="lad", induced=TRUE))
>
> # 4. For each triangle check which pattern it was isomorphic
>
> for(i in 1:k)
> {
>             for(j in 1:n)
>             {
>                weght_triangle <-
>          function_check_which_template_graph_it_was_isomorphic(subisom[j],
> sbg.triangle[i])
>       } # for_j
>
> E(UG)[eids[k]]$weght <- weght_triangle
> } # for_i
>
> plot(UG, edge.arrow.size=0.2, edge.label=E(UG)$weght)
>
> --
> Mikes
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help



reply via email to

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