环形拓扑:
s = 1:5;
t = circshift(s, -1);
三角形 + 环形拓扑:
s = 1:5;
t = circshift(s, -1);
s = [s s(1) s(end)];
t = [t 6 6];
网格拓扑
mat = zeros(3, 3); %# for a grid network
[ro, c] = size(mat); %# Get the matrix size, row and column
diagVec1 = repmat([ones(c - 1,1); 0], ro, 1); %# Make the first diagonal vector
%# (for horizontal connections)
diagVec1 = diagVec1(1:end-1); %# Remove the last value
diagVec2 = ones(c * (ro - 1), 1); %# Make the second diagonal vector
%# (for vertical connections)
adj = diag(diagVec1, 1) + ... %# Add the diagonals to a zero matrix
diag(diagVec2, c);
[s, t] = find(sparse(adj));
arpnet拓扑
s = [1, 1, 1, 1, 2, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
t = [2, 8, 12, 16, 3, 11, 13, 4, 5, 6, 10, 7, 9, 14, 21,15, 15, 16, 17, 17, 19, 17, 18, 19, 20, 21];
speeds = edge_spds_r(randi(numel(edge_spds_r), length(s), 1));
Gr = digraph(s, t, 1);
Gr.Edges.Speed(findedge(Gr, s, t)) = speeds;
if duplexd
Gr = addedge(Gr, t, s, 1);
Gr.Edges.Speed(findedge(Gr, t, s)) = speeds;
end
router_idcs = 1:numnodes(Gr);
mkrs = ['o', 's'];
colrs = [1 0 0; 0 1 0];
figure(fig_idx);
gtype = ones(1, router_idcs(end));
pgt = plot(Gr, 'Marker', num2cell(mkrs(gtype)), 'NodeColor', colrs(gtype, :));
labeledge(pgt, 1:numedges(Gr), 1:numedges(Gr));
fig_idx = fig_idx + 1;
x_router = [120, 220, 320, 420, 520, 620, 720, 160, 790, 520, 410, 40, 230, 210, 520, 120, 250, 380, 520, 620, 710];
y_router = [390, 390, 390, 390, 390, 390, 390, 290, 200, 290, 220, 200, 210, 130, 130, 20, 20, 20, 20, 20, 20];
pgt.XData = x_router;
pgt.YData = y_router;