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: MikeS
Subject: Re: [igraph] Turn a directed network into a weighted undirected network
Date: Tue, 31 May 2016 13:22:42 +0700

I have tried to map the vertex IDs to edge IDs with function get.edge.ids().
At fisrt, I run
ei   <- get.edge.ids(UG, c("a","b", "b","c", "c","a"))
E(UG)[ei]
then result is
+ 3/10 edges (vertex names):
[1] a--b b--c a--c

Then, I need to pass the list of indicent vertices into the function
get.edge.ids() in general case:

e1 <- get.edge.ids(UG, _some_function_(sbg.triangle[[1]])))

My question is: how to convert the list 'sbg.triangle[[1]] = a, b, c'
into 'a,b, b,c, c,a'?
Or maybe someone can give an idea how to pass the list of indicent
vertices into function get.edge.ids() without conversion.

library(igraph)
set.seed(42)

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")
V(G)$name <- letters[1:5]
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)

par(mfrow=c(2,2))

# The four triangles all contain a directed 3-cycle subgraph
xlabel <- c('Cycle','One reciprocal edge','Two reciprocal
edges','Three reciprocal edges')
lapply(1:n, function(x) plot(pattern[[x]], edge.curved=TRUE, xlab=xlabel[x]))

# 1. Convert the graph to undirected

UG <- simplify(G)
UG <- as.undirected(UG)
#windows();plot(UG)

# 2. Search for triangles in the undirected graph

triangle     <- graph.full(3)
sbg.triangle <- graph.get.subisomorphisms.vf2(UG, triangle)

# to map the vertex IDs to edge IDs
#ei  <- get.edge.ids(UG, c(1,2, 2,3, 3,1))
ei   <- get.edge.ids(UG, c("a","b", "b","c", "c","a"))
E(UG)[ei]
#+ 3/10 edges (vertex names):
#[1] a--b b--c a--c



reply via email to

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