0

Is it possible to modify agent's variable by tracing it's position whether it's inside or outside a certain node?

I have a string variable position inside pedestrian which I want to define depending if agent is outside, inside green or red node (ex. "Green", "Red" or "None".).

I digged up the following code that works fine where it comes to tracing if agents are inside a given node or not, but I don't know how to use it so it actually modifies a variable inside an agent.

nodeGreen.getPeds(),p->node.contains(p.getX(),p.getY())

my simple model with green and red node

new agent - "pedestrian" with string variable

Many thanks for help, Peter

Peter B-S
  • 27
  • 6

1 Answers1

0

Well, you need to periodically check within the Pedestrian agent and adjust the variable accordingly.

Best set a cyclic event that executes:

if (main.nodeGreen.contains(getX(), getY()) {
    position = "Green"
} else if // ... do for the other types

Side note: using Strings here is very error-prone and not scalable. Maybe create a function instead in your Pedestrian agent type such as f_getCurrentNode that returns a Node using the (adjusted) code above. Make it return null if the ped is in no node. Now, you can dynamically check for each agent where it is.

Benjamin
  • 10,603
  • 3
  • 16
  • 28
  • 1
    This is truly great, many thanks for help. I will try with function instead of String too, thanks for the suggestion and best practices! – Peter B-S Jun 29 '21 at 08:33