@@ -6,8 +6,8 @@ import ..OperationsResearchModels: solve
66
77export JohnsonResult
88export JohnsonException
9- export makespan
10- export johnsons_ga
9+ export makespan
10+ export johnsons_ga
1111
1212
1313struct JohnsonException <: Exception
@@ -46,10 +46,10 @@ struct JohnsonResult
4646end
4747
4848struct Process
49- start
50- duration
51- finish
52- end
49+ start:: Any
50+ duration:: Any
51+ finish:: Any
52+ end
5353
5454
5555"""
@@ -91,14 +91,21 @@ result = johnsons_ga(JohnsonProblem(times))
9191println(result.permutation)
9292```
9393"""
94- function johnsons_ga (problem:: JohnsonProblem ; popsize = 100 , ngen = 1000 , pcross = 0.8 , pmutate = 0.01 , nelites = 1 ):: JohnsonResult
94+ function johnsons_ga (
95+ problem:: JohnsonProblem ;
96+ popsize = 100 ,
97+ ngen = 1000 ,
98+ pcross = 0.8 ,
99+ pmutate = 0.01 ,
100+ nelites = 1 ,
101+ ):: JohnsonResult
95102
96103 times = problem. times
97104 n, _ = size (times)
98-
105+
99106 function costfn (perm:: Vector{Int} )
100107 return makespan (problem, perm)
101- end
108+ end
102109
103110 finalpop = run_ga (popsize, n, costfn, ngen, pcross, pmutate, nelites)
104111
@@ -163,7 +170,7 @@ function solve(problem::JohnsonProblem)::JohnsonResult
163170end
164171
165172function dofirst! (locrow:: Int , permutation:: Vector{Int} )
166- for i in 1 : length (permutation)
173+ for i = 1 : length (permutation)
167174 if permutation[i] == - 1
168175 permutation[i] = locrow
169176 return
@@ -172,7 +179,7 @@ function dofirst!(locrow::Int, permutation::Vector{Int})
172179end
173180
174181function dolast! (locrow:: Int , permutation:: Vector{Int} )
175- for i in length (permutation): - 1 : 1
182+ for i = length (permutation): - 1 : 1
176183 if permutation[i] == - 1
177184 permutation[i] = locrow
178185 return
@@ -187,8 +194,8 @@ function johnsons_2machines(timesmatrix::Matrix)::JohnsonResult
187194
188195 typed_inf = typemax (eltype (times))
189196
190- permutation = [- 1 for i in 1 : n]
191- for i in 1 : n
197+ permutation = [- 1 for i = 1 : n]
198+ for i = 1 : n
192199 locrow, loccol = argmin (times). I
193200 if loccol == 1
194201 dofirst! (locrow, permutation)
@@ -207,14 +214,18 @@ function johnsons_nmachines(times::Matrix)::JohnsonResult
207214 maxothers = maximum (times[:, 2 : (end - 1 )])
208215
209216 if ! ((minfirst >= maxothers) || (minlast >= maxothers))
210- throw (JohnsonException (" The problem cannot be reduced to a 2-machine problem: minfirst >= maxothers and/or minlast >= maxothers" ))
217+ throw (
218+ JohnsonException (
219+ " The problem cannot be reduced to a 2-machine problem: minfirst >= maxothers and/or minlast >= maxothers" ,
220+ ),
221+ )
211222 end
212223
213224 Gcollection = times[:, 1 : (end - 1 )]
214225 Hcollection = times[:, 2 : end ]
215226
216- G = sum (Gcollection, dims= 2 )
217- H = sum (Hcollection, dims= 2 )
227+ G = sum (Gcollection, dims = 2 )
228+ H = sum (Hcollection, dims = 2 )
218229
219230 return johnsons_2machines ([G H])
220231end
@@ -257,8 +268,8 @@ function makespan(problem::JohnsonProblem, permutation::Vector{Int})::Float64
257268
258269 timetable = Matrix {Process} (undef, m, n)
259270
260- for machine_id in 1 : m
261- for task_id in 1 : n
271+ for machine_id = 1 : m
272+ for task_id = 1 : n
262273 current_task = permutation[task_id]
263274 if machine_id == 1
264275 if task_id == 1
@@ -270,7 +281,10 @@ function makespan(problem::JohnsonProblem, permutation::Vector{Int})::Float64
270281 if task_id == 1
271282 start = timetable[machine_id- 1 , task_id]. finish
272283 else
273- start = max (timetable[machine_id, task_id- 1 ]. finish, timetable[machine_id- 1 , task_id]. finish)
284+ start = max (
285+ timetable[machine_id, task_id- 1 ]. finish,
286+ timetable[machine_id- 1 , task_id]. finish,
287+ )
274288 end
275289 end
276290 duration = times[current_task, machine_id]
@@ -282,4 +296,4 @@ function makespan(problem::JohnsonProblem, permutation::Vector{Int})::Float64
282296 return timetable[end , end ]. finish
283297end
284298
285- end # end of module Johnsons
299+ end # end of module Johnsons
0 commit comments