Reputation: 41
I'm rather new to NetLogo but I want to simulate the collective charging behaviour of drivers. For now, I want to implement a schedule (e.g. that the drivers are on the road between 8am and 5pm and therefore are eligible to charge before and after these hours). In order to do so, I anchored the time to the ticks. But now the implementation of the "to setup-schedule" does not work. I already looked at the collinsheppard/time example: "Discrete Event Scheduling" but that does not run either on my computer (an internal error is announced). I would appreciate your help a lot!
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
Upvotes: 0
Views: 127
Reputation: 1736
I am afraid that the discrete event scheduling part of the time extension is not working with the current version of NetLogo. (The rest of the extension still does, even though you may get a warning when starting a model with NetLogo 6.1.)
The NetLogo development team started to fix the time extension for packaging with NetLogo but the work seems to have slowed down. (The original programmer of the extension is no longer available to support it.) I will ask them to give it more priority but anyone else wanting to do discrete event simulation (in addition to the extension's other features, such as linking ticks to specific amounts of time) might also want to let the developers know.
Upvotes: 3
Reputation: 17678
If you have a tick representing one hour and you want all your turtles to go to do something at a particular time each day, then just use the mod
function. Something like:
if ticks mod 24 = 9 [ask turtles [go-to-work] ]
Upvotes: 2