-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from rafaelmartinelli/v0.1.0
v0.1.0
- Loading branch information
Showing
66 changed files
with
330 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,21 @@ | ||
# This file is machine-generated - editing it directly is not advised | ||
|
||
[[Libdl]] | ||
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" | ||
|
||
[[Printf]] | ||
deps = ["Unicode"] | ||
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" | ||
|
||
[[Unicode]] | ||
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" | ||
|
||
[[ZipFile]] | ||
deps = ["Libdl", "Printf", "Zlib_jll"] | ||
git-tree-sha1 = "c3a5637e27e914a7a445b8d0ad063d701931e9f7" | ||
uuid = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea" | ||
version = "0.9.3" | ||
|
||
[[Zlib_jll]] | ||
deps = ["Libdl"] | ||
uuid = "83775a58-1f1d-513f-b197-d71354ab007a" |
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,6 +1,79 @@ | ||
# GAPLib.jl | ||
|
||
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://rafaelmartinelli.github.io/GAPLib.jl/stable) | ||
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://rafaelmartinelli.github.io/GAPLib.jl/dev) | ||
[![Build Status](https://github.com/rafaelmartinelli/GAPLib.jl/workflows/CI/badge.svg)](https://github.com/rafaelmartinelli/GAPLib.jl/actions) | ||
[![Coverage](https://codecov.io/gh/rafaelmartinelli/GAPLib.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/rafaelmartinelli/GAPLib.jl) | ||
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) | ||
|
||
GAPLib reads data files in `gap` format for Generalized Assignmnent Problem (GAP) instances. | ||
|
||
## Usage | ||
|
||
The main type used by the package is `GAPData`, defined as follows: | ||
|
||
```julia | ||
struct GAPData | ||
name ::String # Instance name | ||
agents ::Vector{GAPAgent} # Vector of Agents | ||
jobs ::Vector{GAPJob} # Vector of Jobs | ||
|
||
lb ::Int64 # Lower bound (typemin(Int64) if not known) | ||
ub ::Int64 # Upper bound (typemax(Int64) if not known) | ||
end | ||
``` | ||
|
||
Type `GAPAgent` is defined as follows: | ||
|
||
```julia | ||
struct GAPAgent | ||
id::Int64 # Sequential agent ID | ||
capacity::Int64 # Agent capacity | ||
costs::Vector{Int64} # List of jobs costs for this agent | ||
consumption::Vector{Int64} # List of jobs consumptions for this agent | ||
end | ||
``` | ||
|
||
Type `GAPJob` is defined as follows: | ||
|
||
```julia | ||
struct GAPJob | ||
id::Int64 # Sequential job ID | ||
costs::Vector{Int64} # List of agents costs for this job | ||
consumption::Vector{Int64} # List of agents consumptions for this job | ||
end | ||
``` | ||
So, `costs` and `consumptions` are duplicated in both types. | ||
|
||
Some classical GAP instances from the literature are preloaded. For example, to load GAP instance `a05100`: | ||
|
||
```julia | ||
data = loadGAP(:a05100) | ||
``` | ||
|
||
See the [full list](https://github.com/rafaelmartinelli/GAPLib.jl/tree/main/data). | ||
|
||
GAPLib also loads custom GAP instances (following [ORLib format](http://people.brunel.ac.uk/~mastjjb/jeb/orlib/gapinfo.html)): | ||
|
||
```julia | ||
data = loadGAP("/path/to/your/GAP/instance.txt") | ||
``` | ||
|
||
## Installation | ||
|
||
GAPLib is *not* a registered Julia Package. | ||
You can install GAPLib through the Julia package manager. | ||
Open Julia's interactive session (REPL) and type: | ||
|
||
```julia | ||
] add https://github.com/rafaelmartinelli/GAPLib.jl | ||
``` | ||
|
||
## Related links | ||
|
||
- [Mutsunori Yagiura's GAP Page](http://www.al.cm.is.nagoya-u.ac.jp/~yagiura/gap/) | ||
- [ORLib's GAP page](http://people.brunel.ac.uk/~mastjjb/jeb/orlib/gapinfo.html) | ||
|
||
## Other packages | ||
|
||
- [KnapsackLib.jl](https://github.com/rafaelmartinelli/KnapsackLib.jl): Knapsack algorithms in Julia | ||
- [BPPLib.jl](https://github.com/rafaelmartinelli/BPPLib.jl): Bin Packing and Cutting Stock Lib | ||
- [CARPData.jl](https://github.com/rafaelmartinelli/CARPData.jl): Capacitated Arc Routing Problem Lib |
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.
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.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
struct GAPAgent | ||
id::Int64 | ||
capacity::Int64 | ||
costs::Vector{Int64} | ||
consumption::Vector{Int64} | ||
end | ||
|
||
function Base.show(io::IO, agent::GAPAgent) | ||
print(io, "A($(agent.id))") | ||
end | ||
|
||
struct GAPJob | ||
id::Int64 | ||
costs::Vector{Int64} | ||
consumption::Vector{Int64} | ||
end | ||
|
||
function Base.show(io::IO, job::GAPJob) | ||
print(io, "J($(job.id))") | ||
end | ||
|
||
struct GAPData | ||
name::String | ||
agents::Vector{GAPAgent} | ||
jobs::Vector{GAPJob} | ||
|
||
lb::Int64 | ||
ub::Int64 | ||
end | ||
|
||
function Base.show(io::IO, data::GAPData) | ||
print(io, "GAP Data $(data.name)") | ||
print(io, " ($(length(data.agents)) agents,") | ||
print(io, " $(length(data.jobs)) jobs)") | ||
if data.lb != typemin(Int64) | ||
print(io, " [$(data.lb),") | ||
else | ||
print(io, " [-Inf,") | ||
end | ||
if data.ub != typemax(Int64) | ||
print(io, " $(data.ub)]") | ||
else | ||
print(io, " Inf]") | ||
end | ||
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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
module GAPLib | ||
|
||
# Write your package code here. | ||
export GAPData, GAPAgent, GAPJob, loadGAP | ||
|
||
const data_path = joinpath(pkgdir(GAPLib), "data") | ||
|
||
using ZipFile | ||
|
||
include("Data.jl") | ||
include("Loader.jl") | ||
|
||
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,51 @@ | ||
function loadGAP(instance::Symbol) | ||
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 = parse.(Int64, split(read(file.files[1], String))) | ||
|
||
return load(values, name) | ||
end | ||
|
||
function loadGAP(file_name::String) | ||
if !isfile(file_name) | ||
println("File $file_name not found!") | ||
return nothing | ||
end | ||
|
||
name = splitext(basename(file_name))[1] | ||
values = parse.(Int64, split(read(file_name, String))) | ||
|
||
return load(values, name) | ||
end | ||
|
||
function load(values::Array{Int64}, name::String) | ||
m = values[1] | ||
n = values[2] | ||
|
||
counter = 3 | ||
|
||
costs = zeros(Int64, n, m) | ||
for j in 1:m | ||
costs[:, j] = values[counter:counter + n - 1] | ||
counter += n | ||
end | ||
|
||
consumptions = zeros(Int64, n, m) | ||
for j in 1:m | ||
consumptions[:, j] = values[counter:counter + n - 1] | ||
counter += n | ||
end | ||
|
||
capacities = values[counter:counter + m - 1] | ||
|
||
agents = [ GAPAgent(j, capacities[j], costs[:, j], consumptions[:, j]) for j in 1:m ] | ||
jobs = [ GAPJob(i, costs[i, :], consumptions[i, :]) for i in 1:n ] | ||
|
||
return GAPData(name, agents, jobs, typemin(Int64), typemax(Int64)) | ||
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,92 @@ | ||
5 100 | ||
36 46 34 25 29 17 15 29 38 50 39 50 | ||
37 39 25 13 11 11 32 50 23 44 15 25 | ||
42 13 41 31 16 44 49 25 31 14 45 44 | ||
36 50 49 30 15 22 31 45 40 41 22 34 | ||
13 26 14 34 31 22 47 37 42 47 42 24 | ||
32 25 41 40 35 20 43 10 29 28 30 23 | ||
20 28 26 47 46 30 18 47 17 17 40 45 | ||
43 44 48 24 48 23 38 45 27 36 20 11 | ||
26 35 27 41 | ||
12 33 26 10 32 49 46 44 41 49 41 45 | ||
43 44 24 14 17 21 32 39 25 29 28 38 | ||
38 12 17 42 22 43 31 47 15 10 40 12 | ||
39 34 28 23 35 46 48 40 29 13 38 37 | ||
14 16 30 32 20 37 48 32 48 38 41 11 | ||
49 35 43 19 10 19 45 32 28 23 23 11 | ||
23 40 14 21 44 41 25 41 40 41 42 13 | ||
45 31 43 13 20 25 30 19 10 10 43 31 | ||
35 21 31 45 | ||
34 23 36 34 21 39 48 37 34 10 44 39 | ||
41 13 45 11 35 43 35 46 27 36 19 23 | ||
21 20 46 29 29 12 40 11 14 50 25 34 | ||
32 37 28 36 35 15 25 37 30 41 28 32 | ||
48 32 40 32 40 41 17 41 34 40 19 42 | ||
36 15 50 26 49 47 20 35 39 20 10 23 | ||
42 39 14 44 44 22 34 23 26 50 26 35 | ||
15 39 46 26 48 17 47 16 44 39 50 46 | ||
21 50 50 17 | ||
10 42 25 24 16 31 11 25 21 43 41 27 | ||
38 31 36 35 14 17 18 36 25 27 44 18 | ||
24 46 43 44 21 20 11 42 20 24 33 42 | ||
41 32 50 25 47 15 38 29 32 46 25 10 | ||
42 33 27 20 11 33 41 31 11 23 49 12 | ||
20 50 39 47 45 38 50 19 45 49 33 49 | ||
25 44 32 30 42 47 25 21 45 11 13 33 | ||
17 48 19 37 27 29 17 44 34 37 19 50 | ||
43 22 27 38 | ||
39 19 24 16 50 20 39 11 26 40 18 44 | ||
37 26 13 25 16 12 39 19 31 29 34 48 | ||
42 11 32 27 39 26 47 37 39 49 37 50 | ||
33 26 12 12 26 38 22 13 11 20 40 44 | ||
25 38 29 37 11 19 39 33 27 50 33 35 | ||
40 47 47 15 23 11 38 29 36 50 39 12 | ||
47 21 50 24 29 47 35 39 25 42 35 30 | ||
19 23 22 28 16 39 10 46 37 29 18 30 | ||
16 32 30 33 | ||
15 8 11 16 24 8 19 9 15 7 6 13 | ||
10 12 25 16 21 18 21 21 22 8 18 11 | ||
12 24 15 13 17 21 24 23 23 19 20 17 | ||
13 12 9 22 13 14 25 7 9 25 20 13 | ||
21 20 25 5 11 20 10 17 5 25 11 6 | ||
14 24 17 7 16 10 15 9 15 13 23 13 | ||
12 13 5 8 15 19 7 13 21 10 12 9 | ||
11 11 23 5 18 13 19 20 24 9 22 25 | ||
21 14 19 21 | ||
8 10 7 23 20 9 7 11 21 9 16 20 | ||
9 25 10 14 20 23 23 25 13 14 7 14 | ||
9 25 18 17 10 14 21 6 15 8 10 24 | ||
17 25 15 21 20 12 15 16 7 17 12 8 | ||
21 19 14 19 7 25 16 20 17 18 21 8 | ||
11 10 19 11 16 13 11 14 16 15 17 13 | ||
7 10 5 25 7 12 18 12 16 12 16 14 | ||
8 17 8 16 11 23 22 22 23 17 16 8 | ||
18 19 10 7 | ||
22 9 13 12 22 7 10 8 15 12 15 15 | ||
12 16 7 15 17 20 16 12 21 17 10 19 | ||
16 21 23 23 6 21 24 18 8 11 8 10 | ||
22 16 5 9 5 12 18 15 16 8 22 5 | ||
5 12 17 5 18 24 12 20 13 25 17 7 | ||
9 21 23 20 5 20 13 12 9 8 6 7 | ||
8 21 5 21 17 13 9 8 17 11 17 25 | ||
12 8 11 6 8 5 23 25 18 25 18 5 | ||
12 8 7 9 | ||
6 5 24 24 24 23 8 8 6 18 20 7 | ||
8 6 7 5 21 25 5 18 7 13 11 5 | ||
23 20 15 8 21 23 15 23 20 9 6 17 | ||
23 15 19 25 17 15 17 23 5 23 7 15 | ||
17 5 13 15 9 15 21 12 19 24 19 19 | ||
13 5 9 24 15 9 18 7 10 12 19 5 | ||
25 20 23 18 10 18 22 9 20 12 6 15 | ||
23 10 16 15 22 12 7 9 7 12 9 14 | ||
22 15 22 13 | ||
23 19 18 17 25 14 15 12 11 5 25 14 | ||
8 8 16 17 11 12 8 14 10 9 20 9 | ||
9 13 21 22 10 5 15 12 6 19 10 12 | ||
16 23 11 6 14 12 14 22 5 23 9 18 | ||
7 9 17 18 22 22 8 9 18 14 16 6 | ||
12 20 15 21 23 7 18 16 20 14 22 21 | ||
13 22 18 18 14 9 10 15 18 6 7 6 | ||
20 22 25 18 25 12 17 18 25 24 14 17 | ||
22 13 11 22 | ||
342 342 342 342 342 |
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,6 +1,36 @@ | ||
using GAPLib | ||
using Test | ||
|
||
@testset "GAPLib.jl" begin | ||
# Write your tests here. | ||
@testset "LoadSymbol" begin | ||
data = loadGAP(:a05200) | ||
@test data.name == "a05200" | ||
@test data.agents[3].capacity == 671 | ||
@test length(data.agents) == 5 | ||
@test length(data.jobs) == 200 | ||
@test data.lb == typemin(Int64) | ||
@test data.ub == typemax(Int64) | ||
@test_nowarn println(data) | ||
@test_nowarn println(data.agents[1]) | ||
@test_nowarn println(data.jobs[1]) | ||
end | ||
|
||
@testset "ErrorSymbol" begin | ||
data = loadGAP(:notaninstance) | ||
@test data === nothing | ||
end | ||
|
||
@testset "LoadString" begin | ||
data = loadGAP(joinpath(pkgdir(GAPLib), "test/data/a05100")) | ||
@test data.name == "a05100" | ||
@test data.agents[3].capacity == 342 | ||
@test length(data.agents) == 5 | ||
@test length(data.jobs) == 100 | ||
@test data.lb == typemin(Int64) | ||
@test data.ub == typemax(Int64) | ||
@test_nowarn println(data) | ||
end | ||
|
||
@testset "ErrorString" begin | ||
data = loadGAP("notaninstance") | ||
@test data === nothing | ||
end |