同构
计算两个图之间的同构
描述
computes agraph isomorphism图之间的等价关系p
= isomorphism(G1,G2
)G1
和G2
,如果存在。如果不存在同构,那么p
is an empty array.
例子
Compute Isomorphism Permutation
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)
P =同构(G1,G2)
p =4×13 1 4 2
结果表明重新订购(G2,P)
具有与G1
。
计算具有不同标签和布局的图表之间的同构
Create and plot two graphs,G1
和G2
。
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
Compute Isomorphism and Preserve Node Properties
计算两个图之间的两个不同的同构关系。其中一个关系保留了节点属性,而另一个关系忽略了它。
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')
计算图之间的同构,忽略颜色
财产。
P =同构(G1,G2)
p =3×11 2 3
再次计算同构,但是这次保留了颜色
比较中的属性。同构
返回不同的排列,以保留颜色
财产。
P =同构(G1,G2,'NodeVariables',,,,'颜色')
p =3×13 1 2
查看节点G1
和G2
that the isomorphism matches together.
[G1.Nodes.Name, G2.Nodes.Name(p)]
ans =3x2单元{'d'} {'c'} {'e'} {'a'} {'f'} {'b'}
输入参数
名称值参数
将可选的参数对name1 = value1,...,namen = valuen
, 在哪里姓名
是参数名称和价值
是相应的值。名称值参数必须在其他参数之后出现,但是对的顺序并不重要。
在R2021a之前,请使用逗号分隔每个名称和值,并附上姓名
用引号。
例子:p =同构(g1,g2,'nodevariables',{'var1''var2'})
edgevariables
-边缘变量要保存
角色向量|字符串标量|字符向量的单元格数|字符串数组
边缘变量要保留,指定为逗号分隔对“ 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.Edges
和G2.Edges
。The isomorphism must preserve the specified edge variables in order to be valid.
如果G
is a multigraph, then you can specify the second outputedgeperms
启用重新排序的边缘变量。
数据类型:char
|细绳
|细胞
NodeVariables
-Node variables to preserve
角色向量|字符串标量|字符向量的单元格数|字符串数组
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.nodes
和g2.nodes
。同构必须保留指定的节点变量才能有效。
数据类型:char
|细绳
|细胞
输出参数
p
— Permutation vector for isomorphism
列向量|[]
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
。
edgeperm
— Edge permutation
column vector
边置换,返回为列向量。在使用多编码时,Edge置换矢量使您能够保留由“ edgevariables”
名称对。使用这些命令重新排序重复边的边缘变量:
[p,edgeperm] =同构(g1,g2,'edgevariables',edgevars);g2perm = reordernodes(g2,p);g2perm.edges(:,2:end)= g2perm.edges(Edgeperm,2:end);
更多关于
Graph Isomorphism
两个图,G1
和G2
, are isomorphic if there exists a permutation of the nodesp
这样重新订购(G2,P)
具有与G1
。
同构的两个图具有相似的结构。例如,如果图包含一个循环,则所有图与该图的同构也包含一个循环。
版本历史记录
matlab命令
您单击了与此MATLAB命令相对应的链接:
通过在MATLAB命令窗口中输入该命令。Web浏览器不支持MATLAB命令。金宝app
您还可以从以下列表中选择一个网站:
如何获得最佳网站性能
选择中国网站(中文或英语)以获得最佳场地性能。其他Mathworks乡村网站未针对您所在的访问进行优化。
美洲
- AméricaLatina(Español)
- 加拿大(英语)
- 美国(英语)