-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculateGraphCost.m
31 lines (23 loc) · 910 Bytes
/
CalculateGraphCost.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function [cost] = CalculateGraphCost(edges, positions, number_of_uavs)
% Function: CalculateGraphCost
% Description: calculate the costs of edges
% Input: 1) edges: the collections of edges in communication graph
% 2) number_of_uavs
% Output: cost: edge weight matrix
% Author: Zihao Zhou, eezihaozhou@gmail.com
% Updated at: 2024/3/30
cost = zeros([number_of_uavs+2, number_of_uavs+2]); % initialization
cost(end, :) = inf; % packets are not allowed to go out from the BS
[edges_num, ~] = size(edges);
for e = 1:edges_num
edge = edges(e, :);
if cost(edge(1), edge(2)) ~= inf
distance = pdist2(positions(edge(1), :), positions(edge(2), :), 'squaredeuclidean');
edgecost = distance;
cost(edge(1), edge(2)) = edgecost ;
if cost(edge(2), edge(1)) ~= inf
cost(edge(2), edge(1)) = edgecost;
end
end
end
end