Skip to content

Supply chain network design

A company serves its customers from warehouses. Where should it open them, and how large? More warehouses mean shorter trips but higher fixed costs. Some sites run on green energy: they emit less CO2, but cost more. With cost and emissions as two goals, there is no single best network, but a front of trade-offs for the company to choose from.

Candidate warehouse sites, closed, small or large, with green or grid energy, and one line from each customer to the open site that serves it
Each site is closed, small or large, and some sites run on green energy. Each line joins a customer to its nearest open site.

This instance has 12 candidate sites and 40 customers, generated from a seed:

  • a small site costs 500 per day to open and handles up to 400 units per day, a large one 900 and 1000 units,
  • green sites cost 50 percent more to open, but emit 0.05 kg of CO2 per unit handled, against 0.4 kg at the other sites,
  • transport costs 0.1 per unit and km, and emits 0.002 kg of CO2 per unit and km.

Three choices at 12 sites give 3^12 = 531 441 designs, few enough to check them all in a few seconds. So the exact front is known, and the algorithms can be measured against it. Real networks have many more sites, and then checking every design is out of reach.

The model

The variable is the size of each site: one Integer vector of 12 values, 0 (closed), 1 (small) or 2 (large). The objective assigns each customer to its nearest open site and returns:

  • the two objectives: the cost per day (opening plus transport) and the CO2 per day (transport plus handling),
  • one inequality constraint: the largest excess of load over capacity among the sites, which must be at most 0.

It is vectorized and evaluates a whole population of designs at once. space="native" lets the algorithm use crossover and mutation made for integers (see Native operators).

import numpy as np
import ypea

n_sites = 12
n_customers = 40

# the instance, generated from a seed
rng = np.random.default_rng(7)
sites = rng.uniform(0, 100, (n_sites, 2))  # positions in km
customers = rng.uniform(0, 100, (n_customers, 2))
demand = rng.integers(10, 60, n_customers).astype(float)  # units per day
green = rng.random(n_sites) < 0.4  # sites with green energy
distance = np.linalg.norm(customers[:, None, :] - sites[None, :, :], axis=2)

# by size: 0 closed, 1 small, 2 large
opening_cost = np.array([0, 500, 900.0])  # per day
capacity = np.array([0, 400, 1000.0])  # units per day
premium = np.where(green, 1.5, 1.0)  # green sites cost 50 percent more to open
handling_co2 = np.where(green, 0.05, 0.4)  # kg of CO2 per unit handled
transport_cost = 0.1  # per unit and km
transport_co2 = 0.002  # kg per unit and km


def cost_and_co2(sol):
    size = sol.size  # (n, 12): the size of each site in a batch of designs
    n = len(size)
    is_open = size > 0
    # each customer goes to its nearest open site
    d = np.where(is_open[:, None, :], distance[None, :, :], np.inf)
    nearest = np.argmin(d, axis=2)
    km = np.min(d, axis=2)

    load = np.zeros((n, n_sites))
    for site in range(n_sites):
        load[:, site] = np.sum(demand * (nearest == site), axis=1)

    transport = np.sum(km * demand, axis=1)  # unit km
    cost = np.sum(opening_cost[size] * premium, axis=1) + transport_cost * transport
    co2 = transport_co2 * transport + np.sum(load * handling_co2, axis=1)
    excess = np.max(load - capacity[size], axis=1)  # <= 0 when every site has room

    no_site = ~is_open.any(axis=1)  # every site closed: serves nobody
    cost[no_site] = np.inf
    co2[no_site] = np.inf
    excess[no_site] = np.inf
    return np.column_stack([cost, co2]), excess[:, None]


problem = ypea.Problem(
    ypea.Integer("size", shape=n_sites, lb=0, ub=2),
    cost_and_co2,
    n_obj=2,
    vectorized=True,
    name="supply chain",
)
result = ypea.NSGAIII(max_nfe=20_000, space="native").solve(problem, seed=1)
print(result.summary())
NSGA-III on supply chain
  front: 13 solutions, 13 feasible
  objective ranges: [5971.95, 8772.61], [137.902, 365.239]
  evaluations: 20000, iterations: 199, time: 0.586 s, stopped by: max_nfe

Differs from Python: MATLAB draws its own random numbers and its own instance from the seed, so the results differ from Python's.

n_sites = 12;
n_customers = 40;

% the instance, generated from a seed
generator = ypea.Rng(7);
sites = generator.uniform(0, 100, n_sites, 2);  % positions in km
customers = generator.uniform(0, 100, n_customers, 2);
green = generator.random(1, n_sites) < 0.4;  % sites with green energy

chain = struct();
chain.demand = generator.integers(10, 60, n_customers, 1);  % units per day
chain.distance = sqrt((customers(:, 1) - sites(:, 1)').^2 + (customers(:, 2) - sites(:, 2)').^2);

% by size: 0 closed, 1 small, 2 large (positions 1, 2 and 3)
chain.opening_cost = [0 500 900];  % per day
chain.capacity = [0 400 1000];  % units per day
chain.premium = ones(1, n_sites);
chain.premium(green) = 1.5;  % green sites cost 50 percent more to open
chain.handling_co2 = 0.4 * ones(1, n_sites);  % kg of CO2 per unit handled
chain.handling_co2(green) = 0.05;
chain.transport_cost = 0.1;  % per unit and km
chain.transport_co2 = 0.002;  % kg per unit and km

problem = ypea.Problem( ...
    vars=ypea.Integer("size", shape=n_sites, lb=0, ub=2), ...
    objective=@(sol) cost_and_co2(sol, chain), ...
    outputs=2, ...
    n_obj=2, ...
    vectorized=true, ...
    name="supply chain");
result = ypea.NSGAIII(max_nfe=20000, space="native").solve(problem, seed=1);
disp(result.summary())

function [f, excess] = cost_and_co2(sol, chain)
site_size = sol.size;  % (n, 12): the size of each site in a batch of designs
[n, n_sites] = size(site_size);
cost = zeros(n, 1);
co2 = zeros(n, 1);
excess = zeros(n, 1);
for i = 1:n
    open_sites = find(site_size(i, :) > 0);
    if isempty(open_sites)  % every site closed: serves nobody
        cost(i) = Inf;
        co2(i) = Inf;
        excess(i) = Inf;
        continue
    end
    % each customer goes to its nearest open site
    [km, nearest] = min(chain.distance(:, open_sites), [], 2);
    load = zeros(1, n_sites);
    for c = 1:numel(nearest)
        site = open_sites(nearest(c));
        load(site) = load(site) + chain.demand(c);
    end

    level = site_size(i, :) + 1;  % the position of each size in the tables
    transport = sum(km .* chain.demand);  % unit km
    cost(i) = sum(chain.opening_cost(level) .* chain.premium) + chain.transport_cost * transport;
    co2(i) = chain.transport_co2 * transport + sum(load .* chain.handling_co2);
    excess(i) = max(load - chain.capacity(level));  % <= 0 when every site has room
end
f = [cost, co2];
end
NSGA-III on supply chain
  front: 20 solutions, 20 feasible
  objective ranges: [4408.78, 9048.28], [187.916, 537.776]
  evaluations: 20000, iterations: 199, time: 2.35 s, stopped by: max_nfe

NSGA-III finds 13 designs in under a second, and they are exactly the 13 designs of the true front. The full script, examples/applications/supply_chain.py, finds the exact front by checking every design and compares.

Results

Four multi-objective algorithms with native operators, each with 10 seeded runs of 20 000 evaluations, about 4 percent of the number of designs. The IGD is measured with both objectives scaled to [0, 1] by the range of the exact front.

Algorithm Front points found: best Mean Worst Runs with the whole front Mean IGD
NSGA-II 13 12.4 11 5 of 10 0.0072
NSGA-III 13 12.6 12 6 of 10 0.0041
SPEA2 13 10.8 9 2 of 10 0.0144
MOEA/D 10 9.0 7 0 of 10 0.0314

NSGA-III and NSGA-II find the whole front in about half the runs, and miss at most one or two designs in the others.

The front of NSGA-III with seed 1 on the exact front
The 13 designs of NSGA-III with seed 1 (blue) on the exact front (gray circles). From left to right, the networks cost more and emit less: the cheapest emits 365 kg of CO2 per day, and the cleanest 138 kg for about 47 percent more cost.

Try it on your own network

Replace the positions, demands and costs with your own data. With more sites, or more sizes per site, checking every design is no longer possible, but the model and the algorithms stay the same. Other rules fit the same way, for example a budget as a constraint, or road distances instead of straight lines.