forked from dgleich/matlab-bgl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprim_mst.m
47 lines (42 loc) · 1.37 KB
/
prim_mst.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function [varargout] = prim_mst(A,varargin)
% PRIM_MST Compute a minimum spanning with Prims's algorithm.
%
% Prim's MST algorithm computes a minimum spanning tree for a graph.
%
% This method works on weighted symmetric graphs without negative edge
% weights.
% The runtime is O(E log (V)).
%
% In Boost 1.36.0 and prior versions, Prim's algorithm has a problem with
% incorrect output and diagonal entries.
%
% See MST for calling information. This function just calls
% mst(...,struct('algname','prim'));
% options.root: specify the root vertex for prim's algorithm
% [{'none'} | any vertex number]
% options.fix_diag: remove any diagonal entries to get correct output
% from Prim's algorithm [0 | {1}]; beware this option with the
% edge_weight option too.
%
% Example:
% load graphs/clr-24-1.mat
% prim_mst(A)
% T = prim_mst(A,struct('root',5));
%
% See also MST, KRUSKAL_MST.
% David Gleich
% Copyright, Stanford University, 2006-2008
%% History
% 2006-04-23: Initial version
% 2007-04-23: Fixed bug with output without parameters
% 2007-07-08: Fixed documentation typo
% 2008-10-07: Changed options parsing
%%
algname = 'prim';
if ~isempty(varargin),
options = merge_options(struct(),varargin{:});
options.algname= algname;
else options = struct('algname',algname);
end
varargout = cell(1,max(nargout,1));
[varargout{:}] = mst(A,options);