Search code examples
anylogic

How to export agent population data into excel in Anylogic


I want to take a time snapshot of agent population within system with all the parameter. Is there a way to export this data into excel or csv. Basically I want to validate few calculations manually.


Solution

  • Simplest solution, drag the text file object from the connectivity pallet to your model. Change it to write, create a new text file and link it to the file you created.

    Then have some button, event or function and you simply add the following type of code:

    for (MyAgent myAgent:myAgentPopulation) {
        file.println(
            myAgent.name + "\t" +
            myAgent.age + "\t"
            myAgent.gender + "\t"
            myAgent.work + "\t"
        );
    }
    
    

    the "\t" is for creating a tab separated file, you can use ""` for comma separated CSV