私は物事を行うエージェントクラスを持っています:
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 人のエージェントを女性として構築していると思います。女性としてランダムに作成されるようにするにはどうすればよいですか? 作成するエージェントの数をかなり変更します。