Netlogo:使用正确数目的节点创建层次(树)网络 [英] Netlogo: Creating Hierarchical (tree) network with correct number of nodes

查看:278
本文介绍了Netlogo:使用正确数目的节点创建层次(树)网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用参数expansion rate创建一个分层"或树"网络结构.首先,在顶部放置一个节点,网络中的每个节点都连接到其下方等于expansion rate的多个节点.目前,我的代码如下:

I'm trying to create a 'Hierarchical' or 'Tree' network structure with a parameter expansion rate. At first, one node is placed at the top, and each node in the network is connected to a number of nodes below him equal to expansion rate. Currently my code looks like this:

to wire-tree
  clear-all
  ask patches [ set pcolor white ]
  create-nodes 1 [         ; create root node of tree
    set shape "circle"
    set color red
    set branch 0
    expand-network
    rewire-branches
  ]

  radial-layout


  reset-ticks
end

to expand-network

  if expansion-rate = 0 [ stop ]
  while [count nodes < num-nodes] [
     ask nodes with-max [branch] [
      hatch expansion-rate [
      create-edge-with myself
      set branch branch + 1
      ]
    ]
  ]

end

网络当前具有正确的结构,但是网络中的节点数超过了num-nodes滑块选择的节点数.这是因为首先检查是否在count nodes < num-nodes之后执行最后的填充.但是,我想要的是节点的最后一个填充要一直执行到达到num-nodes然后停止.因此,尽管最后一个层次之前的层次结构的每个级别包含等于

The network currently has the correct structure, but the number of nodes in the network exceed the number of nodes selected by the num-nodesslider. This is because there is first checked if count nodes < num-nodes after which the last hatch is performed. However, what I want is that this last hatch of nodes is performed up until num-nodes is reached and then stops. Thus, while each level of the hierarchy before the last one contains a number of nodes equal to a power of expansion rate, the last level may have fewer than this if the population does not divide properly.

我该如何实现?

我需要乌龟拥有的branch变量,因为以后我想以固定的概率重新连接某些分支中的节点.稍后可能会发布有关此问题的问题;)

I need the turtle-owned branch variable because I later want to rewire the nodes in certain branches with a fixed probability. Will probably post a question about that later ;)

推荐答案

hatch expansion-rate替换为hatch min expansion-rate (num-nodes - count nodes),这样它将创建两个最小的数字-扩展率和仍然需要的总数.

Replace your hatch expansion-rate with hatch min expansion-rate (num-nodes - count nodes) so it creates the minimum of two numbers - the expansion rate and the total you still need.

这篇关于Netlogo:使用正确数目的节点创建层次(树)网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆