Mathematica - Reflect/invert 单向图边

Mathematica - Reflect/invert unidirect graph edges

给定的是一张包含 mathematica-11 数据的图表。该图包括节点和独立节点(未连接)之间的无向边。

Graph[{1 <-> 2, 2<-> 3, 3<-> 1, 4<-> 5, 5<-> 6, 6<-> 2, 2<-> 4}, VertexLabels -> "Name", VertexShapeFunction -> "Diamond", VertexSize -> Small]

问题:

如何反映(反转)节点之间的边?

因为它们是单向的,所以 reflecting/inverting 我的意思是那些节点应该连接到之前没有边的地方(并且以前的边已经消失)。

Mathematica-11 提供了 ReverseGraph 函数,但是这个函数只按方向反映有向边。有任何想法吗?

想法:

将图形转换为 AdjacencyMatrix 并将其反转。然后,逆矩阵可用于创建 reflected/inverted 图。 但是,我坚持反转 AdjacencyMatrix,因为结果会很奇怪:

如此简单,在使用 Inverse (AdjacencyMatrix[data]) // MatrixForm

时,真值被替换为倒​​数项

相关:

This article 介绍了如何反映边缘权重,但不包括边缘本身。

我不确定我是否完全理解您的问题,所以如果这不是答案,请告诉我们原因:

opts = {VertexLabels -> "Name", VertexShapeFunction -> "Diamond", VertexSize -> Small}

g1 = Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1, 4 <-> 5, 5 <-> 6, 6 <-> 2, 2 <-> 4}];

那你可能会喜欢

GraphComplement[g1, opts]

或者,如果您想要从每个节点到自身的边

AdjacencyGraph[Table[1, {VertexCount[g1]}, {VertexCount[g1]}] - AdjacencyMatrix[g1], opts]