Walks and eccentricity, graph theory

6 visualizzazioni (ultimi 30 giorni)
The Jesus
The Jesus il 29 Mag 2021
Risposto: Jaynik il 27 Set 2024
Hi, i have an adjacency matrix where Aij denotes the number of edges from vi to vj, edges going out from the vi gives the elements in the first row and now of the matrix and now i want to:
  • first, write a function exwalk(A) compute a matrix containing the number of walks between vi and vj in exactly k steps.
  • use exwalk(A) to create a function maxwalk(A, k) compute the number of walks in at most k steps.
  • write a function eccentricities(A) compute a list of ecc(v) eccentricities for all vertices.

Risposte (1)

Jaynik
Jaynik il 27 Set 2024
Hi,
  1. To calculate the number of walks of exactly k steps, you just need to multiply the Adj matrix k times.
  2. Once you have the exwalk, you can define the maxwalk function as follows:
function W = maxwalk(Adj, k)
n = size(Adj, 1);
W = zeros(n);
for i = 1:k
W = W + exwalk(Adj, i);
end
end
3. For the eccentricity calculation, you can use the Floyd Warshall algorithm to find the shortest path between all the nodes and get the max distance for each.
function ecc = eccentricities(A)
% Compute the shortest path lengths using the Floyd-Warshall algorithm
D = floydWarshall(A);
ecc = max(D, [], 2);
end
You will need to define the floydWarshall function on your own.
Hope this helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by