-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSchedule_Generator.m
66 lines (65 loc) · 1.57 KB
/
Schedule_Generator.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
function [ new_s] = Schedule_Generator( s)
%Generate a new random schedule based on previous schedule by I) exchanging two jobs from two machine
%or II) transfering a job from a machine to another machine
[m,n]=size(s);
new_s=s;
%Cheking if plan I is possible (there are two machines with assigned job)
nasm=0;
for i=1:m
if nnz(s(i,:))>0
nasm=nasm+1;
end
end
if nasm>=2
r0=rand;
else %if plan I is not possible, plan II should execute
r0=1;
end
if r0<0.5
%plan I:
%randomly choosing two different assigned machines
v=randi(m);
while nnz(s(v,:))==0
v=randi(m);
end
c=randi(m);
while v==c
c=randi(m);
end
while nnz(s(c,:))==0
c=randi(m);
end
%randomly choosing one job from each machine
%first machine:
x1=find(s(v,:)~=0);
r1=randi(length(x1));
vv=x1(r1);
%second machine:
x2=find(s(c,:)~=0);
r2=randi(length(x2));
cc=x2(r2);
%exchanging jobs:
new_s(v,vv)=s(c,cc);
new_s(c,cc)=s(v,vv);
else %plan II:
%randomly choosing two different machines
v=randi(m);
while nnz(s(v,:))==0
v=randi(m);
end
c=randi(m); %second machine can be unassigned
while v==c
c=randi(m);
end
%randomly choosing one job from each machine
x1=find(s(v,:)~=0);
r1=randi(length(x1));
vv=x1(r1);
%job in second machine should be a zero element
x2=find(s(c,:)==0);
r2=randi(length(x2));
cc=x2(r2);
%transfering
new_s(c,cc)=s(v,vv);
new_s(v,vv)=0;
end