{"id":21084109,"url":"https://github.com/bergant/networkflow","last_synced_at":"2026-02-03T02:03:26.041Z","repository":{"id":21948063,"uuid":"25272573","full_name":"bergant/NetworkFlow","owner":"bergant","description":"Dynamic network structure model","archived":false,"fork":false,"pushed_at":"2016-03-27T21:39:48.000Z","size":176,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-20T23:49:10.232Z","etag":null,"topics":["agent-based-modeling","netlogo","networks"],"latest_commit_sha":null,"homepage":null,"language":"NetLogo","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bergant.png","metadata":{"files":{"readme":"readme.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-15T20:38:12.000Z","updated_at":"2024-03-09T09:56:16.000Z","dependencies_parsed_at":"2022-08-18T01:01:05.110Z","dependency_job_id":null,"html_url":"https://github.com/bergant/NetworkFlow","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bergant%2FNetworkFlow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bergant%2FNetworkFlow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bergant%2FNetworkFlow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bergant%2FNetworkFlow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bergant","download_url":"https://codeload.github.com/bergant/NetworkFlow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243526953,"owners_count":20305115,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent-based-modeling","netlogo","networks"],"created_at":"2024-11-19T20:22:24.007Z","updated_at":"2026-02-03T02:03:25.988Z","avatar_url":"https://github.com/bergant.png","language":"NetLogo","readme":"---\ntitle: \"Network Flow Model\"\noutput: \n  html_document: \n    keep_md: yes\n    self_contained: no\n---\n\n[![DOI](https://zenodo.org/badge/21125/bergant/NetworkFlow.svg)](https://zenodo.org/badge/latestdoi/21125/bergant/NetworkFlow)\n\n```{r setup, include=FALSE}\nknitr::opts_chunk$set(echo = FALSE, fig.path = \"img/README-\")\n```\n\n```{r}\nlibrary(nlexperiment)\nnl_netlogo_path(\"c:/Program Files (x86)/NetLogo 5.2.0\") \n```\n\n\n## PURPOSE\nThe model demonstrates self-organisation of network structure, optimising flow from fixed diverse inputs to fixed diverse outputs.\n\n![](img/model-netlogo.png)\n\n\n## HOW IT WORKS\n\n**Open System**\n\nModel 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.\n\n**Network Structure**\n\nIntermediate 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.\n\n**Dynamic System**\n\nThe 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.\t\n\n**Bounded Information**\n\nEach vertex can only use the information available at neighbour vertices. \tAlso there is a maximum number of connections each vertex can handle. But there is no quantitative restrictions on flow for nodes nor connections.\t\n\n**Diversity**\n\nEach 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). \t\n\n![](img/model-flow-diversity.png)\n\n## HOW TO USE IT\n\nParameters:\n\n- Set the number of inputs and outputs (from 20 to 60 should be OK)\n\n- Set the number of initial links (3 is enough to start with)\n\n- 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.\n\n- new-processes-factor defines how many new nodes will model try to add at each iteration (number of nodes * factor)\n\nUse **Setup** to apply your parameters and start with **Go**.\n\n## THINGS TO NOTICE\n\nUsually the system nodes get organised in a double-tree hierarchical structure.\n\n\n```{r init_model}\nparam_values \u003c- list(\n  total_outputs = 20,\n  total_inputs = 20,\n  initial_links = 3,\n  link_balance = 0.20,\n  BranchRule_. = TRUE,\n  new_processes_factor = 0.25,\n  # display:\n  t_size = 1.5\n)\n\nexperiment \u003c- nl_experiment(\n  model_file = \"C:/Users/dare/Documents/NetLogo/NetworkFlow/NetworkFlow/NetworkFlow.nlogo\",\n  param_values = param_values,\n  mapping = nl_default_mapping(param_values),\n  random_seed = 2,\n  export_view = TRUE,\n  iterations = 1\n)\n\n```\n\n```{r iteration_function}\nrun_iter \u003c- function(experiment, iterations) {\n  for(iter in iterations) {\n    experiment$iterations = iter\n    result \u003c- nl_run(experiment)\n    print(nl_show_views_grid(result))\n  } \n}\n```\n\nStep 0, 1 and 2:\n\n```{r iterations_1, fig.width=2.5, fig.height=3, echo=FALSE, cache=TRUE}\nrun_iter(experiment, 0:2) \n```\n\nSimulation at 5, 10 and 15:\n\n```{r iterations_2,  fig.width=2.5, fig.height=3, echo=FALSE, cache=TRUE}\nrun_iter(experiment, c(5, 10, 15))\n```\n\nSimulation at 100:\n\n```{r iteration_final, fig.width=2.5, fig.height=3, echo=FALSE, cache=TRUE}\nrun_iter(experiment, c(100))\n```\n\n## MEASURES\n\nOverall system flow can be measured as a sum of flows at the outputs (f).\n\nMore interesting measure is corrected flow based on expected diversity (h).\nIt is calculated by dividing the flow on every output by number\nof expected inputs (= number of system inputs) and multiplied by\nthe number of realised inputs.\n\nIf every input is represented in every output, the corrected flow is\nsame as overall system flow.\n\n\n```{r measures, cache=TRUE}\nparam_values \u003c- list(\n  total_outputs = 30,\n  total_inputs = 30,\n  initial_links = 3,\n  link_balance = 0.20,\n  BranchRule_. = TRUE,\n  new_processes_factor = 0.25,\n  # display:\n  t_size = 1.5\n)\n\nexperiment \u003c- nl_experiment(\n  model_file = \"C:/Users/dare/Documents/NetLogo/NetworkFlow/NetworkFlow/NetworkFlow.nlogo\",\n  param_values = param_values,\n  mapping = nl_default_mapping(param_values),\n  random_seed = 2,\n  iterations = 250,\n  step_measures = measures(\n    f = \"sum [node-flow] of outputs\",\n    h = \"flow-diversity\"\n  )\n)\n\nresults \u003c- nl_run(experiment)\n\nlibrary(ggplot2)\nlibrary(tidyr)\n\nmeasures \u003c- \n  tidyr::gather(\n    results$step[, c(\"f\", \"h\", \"step_id\")], key = \"measure\", value = \"value\", -step_id)\nggplot(data = measures, aes(x = step_id, y= value, color = measure)) +\n  geom_line() +\n  theme_minimal() +\n  ggplot2::labs(x = \"Simulation step\", y = \"Measure Value\", title = \"Simulation Measures\")\n```\n\n\n## THINGS TO TRY\n\nTry to change link-balance parameter and observe the speed of convergence and structure shape.\n\nIf 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.\n\n\n\n## CREDITS AND REFERENCES\n\nDarko Bergant \n\nhttps://github.com/bergant/NetworkFlow\n\nThis work is licensed under a [Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License](http://creativecommons.org/licenses/by-nc-sa/3.0/)\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbergant%2Fnetworkflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbergant%2Fnetworkflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbergant%2Fnetworkflow/lists"}