I'm creating an agent based on another by code. The original agent is in a delay block being processed and I want to create copies where only the id will change and execute the method take in an Enter block.
In order to copy information from the original agent I can't seem to find a better way than to specify each parameter as in:
newAgent.color = original.color;
newAgent.component = original.component;
newAgent.geometry = original.geometry;
...
newAgent.LastParameter = original.LastParameter;
and so on.
Is there a way to iterate over an agent parameters to improve this action?
Thank you in advance, Luís
I managed to solve my problem and I'm posting the answer as other people might face it in the future. It's something simple that I had already tried but with a type casting problem.
The code structure is as follows:
add_myAgents();
for(String p : agent.getParameterNames())
{
myAgents.get(myAgents.size()-1).setParameter(p, agent.getParameter(p), true);
}
enter.take(myAgents.get(myAgents.size()-1));
I found that using myAgent prod = new MyAgent()
did not work. The duplicate must be inserted in a population so I created an intially empty population called myAgents and there's where I add the duplicate.