Reputation: 2220
Dear Netlogo community,
I want to put some timer constraint in my simulation for agents to make decision. I know we can implement by using ticks but in my simulation all agents should make decision with in a tick and to avoid any deadlock I want to introduce some time constraint for agent to make decision. If agent does not make the decision with in specified time the control of resource should go to other agent. Any help would be really appreciated. Thanks
Upvotes: 2
Views: 740
Reputation: 1295
If you don't have any constraint related to any tick limit you could make a procedure that counts a number of ticks since the main turtle procedure started, something like...
EDITED Code:
procedure turtle-decision-making
set time_passed 0
while time_passed < time_limit
decision-taking-part <<
if decision taken
break while loop
else
set time_passed (ticks_passed + 1)
;; tick Might be that this procedure is the outermost loop, might be that is not.
end while
end turtle-decision-making
Upvotes: 1
Reputation: 30453
If you want to halt the turtle based on how much CPU or "wall clock" time has passed, that it simply isn't possible in NetLogo. There's no way to stop an arbitrary piece of NetLogo code in its tracks from the outside without halting the entire model. Besides, NetLogo is single threaded, so there's only ever one piece of NetLogo code running at any given time, so there's no way to have other NetLogo code interrupt or intervene.
You'll have to do something more like what JenB suggests, or like what David suggests -- both seem like potentially valid approaches, depending on your goals.
Upvotes: 0