Description Usage Arguments Value Examples
Add random edges to a supply network
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
)
|
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 |
An igraph object with n
more edges.
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"])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.