Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bergant/networkflow

Dynamic network structure model
https://github.com/bergant/networkflow

agent-based-modeling netlogo networks

Last synced: about 1 month ago
JSON representation

Dynamic network structure model

Awesome Lists containing this project

README

        

---
title: "Network Flow Model"
output:
html_document:
keep_md: yes
self_contained: no
---

[![DOI](https://zenodo.org/badge/21125/bergant/NetworkFlow.svg)](https://zenodo.org/badge/latestdoi/21125/bergant/NetworkFlow)

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, fig.path = "img/README-")
```

```{r}
library(nlexperiment)
nl_netlogo_path("c:/Program Files (x86)/NetLogo 5.2.0")
```

## PURPOSE
The model demonstrates self-organisation of network structure, optimising flow from fixed diverse inputs to fixed diverse outputs.

![](img/model-netlogo.png)

## HOW IT WORKS

**Open System**

Model simulates a distribution of demand and supply to intermediate network nodes based on system inputs and outputs. Inputs represent fixed diverse supply and outputs represent fixed diverse demand.

**Network Structure**

Intermediate nodes are connected to each other as inputs and outputs. Each node represents a demand to his input nodes and supply to his output nodes. Each node is also an information source to other nodes – current demand level is sensed from output nodes and supply level is sensed from input nodes.

**Dynamic System**

The network structure is self-designed and based on the decisions of individual vertices. The connection between two vertices is kept only if there is enough flow between the vertices which share the connection. New vertices are born periodically and they survive only if they carry enough flow. Flow is defined as the least of supply and demand.

**Bounded Information**

Each vertex can only use the information available at neighbour vertices. Also there is a maximum number of connections each vertex can handle. But there is no quantitative restrictions on flow for nodes nor connections.

**Diversity**

Each input node represent unique supply (good or service) and each output node represent special demand. The model defines each system input as a unit vector in N-dimensional space (if there are N inputs). In English: in case of 4 input nodes they would be defined as 1000, 0100, 0010 and 0001. Same with outputs. Merging two different inputs in some intermediate node would result in a combination of different types of flows (e.g. 1100 or 1010).

![](img/model-flow-diversity.png)

## HOW TO USE IT

Parameters:

- Set the number of inputs and outputs (from 20 to 60 should be OK)

- Set the number of initial links (3 is enough to start with)

- Link balance is the threshold for killing links with less flow then a percentage of node flow. With 0.2 you can expect around 2 or 3 links per node.

- new-processes-factor defines how many new nodes will model try to add at each iteration (number of nodes * factor)

Use **Setup** to apply your parameters and start with **Go**.

## THINGS TO NOTICE

Usually the system nodes get organised in a double-tree hierarchical structure.

```{r init_model}
param_values <- list(
total_outputs = 20,
total_inputs = 20,
initial_links = 3,
link_balance = 0.20,
BranchRule_. = TRUE,
new_processes_factor = 0.25,
# display:
t_size = 1.5
)

experiment <- nl_experiment(
model_file = "C:/Users/dare/Documents/NetLogo/NetworkFlow/NetworkFlow/NetworkFlow.nlogo",
param_values = param_values,
mapping = nl_default_mapping(param_values),
random_seed = 2,
export_view = TRUE,
iterations = 1
)

```

```{r iteration_function}
run_iter <- function(experiment, iterations) {
for(iter in iterations) {
experiment$iterations = iter
result <- nl_run(experiment)
print(nl_show_views_grid(result))
}
}
```

Step 0, 1 and 2:

```{r iterations_1, fig.width=2.5, fig.height=3, echo=FALSE, cache=TRUE}
run_iter(experiment, 0:2)
```

Simulation at 5, 10 and 15:

```{r iterations_2, fig.width=2.5, fig.height=3, echo=FALSE, cache=TRUE}
run_iter(experiment, c(5, 10, 15))
```

Simulation at 100:

```{r iteration_final, fig.width=2.5, fig.height=3, echo=FALSE, cache=TRUE}
run_iter(experiment, c(100))
```

## MEASURES

Overall system flow can be measured as a sum of flows at the outputs (f).

More interesting measure is corrected flow based on expected diversity (h).
It is calculated by dividing the flow on every output by number
of expected inputs (= number of system inputs) and multiplied by
the number of realised inputs.

If every input is represented in every output, the corrected flow is
same as overall system flow.

```{r measures, cache=TRUE}
param_values <- list(
total_outputs = 30,
total_inputs = 30,
initial_links = 3,
link_balance = 0.20,
BranchRule_. = TRUE,
new_processes_factor = 0.25,
# display:
t_size = 1.5
)

experiment <- nl_experiment(
model_file = "C:/Users/dare/Documents/NetLogo/NetworkFlow/NetworkFlow/NetworkFlow.nlogo",
param_values = param_values,
mapping = nl_default_mapping(param_values),
random_seed = 2,
iterations = 250,
step_measures = measures(
f = "sum [node-flow] of outputs",
h = "flow-diversity"
)
)

results <- nl_run(experiment)

library(ggplot2)
library(tidyr)

measures <-
tidyr::gather(
results$step[, c("f", "h", "step_id")], key = "measure", value = "value", -step_id)
ggplot(data = measures, aes(x = step_id, y= value, color = measure)) +
geom_line() +
theme_minimal() +
ggplot2::labs(x = "Simulation step", y = "Measure Value", title = "Simulation Measures")
```

## THINGS TO TRY

Try to change link-balance parameter and observe the speed of convergence and structure shape.

If you switch off the branch rule, the system can't find the path to organized structure. Branch rule prohibits cycles in the structure for new nodes and connections.

## CREDITS AND REFERENCES

Darko Bergant

https://github.com/bergant/NetworkFlow

This work is licensed under a [Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License](http://creativecommons.org/licenses/by-nc-sa/3.0/)