|
4 | 4 | import numpy as np |
5 | 5 | from itertools import permutations |
6 | 6 | from functools import lru_cache |
| 7 | + |
7 | 8 | class Flowshop(object): |
8 | 9 | """ |
9 | 10 | A class for initiaizing & solving a Permutation Flowshop Scheduling Problem |
@@ -156,19 +157,14 @@ def neh_heuristic(self): |
156 | 157 | for j in range(self.nb_machines)]) |
157 | 158 | sums.append((job_id, p_ij)) |
158 | 159 | 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 | + |
172 | 168 | schedules = np.zeros((self.nb_machines, self.nb_jobs), dtype=dict) |
173 | 169 | # schedule first job alone first |
174 | 170 | task = {"name": "job_{}".format( |
|
0 commit comments