破圈法求最小支撑树matlab_破圈法求最小生成树 MATLAB

本文介绍了一种使用MATLAB实现破圈法寻找无向图最小支撑树的方法。通过输入权重矩阵W,代码首先获取边及其权重,然后按权重排序,并通过并查集操作找到未连接的最小权重边,最终构建最小支撑树。
摘要由CSDN通过智能技术生成

破圈法

% For undirected graph only, but can be changed easily to

directed graph.

% input: W - weight matrix. Since the graph is undirected, the

matrix is symmetric. So we just use the

% upper triangular sub matrix of W. In directed graph, use them

all.

% output: A - minimum span tree edge matrix, each row is a

vector including vertices of an edge and its

% weight in the minimum span tree.

fun.m

function A = fun(W)

[m, n] = size(W);

e = 0;

for i = 1 : n

for j = i

: n

if W(i, j) ~= 0

e = e + 1;

E(e, :) = [i, j, W(i, j)];

end

end

end

% sort W's edge by weight

for i = 1 : e - 1

for j = i

+ 1 : e

if E(i, 3) > E(j, 3)

temp = E(j, :);

E(j, :) =

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值