public FacilityLocationProblem build()

in use-cases/facility-location/src/main/java/org/acme/facilitylocation/bootstrap/DemoDataBuilder.java [76:118]


    public FacilityLocationProblem build() {
        if (demand < 1) {
            throw new IllegalStateException("Demand (" + demand + ") must be greater than zero.");
        }
        if (capacity < 1) {
            throw new IllegalStateException("Capacity (" + capacity + ") must be greater than zero.");
        }
        if (facilityCount < 1) {
            throw new IllegalStateException("Number of facilities (" + facilityCount + ") must be greater than zero.");
        }
        if (consumerCount < 1) {
            throw new IllegalStateException("Number of consumers (" + consumerCount + ") must be greater than zero.");
        }
        if (demand > capacity) {
            throw new IllegalStateException("Overconstrained problem not supported. The total capacity ("
                    + capacity + ") must be greater than or equal to the total demand (" + demand + ").");
        }
        // TODO SW<NE

        Random random = new Random(0);
        PrimitiveIterator.OfDouble latitudes = random.doubles(southWestCorner.latitude, northEastCorner.latitude)
                .iterator();
        PrimitiveIterator.OfDouble longitudes = random.doubles(southWestCorner.longitude, northEastCorner.longitude)
                .iterator();
        Supplier<Location> locationSupplier = () -> new Location(latitudes.nextDouble(), longitudes.nextDouble());
        List<Facility> facilities = Stream.generate(locationSupplier)
                .map(location -> new Facility(
                        sequence.incrementAndGet(),
                        location,
                        averageSetupCost + (long) (setupCostStandardDeviation * random.nextGaussian()),
                        capacity / facilityCount))
                .limit(facilityCount)
                .collect(Collectors.toList());
        List<Consumer> consumers = Stream.generate(locationSupplier)
                .map(location -> new Consumer(
                        sequence.incrementAndGet(),
                        location,
                        demand / consumerCount))
                .limit(consumerCount)
                .collect(Collectors.toList());

        return new FacilityLocationProblem(facilities, consumers, southWestCorner, northEastCorner);
    }