Peter Schwemberger
Peter Schwemberger

Reputation: 1

Netlogo - Turtles crossing Line

i want to count the turtles which cross the line - i tried with "turtle on patch" but if the turtle stop it counts twice. If the turtle moves more then 1 patch it counts nothing... any ideas? Thanks Peter

Line

Upvotes: 0

Views: 100

Answers (2)

JenB
JenB

Reputation: 17678

If the line is definitely going to be vertical (as in your diagram) then the easiest way may be simply to count the turtles with pxcor larger than whatever coordinate the line is at plus something for the car size.

Upvotes: 0

Wade Schuette
Wade Schuette

Reputation: 1473

From the picture you added it looks like you are running a single-lane traffic model with a very narrow "finish line" that turtles can cross entirely in one tick.

To catch crossings:

One thing you could do is make a thicker "line" on the far side of the finish line. Maybe make it 5 patches wide. You could color it yellow while you're testing, and change it to hidden when you're sure it is working. If a turtle is on that patch, it has crossed the line. If you make it wide enough it should be impossible to leap over at any speed. It should be easy to test using only one turtle and running the model slowly.

To count stopped cars:

Without seeing your code it's hard to tell why you are counting stopped cars twice. Can you post your code or the relevant section of it here? I'm guessing you have some global that you are incrementing each time you find a new stopped car.

It's less efficient, but much more reliable to let the cars own a variable like "stopped?" that you initialize to false and set to true when the car crosses the line. Then at any time you can get the accurate count of stopped cars with

count cars with [ stopped? = true ]

Assuming you have a variable called my-count of stopped cars, and you want to see when that goes wrong, you could insert a line of code like

if mycount != count cars with [stopped? = true] [user-message "count is wrong!"]

Upvotes: 0

Related Questions