anylogicregionagent-based-modeling

How to place predefined number of agents to multiple regions in AnyLogic


Let say I have a shapefile uploaded in AnyLogic with multiple regions (region1, region2,...region5). I have an excel file with a column "No. of people" [10,15,20,30,15] for those 5 regions. How can I place those agents to the corresponding regions? Also, I want to place those people in random locations. For instance, 10 people will be randomly placed in region1, 15 on region2, and so on.

It seems I can add those 10 people on region1 only. Is there any way I can add all sequentially?


Solution

  • something like this.. i didn't test and i don't know your database or agents

    List <Tuple> rows=selectFrom(database).list();
    for(Tuple t : rows){
         GISRegion region=findFirst(multi.getRegions(),r->r.getName().equals(t.get(database.region_name)));
         for(int i=0;i<(int)t.get(database.num_people);i++){
              MyAgent myAgent=add_myAgents();
             Point point=region.randomPointInside();
              myAgent.setLocation(point);
         }
    }