Delivery Drone System
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
(a general understanding of what the model is trying to show or explain)
HOW IT WORKS
(what rules the agents use to create the overall behavior of the model)
HOW TO USE IT
(how to use the model, including a description of each of the items in the Interface tab)
THINGS TO NOTICE
(suggested things for the user to notice while running the model)
THINGS TO TRY
(suggested things for the user to try to do (move sliders, switches, etc.) with the model)
EXTENDING THE MODEL
(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)
NETLOGO FEATURES
(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)
RELATED MODELS
(models in the NetLogo Models Library and elsewhere which are of related interest)
CREDITS AND REFERENCES
(a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links)
Comments and Questions
;; ============================================================ ;; DELIVERY DRONE SYSTEM - Agent-Based Simulation (NetLogo) ;; SE404.3 Agent-Based Systems - Group Assignment ;; ------------------------------------------------------------ ;; Autonomous drones pick up parcels at a depot and deliver them ;; to customers while managing battery, avoiding obstacles and ;; other drones, and coping with weather. System-level patterns ;; (congestion at the depot / charging stations, delivery ;; throughput) EMERGE from simple local agent rules. ;; ;; HOW TO USE: ;; Paste this whole block into the NetLogo "Code" tab. ;; Then build the interface widgets listed at the bottom. ;; ============================================================ ;; ---------- AGENT TYPES (breeds) ---------- breed [ drones drone ] breed [ customers customer ] breed [ depots depot ] breed [ stations station ] ;; charging stations ;; ---------- GLOBAL VARIABLES ---------- globals [ completed-deliveries ;; total parcels delivered failed-deliveries ;; missions lost to a flat battery depot-x depot-y ] ;; ---------- AGENT ATTRIBUTES ---------- drones-own [ battery ;; energy level 0-100 carrying? ;; is it holding a parcel? target ;; the customer being served state ;; FSM state: to-depot / to-customer / to-charge deliveries-made ;; parcels this drone delivered ] customers-own [ waiting? ;; still needs a parcel? assigned? ;; already claimed by a drone? wait-time ;; ticks spent waiting ] patches-own [ obstacle? ;; no-fly zone / building bad-weather? ;; slows drones and drains battery ] ;; ============================================================ ;; SETUP ;; ============================================================ to setup clear-all setup-environment setup-depot setup-stations setup-customers setup-drones set completed-deliveries 0 set failed-deliveries 0 reset-ticks end to setup-environment ask patches [ set obstacle? false set bad-weather? false set pcolor black ] ;; scatter buildings / no-fly zones (keep the depot area clear) ask n-of number-of-obstacles patches with [ distancexy 0 0 > 3 ] [ set obstacle? true set pcolor gray ] ;; seed weather cells if the weather switch is on if weather? [ seed-weather ] end to seed-weather ask patches with [ bad-weather? ] [ set bad-weather? false set pcolor black ] ask n-of 30 patches with [ not obstacle? ] [ set bad-weather? true set pcolor blue - 3 ] end to setup-depot set depot-x 0 set depot-y 0 create-depots 1 [ setxy depot-x depot-y set shape "house" set color yellow set size 3 ] end to setup-stations create-stations number-of-charging-stations [ move-to one-of patches with [ not obstacle? and distancexy 0 0 > 6 ] set shape "circle" set color green set size 2 ] end to setup-customers create-customers number-of-customers [ move-to one-of patches with [ not obstacle? and distancexy 0 0 > 4 ] set shape "person" set color white set size 1.5 set waiting? true set assigned? false set wait-time 0 ] end to setup-drones create-drones number-of-drones [ setxy depot-x depot-y set shape "airplane" set color sky set size 2 set battery 100 set carrying? false set target nobody set state "to-depot" set deliveries-made 0 ] end ;; ============================================================ ;; MAIN LOOP ;; ============================================================ to go ;; stop when every parcel has been delivered if not any? customers with [ waiting? ] [ stop ] ask drones [ consume-battery ;; behaviour 1: use energy run-behaviour ;; behaviour 2: act on the current state ] update-weather ;; dynamic environment ask customers with [ waiting? ] [ set wait-time wait-time + 1 ] tick end ;; ---------- ENERGY (with dead-battery handling) ---------- to consume-battery let drain drain-rate if [ bad-weather? ] of patch-here [ set drain drain * 2 ] ;; env. interaction set battery battery - drain if battery <= 0 [ ;; DECISION RULE: flat battery = failed mission, drone is replaced set failed-deliveries failed-deliveries + 1 if target != nobody [ ask target [ set assigned? false ] ] set target nobody set carrying? false setxy depot-x depot-y set battery 100 set state "to-depot" ] end ;; ---------- FINITE-STATE DECISION MODEL ---------- to run-behaviour if state = "to-depot" [ head-to-depot ] if state = "to-customer" [ head-to-customer ] if state = "to-charge" [ head-to-charge ] end ;; State: go to the depot, pick up a parcel, choose a customer to head-to-depot ;; DECISION RULE: recharge before it is too late if battery < battery-threshold [ set state "to-charge" stop ] ifelse distancexy depot-x depot-y < 1 [ ifelse any? customers with [ waiting? and not assigned? ] [ set target one-of customers with [ waiting? and not assigned? ] ask target [ set assigned? true ] set carrying? true set state "to-customer" ] [ ;; nothing to deliver right now: wait at the depot ] ] [ move-toward depot-x depot-y ] end ;; State: deliver the parcel to the assigned customer to head-to-customer if target = nobody [ set state "to-depot" stop ] ifelse distance target < 1 [ ask target [ set waiting? false set assigned? false ] set completed-deliveries completed-deliveries + 1 set deliveries-made deliveries-made + 1 set carrying? false set target nobody ;; DECISION: recharge if low, otherwise fetch the next parcel ifelse battery < battery-threshold [ set state "to-charge" ] [ set state "to-depot" ] ] [ move-toward [ xcor ] of target [ ycor ] of target ] end ;; State: fly to the nearest charging station and refill to head-to-charge let nearest-station min-one-of stations [ distance myself ] ifelse nearest-station = nobody [ ;; no station available: recharge at the depot ifelse distancexy depot-x depot-y < 1 [ set battery 100 set state "to-depot" ] [ move-toward depot-x depot-y ] ] [ ifelse distance nearest-station < 1 [ set battery battery + charge-rate ;; interaction with the station if battery >= 100 [ set battery 100 set state "to-depot" ] ] [ move-toward [ xcor ] of nearest-station [ ycor ] of nearest-station ] ] end ;; ---------- MOVEMENT + AVOIDANCE ---------- to move-toward [ tx ty ] facexy tx ty ;; INTERACTION RULE: veer away from other drones just ahead if collision-avoidance? [ if any? other drones in-cone 2 45 [ rt 40 ] ] ;; ENVIRONMENT INTERACTION: steer around obstacles let ahead patch-ahead 1 if ahead != nobody and [ obstacle? ] of ahead [ rt 60 set ahead patch-ahead 1 if ahead != nobody and [ obstacle? ] of ahead [ lt 120 ] ] ;; weather slows the drone down let spd drone-speed if [ bad-weather? ] of patch-here [ set spd spd * 0.5 ] fd spd end ;; ---------- DYNAMIC WEATHER ---------- to update-weather if not weather? [ stop ] if ticks mod 50 = 0 [ seed-weather ] ;; weather shifts periodically end ;; ============================================================ ;; OUTPUT REPORTERS (used by monitors / plots) ;; ============================================================ to-report avg-battery ifelse any? drones [ report precision (mean [ battery ] of drones) 1 ] [ report 0 ] end to-report drones-charging report count drones with [ state = "to-charge" ] end to-report avg-wait let w customers with [ waiting? ] ifelse any? w [ report precision (mean [ wait-time ] of w) 1 ] [ report 0 ] end ;; ============================================================ ;; INTERFACE WIDGETS TO ADD (if you build the interface by hand) ;; ------------------------------------------------------------ ;; BUTTONS : setup | go (tick the "forever" box) ;; SLIDERS : number-of-drones 1 - 30 (8) ;; number-of-customers 5 - 80 (40) ;; number-of-obstacles 0 - 150 (50) ;; number-of-charging-stations 1 - 10 (4) ;; drone-speed 0.1- 2 (0.5, step 0.1) ;; drain-rate 0.1- 3 (0.5, step 0.1) ;; battery-threshold 5 - 50 (25) ;; charge-rate 1 - 20 (5) ;; SWITCHES: collision-avoidance? | weather? ;; MONITORS: completed-deliveries | failed-deliveries | ;; avg-battery | drones-charging | avg-wait ;; PLOTS : "Deliveries" -> pen1: plot completed-deliveries ;; pen2: plot failed-deliveries ;; "Average Battery" -> pen: plot avg-battery ;; ============================================================
There is only one version of this model, created 13 days ago by Luthira dissanayeka.
Attached files
| File | Type | Description | Last updated | |
|---|---|---|---|---|
| Delivery Drone System.png | preview | Preview for 'Delivery Drone System' | 13 days ago, by Luthira dissanayeka | Download |
This model does not have any ancestors.
This model does not have any descendants.
Download this model