Re: [netlogo-users] How to check if 2 different breeds of turtles are on the same patch

172 views
Skip to first unread message
Message has been deleted

Efrat Dener

unread,
Apr 12, 2020, 1:40:23 AM4/12/20
to ZINAN, netlogo-users
You can use turtle-set to make a set from two different breeds and perform actions on them

On Sun, 12 Apr 2020 at 1:38 ZINAN <tiagoricar...@gmail.com> wrote:

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]

  [

  ]

--
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/23f9f913-74ac-4b5d-b7e5-5d5e7a0c77a5%40googlegroups.com.
Message has been deleted

Arthur Hjorth

unread,
Apr 14, 2020, 3:38:42 AM4/14/20
to ZINAN, netlogo-users
The simple reporter statement for what you want to do is (assuming cars and people are the plural names of your turtle breeds):

cars with [any? people-here] 

alternatively

people with [any? cars-here]

This will give you an agentset with all cars that have a person on the same patch / people that have a car on the same patch.

Please not that your java example is not exactly what this does. It does not do a check on x or y coordinates. It only checks on patches. You can do a check on x and y coordinates, but this will slow it down (and given the 17 decimals is unlikely to give positives, unless you round off).

On Sun, Apr 12, 2020 at 1:40 PM ZINAN <tiagoricar...@gmail.com> wrote:
Didn't really understand that, please explain


On Sunday, April 12, 2020 at 6:40:23 AM UTC+1, Ef D wrote:
You can use turtle-set to make a set from two different breeds and perform actions on them
On Sun, 12 Apr 2020 at 1:38 ZINAN <tiagoricar...@gmail.com> wrote:

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]

  [

  ]

--
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 netlog...@googlegroups.com.

--
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.


--
Arthur Hjorth
Post Doctoral Fellow
Aarhus University

s: arthurhjorth

Aaron Andre Brandes

unread,
Apr 14, 2020, 10:48:12 AM4/14/20
to ZINAN, netlogo-users

Hi,

I have attached a simple model in which collision info is output to the command center.

You can write the output to a file. See

https://ccl.northwestern.edu/netlogo/docs/dictionary.html#file-type

 

and the associated links.

 

The most relevant method is record-collision (see below) in which the people check for cars on their location using cars-here.

We need to be careful to account for the case when there are no cars here, so any? Is used.

 

See <breeds>-here

https://ccl.northwestern.edu/netlogo/docs/dictionary.html#turtles-here

 

and 

 

any?

https://ccl.northwestern.edu/netlogo/docs/dictionary.html#any

 

 

to record-collision

  ; If a person has a car on its location, that is a collision.

  ; Note: if neither turtle moves, another collision at the same point will

  ; be recorded

  ask people [

    if any? cars-here [

      type "Ouch! Collsion at "

      type xcor

      type " "

      print ycor

    ]

  ]

End

 

Aaron

 

 

 

 

(I sent this earlier, but forgot to reply-all)

 

-- 

Aaron Brandes, Software Developer

Center for Connected Learning and Computer-Based Modeling

 

 

From: <netlog...@googlegroups.com> on behalf of ZINAN <tiagoricar...@gmail.com>
Date: Saturday, April 11, 2020 at 6:39 PM
To: netlogo-users <netlog...@googlegroups.com>
Subject: [netlogo-users] How to check if 2 different breeds of turtles are on the same patch

 

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]
 
  [
 
  ]

--
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.

record-collisions-cars-people.nlogo
Reply all
Reply to author
Forward
0 new messages