Energy flow
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
breed [lconsumers lconsumer] breed [dconsumers dconsumer] breed [plants plant] lconsumers-own [ energy pursuit? age max-lifespan ] dconsumers-own [ d-energy decay-time ] plants-own [ growth-rate plant-energy ] patches-own [dead-energy] ;;;;;;;;;;;;;;;;;;;;; ;;; SETUP ;;;;;;;;;;;;;;;;;;;;; to setup clear-all set-default-shape lconsumers "circle" set-default-shape dconsumers "x" set-default-shape plants "triangle" create-lconsumers num-consumers [ set-random-color-nonblack set size 3 setxy random-xcor random-ycor set max-lifespan 30000 + random (30000 - 10) set energy size ] create-plants 50 [ set color 60 set size 1 setxy random-xcor random-ycor set growth-rate random-float 1 set plant-energy 0.5 ] reset-ticks end to set-random-color-nonblack let c random 140 while [c = black] [ set c random 140 ] set color c end ;;;;;;;;;;;;;;;;;;;;; ;;; MAIN LOOP ;;;;;;;;;;;;;;;;;;;;; to go ask lconsumers [ ageing pursue eat check-overlaps if age > max-lifespan [ killconsumer ] ] ask plants [ grow mature ] ask dconsumers [ decay ] replenish-plants replenish-consumers ;; plot total energy set-current-plot "Total Energy" set-current-plot-pen "energy" plot sum [energy] of lconsumers tick end to check-overlaps ;; only for lconsumers if breed = lconsumers [ let opponent one-of other lconsumers with [ distance myself < ((size + [size] of myself) / 2) ] if opponent != nobody [ fight opponent ] ] end ;;;;;;;;;;;;;;;;;;;;; ;;; MOVEMENT ;;;;;;;;;;;;;;;;;;;;; to bounce if xcor >= max-pxcor [ set heading 180 - heading set xcor max-pxcor - 3 ] if xcor <= min-pxcor [ set heading 180 - heading set xcor min-pxcor + 3 ] if ycor >= max-pycor [ set heading 360 - heading set ycor max-pycor - 3 ] if ycor <= min-pycor [ set heading 360 - heading set ycor min-pycor + 3 ] end to turn-towards [target max-turn] if target != self [ ;; prevent self-targeting let angle subtract-headings (towards target) heading if abs angle < max-turn [ set heading heading + angle ] if abs angle >= max-turn [ ifelse angle > 0 [ rt max-turn ] [ lt max-turn ] ] ] end to smooth-wiggle rt random-normal 0 10 fd 0.5 + random-float 0.5 end ;;;;;;;;;;;;;;;;;;;;; ;;; PLANTS ;;;;;;;;;;;;;;;;;;;;; to grow if size <= 5 [ set size size + growth-rate set plant-energy size / 10 ] end to mature if 60 + size * 2 <= 69.9 [ set color 60 + size * 2 ] end to replenish-plants if count plants < 50 [ create-plants production-rate [ set color 60 set size 1 setxy random-xcor random-ycor set growth-rate random-float 1 set plant-energy 0.5 ] ] end ;;;;;;;;;;;;;;;;;;;;; ;;; CONSUMERS ;;;;;;;;;;;;;;;;;;;;; to replenish-consumers if count lconsumers < num-consumers [ create-lconsumers num-consumers - count lconsumers [ set color random 140 set size 3 setxy random-xcor random-ycor set max-lifespan 10000 + random (10000 - 10) set energy size / 2 ] ] end to ageing set age age + 1 end to decay set decay-time decay-time + 1 if decay-time > 3000 + random (3000 - 1000) [ die ] end to pursue ifelse any? other turtles in-radius radius [ let most-energetic-dead max-one-of dconsumers in-radius radius [d-energy] let most-energetic-alive max-one-of other lconsumers in-radius radius [energy] let most-energetic-plant max-one-of plants in-radius radius [plant-energy] ifelse (most-energetic-dead != nobody) [ turn-towards most-energetic-dead 5 fd 0.5 + random-float 0.5 ] [ ifelse (most-energetic-plant != nobody) [ turn-towards most-energetic-plant 5 fd 0.5 + random-float 0.5 ] [ ifelse (most-energetic-alive != nobody) [ turn-towards most-energetic-alive 5 fd 0.5 + random-float 0.5 ] [ smooth-wiggle ] ] ] ] [ smooth-wiggle ] end ;;;;;;;;;;;;;;;;;;;;; ;;; EATING & FIGHTING ;;;;;;;;;;;;;;;;;;;;; to eat let myradius size / 2 if myradius <= 0 [set myradius 0.1] let neighbour min-one-of other turtles in-radius myradius [distance myself] if neighbour != nobody and distance neighbour <= (size / 2) [ let b [breed] of neighbour if b = lconsumers [ fight neighbour ] if b = dconsumers [ nibble-dead neighbour ] if b = plants [ nibble-plant neighbour ] ] end to nibble-plant [food] let bite-size 0.5 if [plant-energy] of food > 0 [ set energy energy + bite-size * energy-ratio ask food [ set plant-energy plant-energy - bite-size set size plant-energy * 10 ;; size reflects remaining energy if plant-energy <= 0 [ die ] ] ifelse energy <= 60 [set size energy] [set size 60 + (energy - 60) * 0.1] ] end to nibble-dead [corpse] ;; transfer *all* the corpse's energy to eater let gain [d-energy] of corpse set energy energy + (gain * energy-ratio) ifelse energy <= 60 [set size energy] [set size 60 + (energy - 60) * 0.1] ;; remove the corpse ask corpse [ die ] end to fight [opponent] let other-size [size] of opponent let death-prob (other-size / (size + other-size)) ifelse random-float 1 < death-prob [ killconsumer ] [ ask opponent [ killconsumer ] ] end to killconsumer ask patches in-radius 30 [ set dead-energy [energy] of myself ] let remaining-energy [dead-energy] of patch-here let nspawn (floor remaining-energy / 3) hatch-dconsumers nspawn [ move-to one-of patches in-radius 15 set d-energy (remaining-energy / nspawn ) * energy-ratio set size 3 ] ask patches in-radius 30 [ set dead-energy 0 ] die end
There is only one version of this model, created 3 days ago by Caius Gibeily.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Energy flow.png | preview | Preview for 'Energy flow' | 3 days ago, by Caius Gibeily | Download |
This model does not have any ancestors.
This model does not have any descendants.