hi,
I have a model with replicated agents which are registered to an environment in the Main object.
In the environment I want to iterate through the agents and pick the ones with the highest value in the variable
agent.choice.
I think that I have to use a collection variable? - but out of the manuell I can not figure out how to use / implement
it. (guess I am lacking the java programing skils)
I would appreciate any help about this topic!
cheers
martin
Pavel — 09.07.08
Hi Matin,
I recommend you to use the FOR-loop like below:
Agent agentWithTheHighestValue = agent.get(0); // create the new variable to store the required agent
for(int i=1; i<agents.size(); i++){
Agent nextAgent = agent.get(i);
if(nextAgent.choice >= agentWithTheHighestValue.choice)
agentWithTheHighestValue = nextAgent;
}
I hope it will help you.
martin — 16.07.08
hi pavel,
I have tried to use your code like this:
Agent agentWithTheHighestValue = new Agent();
// create the new variable to store the required agent
agentWithTheHighestValue = landunit.get(0);
// set the initial value
for(int i=1; i<=landunit.size()-1; i++)
{ if(landunit.get(i).HarverstEfficiency >= landunit.get(i-1).HarverstEfficiency)
agentWithTheHighestValue = landunit.get(i); }
but I get following error: "The constructor Agent is undefined".
cheers
martin
Pavel — 17.07.08
Hi Martin,
I recommend you to use the code from the previous post. You shouldn't use the constructor "new Agent()", you
may type the line of the code like below:
Agent agentWithTheHighestValue = landunit.get(0);
It is more elegant and will help you to increase the model's velocity if you have a great amount of agents.