Main Content

conncomp

Connected graph components

Description

例子

垃圾箱= Conncomp(G返回连接的组件of graphG作为垃圾箱。bin编号表示图中每个节点属于哪个组件。

  • IfG是一个无方向的图,然后如果有一个连接它们的路径,则两个节点属于同一组件。

  • IfG一世s a directed graph, then two nodes belong to the same strong component only if there is a path connecting them in both directions.

例子

垃圾箱= Conncomp(G,,,,姓名,,,,Valueuses additional options specified by one or more Name-Value pair arguments. For example,conncomp(G,'OutputForm','cell')返回单元格数组来描述连接的组件。

[[垃圾箱,,,,binsizes] = conncomp(___also returns the size of the connected components.布局(i)gives the number of nodes in component一世

Examples

collapse all

创建并绘制具有三个连接组件的无向图。采用conncompto determine which component each node belongs to.

g =图([1 1 4],[2 3 5],[1 1 1],6);图(g)

图包含一个轴对象。轴对象包含类型图形图的对象。

bin = Conncomp(G)
bin =1×61 1 1 2 2 3

创建并绘制有向图,然后计算强连接的组件和弱连接的组件。弱连接的组件忽略了连接边缘的方向。

s = [1 2 2 3 3 3 4 5 5 5 8 8];t = [2 3 4 1 4 5 5 3 6 7 9 10];g = digraph(s,t);情节(g,'布局',,,,'layered'

图包含一个轴对象。轴对象包含类型图形图的对象。

str_bins = Conncomp(G)
str_bins =1×104 4 4 4 4 6 5 1 3 2
feek_bins = conncomp(g,'Type',,,,'虚弱的'
feek_bins =1×101 1 1 1 1 1 1 1 2 2 2

采用the second output ofconncompto extract the largest component of a graph or to remove components below a certain size.

Create and plot a directed graph. The graph has one large component, one small component, and several components that contain only a single node.

s = [1 2 2 3 3 3 4 5 5 5 8 8 9];t = [2 3 4 1 4 5 5 3 6 7 9 10 10];g = digraph(s,t,[],20);情节(g,'布局',,,,'layered'

图包含一个轴对象。轴对象包含类型图形图的对象。

计算弱连接的组件,并将两个输出指定为conncomp获取每个组件的大小。

[bin,binsize] = conncomp(g,'Type',,,,'虚弱的'
bin =1×201 1 1 1 1 1 1 1 2 2 23 4 5 6 7 8 9 10 11 12
binsize=1×127 3 1 1 1 1 1 1 1 1 1 1 1

采用binsize从图中提取最大的组件。IDX一世s a logical index indicating whether each node belongs to the largest component. Thesubgraphfunction extracts the nodes selected byIDXfromG

idx = binsize(bin)== max(binsize);SG =子图(G,IDX);情节(SG)

图包含一个轴对象。轴对象包含类型图形图的对象。

类似的用途binsizes是根据大小过滤组件。该过程类似于提取最大的组件,但是在这种情况下,每个节点都可以属于满足大小需求的任何组件。

滤除任何组件G少于3个节点。IDX是一个逻辑索引,指示每个节点是否属于具有3个或更多节点的组件。

IDX= binsize(bin) >= 3; SG = subgraph(G, idx); plot(SG)

图包含一个轴对象。轴对象包含类型图形图的对象。

Input Arguments

collapse all

输入图,指定为图形ordigraph目的。采用图形to create an undirected graph ordigraphto create a directed graph.

Example:G= graph(1,2)

Example:g = digraph([1 2],[2 3])

名称值参数

Specify optional pairs of arguments asname1 = value1,...,namen = valuen,,,,where姓名是参数名称和Value一世s the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

在R2021a之前,请使用逗号分隔每个名称和值,并附上姓名用引号。

Example:bin = conncomp(g,'outputform','cell')

输出类型,,,,specified as the comma-separated pair consisting of“输出形式”and either'向量'or'cell'

Option 输出
'向量'(default) 垃圾箱一世s a numeric vector indicating which connected component each node belongs to.
'cell' 垃圾箱是一个单元格数组,垃圾箱{J}包含属于组件的所有节点的节点IDj

笔记

'Type'option is supported only for directed graphs created usingdigraph

连接组件的类型,指定为逗号分隔对'Type'and either'strong'(默认)或'虚弱的'

Option Result
'strong'(default) 两个节点属于相同的连接组件bothdirections.
'虚弱的' 如果有一个路径连接它们,忽略边缘方向,则两个节点属于相同的连接组件。

Example:bin =conncomp(G,'Type','weak')computes the weakly connected components of directed graphG

输出参数

collapse all

连接的组件,返回为矢量或单元格数组。垃圾箱编号将图中的每个节点分配给连接的组件:

  • If输出Form一世s'向量'(default), then垃圾箱是一个数字向量,指示每个节点属于哪个连接的组件(bin)。

  • If输出Form一世s'cell', 然后垃圾箱是一个单元格阵列,带有垃圾箱{J}containing the node IDs for all nodes that belong to componentj

Size of each connected component, returned as a vector.布局(i)gives the number of elements in component一世。长度binsizes一世s equal to the number of connected components,max(bins)

更多关于

collapse all

Weakly Connected Components

如果有一个连接它们的路径(忽略边缘方向),则两个节点属于相同的弱连接组件。两个弱连接的组件之间没有边缘。

这concepts of strong and weak components apply only to directed graphs, as they are equivalent for undirected graphs.

紧密连接的组件

如果有两个方向连接的路径,则两个节点属于相同的强连接组件。两个强烈连接的组件之间可以存在边缘,但是这些连接边缘绝不是周期的一部分。

固定连接组件的bin数字使得连接两个组件的任何边缘从较小的bin编号的组件连接到具有较大bin号的组件的组件。

这concepts of strong and weak components apply only to directed graphs, as they are equivalent for undirected graphs.

扩展功能

版本历史记录

Introduced in R2015b

也可以看看

||