Reputation: 51
I understood that I can insert different types of agents in the same block by changing the agent type in the whole process to the generic Agent
(works well thanks to Amy). snapshot
But, I am stuck on how to get them out using a manual casting for the process selectOutputIn1
. Each Agent type has a parameter called p_new_location
with type SelectOutputOut
.
passing what is equivalent to agent.p_new_location
if properly casted through selectOutputIn1
.
creating a function with manual casting:
if( agent instanceof Wife){
return ((Wife)agent).p_new_location ;
} else if(agent instanceof Child_M){
return ((Child_M)agent).p_new_location ;
} else if(agent instanceof Child_F){
return ((Child_F)agent).p_new_location ;}
Unfortunately, as you can see there is an error saying the method must return a result of type SelectOutputOut although it is already defined.
The parameter type in each class looks like exactly like this. And from inside the simulation, it looks like this before passing the value and like this after passing its value. Furthermore, I noticed that the value of an uncommon parameter type like SelectOutputOut
, is not showing during the simulation as shown here. As you can see parameters (age
, countDb
and taken
) are all there with their values but, not p_new_location
.
Thanks to Amy Again :)
The compiler is seeing if / else if / else if. What if none of those are true? If your last else if is the only option, just change that to an else or put in appropriate code for what you want to do.
This is how the code looks like now
if( agent instanceof Wife){
return ((Wife)agent).p_new_location ;
} else if(agent instanceof Child_M){
return ((Child_M)agent).p_new_location ;
} else{
return ((Child_F)agent).p_new_location ;}
Thanks inAdvance;
Upvotes: 1
Views: 803
Reputation: 726
Yes, AnyLogic can easily handle multiple agent types in a single process block. A few things to keep in mind:
Upvotes: 1