主要内容

isisomorphic

Determine whether two graphs are isomorphic

Description

example

tf = iSisomorphic(G1,G2)returns logical1(真的) if a图同构exists between graphsG1G2; otherwise, it returns logical0(false).

example

tf = iSisomorphic(G1,G2,Name,Value)用一个或多个名称值对参数指定其他选项。例如,您可以指定“节点”和a list of node variables to indicate that the isomorphism must preserve these variables to be valid.

Examples

collapse all

创建和绘制两个有向图,然后确定它们是否是同构。

G1 = digraph([1 1 1 2 3 4],[2 3 4 4 4 1]); G2 = digraph([3 3 3 2 1 4],[1 4 2 3 2 2]); subplot(1,2,1) plot(G1) subplot(1,2,2) plot(G2)

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

isisomorphic(G1,G2)
ans =logical1

Create and plot two graphs,G1G2

G1 = graph([1 1 1 2 2 3 3 4 5 5 7 7],[2 4 5 3 6 4 7 8 6 8 6 8]); plot(G1,'XData',[1 4 4 1 2 3 3 2],'YData',[4 4 1 1 3 3 2 2])

Figure contains an axes object. The axes object contains an object of type graphplot.

G2 = graph({'a''a''a''b''b''b''c''c''c''d''d''d'},。。。{'g''h''i''g''h''j''g''i''j''h''i''j'});情节(g2,'XData',[1 2 2 2 2 1 2 1],,'YData',[4 4 3 2 3 1 2 1])

Figure contains an axes object. The axes object contains an object of type graphplot.

Determine whether an isomorphism exists forG1G2。结果表明,尽管标签和布局不同,但图形在结构上是相同的。

tf = iSisomorphic(G1,G2)
tf =logical1

采用two different comparisons to determine if there is an isomorphism relation between two graphs. One of the comparisons preserves a node property, while the other ignores it.

创建两个类似的图。添加节点属性Colorto each of the graphs.

G1 = graph({'d''e''f'},{'e''f''d'});G1.Nodes.Color = {'red''red''blue'}'; G2 = graph({'a''b''c'},{'b''c''a'});G2.Nodes.Color = {'blue''blue''red'}';

在同一图中并排绘制图形。为有红色的节点染色颜色='红色'

subplot(1,2,1) p1 = plot(G1); highlight(p1,{'d''e'},'NodeColor','r') subplot(1,2,2) p2 = plot(G2); highlight(p2,'c','NodeColor','r')

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

Determine if the graphs are isomorphic, ignoring theColorproperty.

tf = iSisomorphic(G1,G2)
tf =logical1

Determine if the graphs are isomorphic and preserve the value of theColorproperty in the comparison. In this case, there is no isomorphism since theColorproperty of each graph contains different numbers of'red''blue'values.

tf = iSisomorphic(G1,G2,“节点”,'颜色')
tf =logical0

Input Arguments

collapse all

输入图,指定为单独的参数graph或者digraph对象。采用graphto create an undirected graph ordigraphto create a directed graph.

G1G2必须两者兼而有之graph对象或两者兼而有之digraph对象。

Example:G1 = graph(1,2)

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

Name-Value Arguments

将可选的参数对Name1=Value1,...,NameN=ValueN, whereNameis the argument name and价值是相应的值。名称值参数必须在其他参数之后出现,但是对的顺序并不重要。

Before R2021a, use commas to separate each name and value, and encloseNamein quotes.

Example:tf = iSisomorphic(G1,G2,'NodeVariables',{'Var1' 'Var2'})

Edge variables to preserve, specified as the comma-separated pair consisting of'EdgeVariables'以及字符向量,字符串标量,字符矢量的单元格数或字符串数​​组。使用此选项来指定两者中的一个或多个边缘变量G1.Edgesg2.edges。同构比较必须保留指定的边缘变量才能有效。对于在相同两个节点之间具有多个边缘的多编码,相同节点对的边缘变量排序是无关的。

Data Types:char|string|cell

节点变量要保留,指定为逗号分隔对“节点”以及字符向量,字符串标量,字符矢量的单元格数或字符串数​​组。使用此选项来指定两者中的一个或多个节点变量G1.NodesG2.Nodes。The isomorphism comparison must preserve the specified node variables in order to be valid.

Data Types:char|string|cell

More About

collapse all

图同构

Two graphs,G1G2,如果存在节点的排列,则是同构Psuch that重新订购(G2,P)has the same structure asG1

Two graphs that are isomorphic have similar structure. For example, if a graph contains one cycle, then all graphs isomorphic to that graph also contain one cycle.

Version History

Introduced in R2016b