How to crossover between a set of N matrices?
5 次查看(过去 30 天)
显示 更早的评论
For example, we have 5 matrices A,B,C,D,E and we select the best matrix based on a certain parameter (TF) and call it teacher, then we do the crossover. For the crossover, we randomly select any two rows from teacher matrix and replace with corresponding rows of other matrices. Code for my problem is given below. I have to select best matrix based on TF (max value is the best)as the teacher and then do the crossover.
clc
clear all
N = 5; % Population size
P = 5; % The number of competitive projects
T = 10; % The number of time periods
% The Expected benefit in each time period
B = [25 23 20 17 16 14 10 0 0 0; 30 28 25 21 19 17 0 0 0 0; 20 19 17 15 14 12 10 9 0 0; 15 13 12 11 11 10 7 5 3 0; 25 24 21 19 17 14 8 0 0 0];
% Duration of projects
D = [4; 5; 3; 2; 4];
% Resource requirement of a project in each period
% Res Req (type 1) = [3; 5; 1; 2; 4]; Max Availability = 6 R1 = [3*ones(1,10);5*ones(1,10);ones(1,10);2*ones(1,10);4*ones(1,10)];
% Res Req (type 2) = [2; 4; 1; 2; 3]; Max Availability = 4 R2 = [2*ones(1,10);4*ones(1,10);ones(1,10);2*ones(1,10);3*ones(1,10)];
excludedcount = D-1;
X = zeros(P,T);
Result = cell(1, N);
for i = 1:N
while(1)
for row = 1:P
rv = [1, zeros(1, T - excludedcount(row) - 1)];
X(row, 1 : (T - excludedcount(row))) = rv(randperm(numel(rv)));
end
X;
if any(X(1,:))
X([4 5],:)=0;
end
if any(X(2,:))
X(4,:)=0;
end
if any(X(3,:))
X(5,:)=0;
end
if any(X(4,:))
X(2,:)=0;
end
if any(X(5,:))
X([1 3],:)=0;
end
X;
Q = X.*B;
TF = sum(sum(Q));
Y=X;
for row = 1:P
ic=find(Y(row,:));
if ~isempty(ic)
Y(row,ic:ic+D(row)-1)=ones(1,D(row));
end
end
Y;
RR1 = R1.*Y;
CRR1 = sum(RR1);
RR2 = R2.*Y;
CRR2 = sum(RR2);
if ((max(CRR1)>6)||(max(CRR2)>4))
continue;
else
break;
end
CRR1;
CRR2;
TF;
end
ResultC{i} = X;
end
ResultM = cat(3, ResultC{:});
Please help me.
1 个评论
DGM
2024-10-1
Editor's note:
I just fixed the exploded code block formatting. I assume the commented code was unused.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Point Cloud Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!