Как сформировать треугольник стекающейся формации? - PullRequest
0 голосов
/ 27 марта 2019

Я использую MATLAB для имитации управления пластом многоагентных систем. В настоящее время я использую алгоритм флокирования и мне удалось смоделировать круглое стадо. Как я могу смоделировать агентов, чтобы сформировать треугольное стадо? Агенты сойдутся в стадо, используя геометрические образцы решетчатой ​​формы

%Number of agents
prompt = 'Enter number of Agents: ';

Agents = input(prompt);
if Agents > 100
    error('Error! Too many agents, decrease the number of agents');
end
if Agents < 2
    error('Error! Too little agents, increase the number of agents');
end
Step_Num = 400;
%Number of iterations
%Initial condition
p = 10*randn(2,Agents);  %Vector Position p
v = 5*randn(2,Agents);   %Vector Velocity v
t = 0.01;                %Time
Li = 30;                 %Axis Limit
%Separation/Collision Avoidance
S = 1;        %Controls the distance between agents
              %Bigger number, further the agents are from each other
%Cohesion/Flock Centering
K = 1;        %Controls the collision between the agents
              %Bigger number the smaller the flock
%Alignment/Velocity Matching
M = 0;        %Controls the flock motion
%Separation/Collision avoidance gain
ca = 5;       %Larger gain -- agents more spread out
%Cohesion/Flock centering gain
fc = 0.1;     %Larger gain -- flock centering is smaller
%Flocking Model
for n=1:Step_Num           %For every iteration from 1 to desired step
    sv = zeros(2,Agents);  %Collision avoidance vector / Seperation Vector
    kv = zeros(2,Agents);  %Flock centering vector / Cohesion Vector
    for i = 1:Agents          
        for j = 1:Agents          
            if i~= j                         %Distance = 0 when i = j (ignore)
               r = (p(:,j)-p(:,i));          %Distance between two points i & j
               d = sqrt(r(1)^2+(r(2)^2));    %Euclidean distance
               sv(:,i) = sv(:,i) - ca*r/d^2; %Collision avoidance/Seperation
               kv(:,i) = kv(:,i) + fc*r;     %Flock centering/Cohesion
            end
        end
        v(:,i) = S*sv(:,i)+ K*kv(:,i)+ M;  %Total Velocity
        p(:,i) = p(:,i) + v(:,i)*t;        %New Position formula p = p+vt
    end
    %Plot simulations
    figure;
    plot(p(1,:),p(2,:),'k.','LineWidth',3,'Markersize',15);
    grid on;
    axis([-Li Li -Li Li]);   %Axis limit
    xlabel('X-axis')         %X-axis
    ylabel('Y-axis')         %Y-axis
    title(['Step Number :', num2str(n)]);
    F(:,n) = getframe;
    hold off;
end
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...