igraph-help
[Top][All Lists]
Advanced

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

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


From: MikeS
Subject: [igraph] Turn a directed network into a weighted undirected network
Date: Sun, 15 May 2016 22:38:15 +0700

Hello,

I would like to turn a directed network G into a weighted undirected
network G1 with large weights on the edges in the 3-cycles (subgraphs)
based on an approach from the paper
(www.sandia.gov/~tgkolda/pubs/pubfiles/KlGlKo14.pdf)

I need to know the type of 3-cycles in which each edge of G
participates. Then check on the number of reciprocal edges, and store
this information for each edge involved in the triangle.

library(igraph)
set.seed(42)
#setwd('D:/')

d <- matrix(c(0,1,0,1,0, 0,0,1,1,1, 1,0,0,1,1, 0,1,1,0,1,
1,1,1,0,0),nrow=5,ncol=5)
G <- graph.adjacency(d)
V(G)$label <-c("A","B","C","D","E")
plot(G)#, 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
sbgCycle.graph<-lapply(sbgCycle.mat, graph.adjacency)


# The four triangles all contain a directed 3-cycle subgraph
par(mfrow=c(2,2))
plot(sbgCycle.graph[[1]], edge.curved=TRUE, xlab='Cycle')
plot(sbgCycle.graph[[2]], edge.curved=TRUE, xlab='One reciprocal edge')
plot(sbgCycle.graph[[3]], edge.curved=TRUE, xlab='Two reciprocal edges')
plot(sbgCycle.graph[[4]], edge.curved=TRUE, xlab='Three reciprocal edges')

 # Count the number of the different subgraphs

sbg.freq <- c()
sbg.list <- c()

for(i in 1:n){
sbg.freq[i] <- graph.count.subisomorphisms.vf2(G, sbgCycle.graph[[i]])
# graph.get.subisomorphisms.vf2(G, sbgCycle.graph[[i]])
}

I hope that 'i' in the brackets 'sbgCycle.graph[[i]])' corresponds to
the the number of reciprocal edges.
My questions is: How to save a list of all directed cycles in the
network G in order to to denote edge is involved in i-th type of  the
3-cycles?

I have tried to type:
> graph.get.subisomorphisms.vf2(G, sbgCycle.graph[[1]])[1]
[[1]]
+ 3/5 vertices:
[1] 1 2 3
But I'm confused in the nodes labels (A, B, C) and IDs nodes (1,2,3).
--
Mike



reply via email to

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