I am using Anylogic PLE to train an agent with reinforcement learning using the Alpyne library in Python. I have modeled the behavior of an agent with a statechart. In one of the states I initialize a Storage with this function:
int initialStockSize = 72;
AgentMaterial mat;
for (int i = 0; i < initialStockSize; i++) {
mat = new AgentMaterial();
mat.type = "A";
enterFeedA.take(mat);
}
In a later state of the statechart I take a material (agent) from storage and deposit it in an enter element with the following code:
AgentMaterial mat;
mat = (AgentMaterial)storageA.retrieve(storageA.getRandomAgent());
mat.destinationHead = head;
enterCrane2.take(mat);
When I run the model interactively in Anylogic the storage is loaded correctly in the first state and I can see all the materials and how they are being unloaded in the later state of the statechart.
The problem appears when I export the model and run the Python code to train the RL agent. Apparently the initial load does not give any errors, but storageA.getRandomAgent() returns null. When pulling a trace with storageA.size() I get 0, as if no material (agent) was previously loaded.
I can’t imagine where the problem could be since, as I say, in the interactive mode of Anylogic it works correctly and in the training there are no errors when loading the elements in the storage.
Any help is welcome, thanks in advance.
Miguel Ángel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.