Locations Optimization
In this section we will see how to find the best network to service customer demand. We will consider a set of 40 possible storage locations and a set of 350 customers both distributed throughout the US. We specify the cost of operating each storage location and the cost of shipping the product from each storage location to each customer. Finally we indicate the demand for each customer. Once this is done we optimize the network.
using CSV using DataFrames using SupplyChainModeling using SupplyChainOptimization
nm = tempname() url = "https://raw.githubusercontent.com/plotly/datasets/master/2014uscities.csv" download(url, nm) us_cities = CSV.read(nm, DataFrame) rm(nm)
sort!(us_cities, [:pop], rev=true)
sc = SupplyChain(1)
product = Product("Product 1") add_product!(sc, product)
for r in eachrow(first(uscities, 40)) storage = Storage("Storage r.name", Location(r.lat + 0.2, r.lon + 0.2, r.name); fixedcost= 2000000 + r.pop / 2, openingcost=0.0, closingcost=0.0, initialopened=false) addproduct!(storage, product; initialinventory=100000) add_storage!(sc, storage) end
for (i, r) in enumerate(eachrow(first(uscities, 350))) customer = Customer("customer i", Location(r.lat, r.lon, r.name)) addcustomer!(sc, customer) adddemand!(sc, customer, product, [r.pop / 10000]) end
for c in sc.customers, s in sc.storages addlane!(sc, Lane(s, c; unitcost=haversine(s.location, c.location) / 250)) end
minimize_cost!(sc)
After optimizing the network we can visualize the results.
plot_flows(sc; showlegend=false)
In the next example, we optimize a more complete network: we will consider where to build plants, storage locations to service customers and which suppliers to buy from. The customers consume one type of product which is produced by the plants and stored at the storage locations. The plants need a different product as raw material. This product is sourced from suppliers.
The process is similar to the previous example: we setup the network using the built-in concepts, call the optimize_network! function and query the results.
using CSV using DataFrames using SupplyChainOptimization
nm = tempname() url = "https://raw.githubusercontent.com/plotly/datasets/master/2014uscities.csv" download(url, nm) us_cities = CSV.read(nm, DataFrame) rm(nm)
sort!(us_cities, [:pop], rev=true)
sc = SupplyChain(1)
product1 = Product("Product 1") product2 = Product("Product 2") addproduct!(sc, product1) addproduct!(sc, product2)
for r in eachrow(first(uscities, 20)) supplier = Supplier("Supplier r.name", Location(r.lat + 0.2, r.lon - 0.2, r.name)) addproduct!(supplier, product1; unitcost=1.0) addsupplier!(sc, supplier) end
for r in eachrow(first(uscities, 20)) plant = Plant("Plant r.name", Location(r.lat - 0.2, r.lon - 0.2, r.name); fixedcost= 6000000 + r.pop / 2, openingcost=0.0, closingcost=0.0, initialopened=false) addproduct!(plant, product2; billofmaterial=Dict{Product, Float64}(product1 => 1.0), unitcost=1.0) addplant!(sc, plant) end
for r in eachrow(first(uscities, 20)) storage = Storage("Storage r.name", Location(r.lat + 0.2, r.lon + 0.2, r.name); fixedcost= 2000000 + r.pop / 2, openingcost=0.0, closingcost=0.0, initialopened=false) addproduct!(storage, product2; initialinventory=0) addstorage!(sc, storage) end
for (i, r) in enumerate(eachrow(first(uscities, 350))) customer = Customer("customer i", Location(r.lat, r.lon, r.name)) addcustomer!(sc, customer) adddemand!(sc, customer, product2, [r.pop / 10000]) end
for s in sc.suppliers, p in sc.plants addlane!(sc, Lane(s, p; unitcost=haversine(s.location, p.location) / 750)) end
for p in sc.plants, s in sc.storages addlane!(sc, Lane(p, s; unitcost=haversine(p.location, s.location) / 750)) end
for c in sc.customers, s in sc.storages addlane!(sc, Lane(s, c; unitcost=haversine(s.location, c.location) / 250)) end
minimize_cost!(sc)
The network can be visualized (see below). We can see that the optimal network has two clusters of plants/storage locations; one to service the West coast and one to service the East coast. Additionally two smaller storage locations are used as hubs to reduce overall costs.