首页 > 解决方案 > Netlogo:询问其他代理的变量

问题描述

我试图让代理根据另一个代理的变量是否介于第一个代理的个人最小值和最大值之间做出决定。我遇到了 netlogo 预期的语法问题。

这一点,在下面的完整代码中:

to settle-decision
  ask turtles [
    ifelse ( myneighbor mycall ) > myminthresh AND myneighbor mycall < mymaxthresh)
      [ set settled? true ]
      [ set color yellow ]

最终我想让特工做比改变颜色更有趣的事情,但我不能先通过这个!非常感谢任何帮助。

turtles-own [
  myneighbor                                 ;; closest other male frog to myself
  mycall                                     ;; the amplitude (loudness) of my own call
  myminthresh                                ;; when my neighbor's call is below this threshold, I move toward him
  mymaxthresh                                ;; when my neighbor's call is above this threshold, I move away from him
  myNND                                      ;; the distance to my nearest neighbor
  settle?                                    ;; true if male decides to create a territory and stop moving

 ]


to setup

  clear-all
  create-turtles population [                         ;; use the population slider to choose number of males

set size 1.5                                      ;; easy to see but is it actual agent size or just agent image size?
setxy random-xcor random-ycor                     ;; distribute frogs randomly in the landscape

set mycall random 100                             ;; choose the amplitude of my own call from a random distribution 0 to 100
set color scale-color red mycall 0 100            ;; allows easy visualization of variability in call amplitude
                                                  ;; lighter color is a higher amplitude
set myminthresh inputminthresh                    ;; use the input on interface to set the min-threshold
set mymaxthresh inputmaxthresh                    ;; use the input on the interface to set the max-threshold
set myNND 0                                       ;; initialize nearest neighbor distance for all

  ]

  reset-ticks

end

to go
  choose-neighbors
  settle-decision
  move-turtles
  tick
end

to choose-neighbors
   ask turtles [
    set myneighbor min-one-of other turtles [distance myself]  ;; choose my nearest neighbor based on distance
    set myNND distance myneighbor

  ]
end


to settle-decision
  ask turtles [
    ifelse ( myneighbor mycall ) > myminthresh AND myneighbor mycall < mymaxthresh)
    [ set settled? true ]
    [ set color yellow ]
  ]
end

to move-turtles
  ask turtles [
    face myneighbor
    ifelse mycall < myminthresh
        [ set color blue ]
        [ set color yellow ]
                                                              ;; this works but everybody moves so needs more work
    fd 5
    pendown
  ]
end

标签: netlogo

解决方案


您需要的原语是of使用类似[variablename] of agent. 我无法对此进行测试,但可能不是:

to settle-decision
  ask turtles [
    ifelse ( myneighbor mycall ) > myminthresh AND myneighbor mycall < mymaxthresh)
    [ set settled? true ]
    [ set color yellow ]
  ]
end

尝试

to settle-decision
  ask turtles [
    ifelse ([mycall] of myneighbor > myminthresh) AND ([mycall] of myneighbor < mymaxthresh)
    [ set settled? true ]
    [ set color yellow ]
  ]
end

推荐阅读