### A Pluto.jl notebook ### # v0.14.5 using Markdown using InteractiveUtils # ╔═╡ 7845dc2e-5a8b-4a67-adb2-92df4b762df6 begin import Pkg Pkg.activate(mktempdir()) Pkg.add([ Pkg.PackageSpec(name="InteractiveUtils"), Pkg.PackageSpec(name="JuMP"), Pkg.PackageSpec(name="GLPK"), Pkg.PackageSpec(name="XLSX"), Pkg.PackageSpec(name="DataFrames"), Pkg.PackageSpec(name="Plots") ]) using InteractiveUtils, JuMP, GLPK, XLSX, DataFrames, Plots end # ╔═╡ 61e397ee-9fa5-4925-8505-b0bc9d7df0c3 md"## Coverage-based location problems" # ╔═╡ 3b4e2c9c-21f3-4e84-983d-97ee73675840 md" To see the location of your notebook type `pwd()`" # ╔═╡ 9e1cdd63-6a2d-4138-bb0b-1227ea448092 pwd() # ╔═╡ b00d14b1-7f36-47fe-9206-25f0738ae044 df_ambulance = DataFrame(XLSX.readtable("Data/dataset.xlsx", "ambulance")...) # ╔═╡ da8b7342-15cb-4515-9e74-487814689540 df_demand = DataFrame(XLSX.readtable("Data/dataset.xlsx", "demand")...) # ╔═╡ ab3ea4bc-c3bb-462c-9529-1c4895548d88 plt = scatter(df_ambulance.:x, df_ambulance."y", xlabel = "x coordinate", ylabel = "y coordinate", grid = false, label = "Ambulance") # ╔═╡ 58cd468c-9b7a-4d14-84fd-79b72c6b1c25 scatter!(df_demand.:x, df_demand."y", label = "Demand") # ╔═╡ f35e03f4-2ba2-4471-b093-e66677057cf1 md"### Definition of a coverage" # ╔═╡ c802dac0-d3bb-4e3a-88f0-2c81a1638b1b begin for amb in eachrow(df_ambulance) r = 20 th = Array(0:2*pi/100:2*pi+2*pi/100) # theta from 0 to 2pi X = r*cos.(th) + ones(101,1)*amb.:x Y = r*sin.(th) + ones(101,1)*amb.:y plot!(plt, X,Y, c=:blue, legend=false) end end # ╔═╡ f60c5f40-395c-4e6f-ad41-c3b1c3fceaa2 plt # ╔═╡ dc18dacb-9c5f-422d-9600-2494a7a693ba md" ## How many ambulance should be located to cover all demands?" # ╔═╡ cb3bc13c-68e5-40c7-932c-25f64933976e md""" ### Step 1) Set the decision variable """ # ╔═╡ 07eea2bf-f092-4ec1-a82b-a43a63e9fb09 md""" # $X_{i}: ~1~\text{if an ambulance is located at site}~i,~ 0~\text{otherwise}$ """ # ╔═╡ aef7cb22-359c-4fe9-accd-7517f341cd4b md""" #### Step 2) Set the objective function """ # ╔═╡ 54088c2b-b4bc-4786-8a5a-e057c0ddc2f4 md""" # $\min \sum_{i \in V}{X_i}$ """ # ╔═╡ be9f41c6-64aa-4b97-a885-2c66a03ea8ce md""" #### Step 3) Set the constraint """ # ╔═╡ 766a9164-5959-4af6-ab6d-6da21f52cc9a md""" ##### parameter $a_{ij}:~ 1\text{if ambulance}~i~\text{can cover demand}~j,~ 0~\text{otherwise}$ """ # ╔═╡ 7ae345b1-49e9-4a6a-94d5-7db7ce5a82ef md""" $\sum_{i}{a_{ij}\cdot X_{i}} \geq 1~~\forall j \in D$ $X_{i} \in \{0,1\} ~~\forall i \in V$ """ # ╔═╡ ddeb045f-028f-4abc-b0bb-433818b6c31e md"#### Exercise 1: Implement the formulation and find the solution" # ╔═╡ 0b558788-94e9-43fb-9b1c-1c275a5bd2fe md"----- #### Exercise 2 : What if I can locate 3 ambulances only? ##### To where should I locate the ambulances to maximize the coverage?" # ╔═╡ Cell order: # ╟─61e397ee-9fa5-4925-8505-b0bc9d7df0c3 # ╠═7845dc2e-5a8b-4a67-adb2-92df4b762df6 # ╟─3b4e2c9c-21f3-4e84-983d-97ee73675840 # ╠═9e1cdd63-6a2d-4138-bb0b-1227ea448092 # ╠═b00d14b1-7f36-47fe-9206-25f0738ae044 # ╠═da8b7342-15cb-4515-9e74-487814689540 # ╠═ab3ea4bc-c3bb-462c-9529-1c4895548d88 # ╠═58cd468c-9b7a-4d14-84fd-79b72c6b1c25 # ╟─f35e03f4-2ba2-4471-b093-e66677057cf1 # ╠═c802dac0-d3bb-4e3a-88f0-2c81a1638b1b # ╠═f60c5f40-395c-4e6f-ad41-c3b1c3fceaa2 # ╟─dc18dacb-9c5f-422d-9600-2494a7a693ba # ╟─cb3bc13c-68e5-40c7-932c-25f64933976e # ╠═07eea2bf-f092-4ec1-a82b-a43a63e9fb09 # ╟─aef7cb22-359c-4fe9-accd-7517f341cd4b # ╟─54088c2b-b4bc-4786-8a5a-e057c0ddc2f4 # ╟─be9f41c6-64aa-4b97-a885-2c66a03ea8ce # ╟─766a9164-5959-4af6-ab6d-6da21f52cc9a # ╟─7ae345b1-49e9-4a6a-94d5-7db7ce5a82ef # ╟─ddeb045f-028f-4abc-b0bb-433818b6c31e # ╟─0b558788-94e9-43fb-9b1c-1c275a5bd2fe