addRandomEdges: Add random edges to a supply network

Description Usage Arguments Value Examples

View source: R/rewiring.R

Description

Add random edges to a supply network

Usage

1
2
3
4
5
6
7
8
9
addRandomEdges(
  g,
  n = 1,
  from = NULL,
  to = NULL,
  v2connect = NULL,
  multi.edges = FALSE,
  iie.ceil = 4
)

Arguments

g

An igraph object.

n

numeric; the number of edges to add.

from

igraph.vs or character names; vertices sequence of possible edges origins (default: NULL).

to

igraph.vs or character names; vertices sequence of possible edges origins (default: NULL).

v2connect

igraph.vs or character names; vertices sequence edges origin or destinations must be attached to (default: NULL).

multi.edges

boolean; wheter or not multiple edges can be created (default: FALSE).

iie.ceil

numeric; maximal number of edges between intermediaries in the graph (default: 4). TODO Must be changed to Inf

Value

An igraph object with n more edges.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Generate a theoretical supply network, define producers (P),
## intermediaries (I) and distributors (D) vertices.
library(igraph)
g = make_tree(10)
V(g)[!degree(g, mode="in")]$type = "P"
V(g)[degree(g, mode="in") & degree(g, mode="in")]$type = "I"
V(g)[!degree(g, mode="out")]$type = "D"
V(g)$color = c("red","green","blue")[factor(V(g)$type)]
plot(g)
## Add 5 edges going from P to D (short supply chains)
g2 = addRandomEdges(g, n=5, from=V(g)[type=="P"], to=V(g)[type=="D"])
plot(g2)
## Add 3 edges connected to I (belonging long supply chains)
g2 = addRandomEdges(g, n=3, v2connect=V(g)[type=="I"])

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