Skip to content

Commit afaed07

Browse files
committed
Adds johnson's seq static method
1 parent 280bb90 commit afaed07

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

flowshop.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def __init__(self, data=None, nb_machines=2, nb_jobs=6):
1818
nb_machines {int} -- Number of machines for the given problem must be the number of rows of first param (default: {2})
1919
nb_jobs {[type]} -- Number of jobs for the given problem, must be equal to the number of columns of the data param. (default: {6})
2020
"""
21+
2122
self.nb_machines = nb_machines
2223
self.nb_jobs = nb_jobs
2324
if data is not None:
@@ -26,6 +27,7 @@ def __init__(self, data=None, nb_machines=2, nb_jobs=6):
2627
self.data = RandomFlowshop(
2728
self.nb_machines, self.nb_jobs).get_data()
2829

30+
2931
def solve_johnson(self):
3032
"""Solves a permutation flowshop problem using johnson's rule for a permutation problem of 2 machines and N jobs
3133
@@ -82,15 +84,28 @@ def solve_johnson(self):
8284
return seq, [jobs_m1, jobs_m2], optim_makespan
8385

8486
@staticmethod
85-
def johnshon_seq(data):
87+
def johnson_seq(data):
8688
# data matrix must have only two machines
87-
raise NotImplementedError
8889

90+
nb_machines = len(data)
91+
nb_jobs = len(data[0])
92+
93+
machine_1_sequence = [j for j in range(
94+
nb_jobs) if data[0][j] <= data[1][j]]
95+
machine_1_sequence.sort(key=lambda x: data[0][x])
96+
machine_2_sequence = [j for j in range(
97+
nb_jobs) if data[0][j] > data[1][j]]
98+
machine_2_sequence.sort(key=lambda x: data[1][x], reverse=True)
99+
100+
seq = machine_1_sequence + machine_2_sequence
89101

102+
return seq
90103

91104

92-
def cds(self, parameter_list):
105+
106+
def cds(self):
93107
raise NotImplementedError
108+
94109

95110
def palmer_heuristic(self):
96111
"""solves an N machines M jobs pfsp problem using Palmer's Heuristic
@@ -309,9 +324,9 @@ def get_problem_instance(self):
309324
if __name__ == "__main__":
310325
random_problem = RandomFlowshop(5, 8)
311326
random_problem_instance = random_problem.get_problem_instance()
312-
seq, neh_sched, mkspn = random_problem_instance.neh_heuristic()
327+
seq = random_problem_instance.cds()
313328
b_seq, b_scheds, b_opt_makespan = random_problem_instance.brute_force_exact()
314-
print(b_opt_makespan, mkspn)
329+
print(b_opt_makespan, seq)
315330
#print(seq)
316331
#print("Brute Force: {}, Palmer heuristic: {}".format(b_seq, seq))
317332

0 commit comments

Comments
 (0)