I want to randomly select a person
(agent) that is in state1
and instruct this random agent to move to state2
. I also want to change the random agent's var1
(variable) value to "true".
I think that I should use randomWhere(population,condition)
to select the random agent, but I do not know how to code it.
Assume you have an Agent type MyAgentType
with a state chart statechart
and a msg-based transition between state1
and state2
that triggers upon the String "change", and the agents live in a population myPopulation
, then you can do:
MyAgentType agentInState1 = randomWhere(myPopulation, p->p.statechart.isStateActive(MyAgentType.state1));
agentInState1.statechart.fireTransition("change");
agentInState1.var1 = true;