主要内容

同构

计算两个图之间的同构

描述

例子

p= isomorphism(G1,G2computes agraph isomorphism图之间的等价关系G1G2,如果存在。如果不存在同构,那么pis an empty array.

例子

p= isomorphism(___,,,,名称,价值specifies additional options with one or more name-value pair arguments.例如,您可以指定'NodeVariables'and a list of node variables to indicate that the isomorphism must preserve these variables to be valid.

[[p,,,,edgeperm] =同构(___此外,还返回边缘排列的向量,edgeperm。此输出使您可以在使用多编码时保留边缘变量。

例子

全部收缩

Create and plot two directed graphs, and then calculate the isomorphism relation between them.

G1 = Digraph([1 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]);子图(1,2,1)图(G1)子图(1,2,2)图(G2)

图包含2个轴对象。Axes object 1 contains an object of type graphplot.Axes object 2 contains an object of type graphplot.

P =同构(G1,G2)
p =4×13 1 4 2

结果表明重新订购(G2,P)具有与G1

Create and plot two graphs,G1G2

G1 =图([1 1 1 2 2 3 3 4 5 5 7 7],[2 4 5 3 6 4 7 8 6 8 6 8]);情节(g1,'xdata',[1 4 4 1 2 3 3 2],'ydata',[4 4 1 1 1 3 3 2 2])

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

g2 = graph({'一种''一种''一种''b''b''b''C''C''C''D''D''D'},,...{'G''H''一世''G''H''j''G''一世''j''H''一世''j'});plot(G2,'xdata',[1 2 2 2 1 2 1 1],'ydata',[4 4 3 2 3 1 2 1])

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

如果存在,则计算图之间的同构关系。结果表明,尽管具有不同的标签和布局,但可以将图形节点置于同一图。

P =同构(G1,G2)
p =8×11 2 5 3 4 7 6 8

计算两个图之间的两个不同的同构关系。其中一个关系保留了节点属性,而另一个关系忽略了它。

Create two similar graphs. Add a node property颜色到每个图。

g1 = graph({'D''e''F'},{'e''F''D'});g1.nodes.color = {'蓝色的''红色的''红色的'}';g2 = graph({'一种''b''C'},{'b''C''一种'});g2.nodes.color = {'红色的''红色的''蓝色的'}';

Plot the graphs side-by-side in the same figure. Color the nodes red that haveColor = 'red'

子图(1,2,1)p1 =图(G1);突出显示(p1,{'e''F'},,'nodeColor',,,,'r') subplot(1,2,2) p2 = plot(G2); highlight(p2,{'一种''b'},,'nodeColor',,,,'r'

图包含2个轴对象。Axes object 1 contains an object of type graphplot.Axes object 2 contains an object of type graphplot.

计算图之间的同构,忽略颜色财产。

P =同构(G1,G2)
p =3×11 2 3

再次计算同构,但是这次保留了颜色比较中的属性。同构返回不同的排列,以保留颜色财产。

P =同构(G1,G2,'NodeVariables',,,,'颜色'
p =3×13 1 2

查看节点G1G2that the isomorphism matches together.

[G1.Nodes.Name, G2.Nodes.Name(p)]
ans =3x2单元{'d'} {'c'} {'e'} {'a'} {'f'} {'b'}

输入参数

全部收缩

Input graphs, specified as separate arguments of图形或者Digraph对象。采用图形to create an undirected graph orDigraph创建有向图。

G1G2must be both图形objects or bothDigraph对象。

例子:G1 =图(1,2)

例子:g1 = digraph([1 2],[2 3])

名称值参数

将可选的参数对name1 = value1,...,namen = valuen, 在哪里姓名是参数名称和价值是相应的值。名称值参数必须在其他参数之后出现,但是对的顺序并不重要。

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

例子:p =同构(g1,g2,'nodevariables',{'var1''var2'})

边缘变量要保留,指定为逗号分隔对“ edgevariables”and a character vector, string scalar, cell array of character vectors, or string array. Use this option to specify one or more edge variables that are in bothG1.EdgesG2.Edges。The isomorphism must preserve the specified edge variables in order to be valid.

如果Gis a multigraph, then you can specify the second outputedgeperms启用重新排序的边缘变量。

数据类型:char|细绳|细胞

Node variables to preserve, specified as the comma-separated pair consisting of'NodeVariables'and a character vector, string scalar, cell array of character vectors, or string array. Use this option to specify one or more node variables that are in bothg1.nodesg2.nodes。同构必须保留指定的节点变量才能有效。

数据类型:char|细绳|细胞

输出参数

全部收缩

Permutation vector for isomorphism, returned as a column vector when an isomorphism exists or as the empty array[]when an isomorphism does not exist.如果p不是空的,然后重新订购(G2,P)具有与G1

边置换,返回为列向量。在使用多编码时,Edge置换矢量使您能够保留由“ edgevariables”名称对。使用这些命令重新排序重复边的边缘变量:

[p,edgeperm] =同构(g1,g2,'edgevariables',edgevars);g2perm = reordernodes(g2,p);g2perm.edges(:,2:end)= g2perm.edges(Edgeperm,2:end);

更多关于

全部收缩

Graph Isomorphism

两个图,G1G2, are isomorphic if there exists a permutation of the nodesp这样重新订购(G2,P)具有与G1

同构的两个图具有相似的结构。例如,如果图包含一个循环,则所有图与该图的同构也包含一个循环。

版本历史记录

在R2016b中引入