Description Usage Arguments Value Examples
Extends rewire
used with keeping_degseq
with tunable parameters. Possible to force the swap of two edges of different
types, or of the same type. Edges swapping can be used to realize a Degree
Preserving Randomization (DPR). One of the two edges can be imposed (e1).
1 2 3 4 5 6 7 |
g |
An igraph object |
es |
igraph.es; edge sequence among which to choose edges to swap. (default: all edges). |
e1 |
igraph.es; one of the two swapped edges can be imposed (default: NULL). |
edges.types |
character string; either 'random', 'same' or 'different': of what type must be edges swapped. Requir E(g)$type attribute (default: 'random'). |
multi.edges |
boolean; whether or not multiple edges creation is allowed (default: FALSE). |
An igraph object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ## 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="out")]$type = "I"
V(g)[!degree(g, mode="out")]$type = "D"
V(g)$color = c("green","red","yellow")[factor(V(g)$type, levels=c("P","I","D"))]
plot(g)
## Swap edges to conserve supply from P to D.
for (i in 1:100) {
i = ends(g, E(g), names=FALSE)[,1]
j = ends(g, E(g), names=FALSE)[,2]
E(g)$type = paste0(V(g)[i]$type, V(g)[j]$type)
g = swapEdges(g, edges.types="diff")
if (length(E(g)[which_multiple(g, E(g))]))
stop("Multiedges")
if (length(E(g)[which_loop(g, E(g))]))
stop("Loops")
if (length(V(g)[degree(g)==0]))
stop("Isolated vertex")
}
plot(g)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.