transreduction
Transitive reduction
Syntax
Description
returns thetransitive reductionof graphH
= transreduction(G
)G
as a new graph,H
. The nodes inH
are the same as those inG
, butH
有不同的边缘。H
contains the fewest number of edges such that if there is a path from nodei
to nodej
inG
, then there is also a path from nodei
to nodej
inH
.
Examples
Transitive Reduction of Complete Graph
Create and plot a complete graph of order four.
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 asH
.
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 ofG1
. The cycle inG1
is reordered so that the transitive reductionsH
andH1
have the same cycle, (1,2,3,4,1).
H1 = transreduction(G1); plot(H1)
Unique Transitive Reduction
Create and plot a directed acyclic graph.
s = [1 1 1 1 2 3 3 4]; t = [2 3 4 5 4 4 5 5]; G = digraph(s,t); plot(G)
Confirm thatG
does not contain any cycles.
tf = isdag (G)
tf =logical1
Find the transitive reduction of the graph. Since the graph does not contain cycles, the transitive reduction is unique and is a subgraph ofG
.
H = transreduction(G); plot(H)
Input Arguments
G
—Input graph
digraph
object
Input graph, specified as adigraph
object. Usedigraph
创建一个有向图object.
Example:G = digraph([1 2],[2 3])
Output Arguments
H
— Transitive reduction ofG
digraph
object
Transitive reduction ofG
,返回digraph
object. The tableG.Nodes
is copied toH
, but any properties inG.Edges
are dropped.H
might contain new edges not present inG
.
H
contains the fewest number of edges that still preserve the reachability of graphG
. In other words,transclosure(H)
is the same astransclosure(G)
.
Ifisdag(G)
istrue
, thenH
is unique and is a subgraph ofG
.
More About
Transitive Reduction
The transitive reduction of graphG
is the graph with the fewest edges that still shares the same reachability asG
. Therefore, of all the graphs that have the same transitive closure asG
, the transitive reduction is the one with the fewest edges. If two directed graphs have the same transitive closure, they also have the same transitive reduction.
Version History
See Also
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)