I am simulating a classroom to find the total energy consumption from appliances of a classroom. Now I want to run the simulation in BehaviorSpace so that I get the energy consumption (energy-calculation) by varying the number of students in the classroom.
globals[
temp1 simulation-timer number-of-seats number-of-lights
number-of-fans number-of-acs gap row col x-cor y-cor half half2
student-no t-light t-fan t-ac t-energy
]
breed [seats seat]
breed [seat-teachers seat-teacher]
breed [lights light]
breed [fans fan]
breed [acs ac ]
breed [students student ]
seats-own [
seat-color
occupied?
]
seat-teachers-own [
seat-color
]
students-own [
entry-time
found-seat
]
lights-own [
l-energy
]
fans-own [
f-energy
]
acs-own [
a-energy
]
to setup
clear-all
ask patches [ set pcolor 9 ]
set gap floor ((max-pxcor) / (no-of-row-or-col) )
set half ceiling (gap / 2)
set half2 floor (gap / 2)
place-seat-teachers
place-seats-students
place-lights
place-fans
place-acs
ask patches with [ pxcor = 3 * gap + half2 ] [ set pcolor 4 ]
ask patches with [ pxcor = 6 * gap + half2 ] [ set pcolor 4 ]
create-students-classroom
reset-ticks
reset-timer
end
to place-seat-teachers
create-seat-teachers 1 [
setxy ((max-pxcor - min-pxcor) / 2) 1
set shape "square"
set size 3
set color red
]
end
to place-seats-students
set row gap
set col gap
set x-cor 0
set y-cor 0
while [ x-cor <= gap * no-of-row ]
[
ifelse (x-cor = row)[
set col gap
set y-cor 0
while [ y-cor <= gap * no-of-row-or-col ]
[
ifelse (y-cor = col)[
create-seats 1 [
set shape "square"
set size 1.5
set color blue
setxy col row
set label who
set number-of-seats number-of-seats + 1
show (word row ", " col )
]
set col col + gap
set y-cor y-cor + 1
]
[set y-cor y-cor + 1]
]
set row row + gap
set x-cor x-cor + 1
]
[set x-cor x-cor + 1]
]
end
to place-lights
set row gap + half2
set col gap + half
set x-cor 0
set y-cor 0
while [ x-cor <= gap * no-of-row-or-col ]
[
ifelse (x-cor = row)[
set col gap + half
set y-cor 0
while [ y-cor <= gap * no-of-row ]
[
ifelse (y-cor = col)[
create-lights 1 [
set shape "pentagon"
set size 1
set color red
setxy row col
set number-of-lights number-of-lights + 1
show (word row "," col )
]
set col col + ( gap * 2)
set y-cor y-cor + 1
]
[set y-cor y-cor + 1]
]
set row row + ( gap * 2)
set x-cor x-cor + 1
]
[set x-cor x-cor + 1]
]
end
to place-fans
set row ( gap * 2 ) + half2
set col gap + half
set x-cor 0
set y-cor 0
while [ x-cor <= ( gap * no-of-row-or-col ) ]
[
ifelse (x-cor = row)[
set col gap + half
set y-cor 0
while [ y-cor <= ( gap * no-of-row ) ]
[
ifelse (y-cor = col)[
create-fans 1 [
set shape "x" ;; x shape
set size 1
set color red
setxy row col
set number-of-fans number-of-fans + 1
show (word row "," col )
]
set col col + ( gap * 2)
set y-cor y-cor + 1
]
[set y-cor y-cor + 1]
]
set row row + ( gap * 2)
set x-cor x-cor + 1
]
[set x-cor x-cor + 1]
]
end
to place-acs
set row 3
set col 13
set x-cor 0
set y-cor 0
while [ y-cor <= 45 ]
[
ifelse (y-cor = col)[
create-acs 1 [
set shape "star" ;; star shape
set size 1
set color red
setxy row col
set number-of-acs number-of-acs + 1
show (word row "," col )
]
set col col + 10
set y-cor y-cor + 1
]
[set y-cor y-cor + 1]
]
end
to go
set simulation-timer 0
output-show (word "timer = "simulation-timer )
tick
move-students
while [simulation-timer < time ] [
set simulation-timer simulation-timer + 1
output-show (word "timer = "simulation-timer )
]
end
to create-students-classroom
create-students number-of-students [
set entry-time random threshold + 1
let stu-no sort-on [who] students
foreach stu-no [x -> ask x [ show (word x " -> " entry-time ) ]
]
set shape "person"
set color 3
]
end
to move-students
let s sort [who] of seats
let a first s
let l length s
while [ l > (number-of-seats - number-of-students )] [
set temp1 simulation-timer
tick
tick
ask students [ if ( entry-time = temp1 )
[
move-to seat a ; If it does the student moves to a seat
set color red
appliance-on
energy-calculation
show (word temp1 "," l "," a)
set s remove a s
set a a + 1
set l length s
]
]
set simulation-timer simulation-timer + 1
output-show (word "timer = "simulation-timer )
]
end
to appliance-on
ask students [ ask lights in-radius 4
[ set color green ]]
ask students [ ask fans in-radius 4
[ set color green ]]
ask students [ ask acs in-radius 9
[ set color green ]]
stop
end
to energy-calculation
ask lights [ ifelse ( color = green ) [ set l-energy ( light-
wattage * (time - temp1 )) ] [ set l-energy 0 ] ]
ask fans [ ifelse ( color = green ) [ set f-energy ( fan-wattage
* ( time - temp1 )) ] [ set f-energy 0 ] ]
ask acs [ ifelse ( color = green ) [ set a-energy (ac-wattage *
(time - temp1 ))] [ set a-energy 0 ] ]
let light-e sum [l-energy] of lights
let fan-e sum [f-energy] of fans
let ac-e sum [a-energy] of acs
set t-light ( light-e / 60 )
set t-fan (fan-e / 60 )
set t-ac (ac-e / 60 )
show (word "total-ac-time = " t-ac )
set t-energy ( t-light + t-fan + t-ac )
end
In the BehaviorSpace: measure runs using these reporters I am putting energy-calculation but in the spreadsheet everything is showing zero. Why is this happening? When I am seeing the energy-calculation in a monitor it shows a value. What I want to do is run this code several times with different student numbers and get the varied energy-calculation each time. Or should I use file save in .csv for this situation?
You have written
energy-calculationas a command that sets the global variablet-energyrather than as a reported that reportst-energyto the caller. I suspect that in your monitor you have used thet-energyvariable which is reset each timeenergy-calculationis called. But in BehaviorSpace, the reporter by which runs are measured must actually be a reporter. It must return a value to BehaviorSpace. This is easily done by rewritingenergy-calculationasWhether or not you still need the global
t-energyor can simply replace it with the reporter that reports its value, would depend on how else t-energy is used in the code.But, I am actually surprised that the BehaviorSpace experiment tries to run at all. BehaviorSpace should catch that
energy-calculationis not a reporter and throw an error.