0

The final part of my design involves me recording down anytime a car breed drives into or in netlogo terms, is on the same patch or X and Y coordinate as the people breed as they navigate across the edge of the screen. Had this been java I could've done something like

if Car.xPostion == Person.xPostion

(Do something...)

But unfortunately I do not know how to do the same in NetLogo, all I've been able to do so far is just ask the two breeds by giving every turtle a boolean variable called movable and setting them to true and the rest to false, is there anyway I can check the two coordinates of two different turtles on Netlogo? This is all I 've been able to do so far.


to record-accidents

  ask turtles with [movable? = true]

  [

  ]

Mercurial
  • 79
  • 8

1 Answers1

3

If you tried something like your java approach, it would fail because turtle positions are continuous and floating numbers are nearly always not equal.

If I have understood your question correctly, you have given a boolean variable called movable? set to true for cars and false for all other breeds. You don't need to do this, turtles know their own breed so you can do ask cars.

To answer your specific question, there are several ways to approach it depending on the perspective (sort of, which agent is in charge).

You could identify patches where there are accidents:, which is the answer to your question in the title (about identifying patches with two breeds).

let accident-locations patches with [any? people-here and any? cars-here]
if any? accident-locations
[ ask accident-locations
  [ <do something>

But you can also take a turtle perspective. You could start from pedestrians who have been hit. This takes advantage of the fact that turtles can automatically access the patch variables (like turtles-here) for the patch where they are located:

let hit people with [any? cars-here]
if any? hit
[ ask hit...

or from cars:

let hitters cars with [any? people-here]
if any? hitters
[ ask hitters...
JenB
  • 17,620
  • 2
  • 17
  • 45
  • so you don't want to identify these patches, just count them? Then something like `set num-accidents num-accidents + count patches with [any? people-here and any? cars-here]` with num-accidents as a global variable – JenB Apr 12 '20 at 15:16
  • Number of accidents this tick is `count patches with [any? people-here and any? cars-here]`. If you want the total over time, just have the monitor display the global variable that you are increasing. Otherwise, needs a new question so you can explain more fully the problem, – JenB Apr 12 '20 at 15:43