NetLogo 5.3.1错误:Can';不要在观察者上下文中使用GET-EARLYWARN,因为只有海龟

NetLogo 5.3.1错误:Can';不要在观察者上下文中使用GET-EARLYWARN,因为只有海龟,netlogo,Netlogo,我似乎不明白我为什么会犯这个错误。我尝试将询问代理放入get earlywarn过程,但似乎不起作用。它是由ask n-of-n代理引起的吗?我应该把它放在一个单独的程序中吗 代码如下: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; FOR ALL MODELS ;;;;;;;;

我似乎不明白我为什么会犯这个错误。我尝试将询问代理放入
get earlywarn
过程,但似乎不起作用。它是由
ask n-of-n
代理引起的吗?我应该把它放在一个单独的程序中吗

代码如下:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; FOR ALL MODELS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; VARIABLES

globals
  [
  percent-agri
  basin-area
  agri-volume
  yield-max
  water-requirement
  price-rice
  agri-cost
  month-rainfall
  drought
  month
  d
  n
  p
  total-income
  ]

breed [agents agent]

agents-own
  [
  agent-id-sw
  agent-landarea-sw
  agehh-sw
  district-sw
  pcons-sw
  earlywarn-sw
  pprob-sw
  reach
  agent-received
  agent-demand
  agent-volumestored
  agent-volumeused
  agent-yield-sw
  agent-income-sw
  y
  store-capacity
  ]

; SETUP

to setup
  clear-all
  define-month
  set month-rainfall 848.5    ;; max rainfall from 2011 to 2014 in the river basin
  define-agri-volume
  set percent-agri 0.17      ;; assumes 17% of water from river basin is allocated for agriculture use
  set basin-area 9.205e+15    ;; 9.205e+15 sq mm of surface area
  set yield-max 6.15      ;; 6.15 tons of rice/ha
  set water-requirement 528    ;; 528 cubic m/ton of rice
  set price-rice 8963.10    ;; 8,963.10 VND per ton of rice
  set agri-cost 500000      ;; 500,000 VND per cropping season
end

to define-month
    if (ticks  = 1) or (ticks = 13) or (ticks = 25) or (ticks = 37) or (ticks = 49) or (ticks = 61) or (ticks =   73) or (ticks = 85) or (ticks = 97) or (ticks = 109)       
    [ 
      set month "JANUARY" 
    ]
    if (ticks = 2) or (ticks = 14) or (ticks = 26) or (ticks = 38) or (ticks = 50) or (ticks = 62) or (ticks =   74) or (ticks = 86) or (ticks = 98) or (ticks = 110) 
    [ 
      set month "FEBRUARY" 
    ]
    if (ticks = 3) or (ticks = 15) or (ticks = 27) or (ticks = 39) or (ticks = 51) or (ticks = 63) or (ticks =   75) or (ticks = 87) or (ticks = 99) or (ticks = 111) 
    [ 
      set month "MARCH"
    ] 
    if (ticks = 4) or (ticks = 16) or (ticks = 28) or (ticks = 40) or (ticks = 52) or (ticks = 64) or (ticks =   76) or (ticks = 88) or (ticks = 100) or (ticks = 112) 
    [ 
      set month "APRIL" 
    ] 
    if (ticks = 5) or (ticks = 17) or (ticks = 29) or (ticks = 41) or (ticks = 53) or (ticks = 65) or (ticks =   77) or (ticks = 89) or (ticks = 101) or (ticks = 113) 
    [ 
      set month "MAY" 
    ] 
    if (ticks = 6) or (ticks = 18) or (ticks = 30) or (ticks = 42) or (ticks = 54) or (ticks = 66) or (ticks =   78) or (ticks = 90) or (ticks = 102) or (ticks = 114) 
    [ 
      set month "JUNE" 
    ] 
    if (ticks = 7) or (ticks = 19) or (ticks = 31) or (ticks = 43) or (ticks = 55) or (ticks = 67) or (ticks =   79) or (ticks = 91) or (ticks = 103) or (ticks = 115) 
    [ 
      set month "JULY" 
    ] 
    if (ticks = 8) or (ticks = 20) or (ticks = 32) or (ticks = 44) or (ticks = 56) or (ticks = 68) or (ticks =   80) or (ticks = 92) or (ticks = 104) or (ticks = 116) 
    [ 
      set month "AUGUST" 
    ] 
    if (ticks = 9) or (ticks = 21) or (ticks = 33) or (ticks = 45) or (ticks = 57) or (ticks = 69) or (ticks =   81) or (ticks = 93) or (ticks = 105) or (ticks = 117)  
    [ 
      set month "SEPTEMBER" 
    ] 
    if (ticks = 10) or (ticks = 22) or (ticks = 34) or (ticks = 46) or (ticks = 58) or (ticks = 70) or (ticks =   82) or (ticks = 94) or (ticks = 106) or (ticks = 118)  
    [ 
      set month "OCTOBER"
    ] 
    if (ticks = 11) or (ticks = 23) or (ticks = 35) or (ticks = 47) or (ticks = 59) or (ticks = 71) or (ticks =   83) or (ticks = 95) or (ticks = 107) or (ticks = 119) 
    [ 
      set month "NOVEMBER"
    ] 
    if (ticks = 12) or (ticks = 24) or (ticks = 36) or (ticks = 48) or (ticks = 60) or (ticks = 72) or (ticks =   84) or (ticks = 96) or (ticks = 108) or (ticks = 120) 
    [ 
      set month "DECEMBER" 
    ]
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;STORE WATER MODEL
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; RUN MODEL

to go-sw
  tick
  define-agents-sw
  define-agri-volume
  get-earlywarn
  define-received
  define-demand
  store-water
  use-storedwater
  define-yield-sw
  define-income-sw
  define-total-income
  if ticks = 121 [stop]
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; INPUT DATA

to define-agents-sw

  create-agents 111
  ask agents [hide-turtle]

  random-seed new-seed

  file-open "agent_id_sw.txt"
  foreach sort agents [ask ? [set agent-id-sw file-read] ]
  file-close

  file-open "landarea_sw.txt"
  foreach sort agents [ask ? [set agent-landarea-sw file-read] ]
  file-close

  file-open "agehh_sw.txt"
  foreach sort agents [ask ? [set agehh-sw file-read] ]
  file-close

  file-open "district_sw.txt" 
  foreach sort agents [ask ? [set district-sw file-read] ]
  file-close

  file-open "pcons_sw.txt" 
  foreach sort agents [ask ? [set pcons-sw file-read] ]
  file-close

  file-open "earlywarn_sw.txt"
  foreach sort agents [ask ? [set earlywarn-sw file-read] ]
  file-close

  file-open "pprob_sw.txt" 
  foreach sort agents [ask ? [set pprob-sw file-read] ]
  file-close

end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; STORE WATER PROCESS

to define-agri-volume
  set d random 0.9676        ;; or set d random 1
  ifelse d >= 0.8998
    [
    set agri-volume (month-rainfall * (1 - d) * basin-area * percent-agri) 
    set drought "DROUGHT"
    ]
    [
    set agri-volume (month-rainfall * (1 - d) * basin-area * percent-agri) 
    set drought "NODROUGHT"
    ]
end

to get-earlywarn
  if drought = "DROUGHT"
    [
    ifelse (ticks  = 1) or (ticks = 13) or (ticks = 25) or (ticks = 37) or (ticks = 49) or (ticks = 61) or (ticks =   73) or (ticks = 85)     or (ticks = 97) or (ticks = 109) or (ticks = 7) or (ticks = 19) or (ticks = 31) or (ticks = 43) or (ticks = 55) or (ticks = 67) or     (ticks = 79) or (ticks = 91) or (ticks = 103) or (ticks = 115) 
      [
      set n random 111
      ;; n of agents reached by early warning system decided at the start of each cropping season
      set p random 4
      ]
      [
      set n n
      set p p
      ]
    ask n-of n agents 
      [
      set pprob-sw pprob-sw + p
      set y (-0.591 * agehh-sw) + (-0.605 * district-sw) + (-0.249 * pcons-sw) + (2.223 * earlywarn-sw) + (-0.615 * pprob-sw)      ;; y is computed y-hat from logistic regression
      ;; constant numbers are estimates from logistic regression
      ]
    ifelse agents = n-of n agents
      [set reach "REACHED"]
      [set reach "NOTREACHED"]
    ifelse reach = "REACHED"
      [
      ifelse y >= 0.5
        [
        store-water
        use-storedwater        
        ]
        [
        ifelse agent-received > agent-demand
          [set agent-volumeused agent-demand]
          [set agent-volumeused agent-received]
        set agent-volumestored 0
        ]
      ] 
      [
      ifelse agent-received > agent-demand
        [set agent-volumeused agent-demand]
        [set agent-volumeused agent-received]
      set agent-volumestored 0
      ]
    ]
  if drought = "NODROUGHT"
    [
    ifelse agent-received > agent-demand
      [set agent-volumeused agent-demand]
      [set agent-volumeused agent-received]
    set agent-volumestored 0
    ]
end

to define-received
      set agent-received agri-volume * agent-landarea-sw / sum [agent-landarea-sw] of agents
end

to define-demand
      set agent-demand yield-max * water-requirement * agent-landarea-sw
end

to store-water
  set store-capacity random 1000
  ifelse agent-received > agent-demand
  [
  let dif1 agent-received - agent-demand    ;; assumes that stored water only comes from excess of received
         ifelse dif1 >= store-capacity
      [set agent-volumestored agent-volumestored + store-capacity]
             [set agent-volumestored agent-volumestored + dif1]
  ]
      [set agent-volumestored agent-volumestored]
end

to use-storedwater
  let dif2 agent-demand - agent-received
  ifelse agent-received < agent-demand
      [
  ifelse agent-volumestored > dif2 
         [
           set agent-volumeused agent-received + dif2
    set agent-volumestored agent-volumestored - dif2
    ]
          [
    if agent-volumestored > 0
              [
      set agent-volumeused agent-received + agent-volumestored
             set agent-volumestored 0
      ]
    ]
      ]
      [
  set agent-volumeused agent-received
  set agent-volumestored agent-volumestored - 0
  ]
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; GET OUTPUT

to define-yield-sw
  ask agents
  [
  if (ticks = 6) or (ticks = 18) or (ticks = 30) or (ticks = 42) or (ticks = 54) or (ticks = 66) or (ticks =   78) or (ticks = 90) or (ticks =   102) or (ticks = 114) or (ticks = 12) or (ticks = 24) or (ticks = 36) or (ticks = 48) or (ticks = 60) or (ticks = 72) or (ticks =   84) or   (ticks = 96) or (ticks = 108) or (ticks = 120)      ;; assumes 2 cropping seasons per year
  [ifelse agent-volumeused >= agent-demand
     [set agent-yield-sw agent-yield-sw + (yield-max * agent-landarea-sw) / 6]
     [
     set agent-yield-sw agent-yield-sw + 
     (6.15 * agent-landarea-sw * sum [agent-volumeused] of agents / sum [agent-demand] of agents) / 6
     ]
  ]
  ]
end

to define-income-sw
  ask agents
  [
  if (ticks = 6) or (ticks = 18) or (ticks = 30) or (ticks = 42) or (ticks = 54) or (ticks = 66) or (ticks =   78) or (ticks = 90) or (ticks =   102) or (ticks = 114) or (ticks = 12) or (ticks = 24) or (ticks = 36) or (ticks = 48) or (ticks = 60) or (ticks = 72) or (ticks =   84) or   (ticks = 96) or (ticks = 108) or (ticks = 120) 
    [set agent-income-sw (agent-yield-sw * price-rice) - agri-cost]
  ]
end

to define-total-income
  if (ticks = 6) or (ticks = 18) or (ticks = 30) or (ticks = 42) or (ticks = 54) or (ticks = 66) or (ticks =   78) or (ticks = 90) or (ticks =   102) or (ticks = 114) or (ticks = 12) or (ticks = 24) or (ticks = 36) or (ticks = 48) or (ticks = 60) or (ticks = 72) or (ticks =   84) or   (ticks = 96) or (ticks = 108) or (ticks = 120)
    [set total-income sum [agent-income-sw] of agents]
end
《守则》;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; 适用于所有型号 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; 变量 全局变量 [ 农业百分比 盆地面积 农业量 最大产量 需水量 米价 农业成本 月降雨量 干旱 月 D N P 总收入 ] 品种[代理人] 代理拥有 [ 代理id软件 陆域西南部探员 agehh西南 西南区 光子晶体开关 earlywarn西南 pprob西南 达到 代理收到 代理需求 试剂容量计 药剂用量 代理收益率软件 代理收入软件 Y 存储容量 ] ; 设置 设置 清除所有 定义月份 设定月降雨量848.5;;2011年至2014年流域最大降雨量 定义农业产量 设定百分比agri 0.17;;假设流域17%的水分配用于农业 设置流域面积9.205e+15;;9.205e+15平方毫米的表面积 设定产量最大值为6.15;;6.15吨大米/公顷 设定需水量528;;528立方米/吨大米 定价大米8963.10;;每吨大米8963.10越南盾 设定农业成本50万元;;每个种植季节500000越南盾 结束 定义月份 如果(滴答声=1)或(滴答声=13)或(滴答声=25)或(滴答声=37)或(滴答声=49)或(滴答声=61)或(滴答声=73)或(滴答声=85)或(滴答声=97)或(滴答声=109) [ 设定月份“一月” ] 如果(滴答声=2)或(滴答声=14)或(滴答声=26)或(滴答声=38)或(滴答声=50)或(滴答声=62)或(滴答声=74)或(滴答声=86)或(滴答声=98)或(滴答声=110) [ 设定月份“二月” ] 如果(滴答声=3)或(滴答声=15)或(滴答声=27)或(滴答声=39)或(滴答声=51)或(滴答声=63)或(滴答声=75)或(滴答声=87)或(滴答声=99)或(滴答声=111) [ 设定月份“三月” ] 如果(滴答声=4)或(滴答声=16)或(滴答声=28)或(滴答声=40)或(滴答声=52)或(滴答声=64)或(滴答声=76)或(滴答声=88)或(滴答声=100)或(滴答声=112) [ 定月“四月” ] 如果(滴答声=5)或(滴答声=17)或(滴答声=29)或(滴答声=41)或(滴答声=53)或(滴答声=65)或(滴答声=77)或(滴答声=89)或(滴答声=101)或(滴答声=113) [ 设定月份“五月” ] 如果(滴答声=6)或(滴答声=18)或(滴答声=30)或(滴答声=42)或(滴答声=54)或(滴答声=66)或(滴答声=78)或(滴答声=90)或(滴答声=102)或(滴答声=114) [ 设定月份“六月” ] 如果(滴答声=7)或(滴答声=19)或(滴答声=31)或(滴答声=43)或(滴答声=55)或(滴答声=67)或(滴答声=79)或(滴答声=91)或(滴答声=103)或(滴答声=115) [ 设定月份“七月” ] 如果(滴答声=8)或(滴答声=20)或(滴答声=32)或(滴答声=44)或(滴答声=56)或(滴答声=68)或(滴答声=80)或(滴答声=92)或(滴答声=104)或(滴答声=116) [ 设定月份“八月” ] 如果(滴答声=9)或(滴答声=21)或(滴答声=33)或(滴答声=45)或(滴答声=57)或(滴答声=69)或(滴答声=81)或(滴答声=93)或(滴答声=105)或(滴答声=117) [ 设定月份“九月” ] 如果(滴答声=10)或(滴答声=22)或(滴答声=34)或(滴答声=46)或(滴答声=58)或(滴答声=70)或(滴答声=82)或(滴答声=94)或(滴答声=106)或(滴答声=118) [ 设定月份“十月” ] 如果(滴答声=11)或(滴答声=23)或(滴答声=35)或(滴答声=47)或(滴答声=59)或(滴答声=71)或(滴答声=83)或(滴答声=95)或(滴答声=107)或(滴答声=119) [ 设定月份“11月” ] 如果(滴答声=12)或(滴答声=24)或(滴答声=36)或(滴答声=48)或(滴答声=60)或(滴答声=72)或(滴答声=84)或(滴答声=96)或(滴答声=108)或(滴答声=120) [ 设定月份“12月” ] 结束 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;蓄水模型 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; 运行模式 转西南 打上钩 定义代理软件 定义农业产量 提前警告 定义收到的 定义需求 储水 使用储存水 定义产量sw 定义收入sw 定义总收入 如果滴答声=121[停止] 结束 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; 输入数据 定义代理软件 创建代理111 问探员[藏海龟] 随机种子新种子 文件打开“agent\u id\u sw.txt” foreach排序代理[询问?[设置代理id sw文件读取]] 文件关闭 文件打开“landarea_sw.txt” foreach分拣代理[询问?[设置代理landarea sw文件读取]] 文件关闭 文件打开“agehh_sw.txt” foreach排序代理[询问?[设置agehh sw文件读取]] 文件关闭 文件打开“district_sw.txt” foreach分拣代理[询问?[设置地区软件文件读取]] 文件关闭 文件打开“pcons_sw.txt” foreach分拣代理[询问?[设置pcons软件文件读取]] 文件关闭 文件打开“earlywarn_sw.txt” foreach排序代理[询问?[设置早期警告软件文件读取]] 文件关闭 文件打开“pprob_sw.txt” foreach排序代理[询问?[设置pprob sw文件读取]] 文件关闭 结束 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; 贮水工艺 定义农业产量的步骤 随机集d 0.9676;;或将d设置为随机1 If else d>=0.8998 [ 设定农业用水量(月降雨量*(1-d)*流域面积*农业用水量百分比) 使干燥
to go
   fd 1
end
to go
   ask turtles [fd 1]
end
 ifelse reach = "REACHED"
      [
        ifelse y >= 0.5
        [
          store-water
          use-storedwater        
        ]....................