Search code examples
anylogic

AnyLogic: how to programmatically populate the Experiment page with information from Database?


I have a Supply Chain simulation model where the names and locations of the warehouses are fed from the database that I have in the model. What I want to achieve is the following:

  • When simulation starts, it copies the warehouse names from the DB and links them to the respective agents on the Experiment page. That is to say, let's say I have two warehouses: WH1, WH2. It should display theses as text on the Experiment page and when I click on WH1, it should take me to the respective agent. I have various plots inside the agents. The idea is to give the user the flexibility to be able to interact the model and take screenshots of the plots of whatever warehouses they wish.

Is this achievable in AnyLogic? If yes, how?

I tried to follow the recommendation of AnyLogic of creating interim variables, but can't really scale this up when I have hundreds of nodes.

enter image description here


Solution

  • I resolved this issue in the following manner. This creates the list of my agents, sorts them alphabetically by agentName in the Main agent.

    1. Initializing the variables. Here quotient and reminder helps me to keep track of the columns; which of each should contain 60 agent names numberPerColumn.
    int row=0;
    int numberPerColumn=60;
    int quotient=0;
    int remainder=0;
    
    int i1=0;
    int newIndex=0;
    
    
    1. Looping through the agents, creating ShapeText object to display their names.
    while (i1<myAgents.size())
    {
        int ii=i1;
        String myAgentName = myAgent.name;
        ShapeText text = new ShapeText(
                SHAPE_DRAW_2D, true, 300, 300.0, 0.0, 0.0, 
                black, myAgentName,
                font, ALIGNMENT_LEFT )
                
             {
    //3. Overriding the onClick() method with the action that I want to happen upon click. In this case, it will take me to the `viewArea` inside `myAgent`.
        
            @Override
            public boolean onClick(double x, double y)
            {
            
                myAgent.viewArea.navigateTo();  
                return false;
            }};
            
    //4. Setting the objects' position programmatically.
            
        quotient=i1/numberPerColumn;
        remainder=i1%numberPerColumn;
        text.setPos(quotient*250+50, -4550+remainder*20);
    
        presentation.add(text);
        
        i1+=1;
    }