我有一个代理类可以做一些事情:
public class Agent {
private Context<Object> context;
private Geography<Object> geography;
public int id;
boolean female;
public Agent(Context<Object> context, Geography<Object> geography, int id, boolean female) {
this.id = id;
this.context = context;
this.geography = geography;
this.female = female;
}
... setters getters
... do things methods
}
在上下文构建器类中,我的代理被添加到上下文(由纬度和经度坐标组成的地理空间)中,我想让我的代理的随机百分比为女性(女性 = true)。
for (int i = 0; i < 100; i++) {
Agent agent = new Agent(context, geography, i, false);
int id = i++;
if(id > 50) {
boolean female = true;
}
context.add(agent);
//specifies where to add the agent
Coordinate coord = new Coordinate(-79.6976, 43.4763);
Point geom = fac.createPoint(coord);
geography.move(agent, geom);
}
我相信上面的代码将最后 50 个代理构建为女性。我怎样才能使它们随机创建为女性?我改变了相当多的代理数量。