Erratic movement, tick, and teleportation issues

172 views
Skip to first unread message

Samir Saidi

unread,
Dec 29, 2023, 10:22:16 AM12/29/23
to netlogo-users
Hi, 

I have a few questions about issues I have encountered making my NetLogo model. The model has three breeds, robots, enemies, and friends. The first issue comes with the movement of the enemies and of the friends: On each tick, each friend must move one step up, down, left or right (randomly), and each enemy must move one, two, or three steps up, down, left or right (randomly). 

To do this, I generate a random integer to decide the direction and multiply it by 90 to get only up/down/left/right. I also generate a random integer to decide the number of steps, in the case of enemies. I use face `some-patch` and move-to `some-patch` for a given patch (based on what was randomly generated) for the robot, and all enemies and friends. Both procedures run once per tick.

I am reasonably sure that this is correct, however, it seems like each tick they move several times, so, the movement itself is correct, but they should only be able to move once per tick. The robot's movement, in comparison, is fully correct, it only moves once per tick, and I can see this by slowing it down on NetLogo. Which leads me to the second issue...

When I remove all enemies and friends from the model, I can see what happens in each individual tick, and this works fine for the robot, one enemy or one friend also shows correct behavior per tick, but adding even a few more enemies or friends makes NetLogo unable to show me what happens in individual ticks (even slowing it down). I have tried ticking and unticking "View Updates" in the interface, and using both "on ticks" and "continuous", but to no avail, all have the same issue. I'm really not sure what's going on here; if anyone has any suggestions or needs further info please let me know.

Samir

Charles Staelin

unread,
Dec 30, 2023, 7:57:45 AM12/30/23
to netlogo-users
Samir,

I assume that your "go" button is a "forever" button?  If so, you can uncheck the "Forever" box and then literally run the model one step at a time by pressing "go" repeatedly.  If agents make more than one move at each press of the button, then there is indeed a coding error.  It would be hard to diagnose without some code to examine, but you might look for a situation where each agent is asking other agents to move, resulting in multiple moves.  E.g., if friends ask enemies to move, or vice versa.  That would be consistent with the model working when there is only one friend and enemy.

Charles

Samir Saidi

unread,
Jan 3, 2024, 10:56:34 AMJan 3
to netlogo-users
Hi Charles,

I've changed the go button from "forever" to run one step at a time and done some debugging with that; I've finally understood the cause of the erratic movement. It seems like robots and friends are both moving twice per tick, even though the procedures for both are only called once per tick. When increasing the number of robots and friends (if either has, say, 5+ instances) the robot will gradually start to take a greater number of steps per tick, even though it is running exactly everything as described in the code, until at a certain point where the number of steps it takes per tick is enough to reach the goal in one tick. This, then, explains the robot's teleportation. I suspect that the interactions between many friends/enemies might be causing it, possibly because of the slowdown expected when running models at larger parameters; the robot is expected to path across over 400 obstacles in the world to reach the goal and interact with/avoid 140 friends/enemies each. I'm still not entirely sure, though.

The movement for the robot is working perfectly fine when running it one step at a time; I've combed through the code and used a bunch of print statements across the execution to confirm that... In any case, I've uploaded all the relevant parts of the code here: https://pastebin.com/02xjvwCy. The move-enemies and move-friends procedures seem fine to me, if a bit messy. I had shorter, more concise code for this but I wanted to standardize the way movement was done with `path-step` (using both "face" and "move-to" rather than "face" and "fd"), and was concerned that it was causing issues because it was done differently. Now I think the shorter code would have also been fine, it was likely just being called twice. The ifelse blocks all seem correctly set up to me too, unless I'm missing something. If you need anything else please let me know!

Samir

James Steiner

unread,
Jan 3, 2024, 11:53:52 AMJan 3
to Samir Saidi, netlogo-users
It is as was suggested: you are committing the common mistake of using ASK _____ inside a procedure that itself was called by ask.


Since you "ask turtles" that means every turtles runs the code inside.

Then, inside "move robots" you say "ask robots" 

So every turtle causes every robot to move every tick.

Remember that ASK isn't just decoration, it makes things happen.

In other works you code looks like this:


ASK TURTLES
[ ASK ROBOTS [ ..... ]
  ASK ENEMIES [ .... ]
   ASK FRIENDS [ ... ]
]

Can you see the problem now?

~~James

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/2c5defaf-1858-4bc3-9d95-374b6acfe195n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages