Skip to content

Commit 28371d9

Browse files
committed
Changes NEH implementation to a better one
1 parent 6e7e3a0 commit 28371d9

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

flowshop.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55
from itertools import permutations
66
from functools import lru_cache
7+
78
class Flowshop(object):
89
"""
910
A class for initiaizing & solving a Permutation Flowshop Scheduling Problem
@@ -156,19 +157,14 @@ def neh_heuristic(self):
156157
for j in range(self.nb_machines)])
157158
sums.append((job_id, p_ij))
158159
sums.sort(key=lambda x: x[1], reverse=True)
159-
order_seq = [x[0] for x in sums]
160-
seq = [order_seq[0]]
161-
for i in range(1, self.nb_jobs):
162-
min_mkspan = float("inf")
163-
for j in range(0, i+1):
164-
tempo_seq = seq[:]
165-
tempo_seq.insert(j, order_seq[i])
166-
max_mkspn = self._get_makespan(tempo_seq, self.data)
167-
if min_mkspan > max_mkspn:
168-
max_mkspn = min_mkspan
169-
b_seq = tempo_seq
170-
seq = b_seq
171-
160+
seq = []
161+
for job in sums:
162+
cands = []
163+
for i in range(0, len(seq) + 1):
164+
cand = seq[:i] + [job[0]] + seq[i:]
165+
cands.append((cand, self._get_makespan(cand, self.data)))
166+
seq = min(cands, key= lambda x: x[1])[0]
167+
172168
schedules = np.zeros((self.nb_machines, self.nb_jobs), dtype=dict)
173169
# schedule first job alone first
174170
task = {"name": "job_{}".format(

0 commit comments

Comments
 (0)