在特定路径上引导代理 (Netlogo)

Directing an agent on a specific path (Netlogo)

我想问一个问题,当我尝试输入这段代码时,我得到了

的错误

The > operator can only be used on two numbers, two strings, or two agents of the same type, but not on a number and a list.

我想问的是如何解决这个问题,错误发生在代码的这一行:

if pri-lev > [pri-lev] of oppoint1 and pri-lev > [pri-lev] of oppoint2

我试过改成"cars-on"或"cars with"都没有用。我也尝试在 Netlogo 词典中查找,但我没有找到有关将代理引导到特定路径的代码的结果。 我想在这里做的是当代理人来到特定部分时,它会检查是否有任何代理人列为 "oppoint1"; "oppoint2"; "oppoint3"; "oppoint4" 然后将调用 pri-lev 的值与其他值进行比较,以决定继续移动或停止并等待其他值。 这些是我的代码的一部分:

ask cars
[
  let oppoint1 (cars-at (xcor + 2) (ycor + 2))
  let oppoint2 (cars-at (xcor - 1) (ycor + 1))
  let oppoint3 (cars-at (xcor - 2) (ycor + 1))
  let oppoint4 (cars-at (xcor - 3) (ycor + 1))
  ifelse oppoint1 != nobody and oppoint2 != nobody
  [
    if pri-lev > [pri-lev] of oppoint1 and pri-lev > [pri-lev] of oppoint2
      [
        set pri-lev 4
        speed-up
      ]
  ]
  [
    if oppoint2 = nobody and oppoint3 = nobody and oppoint4 = nobody
    [
      set speed 1
      fd speed
      if turning = "Rtrue"
      [
        set heading heading + 90
        speed-up
      ]
    ] 
  ]
]

此致,Minh

您收到此错误的原因似乎是您正在将一个(当前汽车)的属性与许多(oppoint agent-sets)的属性进行比较。您的代码现在说的是 "If my privilege is greater than the privilege of that group, do this thing..." 问题是 [pri-lev] of oppoint1 returns oppoint1 代理集的所有成员的 pri-lev 列表,例如 [ 10 12 13 24 ],Netlogo 不会自动遍历该列表并将每个项目与请求海龟的属性进行比较。

有几种方法可以解决这个问题。例如,您可以确保只比较两只乌龟——也许通过确保在给定时间每个补丁只有一只乌龟。如果您打算将一个代理与一个代理集进行比较,您可以使用 any? 原语来检查您正在查看的组中是否有任何成员满足您的条件语句。例如,给定此设置:

turtles-own [
  pri-lev
]

to setup
  ca
  reset-ticks
  crt 10 [
    set pri-lev 1 + random 10
  ]
end

您可以要求 one-of 您的海龟检查当前补丁上的 not any? 海龟是否比提出要求的海龟具有更高的 pri-lev。如果 none 个这样做,当前的海龟将向前移动。否则,它会打印出当前 patch 上还有一只更高 pri-lev 的海龟。

to compare-with

  ask one-of turtles [
    let other-turtles other turtles-here 
    ifelse not any? other-turtles with [ pri-lev > [pri-lev] of myself ] [
      fd 1
    ]
    [ 
      print ("A turtle here has a higher pri-lev than I do." )
    ]
  ]
  tick

end