in use-cases/vehicle-routing/src/main/java/org/acme/vehiclerouting/bootstrap/DemoDataBuilder.java [81:166]
public VehicleRoutingSolution build() {
if (minDemand < 1) {
throw new IllegalStateException("minDemand (" + minDemand + ") must be greater than zero.");
}
if (maxDemand < 1) {
throw new IllegalStateException("maxDemand (" + maxDemand + ") must be greater than zero.");
}
if (minDemand >= maxDemand) {
throw new IllegalStateException("maxDemand (" + maxDemand + ") must be greater than minDemand ("
+ minDemand + ").");
}
if (vehicleCapacity < 1) {
throw new IllegalStateException(
"Number of vehicleCapacity (" + vehicleCapacity + ") must be greater than zero.");
}
if (customerCount < 1) {
throw new IllegalStateException(
"Number of customerCount (" + customerCount + ") must be greater than zero.");
}
if (vehicleCount < 1) {
throw new IllegalStateException(
"Number of vehicleCount (" + vehicleCount + ") must be greater than zero.");
}
if (depotCount < 1) {
throw new IllegalStateException(
"Number of depotCount (" + depotCount + ") must be greater than zero.");
}
if (northEastCorner.getLatitude() <= southWestCorner.getLatitude()) {
throw new IllegalStateException("northEastCorner.getLatitude (" + northEastCorner.getLatitude()
+ ") must be greater than southWestCorner.getLatitude(" + southWestCorner.getLatitude() + ").");
}
if (northEastCorner.getLongitude() <= southWestCorner.getLongitude()) {
throw new IllegalStateException("northEastCorner.getLongitude (" + northEastCorner.getLongitude()
+ ") must be greater than southWestCorner.getLongitude(" + southWestCorner.getLongitude() + ").");
}
String name = "demo";
Random random = new Random(0);
PrimitiveIterator.OfDouble latitudes = random
.doubles(southWestCorner.getLatitude(), northEastCorner.getLatitude()).iterator();
PrimitiveIterator.OfDouble longitudes = random
.doubles(southWestCorner.getLongitude(), northEastCorner.getLongitude()).iterator();
PrimitiveIterator.OfInt demand = random.ints(minDemand, maxDemand + 1).iterator();
PrimitiveIterator.OfInt depotRandom = random.ints(0, depotCount).iterator();
Supplier<Depot> depotSupplier = () -> new Depot(
sequence.incrementAndGet(),
new Location(sequence.incrementAndGet(), latitudes.nextDouble(), longitudes.nextDouble()));
List<Depot> depotList = Stream.generate(depotSupplier)
.limit(depotCount)
.collect(Collectors.toList());
Supplier<Vehicle> vehicleSupplier = () -> new Vehicle(
sequence.incrementAndGet(),
vehicleCapacity,
depotList.get(depotRandom.nextInt()));
List<Vehicle> vehicleList = Stream.generate(vehicleSupplier)
.limit(vehicleCount)
.collect(Collectors.toList());
Supplier<Customer> customerSupplier = () -> new Customer(
sequence.incrementAndGet(),
new Location(sequence.incrementAndGet(), latitudes.nextDouble(), longitudes.nextDouble()),
demand.nextInt());
List<Customer> customerList = Stream.generate(customerSupplier)
.limit(customerCount)
.collect(Collectors.toList());
List<Location> locationList = Stream.concat(
customerList.stream().map(Customer::getLocation),
depotList.stream().map(Depot::getLocation))
.collect(Collectors.toList());
distanceCalculator.initDistanceMaps(locationList);
return new VehicleRoutingSolution(name, locationList,
depotList, vehicleList, customerList, southWestCorner, northEastCorner);
}