www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/TransitiveReductionOfCompleteGraphExample.m
%% Transitive Reduction of Complete Graph % Create and plot a complete graph of order four. % Copyright 2015 The MathWorks, Inc. G = digraph([1 1 1 2 2 2 3 3 3 4 4 4],[2 3 4 1 3 4 1 2 4 1 2 3]); plot(G) %% % Find the transitive reduction and plot the resulting graph. Since the % reachability in a complete graph is extensive, there are theoretically % several possible transitive reductions, as any cycle through the four % nodes is a candidate. H = transreduction(G); plot(H) %% % Two graphs with the same reachability also have the same transitive % reduction. Therefore, any cycle of four nodes produces the same % transitive reduction as |H|. % % Create a directed graph that contains a different four node cycle: % (1,3,4,2,1). G1 = digraph([1 3 4 2],[3 4 2 1]); plot(G1) %% % Find the transitive reduction of |G1|. The cycle in |G1| is reordered so % that the transitive reductions |H| and |H1| have the same cycle, % (1,2,3,4,1). H1 = transreduction(G1); plot(H1)