In my program, the turtle breed CO2s has initial concentration of 10, and the turtle breed glucose will start with 10 and increase by 10 each tick (as stated in the setup-feed procedure). The to go procedure includes a turtle breed bacteria that eats CO2s and glucose each tick. The problem is that with my current code both breed of turtles, CO2s and glucose, increase each tick. My current output Excel looks like this:
I hope my output Excel can look like this:
Any comments or suggestions on this issue?
Breed [glucose a-glucose];; Glucose
Breed [CO2s CO2]
Breed [bacteria bacterium]
glucose-own [glucose_mass]
bacteria-own [bacteria_mass]
CO2s-own [CO2s_mass]
Globals
[
time
Initial_concentration_glucose
Initial_concentration_CO2s
total_glucose
total_CO2s
]
to setup
clear-all
set time 0
set Initial_concentration_glucose 0
set Initial_concentration_CO2s 0
set total_glucose 0
set total_CO2s 0
;;; BACTERIA;;;
set-default-shape bacteria "default"
create-bacteria (20)
[ set color cyan
set bacteria_mass 20 / 20
]
;;; CO2s;;;
set-default-shape CO2s "circle"
create-CO2s (10)
[set color orange
set CO2s_mass (10 / 10)
setxy random-xcor random-ycor
]
setup-feed
output-1
reset-ticks
end
to setup-feed
set-default-shape glucose "circle";; Glucose shape
Create-glucose (10)
[
set glucose_mass 10 / 10
setxy random-xcor random-ycor
]
end
to output-1
if (file-exists? "TestINOUT-AD.csv") [carefully [file-delete "TestINOUT-AD.csv"] [print error-message]]
file-open "TestINOUT-AD.csv"
file-type "tick,"
file-type "Initial_concentration_glucose,"
file-type "Initial_concentration_CO2s,"
file-type "Bacteria,"
file-type "CO2s,"
file-print "glucose,"
file-close
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; PROCEDURES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go
if not any? turtles [stop]
Calculate_concentrations
ask bacteria
[ eat
]
set time time + 1
count_glucose
count_CO2s
output-2
tick
if (time = 72) [stop]
end
;;;;;;;;;;;;;;;;HELPER PROCEDURES
to Calculate_concentrations
set Initial_concentration_glucose (Initial_concentration_glucose + sum [glucose_mass] of glucose + 0.0000001)
set Initial_concentration_CO2s (Initial_concentration_CO2s + sum [CO2s_mass] of CO2s + 0.0000001)
end
to eat
let prey one-of glucose-here
if prey != nobody
[ask prey [die]]
let prey2 one-of CO2s-here
if prey2 != nobody
[ask prey2 [die]]
end
to output-2
file-open "TestINOUT-AD.csv"
file-type ticks file-type ","
file-type Initial_concentration_glucose file-type ","
file-type Initial_concentration_CO2s file-type ","
file-type total_CO2s file-type ","
file-print total_glucose
file-close
end
to count_glucose
set total_glucose (total_glucose + sum [glucose_mass] of glucose)
end
to count_CO2s
set total_CO2s (total_CO2s + sum [CO2s_mass] of CO2s )
end
Turtles are not being created, your procedure count_glucose is a cumulative sum of glucose_mass and this is what is being output in your file. But your question suggests that you think this is reporting the number of glucose agents.
to count_glucose
set total_glucose (total_glucose + sum [glucose_mass] of glucose)
end
If you actually want to count the glucose agents, then you want count glucose
file-print count glucose
instead of:
file-print total_glucose