I have tried to use add_people() in an event during running the Agent population and SD housing example of anylogic, in order to add more agents to the model during the simulation but I face this error. How can I solve this problem?
[Exception during discrete event execution:
-1
java.lang.ArrayIndexOutOfBoundsException: -1
at com.anylogic.engine.Dimension.getIndexPosition(Unknown Source)
at com.anylogic.engine.HyperArray.getPosOf(Unknown Source)
at com.anylogic.engine.HyperArray.get(Unknown Source)
at agent_population_and_sd_housing.Person.makeDecision(Person.java:428)
at agent_population_and_sd_housing.Person.executeActionOf(Person.java:408)
at com.anylogic.engine.EventRate.execute(Unknown Source)
at com.anylogic.engine.Engine.m(Unknown Source)
at com.anylogic.engine.Engine.jd(Unknown Source)
at com.anylogic.engine.Engine.h(Unknown Source)
at com.anylogic.engine.Engine$g.run(Unknown Source)]
This is because in the Person agent, there is a variable called district that has an initial value of -1... (meaning that it doesn't have an assigned district).
To fix this, you need to assign a district to the new person you are creating: This code:
Person p=add_people();
p.district=3;
Will create a person and assign a district equals to 3... I chose 3 arbitrarily and you have to figure out what district you want for that person in particular yourself.