globals [intake15m ticks daytime plotreset]
turtles-own [TIW Lean_Weight Lean_Energy Fat_Weight Fat_Energy Energy BMR W Wt1 Wdot critical_W ill_W critical_E rand_BMR grass_aten MaxW MovCost kolor]
patches-own [cell_mass first_mass]
to-report time
report (ticks / 4) / 24
end
to-report hour
report daytime
end
to-report basal-metabolic-rate [ weight ]
report ((1.4 + (0.03 * weight)) * 1000 ) / 96.0 ;; # basal cost each 15min
end
to rapport
print ""
print ""
print "Weight"
print W
print "Lean_Weight"
print Lean_Weight
print "Lean_Energy"
print Lean_Energy
print "Fat_Weight"
print Fat_Weight
print "Fat_Energy"
print Fat_Energy
print "Total energy"
print Energy
print "Critical weight"
print critical_W
print "Ill weight limit"
print ill_W
print "BMR"
print BMR
end
to setup_patches
ask patches [
set cell_mass 0
set first_mass cell_mass
]
ask patches with [(pxcor > 0) and (pycor > 0)] [
set cell_mass (random-float npp)
set first_mass cell_mass
cell_repaint
]
end
to setup
ca ; #clear all
set daytime 1
set intake15m 0.10417 ;; Kg
set plotreset 0
create-turtles asses
ask turtles [
ifelse randpos?
[
setxy random-xcor random-ycor
][
setxy random-normal 0 3 random-normal 0 3
]
set TIW 200 ;; #Total Initial Weight 200kg
set W TIW
;; set MaxW (W + (W * 0.01)) ;; # Max weight, 20% plus than the initial weight
set MaxW W
set Wt1 W
set Wdot 0 ;; rate of change of the weight
set Lean_Weight (W * 0.8) ;; #Lean weight: 80% of initial weight
set Lean_Energy (Lean_Weight * 4000) ;; #1kg Lean -> 4000kcal (Wikipedia)
set Fat_Weight (W * 0.2) ;; #Fat weigth 20% of initial weight
set Fat_Energy (Fat_Weight * 7800) ;; #1kg Fat -> 7800Kcal (Wikipedia)
set Energy (Fat_Energy + Lean_Energy)
set BMR basal-metabolic-rate (Lean_Weight) ;; #Basal metabolic rate
set critical_W ( Lean_Weight * 0.7 ) ;; # Bottom weight limit the animal has,
;; # defined as the 70% of the Lean weight
;; # if the animal reach this weight, must die
set critical_E (critical_W * 4000)
set ill_W (W - (W * .18)) ;; # Ill limit
set kolor color
;; rapport
]
;; ask patches [
;; set cell_mass (random-float npp)
;; set first_mass cell_mass
;; ;; set pcolor scale-color green cell_mass 0 npp
;; cell_repaint
;; ]
setup_patches
end
to cell_repaint
ifelse showgrass? [
set pcolor scale-color green cell_mass 0 npp
] [
set pcolor black
]
end
to-report grass2fat [grass]
report grass * 0.14525641025641026 ;; 1kg grass -> 0.14525641025641026kg of fat (1133kg_grass / 7800kg_fat)
end
to-report kcal2fat [fat]
report fat / 7800.0
end
to-report kcal2lean [lean]
report lean / 4000.0
end
to eat_grass
set grass_aten 0
if (cell_mass > intake15m) [
set grass_aten (random-normal (intake15m + (hunger / 96)) 0.05) ;; 10kg/day (0.10417kg/15min) , random window 0.5kg/day (0.0052084/15min)
if (grass_aten < 0) [
set grass_aten 0
]
set cell_mass (cell_mass - grass_aten)
cell_repaint
set Fat_Energy Fat_Energy + (grass_aten * 1133) ;; 1133kcal/kgr of dry grass
set Fat_Weight Fat_Weight + grass2fat grass_aten
set W (Fat_Weight + Lean_Weight)
set Energy (Fat_Energy + Fat_Energy)
]
ifelse showenergy?
[
ifelse (grass_aten = 0)[
set label-color blue
][
set label-color yellow
]
set label (round (grass_aten * 100 ) ) / 100 + ","+ round W
][
set label ""
]
end
to BMR_substract
set rand_BMR random-normal BMR (BMR / 2.0)
;; set Energy Energy - rand_BMR
ifelse (W > Lean_Weight) [
set Fat_Energy Fat_Energy - rand_BMR
set Fat_Weight Fat_Weight - (kcal2fat rand_BMR)
][
if (W < critical_W)[
die
]
set Lean_Energy Lean_Energy - rand_BMR
set Lean_Weight Lean_Weight - (kcal2lean rand_BMR)
]
set Energy (Fat_Energy + Lean_Energy)
set W (Fat_Weight + Lean_Weight)
end
to move
set MovCost (W ^ (-.25)) * 0.00239
right uphill cell_mass
forward random-normal 1 0.05
ifelse (W > Lean_Weight) [
set Fat_Energy Fat_Energy - MovCost
set Fat_Weight Fat_Weight - (kcal2fat MovCost)
][
if (W < critical_W)[
die
]
set Lean_Energy Lean_Energy - MovCost
set Lean_Weight Lean_Weight - (kcal2lean MovCost)
]
set Energy (Fat_Energy + Lean_Energy)
set W (Fat_Weight + Lean_Weight)
end
to grow_grass
set cell_mass (cell_mass + ((first_mass / 30.0) / 96.0) )
if (cell_mass > first_mass) [
set cell_mass first_mass
]
cell_repaint
end
to plot-energia
set-current-plot "Energy_plot"
set-current-plot-pen "ass"
plot Energy
set-current-plot-pen "critical"
plot critical_E
set-current-plot-pen "Lean_limit"
plot Lean_Energy
set-current-plot-pen "ave-energy"
plot mean values-from turtles [Energy]
end
to plot-weightdot
set-current-plot "weight_dot"
set-current-plot-pen "wdot"
;; plot mean values-from turtles [Wdot]
plot Wdot
end
to-report wdot_all
report mean values-from turtles [Wdot]
end
to go
ask turtles [
ifelse (daytime <= 48) [
set color kolor
ifelse ( W < MaxW ) [
eat_grass ;; eat grass and add its kcals to the fat energy
if (cell_mass < intake15m)[
move
]
][
if (random-float 1.0) < boring [
move
]
]
][
set color grey
]
BMR_substract
set Wdot (Wt1 - W)
set Wt1 W
set plotreset plotreset + 1
if (plotreset > (asses * draw_interval)) [
clear-plot
set plotreset 0
]
plot-energia
plot-weightdot
]
;;plot-weightdot
ask patches [
grow_grass
]
set ticks (ticks + 1)
ifelse (daytime > 96)[
set daytime 1
][
set daytime (daytime + 1)
]
end