@@ -2,10 +2,10 @@ module Johnsons
22
33
44import .. RandomKeyGA: run_ga, Chromosome, Population, generation, run_ga
5+ import .. OperationsResearchModels: solve
56
67export JohnsonResult
78export JohnsonException
8- export johnsons
99export makespan
1010export johnsons_ga
1111
@@ -14,10 +14,35 @@ struct JohnsonException <: Exception
1414 message:: String
1515end
1616
17+ """
18+ JohnsonProblem
19+
20+ # Description
21+
22+ Represents a Johnson problem instance, containing the job processing times.
1723
24+ # Fields
25+
26+ - `times::Matrix{<:Real}`: A matrix of job processing times.
27+ """
28+ struct JohnsonProblem
29+ times:: Matrix{<:Real}
30+ end
31+
32+
33+ """
34+ JohnsonResult
35+
36+ # Description
37+
38+ Represents the result of the Johnson's algorithm, containing the optimal job permutation.
39+
40+ # Fields
41+
42+ - `permutation::Vector{Int}`: The optimal job permutation found by the algorithm.
43+ """
1844struct JohnsonResult
1945 permutation:: Vector{Int}
20- # makespan::Float64
2146end
2247
2348struct Process
2853
2954
3055"""
31- johnsons_ga(times::Matrix ; popsize = 100, ngen = 1000, pcross = 0.8, pmutate = 0.01, nelites = 1)::JohnsonResult
56+ johnsons_ga(problem::JohnsonProblem ; popsize = 100, ngen = 1000, pcross = 0.8, pmutate = 0.01, nelites = 1)::JohnsonResult
3257
33- Given a matrix of times, returns a JohnsonResult with the permutation of the jobs.
34- The function uses a genetic algorithm to find the best permutation of the jobs.
58+ Given a problem containing a matrix of times, returns a JohnsonResult with the permutation of the jobs.
59+ The function uses a genetic algorithm to find the best permutation of the jobs.
3560The genetic algorithm is implemented in the RandomKeyGA module.
3661
3762# Arguments
3863
39- - `times::Matrix`: a matrix of times
64+ - `problem::JohnsonProblem`: a problem containing a matrix of times
4065- `popsize::Int`: the population size. Default is 100
4166- `ngen::Int`: the number of generations. Default is 1000
4267- `pcross::Float64`: the crossover probability. Default is 0.8
@@ -61,17 +86,18 @@ times = Float64[
6186 7.0 4.0
6287]
6388
64- result = johnsons (times)
89+ result = johnsons_ga (times)
6590
6691println(result.permutation)
6792```
6893"""
69- function johnsons_ga (times :: Matrix ; popsize = 100 , ngen = 1000 , pcross = 0.8 , pmutate = 0.01 , nelites = 1 ):: JohnsonResult
94+ function johnsons_ga (problem :: JohnsonProblem ; popsize = 100 , ngen = 1000 , pcross = 0.8 , pmutate = 0.01 , nelites = 1 ):: JohnsonResult
7095
71- n, m = size (times)
96+ times = problem. times
97+ n, _ = size (times)
7298
7399 function costfn (perm:: Vector{Int} )
74- return makespan (times , perm)
100+ return makespan (problem , perm)
75101 end
76102
77103 finalpop = run_ga (popsize, n, costfn, ngen, pcross, pmutate, nelites)
82108
83109
84110"""
85- johnsons(times::Matrix)
111+ johnsons(problem::JohnsonProblem)::JohnsonResult
86112
87- Given a matrix of times, returns a JohnsonResult with the permutation of the jobs.
113+ Given a problem containing a matrix of times, returns a JohnsonResult with the permutation of the jobs.
88114If number of machines is 2, it uses the Johnson's algorithm for 2 machines.
89115If number of machines is greater than 2, it uses the Johnson's algorithm by transforming the
90116problem into a 2-machine problem.
@@ -121,12 +147,13 @@ times = Float64[
121147 7.0 4.0
122148]
123149
124- result = johnsons( times)
150+ result = solve(JohnsonProblem( times) )
125151
126152println(result.permutation)
127153```
128154"""
129- function johnsons (times:: Matrix )
155+ function solve (problem:: JohnsonProblem ):: JohnsonResult
156+ times = problem. times
130157 _, m = size (times)
131158 if m == 2
132159 return johnsons_2machines (times)
@@ -196,13 +223,13 @@ end
196223
197224
198225"""
199- makespan(times::Matrix , permutation::Vector{Int})
226+ makespan(problem::JohnsonProblem , permutation::Vector{Int})
200227
201- Given a matrix of times and a permutation of the jobs, returns the makespan of the jobs.
228+ Given a problem containing a matrix of times and a permutation of the jobs, returns the makespan of the jobs.
202229
203230# Arguments
204231
205- - `times::Matrix`: a matrix of times
232+ - `problem::JohnsonProblem`: a problem containing a matrix of times
206233- `permutation::Vector{Int}`: a permutation of the jobs
207234
208235# Returns
@@ -220,11 +247,12 @@ julia> times = Float64[
220247 2 5 6
221248]
222249
223- julia> result = makespan(times, [1, 4, 5, 3, 2])
250+ julia> result = makespan(JohnsonProblem( times) , [1, 4, 5, 3, 2])
224251```
225252"""
226- function makespan (times :: Matrix , permutation:: Vector{Int} ):: Float64
253+ function makespan (problem :: JohnsonProblem , permutation:: Vector{Int} ):: Float64
227254
255+ times = problem. times
228256 n, m = size (times)
229257
230258 timetable = Matrix {Process} (undef, m, n)
0 commit comments