运行 time:schedule-活动无效

Running time:schedule-event does not work

我对 NetLogo 比较陌生,但我想模拟司机的集体充电行为。现在,我想实施一个时间表(例如,司机在早上 8 点到下午 5 点之间在路上,因此有资格在这些时间之前和之后充电)。为此,我将时间固定在滴答声上。但是现在执行 "to setup-schedule" 不起作用。我已经查看了 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

恐怕时间扩展的离散事件调度部分不适用于当前版本的 NetLogo。 (扩展的其余部分仍然有效,即使您在使用 NetLogo 6.1 启动模型时可能会收到警告。)

NetLogo 开发团队开始修复使用 NetLogo 打包的时间延长,但工作似乎有所放缓。 (扩展的原始程序员不再支持它。)我会要求他们给予它更高的优先级,但任何其他想要进行离散事件模拟的人(除了扩展的其他功能,例如将报价链接到特定数量的时间)可能还想让开发人员知道。

如果您有一个代表一小时的刻度,并且您希望所有海龟每天都在特定时间去做某事,那么只需使用 mod 函数即可。类似于:

if ticks mod 24 = 9 [ask turtles [go-to-work] ]