0

I'm building a pedestrian model using Anylogic. I have set my agents move in several groups between S2/S3/S4 and S1 (the movement direction is indicated by the blue two-way arrow in the figure). Background picture for problem statement

I have build a cyclic event and type these code in "action" to collect their track data:

t = time();    //get time
for(Agent p: level.getPeds()){
        x = p.getX();    //position x
        y = p.getY();    //Position y
        id = p.getId();    //get pedestrian id
        collectionTime.add(t);    //add data
        collectionID.add(id);
        collectionX.add(x);
        collectionY.add(y);
        Timeid.add(t,id);
        XY.add(x,y);
}

I also add these code in "Main-Agent type_Agent actions_On destroy" to write data into excel file:

TrackCollection.writeDataSet(Timeid,1,1,1);    //TrackCollection is the name of excel file
TrackCollection.writeDataSet(XY,1,1,3);

But in this way I can only collect all the trajectories together in the model. How can I collect the tracks of these different groups separately? Or how to collect tracks from different PedSources?

GradyC
  • 1
  • 2
  • can you clarify the code, this is not actual correct syntax. Also, what are TrackCollections? – Benjamin Aug 04 '22 at 12:18
  • Thanks so much, Benjamin, for comments. I have edited my question and clarify the code. The current question is complete. – GradyC Aug 04 '22 at 16:16

1 Answers1

0

Your question is a bit unclear, nevertheless, if you are creating groups, you can do this after creating a groupId variable in your pedestrian agent.

for(Pedestrian p : group.getPeds()){
    p.groupId=group.getId();
}

you can use this groupId and export it to your excel too so you can keep track of the groups

Felipe
  • 8,311
  • 2
  • 15
  • 31