Reflect/invert unidirect graph edges
Given is a graph with data in mathematica-11. The graph includes undirected edges between nodes and standalone nodes (not connected).
Graph[{1 <-> 2, 2<-> 3, 3<-> 1, 4<-> 5, 5<-> 6, 6<-> 2, 2<-> 4}, VertexLabels -> "Name", VertexShapeFunction -> "Diamond", VertexSize -> Small]
Question:
How do I reflect (invert) the edges between the nodes?
Since they are unidirected, by reflecting/inverting I mean that those nodes are supposed to be linked where no edge was before (and the former edges are gone).
Mathematica-11 provides the ReverseGraph function, however this one does only reflect directed edges by their direction. Any ideas?
Idea:
Convert the graph into a AdjacencyMatrix and inverse it. Then, the inversed matrix could be used to create the reflected/inverted graph. However, I am stuck with inverting the AdjacencyMatrix since the result will behavior strange:
So simple the true values are replaced with the term inverse when using Inverse (AdjacencyMatrix[data]) // MatrixForm
Related:
This article covers how to reflect edge weights, but not the edges itself.
I'm not sure I completely understand your question so if this isn't the answer tell us why not:
opts = {VertexLabels -> "Name", VertexShapeFunction -> "Diamond", VertexSize -> Small}
g1 = Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1, 4 <-> 5, 5 <-> 6, 6 <-> 2, 2 <-> 4}];
Then you might like
GraphComplement[g1, opts]
or, if you want edges from each node to itself
AdjacencyGraph[Table[1, {VertexCount[g1]}, {VertexCount[g1]}] - AdjacencyMatrix[g1], opts]
链接地址: http://www.djcxy.com/p/20260.html
上一篇: 这个Jar文件有什么问题?
下一篇: 反射/反转单向图形边缘