-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrossover.m
73 lines (62 loc) · 1.98 KB
/
Crossover.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
%
% Copyright (c) 2015, Mostapha Kalami Heris & Yarpiz (www.yarpiz.com)
% All rights reserved. Please read the "LICENSE" file for license terms.
%
% Project Code: YPEA101
% Project Title: Implementation of Real-Coded Genetic Algorithm in MATLAB
% Publisher: Yarpiz (www.yarpiz.com)
%
% Developer: Mostapha Kalami Heris (Member of Yarpiz Team)
%
% Cite as:
% Mostapha Kalami Heris, Binary and Real-Coded Genetic Algorithms in MATLAB (URL: https://yarpiz.com/23/ypea101-genetic-algorithms), Yarpiz, 2015.
%
% Contact Info: [email protected], [email protected]
%
function [y1, y2] = Crossover(x1, x2, model)
n = length(x1.agents);
taskList = [];
for i=1:n
taskList = [taskList, x1.agents(i).task];
end
% alpha = unifrnd(-gamma, 1+gamma, length(x1));
% y1 = alpha.*x1+(1-alpha).*x2;
% y2 = alpha.*x2+(1-alpha).*x1;
alpha = randi([1 n]); % crossover point
% generate new solutions
y1 = x1;
y2 = x2;
for i = alpha:n
y1.agents(i) = x2.agents(i);
y2.agents(i) = x1.agents(i);
end
% y1 = max(y1, VarMin);
% y1 = min(y1, VarMax);
%
% y2 = max(y2, VarMin);
% y2 = min(y2, VarMax);
% Delete duplicate tasks and add missing tasks
% %% Test bug
% disp("Before feasible:_________ ");
% disp("for solution y1 ")
% for i = 1:length(y1.agents)
% disp("agent "+ i +" : " + num2str(y1.agents(i).task(:)));
% end
% disp("for solution y2 ")
% for i = 1:length(y2.agents)
% disp("agent "+ i +" : " + num2str(y2.agents(i).task(:)));
% end
% %% End test bug
y1 = Feasibilization(y1,model, 8);
y2 = Feasibilization(y2,model, 8);
%
% disp("After feasible:_________ ");
% disp("for solution y1 ")
% for i = 1:length(y1.agents)
% disp("agent "+ i +" : " + num2str(y1.agents(i).task(:)));
% end
% disp("for solution y2 ")
% for i = 1:length(y2.agents)
% disp("agent "+ i +" : " + num2str(y2.agents(i).task(:)));
% end
end