This repository has been archived by the owner on Jun 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcds.py
executable file
·46 lines (37 loc) · 1.49 KB
/
cds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import numpy
import commonFunction
import interface
#####################################################
# algorithm for cds
#####################################################
def get_merge(start_index, end_index, data, nb_jobs):
data_prime = numpy.zeros(nb_jobs)
for j in range(nb_jobs):
data_prime[j] = data[start_index][j]
if start_index + 1 < end_index:
for k in range(start_index + 1, end_index):
for j in range(nb_jobs):
data_prime[j] += data[k][j]
return data_prime
def cds(data, nb_machines, nb_jobs):
c_max_best = float("inf")
for k in range(1, nb_machines):
p1_prime = get_merge(0, k, data, nb_jobs)
p2_prime = get_merge(nb_machines - k, nb_machines, data, nb_jobs)
ss_pb = [p1_prime, p2_prime]
print(ss_pb)
current_seq = commonFunction.u(ss_pb, nb_jobs) + commonFunction.v(ss_pb, nb_jobs)
c_max = commonFunction.makespan(current_seq, data, nb_machines)[nb_machines - 1][nb_jobs]
print(current_seq, c_max)
if c_max < c_max_best:
c_max_best = c_max
best_seq = current_seq
return best_seq, c_max_best
# run CDS
nbm, nbj, p_ij = commonFunction.read_from_file("example2.txt")
seq, cmax = cds(p_ij, nbm, nbj)
print("nbMachines:", nbm)
print("nbJobs:", nbj)
print("data: p_ij, the processing time of jth job on ith machine\n", p_ij)
print("cds:", seq, cmax)
interface.graphic("CDS", seq, nbj, nbm, commonFunction.makespan(seq, p_ij, nbm), p_ij)