deleteRandomEdges: Delete random edges from a supply network

Description Usage Arguments Value See Also Examples

View source: R/rewiring.R

Description

Delete n random edges contained in the es set from supply network g. Deletion of bridges or supply-cut edges can be avoided.

Usage

1
deleteRandomEdges(g, n = 1, es = E(g), supply.cuts = FALSE, bridges = TRUE)

Arguments

g

igraph object; a supply network.

n

numeric; the number of edges to delete (default: 1).

es

igraph.es; the edges which can be deleted (default: all edges).

supply.cuts

boolean; FALSE make impossible the removal of last incoming or outgoing edges of a vertex (default: FALSE).

bridges

boolean; FALSE make impossible the removal of an edge which would increase the number of components in the graph.

Value

an igraph object.

See Also

getBridges

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
library(igraph)
## Create supply network
type = rep(c("P","D"), each=3)
name = paste0(type, rep(1:3, 2))
x    = rep(1:3, 2)
y    = rep(2:1, each=3)
v = data.frame(name=name, type=type, x=x, y=y)
e = c("P1","D1", "P1","D2", "P2","D1", "P2","D2", "P2","D3", "P3","D3")
e = matrix(e, ncol=2, byrow=2)
g = graph_from_data_frame(e, directed=TRUE, v)
plot(g)
## Highlight supply cuts
outdegi = degree(g, ends(g,E(g))[,1], mode="out")
indegj  = degree(g, ends(g,E(g))[,2], mode="in")
supply_cuts = E(g)[outdegi==1  |  indegj==1]
E(g)$color = "grey"
E(g)[supply_cuts]$color = "blue"
plot(g)
## Highlight bridges
bridges = getBridges(g)
E(g)$color = "grey"
E(g)[bridges]$color = "red"
plot(g)
## impossible to delete 2 edges without disconnecting the graph
g = deleteRandomEdges(g, bridges=FALSE)
# Fails
g = deleteRandomEdges(g, bridges=FALSE)

MiloMonnier/supplynet documentation built on Feb. 16, 2021, 8:03 p.m.