✅作者简介:热爱科研的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
⛄ 运行结果