基于共识的捆绑算法CBBA实现多无人机多任务调度附matlab代码

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法       神经网络预测       雷达通信       无线传感器        电力系统

信号处理              图像处理               路径规划       元胞自动机        无人机 

⛄ 内容介绍

Theorem 1. Provided that the scoring function is DMG (Diminishing Marginal Gain), the CBBA process with a conflflict resolution phase over a static communication network with diameter D satisfifiesthe following:

1. CBBA produces the same solution as SGA(sequentional greedy algo) with the corresponding winning bid values and winning agent information being shared across the flfleet ​

2. The convergence time Tc is bounded above by NminD.

⛄ 部分代码

% Runs consensus between neighbors

% Checks for conflicts and resolves among agents

%---------------------------------------------------------------------%

function [CBBA_Data t] = CBBA_Communicate(CBBA_Params, CBBA_Data, Graph, old_t, T)

% Copy data

for n = 1:CBBA_Params.N,

    old_z(n,:) = CBBA_Data(n).winners;

    old_y(n,:) = CBBA_Data(n).winnerBids;    

end

z = old_z;

y = old_y;

t = old_t;

epsilon = 10e-6;

% Start communication between agents

% sender   = k

% receiver = i

% task     = j

for k=1:CBBA_Params.N

    for i=1:CBBA_Params.N

        if( Graph(k,i) == 1 )

            for j=1:CBBA_Params.M

                % Implement table for each task

                

                if( old_z(k,j) == k ) % Entries 1 to 4: Sender thinks he has the task

                

                    % Entry 1: Update or Leave

                    if( z(i,j) == i ) 

                        if( old_y(k,j) - y(i,j) > epsilon )  % Update

                            z(i,j) = old_z(k,j);

                            y(i,j) = old_y(k,j);

                        elseif( abs(old_y(k,j) - y(i,j)) <= epsilon )  % Equal scores

                            if( z(i,j) > old_z(k,j) )  % Tie-break based on smaller index

                                z(i,j) = old_z(k,j);

                                y(i,j) = old_y(k,j);

                            end

                        end

                        

                    % Entry 2: Update

                    elseif( z(i,j) == k ) 

                        z(i,j) = old_z(k,j);

                        y(i,j) = old_y(k,j);

                    

                    % Entry 3: Update or Leave

                    elseif( z(i,j) > 0 ) 

                        if( old_t(k,z(i,j)) > t(i,z(i,j)) )  % Update

                            z(i,j) = old_z(k,j);

                            y(i,j) = old_y(k,j);

                        elseif( (old_y(k,j) - y(i,j)) > epsilon )  % Update

                            z(i,j) = old_z(k,j);

                            y(i,j) = old_y(k,j);

                        elseif( abs(old_y(k,j) - y(i,j)) <= epsilon )  % Equal scores

                            if( z(i,j) > old_z(k,j) )  % Tie-break based on smaller index

                                z(i,j) = old_z(k,j);

                                y(i,j) = old_y(k,j);

                            end

                        end

                

                    % Entry 4: Update

                    elseif( z(i,j) == 0 )

                        z(i,j) = old_z(k,j);

                        y(i,j) = old_y(k,j);

                        

                    else

                        disp('Unknown winner value: Should not be here, please revise')

                    end

                    

                elseif( old_z(k,j) == i ) % Entries 5 to 8: Sender thinks receiver has the task

                    % Entry 5: Leave

                    if( z(i,j) == i ) 

                        % Do nothing

                        

                     % Entry 6: Reset

                    elseif( z(i,j) == k ) 

                        z(i,j) = 0;

                        y(i,j) = 0;

                   

                     % Entry 7: Reset or Leave

                    elseif( z(i,j) > 0 ) 

                        if( old_t(k,z(i,j)) > t(i,z(i,j)) )  % Reset

                            z(i,j) = 0;

                            y(i,j) = 0;

                        end

                        

                    % Entry 8: Leave

                    elseif( z(i,j) == 0 )

                        % Do nothing

                        

                    else

                        disp('Unknown winner value: Should not be here, please revise')

                    end

                   

                elseif( old_z(k,j) > 0 ) % Entries 9 to 13: Sender thinks someone else has the task

                    

                    % Entry 9: Update or Leave

                    if( z(i,j) == i ) 

                        if( old_t(k,old_z(k,j)) > t(i,old_z(k,j)) )

                            if ( (old_y(k,j) - y(i,j)) > epsilon )

                                z(i,j) = old_z(k,j);  % Update

                                y(i,j) = old_y(k,j);

                            elseif( abs(old_y(k,j) - y(i,j)) <= epsilon )  % Equal scores

                                if( z(i,j) > old_z(k,j) )  % Tie-break based on smaller index

                                    z(i,j) = old_z(k,j);

                                    y(i,j) = old_y(k,j);

                                end

                            end

                        end

                        

                     % Entry 10: Update or Reset

                    elseif( z(i,j) == k ) 

                        if( old_t(k,old_z(k,j)) > t(i,old_z(k,j)) )  % Update

                            z(i,j) = old_z(k,j);

                            y(i,j) = old_y(k,j);

                        else  % Reset

                            z(i,j) = 0;

                            y(i,j) = 0;

                        end

                        

                    % Entry 11: Update or Leave

                    elseif( z(i,j) == old_z(k,j) ) 

                        if( old_t(k,old_z(k,j)) > t(i,old_z(k,j)) )  % Update

                            z(i,j) = old_z(k,j);

                            y(i,j) = old_y(k,j);

                        end

                     

                    % Entry 12: Update, Reset or Leave

                    elseif( z(i,j) > 0 ) 

                        if( old_t(k,z(i,j)) > t(i,z(i,j)) )

                            if( old_t(k,old_z(k,j)) >= t(i,old_z(k,j)) )  % Update

                                z(i,j) = old_z(k,j);

                                y(i,j) = old_y(k,j);

                            elseif( old_t(k,old_z(k,j)) < t(i,old_z(k,j)) ) % Reset

                                z(i,j) = 0;

                                y(i,j) = 0;

                            else

                                disp('Should not be here, please revise')

                            end

                        else

                            if( old_t(k,old_z(k,j)) > t(i,old_z(k,j)) )

                                if( (old_y(k,j) - y(i,j)) > epsilon )  % Update

                                    z(i,j) = old_z(k,j);

                                    y(i,j) = old_y(k,j);

                                elseif( abs(old_y(k,j) - y(i,j)) <= epsilon )  % Equal scores

                                    if( z(i,j) > old_z(k,j) )   % Tie-break based on smaller index

                                        z(i,j) = old_z(k,j);

                                        y(i,j) = old_y(k,j);

                                    end

                                end

                            end

                        end

                    % Entry 13: Update or Leave

                    elseif( z(i,j) == 0 )

                        if( old_t(k,old_z(k,j)) > t(i,old_z(k,j)) )  % Update

                            z(i,j) = old_z(k,j);

                            y(i,j) = old_y(k,j);

                        end

                        

                    else

                        disp('Unknown winner value: Should not be here, please revise')

                    end

                    

                elseif( old_z(k,j) == 0 ) % Entries 14 to 17: Sender thinks no one has the task

                    % Entry 14: Leave

                    if( z(i,j) == i ) 

                        % Do nothing

                        

                     % Entry 15: Update

                    elseif( z(i,j) == k ) 

                        z(i,j) = old_z(k,j);

                        y(i,j) = old_y(k,j);

                   

                     % Entry 16: Update or Leave

                    elseif( z(i,j) > 0 ) 

                        if( old_t(k,z(i,j)) > t(i,z(i,j)) )  % Update

                            z(i,j) = old_z(k,j);

                            y(i,j) = old_y(k,j);

                        end

                        

                    % Entry 17: Leave

                    elseif( z(i,j) == 0 )

                        % Do nothing

                        

                    else

                        disp('Unknown winner value: Should not be here, please revise')

                    end

                    

                    % End of table

                    

                else

                    disp('Unknown winner value: Should not be here, please revise')

                end

            end

            

            % Update timestamps for all agents based on latest comm

            for n=1:CBBA_Params.N

                if( n ~= i && t(i,n) < old_t(k,n) )

                    t(i,n) = old_t(k,n);

                end

            end

            t(i,k) = T;

            

        end

    end

end

% Copy data

for n = 1:CBBA_Params.N,

    CBBA_Data(n).winners    = z(n,:);

    CBBA_Data(n).winnerBids = y(n,:);

end​

end

⛄ 运行结果

⛄ 参考文献

⛳️ 代码获取关注我

❤️部分理论引用网络文献,若有侵权联系博主删除

❤️ 关注我领取海量matlab电子书和数学建模资料

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
这是一个非常复杂的任务,需要大量的代码算法。在这里,我将简要介绍一下CBBA算法和人工势场法,以及如何将它们结合起来实现多动态目标的围捕任务。 CBBA算法(Consensus-Based Bundle Algorithm)是一种用于多智能体任务分配的算法。该算法通过协商和交换信息来实现任务的分配,以最小化分配的代价。CBBA算法的基本思想是,每个智能体提出一个任务列表,然后与其他智能体交换信息,以选择和分配任务。任务分配的过程中,每个智能体只能被分配一个任务,而且每个任务只能被一个智能体完成。CBBA算法的优点是简单易实现,能够处理大规模任务分配问题,并且能够适应动态环境。 人工势场法是一种用于路径规划和避障的方法。该方法利用了物理学中的势场概念,将机器人看作一个带电粒子,将障碍物看作带有相反电荷的粒子,然后根据粒子间的相互作用力计算机器人的运动轨迹。人工势场法的优点是简单易实现,能够处理复杂的环境,并且能够适应动态环境。 在多动态目标的围捕任务中,我们需要将CBBA算法和人工势场法结合起来,以实现任务分配和路径规划。具体实现步骤如下: 1. 初始化任务列表和智能体列表,然后进入任务分配循环。 2. 每个智能体根据当前的任务列表和已经完成的任务,计算出自己可完成的任务列表,并将任务列表发送给其他智能体。 3. 每个智能体根据接收到的任务列表,计算出自己最优的任务,并将任务分配结果发送给其他智能体。 4. 每个智能体根据自己被分配的任务,使用人工势场法计算出路径,并执行任务。 5. 当所有任务都完成时,退出任务分配循环。 6. 绘制围捕过程,以便观察和分析。 下面是一个简单的Matlab代码示例,用于实现基于CBBA算法的任务分配和人工势场法的路径规划和避障: ```matlab % 初始化任务列表 task_list = [1,2,3,4,5]; % 初始化智能体列表 agent_list = [1,2,3,4]; % 初始化位置和速度 pos = zeros(length(agent_list),2); vel = zeros(length(agent_list),2); % 进入任务分配循环 while ~isempty(task_list) % 计算可完成的任务列表 for i = 1:length(agent_list) available_tasks = []; for j = 1:length(task_list) % 如果任务没有被分配,并且智能体可以完成该任务,则将任务加入可完成任务列表 if task_list(j) ~= -1 && can_complete_task(agent_list(i), task_list(j)) available_tasks = [available_tasks, task_list(j)]; end end % 将可完成任务列表发送给其他智能体 send_available_tasks(agent_list(i), available_tasks); end % 计算最优任务 for i = 1:length(agent_list) % 接收其他智能体发送的可完成任务列表 available_tasks = recv_available_tasks(agent_list(i)); % 计算最优任务 best_task = find_best_task(agent_list(i), available_tasks); % 将任务分配结果发送给其他智能体 send_task_assignment(agent_list(i), best_task); end % 执行任务 for i = 1:length(agent_list) % 接收任务分配结果 assigned_task = recv_task_assignment(agent_list(i)); % 计算路径 path = calculate_path(agent_list(i), assigned_task); % 避障 path = avoid_obstacles(path); % 移动智能体 pos(i,:) = move_agent(pos(i,:), vel(i,:), path); end % 标记已完成的任务 for i = 1:length(agent_list) assigned_task = recv_task_assignment(agent_list(i)); if assigned_task ~= -1 task_list(assigned_task) = -1; end end end % 绘制围捕过程 plot_capturing_process(); ``` 需要注意的是,上述代码中的函数和变量都需要根据具体情况进行实现和修改。此外,路径规划和避障的具体实现方法也需要根据具体需求进行选择和调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值