WSC Solar Race Simulation
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This program is a simple simulator for the World Solar Challenge. Many things are simplified, and control stops are completely ignored. See the associated blog post for a more detailed explanation: http://scientificgems.wordpress.com/2014/06/23/simulating-the-world-solar-challenge/
HOW TO USE IT
The "Setup" button initialises the simulation, and the "Run" button begins the race. The three green sliders control the car speeds, while the standard slider at the top of the window can be used to speed up the simulation.
Note that the image file "ozmap1.png" is required and that the display will go black during the (simulated) night.
Comments and Questions
breed [ cars car ]
breed [ waypoints waypoint ]
undirected-link-breed [ roads road ]
globals [ car1 car2 car3 car-colors day hour night?
wh-coeff waypoint-coords start-grid start-time conditions
ticks-per-hour km-per-patch initial-battery battery-max ]
patches-own [ old-color ]
cars-own [ car-speed battery goals km-done hours-done history ]
to setup
clear-all
let fname "ozmap1.png"
ifelse (file-exists? fname)
[ import-pcolors fname ]
[ user-message (word "The file \"" fname "\" is needed for map display")
ask patches [ set pcolor brown ]
]
set waypoint-coords [ [ 53 91 "Darwin" ] [ 56 86 "Katherine" ] [ 60 72 "Tennant Ck" ] [ 62 62 "Alice Springs" ] [ 67 45 "Coober Pedy" ] [ 74 26 "Finish" ] ]
let last-waypoint nobody
foreach waypoint-coords [
create-waypoints 1 [
setxy (item 0 ?) (item 1 ?)
set color red
set shape "circle"
set size 2
if (last-waypoint != nobody) [ create-road-with last-waypoint [ set color red ] ]
set last-waypoint self
]
]
set wh-coeff (list -47.619 2.6927 -0.038214 0.00018056)
set start-grid (item 0 waypoint-coords)
set conditions [ "sunny" "hazy" "sunny" "cloudy" "sunny" ]
set ticks-per-hour 60
set start-time 8
set km-per-patch (2996 / (sum [ link-length ] of roads))
set battery-max 5000
set initial-battery battery-max
set night? false
create-cars 3 [
set shape "car"
setxy (item 0 start-grid) (item 1 start-grid)
set goals (but-first waypoint-coords)
let wp (item 0 goals)
facexy (item 0 wp) (item 1 wp)
set heading 90
set size 5
set label-color white
set battery initial-battery
set km-done 0
set hours-done 0
set car-speed 0
set history ""
]
set car-colors [ blue green pink ]
let car-list (sort cars)
(foreach car-list (n-values 3 [ ? ]) [
ask ?1 [
set label (?2 + 1)
set color (item ?2 car-colors)
]
])
set car1 (item 0 car-list)
set car2 (item 1 car-list)
set car3 (item 2 car-list)
reset-ticks
end
to-report watts-input-for-time [ t d ]
let max-solar 1200
let weather (weather-for-day d)
ifelse (weather = "hazy")
[ set max-solar 1000 ]
[ if (weather = "cloudy") [ set max-solar 800 ] ]
ifelse (t <= 6 or t >= 18.5)
[ report 0 ]
[ let a (cos ((t - 12.25) * 180 / 12.5))
let b (max-solar * a)
ifelse (t >= 8 and t <= 17)
[ report b ]
[ report 2 * b ]
]
end
to-report wh-per-km-for-speed [ s ]
report sum (map [ ?1 * ?2 ] wh-coeff (list 1 s (s * s) (s * s * s)))
end
to-report battery-pc
report battery * 100 / battery-max
end
to-report relative-hours-done
report hours-done - km-done / 80
end
to-report weather-for-day [ d ]
ifelse (d >= length conditions)
[ report "cloudy" ]
[ report (item d conditions) ]
end
to-report nice-time [ t d long-form ]
let h (floor t)
let m ((hour - h) * 60)
let m1 (floor (m / 10))
let m2 (floor (m - m1 * 10))
let weather-text ""
let day-text (word " [" (d + 1) "]")
if (long-form) [
set weather-text (word " (" (weather-for-day d) ")")
set day-text (word ", day " (d + 1))
]
report (word h ":" m1 m2 day-text weather-text)
end
to-report run-tick [ t d ]
let w (watts-input-for-time t d)
set battery (battery + w / ticks-per-hour)
ifelse (t < 8 or t > 17 or goals = [])
[ set car-speed 0
if (battery > battery-max) [ set battery battery-max ]
report 0
]
[ set car-speed (ifelse-value (self = car1) [ speed1 ] [ ifelse-value (self = car2) [ speed2 ] [ speed3 ] ])
let wd (wh-per-km-for-speed car-speed)
let dist (car-speed / ticks-per-hour)
while [ wd * dist > battery ] [
set car-speed (car-speed - 1)
set wd (wh-per-km-for-speed car-speed)
set dist (car-speed / ticks-per-hour)
]
set battery (battery - wd * dist)
if (battery > battery-max) [ set battery battery-max ]
set km-done (km-done + dist)
set hours-done (hours-done + 1 / ticks-per-hour)
report dist
]
end
to go ;; single simulation step
let h (start-time + (ticks / ticks-per-hour))
set day (floor (h / 24))
set hour (h - 24 * day)
if (hour >= 6 and night?) [
set night? false
ask patches [ set pcolor old-color ]
]
if (hour >= 18.5 and not night?) [
set night? true
ask patches [ set old-color pcolor set pcolor black ]
]
ask cars [
let dist (run-tick hour day)
while [ dist > 0 and goals != [] ] [
let wp (item 0 goals)
let d0 (km-per-patch * distancexy (item 0 wp) (item 1 wp))
facexy (item 0 wp) (item 1 wp)
ifelse (dist < d0)
[ forward (dist / km-per-patch)
set dist 0
]
[ set dist (dist - d0)
let z (word (item 2 wp) ": " (nice-time hour day false))
ifelse (history = "")
[ set history z ]
[ set history (word history "; " z) ]
set goals (but-first goals)
]
]
]
if (count cars with [ goals != [] ] = 0) [ stop ]
tick
end
There are 2 versions of this model.
Attached files
| File | Type | Description | Last updated | |
|---|---|---|---|---|
| ozmap1.png | png | Background map image (required) | over 11 years ago, by Anthony Dekker | Download |
| WSC Solar Race Simulation.png | preview | Preview for 'WSC Solar Race Simulation' | over 11 years ago, by Anthony Dekker | Download |
This model does not have any ancestors.
This model does not have any descendants.
Download this model
Anthony Dekker
Comment
For a detailed explanation, see the associated blog post at http://scientificgems.wordpress.com/2014/06/23/simulating-the-world-solar-challenge/
Posted over 11 years ago