Netlogo:查询其他代理的变量

时间:2018-09-10 19:41:23

标签: 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

1 个答案:

答案 0 :(得分:1)

您需要的原语是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