Finding the indices of all edges within k steps from a chosen line in an adjacency matrix
2 次查看(过去 30 天)
显示 更早的评论
I have a function where I can find all nodes k number of steps from any initial set of nodes in a sparse adjacency matrix. Normally this intial set is the to-from node for a single branch. I want a list of the branches "used" to reach these nodes.
The function I use to find the connected nodes is as follows:
% nb = number of buses in the system
% branch_list = [from to] = the from/to nodes of each branch
adj_mat = sparse(from,to,1,nb,nb);
node_vec0 = sparse([from0 to0],1,1,nb,1); % from0 and to0 are the "initial nodes"
A = adj_mat + speye(nb); % Add 1's on the diagonal of the adjacency matrix
node_vec = A * node_vec0; % Vector containing all nodes connected to node_vec0
I can repeat the last line k times, and find all nodes k steps from the initial nodes.
What I want to do, is to find the row (in the branch list) of each branch used to reach these nodes.
Is there a good way of doing this without extensive use of loops? Note that I want to get a list of both the nodes, and the branches, as efficient as possible.
Thank you!
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!