netlogoagent-based-modeling

How to detect another agent that is located on the left or right side of the current agent and also in a patch set?


I am currently trying to divide an agent's vision into multiple areas from two in-cone rather than him perceiving with only one area from a radius.

More concretely, what I am looking to achieve is to get :

To obtain these two distinct types of vision angles (one in front and two in the periphery) I started by defining two global variables (inspired by the idea of this post):

globals [
  vision-peripheral
  vision-front
]

In order to get two patch sets as follows :

to get-vision
  ;; define angles
  set full-angle full-angle ; beta angles
  set front-angle front-angle ; alpha angle
  set perception-distance perception-distance ; perception distance

  set vision-front patches in-cone perception-distance front-angle
  set vision-peripheral patches in-cone perception-distance full-angle with [not member? self vision-front]

  ask vision-peripheral [set pcolor white] # for debug purpose
  ask vision-front [set pcolor green] # for debug purpose
end

What I want to do from now on is to detect whether one or more other agents are located in the area in front of me, but also in the right or left peripheral parts. I managed to detect that an agent is located in the peripheral zone by accessing global variables, but I can not know if the agents are exactly located in the right (or left) part of this zone :

to detect
  if (any? other turtles-on vision-peripheral) 
  # how to know in which parts instead of only other turtles in vision-peripheral ?
end

How can I detect in which exact part one or more turtles are located? Ideally, it be helpful to know the exact number of turtles in each zone at each time t.

Thanks for any help


Solution

  • Just to make sure I understandod your question correctly, here is a paraphrasing:

    A turtle is trying to detect patches on its left, front, or right. You want to detect these pathches both as one set of agents as something like patches-in-vision, but also separately such as patches-on-left, patches-in-front, and patches-on-right.

    I don’t know the model context, so I have the following generic recommendation that may help:

    Assuming the turtle’s total vision is 180 degrees, each side (left, front, right) as 60 degrees.

    1. Create 3 separate cones for each side
    2. Combine all three separate cones as one agentset for all other patches in vision

    The trick here is to remember that you can make your turtle change heading during the algorithm as long as you return it to its original heading.

    Here’s an example:

    to detect-turtles-in-vision
      
      ; detect patches in front
      let patches-in-front (patches in-cone perception-distance 60)
      ask patches-in-front [ set pcolor green ]
      
      ; turn left to see left peripheral vision
      left 60 
      let patches-on-right (patches in-cone perception-distance 60) 
      ask patches-on-right [ set pcolor white ]
      
      ; turn right to see right peripheral vision
      right 120
      let patches-on-left (patches in-cone perception-distance 60)
      ask patches-on-left [ set pcolor white ]
      
      ; turn left back to the original heading
      left 60
      
      ; combine all of the seen patches in one agentset if necessary
      let patches-in-vision (patch-set patches-on-left patches-in-front patches-on-right)
      
    end
    

    If you need different angles (e.g., 120 degrees front, 30 degrees peripheral on each side), you will need some super simple angle calculation. I’d recommend just drawing it pen and paper. It’s easy to make weird errors :)

    Also, notice that in-cone will always include the current patch of the turtle. So, if there’s another turtle on the same patch, it’ll be included in both peripheral and front vision agentsets, which may or may not be desirable.

    For other little tips for in-cone, you can check out this page: https://ccl.northwestern.edu/netlogo/bind/primitive/in-cone.html