Find contiguous positions in a hexagonal array.

2 ビュー (過去 30 日間)
Yro
Yro 2021 年 6 月 10 日
編集済み: Yro 2021 年 6 月 10 日
Hi, I am currently working on an optimization problem using Genetic Algorithms (GA). The image shown in Figure 1 is a pattern obtained by applying GA. It is a hexagonal array generated from the scheme presented with Figure 2. During the execution of the algorithm I must restrict the number of contiguous positions (in magenta color) in the pattern. To constrain the positions I performed an algorithm that compares the position of each assembly of the obtained pattern with the adjacent positions. The main problem is that there are still contiguous positions as shown in Figure 1. This is because I have done it for each position independently. My question is how could I find if there are more than two or three adjacent positions in the pattern, any idea how to implement it.
%% Code to find contiguous positions (>3)
for i = 1:length(PATTERNS)
P1(i,:) = [ PATTERNS(i,1) - 1; ...
PATTERNS(i,2) + 1; ...
PATTERNS(i,1) + 0; ...
PATTERNS(i,2) + 1; ...
PATTERNS(i,1) + 1; ...
PATTERNS(i,2) + 0; ...
PATTERNS(i,1) + 1; ...
PATTERNS(i,2) - 1; ...
PATTERNS(i,1) + 0; ...
PATTERNS(i,2) - 1; ...
PATTERNS(i,1) - 1; ...
PATTERNS(i,2) + 0; ...
PATTERNS(i,1) + 0; ...
PATTERNS(i,2) + 0;] ; % El propio ensamble - ensamble central del nodo
end
% Cada ensamble del Patron en celdas 29x(1x2)
PATTERNS_cell = mat2cell(PATTERNS,29, 2);
% Ensambles contiguos en cada nodo 29(7x(1x2))
P1_cell = mat2cell(P1,ones(29,1)', 2*ones(7,1)');
POS = [ 30 30; ...
28 32; ...
30 28; ...
32 30;];
for i = 1 : size(P1_cell,1)
for j = 1 : size(P1_cell,2)
[Lia,Lib] = ismember(P1_cell{i,j},[PATTERNS_FOR_ERANOS_cell{1}; CONTROL_RODS_POS] ,'rows');
Index1(i,j) = Lib; % 1x7
end
Index{i} = Index1; % 7x29
end
for i = 1 : length(Index)
Non_ceros_counts(i) = nnz(Index{end}(i,:));
end
if any(Non_ceros_counts > 3) == 1
fprintf("\n ***** More than 3 positions per node ***** \n\n")
end
end
Thanks in advance.
Figure_1
.Figure_2

回答 (0 件)

カテゴリ

Help Center および File ExchangeSignal Processing についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by