-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from rafaelmartinelli/p-median
P-median and Max Cover
- Loading branch information
Showing
32 changed files
with
232 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
/docs/build/ | ||
Manifest.toml | ||
.vscode/ | ||
/data/*.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
module FacilityLocationProblems | ||
|
||
export loadFacilityLocationProblem, FacilityLocationProblem | ||
export loadPMedianProblem, PMedianProblem | ||
export loadMaximumCoverageProblem, MaximumCoverageProblem | ||
export nf, nc | ||
|
||
const data_path = joinpath(pkgdir(FacilityLocationProblems), "data") | ||
|
||
using Distances | ||
using ZipFile | ||
using Printf | ||
|
||
include("Data.jl") | ||
include("facility-location/Data.jl") | ||
include("facility-location/Loader.jl") | ||
|
||
include("maximum-coverage/Data.jl") | ||
include("maximum-coverage/Loader.jl") | ||
|
||
include("p-median/Data.jl") | ||
include("p-median/Loader.jl") | ||
|
||
include("Util.jl") | ||
include("Loader.jl") | ||
|
||
end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
struct MaximumCoverageProblem | ||
name::String | ||
|
||
medians::Int64 | ||
distance::Int64 | ||
|
||
demands::Vector{Int64} | ||
coverage::Vector{Vector{Int64}} | ||
|
||
lb::Float64 | ||
ub::Float64 | ||
end | ||
|
||
nc(data::MaximumCoverageProblem)::Int64 = length(data.demands) | ||
|
||
function Base.show(io::IO, data::MaximumCoverageProblem) | ||
@printf(io, "Max Cover Data %s", data.name) | ||
@printf(io, " (p = %d,", data.medians) | ||
@printf(io, " dist = %d,", data.distance) | ||
@printf(io, " %d customers)", nc(data)) | ||
@printf(io, " [%.3f, %.3f]", data.lb, data.ub) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
function loadMaximumCoverageProblem(instance::Symbol, distance::Int64)::Union{MaximumCoverageProblem, Nothing} | ||
file_name = joinpath(data_path, string(instance) * ".zip") | ||
if !isfile(file_name) | ||
println("File $(string(instance)) not found!") | ||
return nothing | ||
end | ||
|
||
name = splitext(basename(file_name))[1] | ||
file = ZipFile.Reader(file_name) | ||
values = split(read(file.files[1], String)) | ||
close(file) | ||
|
||
return loadMaximumCoverageProblem(values, distance, name) | ||
end | ||
|
||
function loadMaximumCoverageProblem(file_name::String, distance::Int64)::Union{MaximumCoverageProblem, Nothing} | ||
if !isfile(file_name) | ||
println("File $file_name not found!") | ||
return nothing | ||
end | ||
|
||
name = splitext(basename(file_name))[1] | ||
values = split(read(file_name, String)) | ||
|
||
return loadMaximumCoverageProblem(values, distance, name) | ||
end | ||
|
||
function loadMaximumCoverageProblem(values::Array{SubString{String}}, distance::Int64, name::String)::Union{MaximumCoverageProblem, Nothing} | ||
n = parse(Int64, values[3]) | ||
medians = parse(Int64, values[4]) | ||
|
||
counter = 6 | ||
|
||
x = parse.(Int64, values[counter + 1:4:end]) | ||
y = parse.(Int64, values[counter + 2:4:end]) | ||
demands = parse.(Int64, values[counter + 3:4:end]) | ||
|
||
costs = [ floor(Int64, euclidean([x[i], y[i]], [x[j], y[j]])) for i in 1:n, j in 1:n ] | ||
coverage = [ [ j for j in 1:n if costs[i, j] <= distance ] for i in 1:n ] | ||
|
||
return MaximumCoverageProblem(name, medians, distance, demands, coverage, -Inf64, Inf64) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
struct PMedianProblem | ||
name::String | ||
|
||
medians::Int64 | ||
capacity::Int64 | ||
|
||
demands::Vector{Int64} | ||
costs::Matrix{Float64} | ||
|
||
x::Vector{Int64} | ||
y::Vector{Int64} | ||
|
||
lb::Float64 | ||
ub::Float64 | ||
end | ||
|
||
nc(data::PMedianProblem)::Int64 = length(data.demands) | ||
|
||
function Base.show(io::IO, data::PMedianProblem) | ||
@printf(io, "P-Median Data %s", data.name) | ||
@printf(io, " (p = %d,", data.medians) | ||
@printf(io, " %d customers)", nc(data)) | ||
@printf(io, " [%.3f, %.3f]", data.lb, data.ub) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
function loadPMedianProblem(instance::Symbol)::Union{PMedianProblem, Nothing} | ||
file_name = joinpath(data_path, string(instance) * ".zip") | ||
if !isfile(file_name) | ||
println("File $(string(instance)) not found!") | ||
return nothing | ||
end | ||
|
||
name = splitext(basename(file_name))[1] | ||
file = ZipFile.Reader(file_name) | ||
values = split(read(file.files[1], String)) | ||
close(file) | ||
|
||
return loadPMedianProblem(values, name) | ||
end | ||
|
||
function loadPMedianProblem(file_name::String)::Union{PMedianProblem, Nothing} | ||
if !isfile(file_name) | ||
println("File $file_name not found!") | ||
return nothing | ||
end | ||
|
||
name = splitext(basename(file_name))[1] | ||
values = split(read(file_name, String)) | ||
|
||
return loadPMedianProblem(values, name) | ||
end | ||
|
||
function loadPMedianProblem(values::Array{SubString{String}}, name::String)::Union{PMedianProblem, Nothing} | ||
ub = parse(Int64, values[2]) | ||
n = parse(Int64, values[3]) | ||
medians = parse(Int64, values[4]) | ||
capacity = parse(Int64, values[5]) | ||
|
||
counter = 6 | ||
|
||
x = parse.(Int64, values[counter + 1:4:end]) | ||
y = parse.(Int64, values[counter + 2:4:end]) | ||
demands = parse.(Int64, values[counter + 3:4:end]) | ||
|
||
costs = [ floor(Int64, euclidean([x[i], y[i]], [x[j], y[j]])) for i in 1:n, j in 1:n ] | ||
|
||
return PMedianProblem(name, medians, capacity, demands, costs, x, y, -Inf64, ub) | ||
end |