Each agent has a private boolean variable "Happy?". how to count the agents with [Happy? = True]?
Is there a direct method available in repast? Or I have iterate through all agents and count them individually?
Update:
I have tried the global scheduling method: https://repast.github.io/docs/RepastReference/RepastReference.html#schedule-global
It's not working when I put below code using the @ScheduledMethods in the ContextBuilder.
grid.moveTo(this_girl, group_x,group_y);
}
}
return context;
}
@ScheduledMethod(start = 1, interval = 1, shuffle=true)
public void step () {
Context<Object> context = ContextUtils.getContext(this);
Query<Object> query = new PropertyEquals<Object>(context, "happy", true);
int end_count = 0;
System.out.println(end_count);
for (Object o : query.query()) {
if (o instanceof Boy) {
end_count ++;
}
if (o instanceof Girl) {
end_count ++;
}
}
System.out.println(end_count);
if (end_count == 70) {
RunEnvironment.getInstance().endRun();
}
}
}
It's working if I put above code in either boy agent or girl agent actions.
@ScheduledMethod(start = 1, interval = 1,shuffle=true)
public void step() {
relocation();
update_happiness();
endRun();
}
public void endRun( ) {
Context<Object> context = ContextUtils.getContext(this);
Query<Object> query = new PropertyEquals<Object>(context, "happy", true);
int end_count = 0;
System.out.println(end_count);
for (Object o : query.query()) {
if (o instanceof Boy) {
end_count ++;
}
if (o instanceof Girl) {
end_count ++;
}
}
System.out.println(end_count);
if (end_count == 70) {
RunEnvironment.getInstance().endRun();
}
}