Reputation: 39
I am trying to build 4 classrooms in Netlogo and students will be entering the 4 classrooms one by one according to their random entry-time. So in my go procedure, I will have to use multiple (2 times) reset-timer for the students to enter the 4 classrooms one by one. But the students of one classroom are all entering in 0 minutes. Why is this happening?
to go
reset-timer
tick
create-students-classroom
move-students
reset-timer
move-studentsB
reset-timer
move-studentsC
reset-timer
move-studentsD
wait 1
move-student-out
if ticks >= 1 [stop]
end
Upvotes: 1
Views: 81
Reputation: 14972
If you look a the dictionary entry to reset-timer
, you'll see the following warning:
Note that the timer is different from the tick counter. The timer measures elapsed real time in seconds; the tick counter measures elapsed model time in ticks.
I think that the approach that you have tried so far mixes up "ticks" and "real time", which will lead to all sorts of problems down the road.
In an agent-based model, you should really be focusing on ticks, not real-time. Real-time depends on the speed of your computer, and is pretty much meaningless in the context of a simulation. "Ticks," by contrast are really conceptual "model steps" and they're the relevant unit in almost all cases.
By convention, in NetLogo, we run the go
procedure, once per tick. This is why the skeleton of a NetLogo model should almost always look like this:
to setup
clear-all
; some setup code goes here
reset-ticks
end
to go
; some code goes here
tick
end
I don't know enough about what you're trying to achieve to give you a complete solution, but something like this could be a starting point for a tick-based model:
breed [ classrooms classroom ]
breed [ students student ]
students-own [ entry-time ]
to setup
clear-all
set-default-shape classrooms "square"
set-default-shape students "person"
ask n-of 4 patches [ sprout-classrooms 1 ]
ask n-of 50 patches with [ not any? classrooms-here ] [ sprout-students 1 ]
reset-ticks
end
to go
if all? students [ any? classrooms-here ] [
ask students [ show entry-time ]
stop ; stop when all students are in class
]
ask one-of classrooms [
ask one-of students with [ not any? classrooms-here ] [
move-to myself
set entry-time ticks
]
]
tick
end
I won't explain all the code in details, but I would suggest trying to understand what it does by running through it one tick at time and looking up the primitives you don't know in the dictionary. Even if it's not exactly what you're after, it should give you understand how to build a tick-based model and give you some ideas about how to approach your own problem.
Upvotes: 3