Adding Penalty for Violation
4 ビュー (過去 30 日間)
古いコメントを表示
I have this code snippet that generates a matrix with the notation of chr(:,:,i)
for i=1:10
A=zeros(100,4);
A(:,1)=randi(100,100,1); %Course(1)
A(:,2)=randi(5,100,1); %Day(2)
A(:,3)=randi(10,100,1); %Timeslot(3)
A(:,4)=randi(17,100,1); %Room(4)
chr(:,:,i)=A
end
Is there a way to check for duplicate values (Assuming Row 1, Row 4 & Row 5 contain similar data) and for each time a repeated data is found, a violation score (Let's say 10) is imposed to chr(:,:,i)
For the eg, if Row 4 & Row 5 are similar to Row 1, a violation score of 2*10 should be imposed to chr(:,:,i)
0 件のコメント
採用された回答
Image Analyst
2011 年 10 月 23 日
Well there are a variety of ways to do it, from brute force "for" loop ways to more efficient ways. After your for loop has finished creating the A array, I'd probably call sortrows() and then call diff(). Any row that has a repeat in it will have all zeros in a row of the array that diff() returns. Then check for all zero rows by using sum() or any(). Note which original row number this is by getting it from the index array that sortrows() returns (the second output arg). I expect that you're capable of handling the details, but that's how I'd start approaching it.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Genetic Algorithm についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!