matsim-org / matsim-libs

Multi-Agent Transport Simulation
www.matsim.org
489 stars 449 forks source link

Index out of Bound while copying attributes before replanning #2708

Open Arsham77 opened 1 year ago

Arsham77 commented 1 year ago

Index out of bond error happens when attributes are being copied from one plan to another before re-planning.

the attribute that is being copied is a primitive double and is an attribute of an activity.

2023-07-22T11:29:54,291 ERROR AbstractController:222 Mobsim did not complete normally! afterMobsimListeners will be called anyway.
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
    at org.matsim.utils.objectattributes.attributable.Attributes$EntryIterator.next(Attributes.java:163) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.utils.objectattributes.attributable.Attributes$EntryIterator.next(Attributes.java:150) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.utils.objectattributes.attributable.AttributesUtils.copyTo(AttributesUtils.java:36) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.utils.objectattributes.attributable.AttributesUtils.copyAttributesFromTo(AttributesUtils.java:46) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.core.population.PopulationUtils.copyFromTo(PopulationUtils.java:919) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.core.population.PopulationUtils.createActivity(PopulationUtils.java:927) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.core.population.PopulationUtils.copyFromTo(PopulationUtils.java:887) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.core.mobsim.qsim.agents.BasicPlanAgentImpl.getModifiablePlan(BasicPlanAgentImpl.java:227) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.core.mobsim.qsim.agents.BasicPlanAgentImpl.initializeActivity(BasicPlanAgentImpl.java:169) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.core.mobsim.qsim.agents.BasicPlanAgentImpl.advancePlan(BasicPlanAgentImpl.java:141) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.core.mobsim.qsim.agents.BasicPlanAgentImpl.endLegAndComputeNextState(BasicPlanAgentImpl.java:112) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.core.mobsim.qsim.agents.TransitAgent.endLegAndComputeNextState(TransitAgent.java:70) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.core.mobsim.qsim.DefaultTeleportationEngine.handleTeleportationArrivals(DefaultTeleportationEngine.java:144) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.core.mobsim.qsim.DefaultTeleportationEngine.doSimStep(DefaultTeleportationEngine.java:131) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.core.mobsim.qsim.QSim.doSimStep(QSim.java:395) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.core.mobsim.qsim.QSim.run(QSim.java:254) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.core.controler.NewControler.runMobSim(NewControler.java:124) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.core.controler.AbstractController$8.run(AbstractController.java:211) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.core.controler.AbstractController.iterationStep(AbstractController.java:243) ~[matsim-14.0-PR1512.jar:?]
    at org.matsim.core.controler.AbstractController.mobsim(AbstractController.java:207) [matsim-14.0-PR1512.jar:?]
    at org.matsim.core.controler.AbstractController.iteration(AbstractController.java:154) [matsim-14.0-PR1512.jar:?]
    at org.matsim.core.controler.AbstractController.doIterations(AbstractController.java:121) [matsim-14.0-PR1512.jar:?]
    at org.matsim.core.controler.AbstractController$1.run(AbstractController.java:81) [matsim-14.0-PR1512.jar:?]
    at org.matsim.core.controler.MatsimRuntimeModifications.run(MatsimRuntimeModifications.java:69) [matsim-14.0-PR1512.jar:?]
    at org.matsim.core.controler.MatsimRuntimeModifications.run(MatsimRuntimeModifications.java:52) [matsim-14.0-PR1512.jar:?]
    at org.matsim.core.controler.AbstractController.run(AbstractController.java:89) [matsim-14.0-PR1512.jar:?]
    at org.matsim.core.controler.NewControler.run(NewControler.java:82) [matsim-14.0-PR1512.jar:?]
    at org.matsim.core.controler.Controler.run(Controler.java:249) [matsim-14.0-PR1512.jar:?]
    at EVPricing.RunEVExampleV2.call(RunEVExampleV2.java:300) [classes/:?]
    at EVPricing.RunEVExampleV2.call(RunEVExampleV2.java:1) [classes/:?]
    at picocli.CommandLine.executeUserObject(CommandLine.java:1953) [picocli-4.6.3.jar:4.6.3]
    at picocli.CommandLine.access$1300(CommandLine.java:145) [picocli-4.6.3.jar:4.6.3]
    at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358) [picocli-4.6.3.jar:4.6.3]
    at picocli.CommandLine$RunLast.handle(CommandLine.java:2352) [picocli-4.6.3.jar:4.6.3]
    at picocli.CommandLine$RunLast.handle(CommandLine.java:2314) [picocli-4.6.3.jar:4.6.3]
    at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179) [picocli-4.6.3.jar:4.6.3]
    at picocli.CommandLine$RunLast.execute(CommandLine.java:2316) [picocli-4.6.3.jar:4.6.3]
    at picocli.CommandLine.execute(CommandLine.java:2078) [picocli-4.6.3.jar:4.6.3]
    at EVPricing.RunEVExampleV2.main(RunEVExampleV2.java:108) [classes/:?]
mrieser commented 1 year ago

The version of MATSim you are using (matsim-14.0-PR1512.jar) is more than 2 years old (https://github.com/matsim-org/matsim-libs/tree/03ef648d01461ff9785466cb9f8a67b5760c9667/). Can you try with a newer version?

Looking at the responsible code, I cannot figure out how the exception could happen except if there is some other code running in parallel modifying the attributes. But given the stack trace this seems unlikely.

Does the error happen regularly, can you reproduce it? If yes, can you share a test case so we can debug the issue?