我希望代理仅记住最后一个刻度的全局变量的值,我想将它们存储在列表中,以后再使用,其中代理应比较列表项并为当前刻度做出决定。我已经尝试实现以下代码,但是这些努力都是徒劳的。
`set time-car_t-2 time-car of tick [n - 2]
set time-car_t-1 time-car of last tick
set history-time-car [list time-car_t-1 time-car_t-2 time-car_t]
用于计算时间车的逻辑已经就绪并且可以正常工作,其中所有三个都是全局变量“时间车”,“时间车t-1”和“时间车t-2”]
任何建议都会有所帮助,我将不胜感激。预先感谢。
time-car-history
指定)的history-length
,该长度最初由-1填充。然后,在test
中,每只海龟都获得time-car
的值(这里只是一个随机数),并将其添加到其历史的开头。因此,当前值在其item 0
中为time-car-history
,之前一个刻度的值为item 1 time-car-history
,依此类推,返回四个刻度。请注意,在将当前值添加到time-car-history
时,我使用but-last
删除了最后一个值,因此仅保存了最近的五个值。如果将此代码粘贴到空白模型中,请在命令行中键入“ setup”,然后重复键入“ test”,您应该会看到其工作原理。turtles-own [time-car-history]
to setup
clear-all
let history-length 5 ; the number of periods you want to save
create-turtles 10 [
; creates a history list of the right length, filled with -1's.
set time-car-history n-values history-length [-1]
]
reset-ticks
end
to test
ask turtles [
set time-car-history fput time-car but-last time-car-history
]
ask turtle 3 [
show time-car-history
show item 0 time-car-history
show item 1 time-car-history
show item 2 time-car-history
]
tick
end
to-report time-car
report random 10
end
我希望这可以帮助您入门,并欢迎您进入NetLogo社区。查尔斯