📄 bacon_numbers.m
字号:
function bn = bacon_numbers(A,u)
% BACON_NUMBERS Compute the Bacon numbers for a graph.
%
% bn = bacon_numbers(A,u) computes the Bacon numbers for all nodes in the
% graph assuming that Kevin Bacon is node u.
% allocate storage for the bacon numbers
% the ipdouble call allocates storage that can be modified in place.
bn_inplace = ipdouble(zeros(num_vertices(A),1));
% implement a nested function that can refer to variables we declare. In
% this case, we refer to the bn_inplace variable.
function tree_edge(ei,u,v)
bn_inplace(v) = bn_inplace(u)+1;
end
% setup the bacon_recorder visitor
bacon_recorder = struct();
bacon_recorder.tree_edge = @tree_edge;
% call breadth_first_search
breadth_first_search(A,u,bacon_recorder);
% convert the inplace storage back to standard Matlab storage to return.
bn = double(bn_inplace);
% the end line is required with nested functions to terminate the file
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -