Search code examples
anylogic

Add and remove Train into/from a Train Population


Trying to add a train created within the "trainSource" to my "trainPopulation" by adding add_trainPopulation() in "Actions/On exit field".

It works, the newly created train is added to my "trainPopulation", the size of "trainPopulation" changed from "empty Population" to "1".

However, I'm not able to remove the train from my "trainPopulation" which is about leaving the "trainDispose".

Is there any way to remove train from a user-made population? Please help me with this.

I've tried 'remove_trainPopulation()', 'remove_trainPopulation(this)', 'remove_trainPopulation(agent)', 'remove_trainPopulation(train)', and 'remove_trainPopulation(Train)'.


Solution

  • Trying to add a train created within the "trainSource" to my "trainPopulation" by adding add_trainPopulation() in "Actions/On exit field".

    You are creating 2 trains now: one by the source, and another via the add_ method.

    Instead, check the source properties: it lets you define where to add new agents to: not the "default population" but a custom one of your choice (you need to create an empty population first, then you can select it here).

    You can then use a TrainSink and the trains will be removed from the population as well