⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parse_roofnet.m

📁 best routing protocol
💻 M
字号:
function [node_id, node_coord, neighbor_deliver] = parse_roofnet(rootdir)
%parse roofnet raw data
%node_id: the raw node id array assigned in roofnet
%node_coord(i, x, y): the i-th node geographic coordinate. [-1,-1] if missing
%neighbor_deliver: pairwise deliver rate default is 0 (non-reachable)
if nargin<1
  rootdir = '../data/roofnet/';
end

coord_fn = [rootdir 'node_coordinates_06060624xx'];
summary_fn = [rootdir 'summaries_06060624xx'];

coord = load(coord_fn);
%size(coord)
%plot(coord(:,2), coord(:,3),'o')
%hold on

summary = load(summary_fn);
%idx = find( summary(:,1)==606062403); % rate 1Mb: xx00, 2Mb: xx01, 5.5: xx02, 11: xx03
idx = find( summary(:,1)==606062402); % rate 1Mb: xx00, 2Mb: xx01, 5.5: xx02, 11: xx03

%node_id(i) == the id of the node
node_id = [];
%node_coord(i) == the coordinate of the node (could be missing)
node_coord = [];
%neighbor_deliver is the pairwise deliver rate between neighbor node i & j
neighbor_deliver = [;];

node_count = 0;

for ii =1:length(idx)
  i = idx(ii);
  src = summary(i, 4);
  dst = summary(i, 5);
  deliver = summary(i, 6);
  
  src_id = find(node_id==src);
  if length(src_id)<1
    node_count = node_count + 1;
    node_id(node_count) = src;
    src_id = node_count;
    try
      node_coord(src_id,:) = find_coord(src, coord);
    catch
      %fprintf('%d:%s',src, lasterr);
      node_coord(src_id,:) = [-1,-1];
    end
  elseif length(src_id)>1
    error('no way')
  end

  dst_id = find(node_id == dst);
  if length(dst_id)~=1
    node_count = node_count + 1;
    node_id(node_count) = dst;
    dst_id = node_count;
    try
      node_coord(dst_id,:) = find_coord(dst, coord);
    catch
      %fprintf('%d:%s',dst, lasterr);
      node_coord(dst_id,:) = [-1,-1];
    end
  elseif length(src_id)>1
    error('no way')
  end
  neighbor_deliver(src_id, dst_id) = deliver;
end
fprintf('there are %d nodes\n',node_count);

function c = find_coord(idx, coord)
i = find(coord(:,1)==idx);
if length(i)~=1
  error('sigh. no coord on this node')
else
  c = [coord(i,2), coord(i,3)];
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -