我是NetLogo的新手,但我想模拟驱动程序的集体收费行为。目前,我想执行一个时间表(例如,驾驶员在上午8点至下午5点之间的道路上行驶,因此有资格在这些时间之前和之后进行充电)。为了做到这一点,我将时间固定在刻度上。但是现在“到设置时间表”的实现不起作用。我已经看过collinsheppard / time示例:“ Discrete Event Scheduling”,但这在我的计算机上也不运行(宣布内部错误)。非常感谢您的帮助!
extensions time]
globals [
cars-charging ;; number of cars charging
blackout-patch ;; patch showing the blackout label
home-patches ;; agentset of green patches representing BEVs being at home
charge-patches ;; agentset of blue patches representing the charging stations
work-patches ;; agentset of grey patches representing BEVs not being at home
energy-demanded ;; kW requested by BEVs in charging events
q ;; probability of driving somewhere (i.e. work)
tick-datetime ;; time in the model
; blackout-threshold
]
turtles-own [
battery-level
battery-level-minimum
charge?
]
to setup
__clear-all-and-reset-ticks
;; set the start date to January 1, 2020 and link the ticks to one hour
time:anchor-schedule time:create "2020-01-01 00:00" 1 "hour"
set tick-datetime time:anchor-to-ticks (time:create "2020-01-01 00:00") 1 "hour"
setup-world
setup-turtles
setup-schedule
end
to setup-world
;; Creation of Work
set work-patches patches with [pxcor > 1 and pycor < 1]
ask work-patches [set pcolor 37
]
;; Creation of Home
set home-patches patches with [pxcor < 1]
ask home-patches [set pcolor 57 ]
;; Creation of Charging Stations
set charge-patches patches with [pxcor > 1 and pycor > 1]
ask charge-patches [ set pcolor 98 ]
;; use one of the patch labels to visually indicate whether or not the electricity grid is overloaded
ask patch (1 * max-pxcor) (0.33 * max-pycor) [
set blackout-patch self
set plabel-color red
]
end
to setup-turtles
crt 10
ask turtles [
set size 1
set shape "car"
set color 105
move-to-empty-one-of home-patches ;; start at without charging and at home
]
end
to setup-schedule
;; schedule all of the turtles to perform the "move-to-empty-one-of" work-patches procedure at 12am
time:schedule-event turtles [ [] -> move-to-empty-one-of work-patches ] time:create "2020-01-01 12:00"
;; See what's on the schedule
;print time:show-schedule
end
to go
;; stop when there is a blackout
if energy-demanded > blackout-threshold [stop]
;; update the global variables
ask blackout-patch [ set plabel "" ]
;; advance the clock
tick
end
to move-to-empty-one-of [locations] ;; turtle procedure of not using the same patch = same charging station
move-to one-of locations
while [any? other turtles-here]
[move-to one-of locations]
end
答案 0 :(得分:3)
恐怕时间扩展的离散事件调度部分不适用于当前版本的NetLogo。 (即使使用NetLogo 6.1启动模型时,即使您可能会收到警告,扩展的其余部分仍然有效。)
NetLogo开发团队开始修复与NetLogo打包在一起的时间延长,但是工作似乎已经变慢了。 (该扩展程序的原始程序员不再可以支持它。)我将要求他们给予更高的优先级,但是其他任何想要进行离散事件模拟的人(除了扩展程序的其他功能之外,例如将滴答声链接到特定数量)时间)可能还想让开发人员知道。
史蒂夫·R。
答案 1 :(得分:2)
如果您的滴答声代表一个小时,并且您希望所有海龟每天在特定时间去做某事,则只需使用mod
函数。像这样:
if ticks mod 24 = 9 [ask turtles [go-to-work] ]