netlogo:有补丁使用记者

时间:2017-10-15 08:42:34

标签: netlogo

我正在模拟城市景观以观察运动,其中补丁等同于建筑物并具有不同的影响值。我需要使用一个记者函数来计算每个补丁的值,例如:

 (its own influence) plus (the influence of neighbors) divided by the 
 distance to a specific turtle (max-one-of distance myself) 

然后乌龟将朝着具有最高影响力的补丁移动,但沿着规定的街道移动。

我是使用netlogo的新手,并且已经完全卡住了。

到目前为止,我已经包含了我所拥有的一部分内容,但我无法弄清楚如何编写将计算每个补丁影响值(锥内)的报告函数,以便乌龟可以朝着最佳选择。

to setup-influence-field
  ask patches with [pcolor = green] [set influence commercial-influence]
  ask patches with [pcolor = orange] [set influence production-influence]
  ask patches with [pcolor = yellow] [set influence domestic-influence]
  ask patches with [pcolor = pink] [set influence religious-influence]
  ask patches with [pcolor = blue] [set influence public-influence]
end

to go
  move-serapis
end

to move-serapis
  ask serapis [set-procession-heading]   
  repeat 2 [ ask serapis [ fd .25 ] display ]
  tick
end

;;;;; the reporter values are need for this part of the code so that the turtles (serapis) can move towards the patches with the highest influence value;;;;
   to set-procession-heading
      let direction patches in-cone 4 40 with [influence-field > 0]
      if any? influence-field   
          [face max-one-of influence-field] ;;;; face towards the highest computed influence value 
      ifelse any? patches with [pcolor = black] in-cone 1 25
      [process]
    end

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:1)

我不认为这是完全正确的,我无法测试它,但它应该让你开始,如果你让我们知道错误,也许有人可以解决它。

to set-procession-heading
  let direction-targets patches in-cone 4 40 with [influence-field > 0]
  if any? direction-targets   
  [ face max-one-of direction-targets [ influence-amount self ] ]
end

to-report influence-amount [ target-node ]
  report ( [ influence-field ] + sum [ influence-field] of neighbors ) / distance target-node 
end

我所做的是设置一个单独的程序来报告您的计算结果。该过程采用一个参数(名为target-node),因为您需要能够传递受影响的乌龟的身份。完成该程序后,您只需将代理程序集的潜在方向传递给计算程序,然后选择具有最大值的程序。