Robotic Factory
Model was written in NetLogo 6.2.2
•
Viewed 190 times
•
Downloaded 8 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
turtles-own [ energy goal picking packing dispatching charging turtles-present pending collected packaged dispatched laden? my-speed ] ;;;;;;;;;;;;;;;;;;;;;; ;; SETUP PROCEDURES ;; ;;;;;;;;;;;;;;;;;;;;;; to setup clear-all setup-patches ;; patches draw themselves __change-topology false false ;; square map, instead of torus, means agents cant wrap sides let picking-goal patches with [ ;; make agentset of patches where storage is connected to road pcolor = brown and any? neighbors with [ pcolor = gray + 2 ]] ;; patches that are brown, beside a road let packing-goal patches with ;; make agentset of patches where agents can pack [ pcolor = green and any? neighbors4 with [pcolor = gray + 2 ]] ;; patches that are yellow, beside a road let dispatching-goal patches with ;; make agentset of patches where agents can drop packages [ pcolor = blue and any? neighbors4 with [pcolor = gray + 2 ]] let charging-goal patches with ;; make agentset of patches where agents can charge [ pcolor = yellow and any? neighbors4 with [pcolor = gray + 2 ]] ;; patches that are yellow, beside a road ;; set location, direction, energy and color create-turtles num-turtles [ ;; initlialise n turtles move-to one-of patches with [ pcolor = gray + 2 ] ;; place on road separate set energy 300 set pending num-turtles ;; slider num set color white set picking one-of picking-goal ;; agent goal random storage set packing one-of packing-goal ;; agent goal random pack point set dispatching one-of dispatching-goal ;; agent goal random drop point set charging one-of charging-goal ;; choose random charge point set goal picking ;; agent goal is packing point ] reset-ticks end to setup-patches ;; build warehouse ask patches with [pycor < 15 and pycor > -10 and pxcor < 15 and pxcor > -15] [ set pcolor brown ] ;; STORAGE ask patches [ if pycor = 15 or pycor = -15 or pycor = 10 or pycor = -10 or pycor = 5 or pycor = -5 or pycor = 0 or pxcor = 15 or pxcor = -15 or pxcor = 10 or pxcor = -10 or pxcor = 5 or pxcor = -5 or pxcor = 0 [ set pcolor gray + 2 ] ;; ROAD if pycor > -15 and pycor < -10 [ set pcolor gray + 2 ] ;; ROAD if pxcor = 16 or pxcor = -16 or pycor = 16 or pycor = -16 [ set pcolor black + 3] ;; WALLS if pycor > -16 and pycor < -12 and pxcor > -16 and pxcor > -16 and pxcor < 16 [ set pcolor yellow ] ;; CHARGE STATION if pycor > 10 AND pycor < 15 AND pxcor > -15 AND pxcor < -10 [ set pcolor green ] ;; PACKING if pycor < -5 AND pycor > -10 AND pxcor < 15 AND pxcor > 10 [ set pcolor blue ] ;; DROP OFF ] end to separate ;; separate turtles if any? other turtles-here [ move-to one-of patches with [ pcolor = gray + 2 ]] ;; if collision, place elsewhere end ;;;;;;;;;;;;;;;;;;;;;;;; ;; RUNTIME PROCEDURES ;; ;;;;;;;;;;;;;;;;;;;;;;;; to go check-trail? check-goal? check-charge move tick end to check-trail? ;; agents draw their path ask turtles [ set turtles-present count turtles-here ifelse show-trail? [ pen-down ] [ pen-up ] ] end to check-goal? ;; agents display goal as label ask turtles [ set turtles-present count turtles-here ifelse show-goal? [ if goal = picking [ set label "picking" ] if goal = packing [ set label "packing" ] if goal = dispatching [ set label "dispatching" ] if goal = charging [ set label "charging" ] ] [ set label "" ] ] end to check-charge ask turtles [ ifelse energy < 100 and (goal = picking or goal = packing) ;; if charge below 100 and agent has cancelled pick or pack [ set goal charging set pending pending + 1 ] ;; charge and add order to pending again [ ifelse energy < 100 and (goal = dispatching) ;; if charge below 100 and cancelled dispatch [ set goal charging set packaged packaged - 1 set pending pending + 1 ] ;; charge and cancel packaged [ if energy < 100 [set goal charging set color orange]] ;; otherwise, charge ] ] end to move ask turtles [ face next-patch ;; face goal set-speed ;; move forward if possible ] end to reduce-speed fd -1 set my-speed 0 end to increase-speed fd 1 set my-speed 1 end to set-speed if energy > 505 [ fd 1 ] ;; fixes glitch where agents freeze occasionally after charging ifelse not member? patch-here [neighbors4] of charging [ ifelse any? turtles-on patch-ahead 1 ;; if path is blocked [ lt random 90 ;; incrementally turn ifelse [ pcolor ] of patch-ahead 1 != grey + 2 ;; if not facing path [ lt random 90 set color pink ] ;; incrementally turn and color pink when avoiding obstacle [ increase-speed update-energy ] ;; when path clear move and reduce charge ] [ increase-speed update-energy ] ] ;; move and reduce charge ] [ set heading 0 update-energy ;; face up if pcolor != yellow [ reduce-speed update-energy] ;; stay still and begin charging ] end to update-energy ifelse laden? = true ;; if carrying item, [ set energy energy - 2 ] ;; increase rate of energy consumption [ set energy energy - 1 ] ;; otherwise, normal rate if member? patch-here [neighbors] of charging [ set energy energy + 10 ] ;; increase turtle energy when on bay if pcolor = yellow and energy > 499 [ increase-speed set goal picking ] ;; if full charge leave bay end to-report next-patch ;; establish goal of agent if goal = picking [ set color white ] if goal = picking and (member? patch-here [ neighbors4 ] of picking) [ ;; if goal pick and order picked set goal packing ;; goal set to packing order set color green - 1 set pending pending - 1 set laden? true ;; carrying item ] if goal = packing [ set color green ] if goal = packing and (member? patch-here [ neighbors4 ] of packing) [ ;; if goal pack and order packed set goal dispatching ;; goal set to dispatching order set color blue - 1 set packaged packaged + 1 ] if goal = dispatching [ set color blue ] if goal = dispatching and (member? patch-here [ neighbors4 ] of dispatching) [ ;; if goal drop and order dropped set goal picking ;; goal set to next order set color white set dispatched dispatched + 1 set packaged packaged - 1 set pending pending + 1 set laden? false ;; not carrying item ] ;; CHOICES is agentset of the candidate patches that the robot can move to let choices neighbors with [ pcolor = gray + 2 or pcolor = yellow] ;; grey patches are roads let choice min-one-of choices [ distance [ goal ] of myself ] ;; move to patch closest to goal report choice ;; report chosen patch end to watch-robot stop-watching watch one-of turtles ;; pick random agent ask subject [ inspect self ;; show view set size 1.5 ;; increase size ask picking [ set pcolor yellow - 1 set plabel-color yellow set plabel "picking" ] ask packing [ set pcolor orange - 1 set plabel-color orange set plabel "packing" ] ask dispatching [ set pcolor white - 1 set plabel-color white set plabel "dispatching" ] ask charging [ set pcolor red - 1 set plabel-color red set plabel "charging" ] set label [ plabel ] of goal ] end to stop-watching ;; reset the picking and packing patches from previously watched car(s) to the background color ask patches [ if pcolor = orange - 1 [ stop-inspecting self set pcolor green set plabel "" ] if pcolor = red - 1 [ stop-inspecting self set pcolor yellow set plabel "" ] if pcolor = yellow - 1 [ stop-inspecting self set pcolor brown set plabel "" ] if pcolor = white - 1 [ stop-inspecting self set pcolor blue set plabel "" ] ] ask turtles ;; close open inspectors [ set label "" stop-inspecting self ] reset-perspective end ;; JACK MCGRADY 2022 ;; SOME ELEMENTS INSPIRED FROM " TRAFFIC GRID GOAL" & "FACTORY ROBOTS" (URI WILENSKY)
There is only one version of this model, created almost 2 years ago by Jack M.
This model does not have any ancestors.
This model does not have any descendants.