final RandomGenerator rng = new MersenneTwister(123);
final Simulator simulator = new Simulator(rng, Measure.valueOf(1000L,
SI.MILLI(SI.SECOND)));
// use map of leuven
final RoadModel roadModel = new GraphRoadModel(loadGraph(graphFile));
final DefaultPDPModel pdpModel = new DefaultPDPModel();
// configure simulator with models
simulator.register(roadModel);
simulator.register(pdpModel);
simulator.configure();
// add depots, taxis and parcels to simulator
for (int i = 0; i < NUM_DEPOTS; i++) {
simulator.register(new TaxiBase(roadModel.getRandomPosition(rng),
DEPOT_CAPACITY));
}
for (int i = 0; i < NUM_TAXIS; i++) {
simulator.register(new Taxi(roadModel.getRandomPosition(rng),
TAXI_CAPACITY));
}
for (int i = 0; i < NUM_CUSTOMERS; i++) {
simulator.register(new Customer(roadModel.getRandomPosition(rng),
roadModel.getRandomPosition(rng), SERVICE_DURATION, SERVICE_DURATION,
1 + rng.nextInt(3)));
}
simulator.addTickListener(new TickListener() {
@Override
public void tick(TimeLapse time) {
if (time.getStartTime() > endTime) {
simulator.stop();
} else if (rng.nextDouble() < .007) {
simulator.register(new Customer(
roadModel.getRandomPosition(rng), roadModel
.getRandomPosition(rng), SERVICE_DURATION, SERVICE_DURATION,
1 + rng.nextInt(3)));
}
}