difficult to find the current location of agents i

2019-08-25 02:38发布

问题:

i built a simple model for pedestrian movement from start line towards target line, I want to find the number of moving agents in some area using the XY-coordinates (from X=150 to X=350, Y is the same )

The action for the event is to get the count of agents in that area and set the value for the variable crowd1:

crowd1=count(agents(), p-> p.getX()>150 &&  p.getX()<350)

the problem is that it's always 0 , even though the gents are moving in the simulation.

回答1:

There are no agents in your environment because you haven't created any agent type... For your code to work you need to have a population of pedestrians registered in your environment (meaning that you have to create the agent type and add it to main as a populatin), and then you have to add to a custom population the agents created in pedSource...

Otherwise, you can use this code:

count(pedGoTo.getPeds(),p->p.getX()>150 && p.getX()<350)