Blinders and the fake sleepers
Model was written in NetLogo 6.4.0
•
Viewed 29 times
•
Downloaded 2 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Info tab cannot be displayed because of an encoding error
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
globals [ explored_sub-region_number ] ;;set the global variable to receive results for the sub-region number being explored patches-own [on-path? sub-region turtle-reached? resource-rate num-patches num-turtles] ;;set the patch own properties turtles-own [current-region residence-time initial-heading recognition-ability has-settled? ] ;;set the turtle own properties ;;create three groups of turtles breed [Blds Bld] breed [FSs FS] breed [Insts Inst] ;; Setup procedure to setup clear-all ;;clear all sets from previous run resize-world -50 50 -50 50 ;; Enlarge the world ;; Initialize all patches ask patches [ set on-path? false ;;set all patches with on-path property false set pcolor black ;;set the color ] ;; Set up the cycling path as a spiral loop let radius 0 let angle 0 let max-radius 40 let angle-increment 5.13 ;; Adjust this value to change the spiral tightness, the value is set to let the color of the circles from a specific angle to the center point is approximately the same. ;; Define sub-regions based on radius intervals let sub-region-interval 1 ;; Each sub-region covers a 1-unit radius interval let current-sub-region 1 ;; Start with the first sub-region ;; Create the spiral path while [radius < max-radius] [ let px round (radius * cos angle) let py round (radius * sin angle) if (px >= min-pxcor and px <= max-pxcor and py >= min-pycor and py <= max-pycor) [ ;; Mark the central path patch let width max list 1 (radius / 10) ;; Adjust the width dynamically ask patches with [distancexy px py <= width] [ set on-path? true set sub-region current-sub-region ;;Assign the sub-region set-sub-region-color sub-region ;; Set the color based on sub-region set turtle-reached? false ;; Initialize turtle-reached as false set resource-rate 0 ;; Initialize resource rate to 0 set num-patches 0 ;; Initialize num-patches to 0 set num-turtles 0 ;; Initialize num-turtles to 0 ] ] set angle (angle + angle-increment) set radius (radius + 0.2) ;; Increment the radius gradually ;; Check if we need to move to the next sub-region if radius >= (current-sub-region * sub-region-interval) [ set current-sub-region current-sub-region + 1 ] ];;end of while ;; Get a list of unique sub-regions ;;let unique-subregions remove-duplicates [sub-region] of patches ;; Initialize an index for the while loop ;;let i 0 ;; Calculate the number of patches for each sub-region using a while loop ;;while [i < length unique-subregions] [ ;; let region item i unique-subregions ;; let count-in-region count patches with [sub-region = region] ;; table:put subregion-patch-counts region count-in-region ;; set i i + 1 ;;] ;; Extract keys and sort them ;;let sorted-subregions sort table:keys subregion-patch-counts ;; Print the counts for each sub-region in sorted order ;;foreach sorted-subregions [ region -> ;; show (word region ": " table:get subregion-patch-counts region) ;;] ;; Create 10 Bld turtles with random initial directions create-Blds 10 [ set color white set shape "triangle" let target-patch one-of patches with [sub-region = 40] ;;let the initial position of the turtle in sub-region #40 if target-patch != nobody [ move-to target-patch ] set current-region [sub-region] of patch-here ;;set the current-region property to the sub-region code where the turtle locates set heading random 360 set initial-heading heading set residence-time 0 ;;initialize the residence time to 0 ] reset-ticks end ;; End of setup procedure ;;Go procedure to go ;; Create a number of Blds every 10 ticks if (ticks mod 10 = 0) [ create-Blds Bld_birth_rate [ set color white set shape "triangle" let target-patch one-of patches with [sub-region = 40] ;;let the initial position of the turtle in sub-region #40 if target-patch != nobody [ move-to target-patch ] set current-region [sub-region] of patch-here set heading random 360 ;;random moving direction set initial-heading heading set residence-time 0 ] ] ;; Create a number of FSs every 10 ticks if (ticks mod 10 = 0) [ create-FSs FS_birth_rate [ set color white set shape "circle" set recognition-ability random max_recognition_ability + 1 ;; Assign a random recognition-ability between 1 and max_recognition_ability set has-settled? false;; Initialize has-settled? to false set residence-time 0 ;;set angle1 0 ;;let target-patch one-of patches with [sub-region = 40] ;;if target-patch != nobody [ ;; move-to target-patch ;;set initial-x xcor ;;set initial-y ycor ;;code to set initial position at a single point ;;setxy inital_pxcor inital_pycor ;; Ensure the initial position is on the path ;;while [not on-path?] [ ;; setxy inital_pxcor inital_pycor ;;] ;;set current-region [sub-region] of patch-here ;;set heading random 360 ;;set initial-heading heading ] ] ;; Create 1 instinctor every 100 ticks if (ticks mod 100 = 0) [ create-Insts 1 [ set color black set shape "star" let target-patch one-of patches with [sub-region = 40] if target-patch != nobody [ move-to target-patch ] set current-region [sub-region] of patch-here set heading random 360 set residence-time 0 ] ] ;; Move Bld turtles within the path ask Blds [ ;; Move in the initial direction set heading initial-heading let target-patch patch-ahead 1 ;; Check if the target patch is within bounds and on the path if (target-patch != nobody and [on-path?] of target-patch and [sub-region] of target-patch <= current-region) [ forward 1 ;; Update the current sub-region if moved to a lower/inner one if [sub-region] of target-patch < current-region [ set current-region [sub-region] of target-patch ] ] ;; If hitting the edge of the path, turn in the opposite direction if (target-patch = nobody or not [on-path?] of target-patch or [sub-region] of target-patch > current-region) [ reflect-heading ] let current-patch patch-here let current-sub-region1 [sub-region] of current-patch ;; Store the sub-region of the current patch ;; If a turtle reaches this patch, mark the entire sub-region as reached ask patches with [sub-region = current-sub-region1] [ set turtle-reached? true ] ;; Increment residence-time and check if it reaches the threshold set residence-time residence-time + 1 if residence-time >= residence_time_threshold [ die ] ] ;; Locate FSs within the path ask FSs with [has-settled? = false] [ ;;initialize has-settled property to be false ;;Identify recognized sub-regions based on recognition-ability let recognized-regions sublist (range 1 41) (40 - recognition-ability) 40 ;;Find the sub-region with the maximum resource-rate let max-resource-region max-one-of patches with [ member? sub-region recognized-regions and turtle-reached? = true ] [resource-rate] if max-resource-region != nobody [ ;; Place FS in a random patch in the sub-region with the maximum resource-rate let target-patch one-of patches with [sub-region = [sub-region] of max-resource-region] if target-patch != nobody [ move-to target-patch ;; Move the FS to the target patch set has-settled? true ;; Mark the FS as settled, preventing further movement ] ] let current-patch patch-here let current-sub-region1 [sub-region] of current-patch ;; Store the sub-region of the current patch ;; If a turtle reaches this patch, mark the entire sub-region as reached ask patches with [sub-region = current-sub-region1] [ set turtle-reached? true ] ;; Increment residence-time and check if it reaches the threshold set residence-time residence-time + 1 if residence-time >= residence_time_threshold [ die ] ] ;; Move Insts turtles randomly within the path ask Insts [ right random 360 let target-patch patch-ahead 1 ;; Check if the target patch is within bounds and on the path if (target-patch != nobody and [on-path?] of target-patch and [sub-region] of target-patch <= current-region) [ forward 1 ;; Update the current sub-region if moved to a lower one if [sub-region] of target-patch < current-region [ set current-region [sub-region] of target-patch ] ] let current-patch patch-here let current-sub-region1 [sub-region] of current-patch ;; Store the sub-region of the current patch ;; If a turtle reaches this patch, mark the entire sub-region as reached ask patches with [sub-region = current-sub-region1] [ set turtle-reached? true ] ;; Increment residence-time and check if it reaches the threshold set residence-time residence-time + 1 if residence-time >= 1000000 [ die ] ] ;; Create lists to store the data for plotting let patch-counts [] let turtle-counts [] let resource-rates [] let valid-sub-regions [] ;; List to track sub-regions that are actually being plotted ;; Update num-patches, num-turtles, and resource-rate for each sub-region let all-sub-regions remove-duplicates [sub-region] of patches foreach all-sub-regions [ current-sub-region -> if current-sub-region != 0 [ ;; Ensure the sub-region is valid let patch-count count patches with [sub-region = current-sub-region] let turtle-count count turtles with [sub-region = current-sub-region] let rate 0 ;; Initialize rate to 0 if turtle-count > 0 [ set rate alpha * patch-count / turtle-count ;; Calculate rate if turtles are present ] ;; Update num-patches, num-turtles, and resource-rate for all patches in the sub-region ask patches with [sub-region = current-sub-region] [ set num-patches patch-count set num-turtles turtle-count set resource-rate rate ] ;; Collect the data for this sub-region set patch-counts lput patch-count patch-counts set turtle-counts lput turtle-count turtle-counts set resource-rates lput rate resource-rates set valid-sub-regions lput current-sub-region valid-sub-regions ] ] ;; Identify unique sub-regions with turtle-reached? = true let explored-sub-regions remove-duplicates [sub-region] of patches with [turtle-reached? = true] ;; Count the number of these sub-regions set explored_sub-region_number length explored-sub-regions ;; Plot the values for each sub-region set-current-plot "Patch_num_subregion" ;; Iterate over each valid sub-region to plot the collected data let sub-region-index 0 foreach valid-sub-regions [ current-sub-region -> ;; Plot for num-patches set-current-plot-pen (word "sub-" current-sub-region) plotxy ticks item sub-region-index patch-counts set sub-region-index sub-region-index + 1 ] ;; Plot the values for each sub-region set-current-plot "Turtle_count_subregion" ;; Iterate over each valid sub-region to plot the collected data let sub-region-index1 0 foreach valid-sub-regions [ current-sub-region -> ;; Plot for turtle-counts set-current-plot-pen (word "sub-" current-sub-region) plotxy ticks item sub-region-index1 turtle-counts set sub-region-index1 sub-region-index1 + 1 ] ;; Plot the values for each sub-region set-current-plot "Resource_rate_subregion" ;; Iterate over each valid sub-region to plot the collected data let sub-region-index2 0 foreach valid-sub-regions [ current-sub-region -> ;; Plot for resource-rates set-current-plot-pen (word "sub-" current-sub-region) plotxy ticks item sub-region-index2 resource-rates set sub-region-index2 sub-region-index2 + 1 ] tick end ;;end of Go procedure ;;funtion to set sub-region color to set-sub-region-color [sub-region1] ;; Use a color scale based on the sub-region number let color-map [red orange yellow green blue violet magenta] let color-index (sub-region1 - 1) mod length color-map set pcolor item color-index color-map end ;;function to reflect heading of Blds to reflect-heading ;; Calculate the normal to the edge let normal (towardsxy (pxcor + 1) pycor) - 90 set heading (2 * normal - heading) mod 360 set initial-heading heading end ;;==================================================================================================================================================================================== ;;Temporal codes for tests ;;==================================================================================================================================================================================== ;; Helper function to check if a patch exists ;;to-report patch-exists? [x y] ;; report (x >= min-pxcor and x <= max-pxcor and y >= min-pycor and y <= max-pycor) ;;end ;; Calculate and mark the middle patch for each angle ;;to calculate-middle-patches ;; ask patches [ ;; set middle-patch? false ;; Reset all patches ;; ] ;; let angles (list 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200 205 210 215 220 225 230 235 240 245 250 255 260 265 270 275 280 285 290 295 300 305 310 315 320 325 330 335 340 345 350 355) ;; foreach angles [ ;; angle -> ;; let patches-at-angle patches with [round towardsxy 0 0 = angle and on-path?] ;; if any? patches-at-angle [ ;; let sorted-patches sort-by [distancexy 0 0] patches-at-angle ;; let middle-index (length sorted-patches / 2) ;; let middle-patch item middle-index sorted-patches ;; ask middle-patch [ ;; set middle-patch? true ;; set pcolor blue ;; Mark the middle patch for visualization ;; ] ;; ] ;;] ;;end ;;to go ;; ask Blds [ ;; let moved? false ;; let attempts 0 ;; while [not moved? and attempts < 8] [ ;; right random 360 / 8 ;; Try different directions in 45-degree increments ;; let target-patch patch-ahead 1 ;; Check if the target patch is valid, on the path, and within the allowed sub-region ;; if (target-patch != nobody and [on-path?] of target-patch and [sub-region] of target-patch <= current-region) [ ;; move-to target-patch ;; set moved? true ;; Update the current sub-region if moved to a lower one ;; if [sub-region] of target-patch < current-region [ ;; set current-region [sub-region] of target-patch ;; ] ;; ] ;; set attempts attempts + 1 ;; ] ;; ] ;; tick ;;end
There is only one version of this model, created 26 days ago by Yizhao Chen.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Blinders and the fake sleepers.png | preview | Preview for 'Blinders and the fake sleepers' | 26 days ago, by Yizhao Chen | Download |
This model does not have any ancestors.
This model does not have any descendants.