每个代理都有一个私有布尔变量“Happy?”。如何计算具有[快乐?=真]?
有没有直接吃的方法?或者我已经遍历所有代理并单独计算它们?
更新:
我试过全局调度方法:https ://repast.github.io/docs/RepastReference/RepastReference.html#schedule-global
当我使用 ContextBuilder 中的 @ScheduledMethods 放置以下代码时,它不起作用。
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();
}
}
}
如果我将上述代码放在男孩代理或女孩代理操作中,它就会起作用。
@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();
}
}