% 1. Input your complete 42-node edge vectors
A=[1 2 3 4 5 6 7 8 9 10 1 1 11 3 12 13 14 15 5 5 16 17 18 8 18 19 20 21 22 20 23 25 26 26 27 23 26 9 28 29 30 31 32 32 11 33 33 35 36 11 36 37 42 13 38 38 40 41 42 42 43 44 45 46 47 43 48 49 50 50 51 14 52 52 53 54 55 52 55 56 58 55 58 58 59 60 62 63 66 66 60 63 63 64 65 20];
B=[2 3 4 5 6 7 8 1 8 9 10 11 3 12 13 4 4 14 15 16 7 7 17 18 19 20 21 22 23 23 24 24 25 27 9 26 28 28 29 30 31 28 31 34 34 31 34 34 35 36 37 39 39 42 36 39 39 40 41 43 44 13 43 45 46 47 47 48 49 47 50 51 14 50 52 53 54 55 56 58 16 57 57 59 60 16 60 62 63 18 61 61 64 65 66 66];
num_nodes = max([A, B]);
% 2. Create the Adjacency Matrix
Adj = zeros(num_nodes, num_nodes);
for i = 1:length(A)
Adj(A(i), B(i)) = 1;
Adj(B(i), A(i)) = 1;
end
% 3. Optimized Fast Positioning Engine (Reduced iterations for speed)
rng(101);
x = rand(1, num_nodes) * 4 - 2;
y = rand(1, num_nodes) * 4 - 2;
iterations = 15; % Drastically reduced to prevent platform timeouts
k_force = sqrt(10.0 / num_nodes);
t = 0.2;
for step = 1:iterations
disp_x = zeros(1, num_nodes);
disp_y = zeros(1, num_nodes);
for i = 1:num_nodes
for j = 1:num_nodes
if i ~= j
dx = x(i) - x(j); dy = y(i) - y(j);
delta_len = max(sqrt(dx*dx + dy*dy), 1e-4);
fr = (k_force * k_force) / delta_len;
disp_x(i) = disp_x(i) + (dx / delta_len) * fr;
disp_y(i) = disp_y(i) + (dy / delta_len) * fr;
end
end
end
for i = 1:num_nodes
for j = i+1:num_nodes
if Adj(i,j) == 1
dx = x(i) - x(j); dy = y(i) - y(j);
delta_len = max(sqrt(dx*dx + dy*dy), 1e-4);
fa = (delta_len * delta_len) / k_force;
disp_x(i) = disp_x(i) - (dx / delta_len) * fa;
disp_y(i) = disp_y(i) - (dy / delta_len) * fa;
disp_x(j) = disp_x(j) + (dx / delta_len) * fa;
disp_y(j) = disp_y(j) + (dy / delta_len) * fa;
end
end
end
disp_len = max(sqrt(disp_x.^2 + disp_y.^2), 1e-4);
x = x + (disp_x ./ disp_len) .* min(disp_len, t);
y = y + (disp_y ./ disp_len) .* min(disp_len, t);
t = t * 0.95;
end
% 4. Clean Textbook Graph Theory Plot Window
figure; hold on;
for i = 1:num_nodes
for j = i+1:num_nodes
if Adj(i,j) == 1
plot([x(i), x(j)], [y(i), y(j)], 'k-', 'LineWidth', 1);
end
end
end
plot(x, y, 'ko', 'MarkerFaceColor', 'w', 'MarkerSize', 14, 'LineWidth', 1);
for i = 1:num_nodes
text(x(i), y(i), num2str(i), 'Color', 'k', 'FontSize', 8, 'FontWeight', 'bold', 'HorizontalAlignment', 'center');
end
title('Graph G Layout (42 Vertices Network Map)');
axis off; axis equal; hold off;
% 5. INSTANT Vectorized Distance Matrix Calculation (Replaces slow loops)
D = inf(num_nodes, num_nodes);
D(logical(eye(num_nodes))) = 0;
D(Adj > 0) = 1;
% Core vectorized Floyd-Warshall operation (Runs in milliseconds)
for k = 1:num_nodes
D = min(D, D(:, k) + D(k, :));
end
% 6. Output bracket matrix array directly to terminal box
disp(' '); disp('--- COPY BRACKET ARRAY DATA BELOW ---');
for i = 1:size(D, 1)
fprintf('['); fprintf('%d,', D(i, 1:end-1)); fprintf('%d', D(i, end)); fprintf('],\n');
end
disp('--- END OF DATA ---');
To embed this project on your website, copy the following code and paste it into your website's HTML: