限制代理可以生成V2的链接数

时间:2017-06-21 15:38:26

标签: hyperlink netlogo

我知道,这里是question。问题是......我一直试图实施它,但它似乎并不适合我。我的模拟正在运行,但即使links面向agentes activities,也会{0} sight-radius。这是代码:

to participate
  ask activities [
    if count my-links < n-capacity [
      ask other agentes in-radius sight-radius with
      [shared-culture = [shared-culture] of other agentes] [
        create-participations-with n-of n-capacity agentes
        ]
        ask links [
          set color blue]
      ]
    ]
end

如果代码不够清楚,我希望活动: 1-知道他们可以拥有多少agentes。 2-如果他们具有相同的shared-culture并且他们是in-radius,则接受他们。 3-代表这个&#34;接受&#34;和&#34;参与&#34;蓝色链接。

我尝试了与while相似但结果为0的内容。

1 个答案:

答案 0 :(得分:1)

如果没有看到更多代码,很难说,但是有一些问题可能导致您的问题。根据您的摘要,我的理解是,您基本上希望activities代理在agentes内与sight-radius形成链接,直至n-capacity定义的数字。但是,在您的代码中,您有活动检查if count my-links < n-capacity,在该活动的视线范围内有其他 agentes 来创建与其他代理的参与链接,而不是原来的activity代理我明白你想要一些链接。

假设n-capacityactivities-own变量,您可以通过切换

来更接近您想要的内容
ask other agentes in-radius sight-radius with
      [shared-culture = [shared-culture] of other agentes] [
        create-participations-with n-of n-capacity agentes
        ]

用[共享文化= [共享文化]自己] [创建参与 - 自己]

询问n-capacity agentes in-radius sight-radius

修改:忘记原始的of

ask n-of n-capacity agentes in-radius sight-radius with
  [shared-culture = [shared-culture] of myself] [
    create-participation-with myself
    ]

但是,由于我无法测试,因为我没有您的设置和其他代码,我将向您展示一个我知道有效的不同示例,可能就是您的后。下面是所有需要的代码,为setup创建一个按钮,为go创建一个永久按钮,并观察狼与具有相同颜色的绵羊代理最多建立三个链接:

breed [ wolves wolf ]
breed [ sheeps sheep ]
undirected-link-breed [ participations participation ]

to setup
  ca
  reset-ticks

  create-wolves 3 [
    set shape "wolf"
    setxy random 32 - 16 random 32 - 16
    set color one-of [ blue red ]
    set size 2
  ]

  create-sheeps 25 [
    set shape "sheep"
    setxy random 32 - 16 random 32 - 16
    set color one-of [ blue red ]
  ]

end


to go
  ask turtles [
    rt random 90 - 45 
    fd 0.1
  ]
  links-with-if
  tick  
end


to links-with-if
  ask wolves [
    if count my-links < 3 [
      ; Make sure the links a wolf tries to form
      ; does not exceed the max number of links it can make
      ; or the number of sheep available
      let n-to-link ( 3 - count my-links)      
      let n-sheep-in-radius count ( sheeps with [ color = [color] of myself ] in-radius 5 )
      if n-sheep-in-radius < n-to-link [
        set n-to-link n-sheep-in-radius
      ]

      ; Ask the appropriate sheeps to form a link with
      ; the asking wolf
      ask n-of n-to-link sheeps with [ color = [color] of myself ] in-radius 5  [
        create-participation-with myself [ set color red ]
      ]
    ]
  ]
end