-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSemiActiveDecoding.m
110 lines (83 loc) · 3.75 KB
/
SemiActiveDecoding.m
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
function [Jobs,Cmax,MachineList,ST,PT] = SemiActiveDecoding(T,Chromosome)
%% INPUT:
%T--input matrix:
%Each instance consists of a line of description, a line containing the number of jobs and the number of machines, and then one line for each job,
%listing the machine number and processing time for each step of the job. The machines are numbered starting with 0.
% +++++++++++++++++++++++++++++
% Fisher and Thompson 6x6 instance, alternate name (mt06)
% 6 6
% 2 1 0 3 1 6 3 7 5 3 4 6
% 1 8 2 5 4 10 5 10 0 10 3 4
% 2 5 3 4 5 8 0 9 1 1 4 7
% 1 5 0 5 2 5 3 3 4 8 5 9
% 2 9 1 3 4 5 5 4 0 3 3 1
% 1 3 3 3 5 9 0 10 4 4 2 1
% +++++++++++++++++++++++++++++
%Chromosome -- A chromosome to be decoded
%% OUTPUT:
%JobList-- job sequences
%Cmax --the max makespan
%MachineList--The machine sequences corresponding to chromosome
%ST --the start time for each job step in chromosome
%PT --The operation time for each job step in chromome
%% start
[num_of_jobs,number_of_machines]=size(T);
number_of_machines = number_of_machines/2; % number of jobs and machines
Jobs = unique(Chromosome);
StepList = []; %steps for all genes
MachineList = [];
DecodedGenes =[];
ST = [];
PT = [];
len_of_chromosome = num_of_jobs*number_of_machines;
%% Caculate MachineList and PT
for index = 1:len_of_chromosome
DecodedGenes=[DecodedGenes Chromosome(index)];
postion = length(find(DecodedGenes==Chromosome(index)));
StepList = [StepList postion];
pos1 = postion*2-1;
pos2 =postion*2;
MachineList = [MachineList T(Chromosome(index),pos1)];
PT = [PT T(Chromosome(index),pos2)];
end
%% Caculate ST
Machines = unique(MachineList);
steps = unique(StepList);
job_start_time = cell(num_of_jobs,1);
job_end_time = cell(num_of_jobs,1);
machine_start_time = cell(number_of_machines,1);
machine_end_time = cell(number_of_machines,1);
machine_state = zeros(1,number_of_machines); %0--FirstWork;1--NotFirst
for index = 1:len_of_chromosome
job = Chromosome(index);
machine = MachineList(index);
pt = PT(index);
step = StepList(index);
pos_m = find(Machines==machine);
pos_j = find(Jobs==job);
if step==1 %first step without considering the constrains between steps of same job
if machine_state(pos_m)==0 % The machine is first used
job_start_time{pos_j}=[0,pos_m];
job_end_time{pos_j}=[job_start_time{pos_j}(1)+pt,pos_m];
else
job_start_time{pos_j}=[machine_end_time{pos_m}(1),pos_m];
job_end_time{pos_j}=[job_start_time{pos_j}(1)+pt,pos_m];
end
else
if machine_state(pos_m)==0 % The machine is first used
job_start_time{pos_j}=[job_end_time{pos_j}(1),pos_m];
job_end_time{pos_j}=[job_start_time{pos_j}(1)+pt,pos_m];
else
job_start_time{pos_j}=[max(machine_end_time{pos_m}(1),job_end_time{pos_j}(1)),pos_m];
job_end_time{pos_j}=[job_start_time{pos_j}(1)+pt,pos_m];
end
end
machine_start_time{pos_m}= [job_start_time{pos_j}(1)];
machine_end_time{pos_m} = [job_end_time{pos_j}(1)];
machine_state(pos_m)=1;
ST=[ST, job_start_time{pos_j}(1)];
end
%% Caculate Cmax
end_time=cell2mat(job_end_time);
Cmax = max(end_time(:,1));
end