Mathematica中的多图形8 [英] Multigraphs in Mathematica 8
问题描述
我只花了几个小时试图转换超过图表
的 LayeredDrawing
。
获得3个世界最好的方法是使用 Graph
对象作为图形存储的主要工具,并为 GraphPlot
, Combinatorica
和 GraphUtilities
函数接受图
对象
例如: 您需要 您需要像这里,或多边形图形 - 制作一个包装函数 您想使用
GraphUtilities
- 创建一个包装 someAlgorithm
,它包含 Graph
对象,将其转换到边的列表或> Combinatorica
图( GraphUtilities'ToCombinatoricaGraph
有帮助),运行al gorithm,将它转换回 Graph
对象,注意设置正确的 GraphStyle
和 VertexCoordinates
来自原始图形对象。由于冲突,确保 Combinatorica
和 GraphUtilities
不在上下文路径中,I 执行使用$ Pre
someGraphPlot
,它接受图
对象,将其转换为正确的表示形式,然后使用 GraphPlot
或者可能会创建一个临时图形
对象顶点/边缘形状用于这个图的目的。请注意,您可以使用 SetProperty
附加属性到边缘,这样您就可以将多图形存储在 Graph
中。
GraphPlot
中的一个布局,并将坐标存储在 Graph
- 使用像这里从 GraphPlot
布局获取顶点坐标,并使用 VertexCoordinates 来将它们存储在
图形
code>
以下是笔记本展示这些使用案例和其他一些案例
I just spent a couple of hours trying to convert some old code that uses Mathematica 7's GraphPlot
to use the new Mathematica 8 Graph functions. It seemed sensible since the new graph drawing is much nicer and it has things like AdjacencyMatrix
and KirchhoffMatrix built in.
The problem is that I can not figure out how to get graphs with multiple edges to work in Mma 8.
The Feynman graph that I use as my canonical example is the two-loop vacuum graph
GraphPlot[{1 -> 2, 1 -> 2, 1 -> 2}, MultiedgeStyle -> .5,
DirectedEdges -> True, VertexCoordinateRules -> {{-1, 0}, {1, 0}}]
Trying to make the similar graph in Mma 8
Graph[{DirectedEdge[1, 2], DirectedEdge[1, 2], DirectedEdge[1, 2]},
VertexCoordinates -> {{-1, 0}, {1, 0}}]
yields the error message
Graph::supp: Mixed graphs and multigraphs are not supported. >>
How can I construct (and work with) a similar graph using Mathematica 8's Graph[]
objects?
Edit: This problem still exists in Mathematica 9
I went through a similar process of trying to use Graph
for everything, and found that it it does not replace Combinatorica
and GraphPlot
. The best use for Graph
is to use it as a container type to store vertices + edges + coordinates.
For example, most of the functions from "Algorithmic Graph Theory" of Combinatorica
tutorial are not available for new Graph
objects. When I talked with a WRI developer on Graph
project, my understanding was providing all of Combinatorica
functions for Graph
is not a priority because the design goal is to provide methods that solve tasks in algorithmic agnostic way. For instance, you may have method to find vertex cover and graph coloring for new Graph
object, but for algorithmic specific tasks like Brelaz coloring and Greedy Vertex Cover, you may always have to defer to Combinatorica
.
In addition to multi-graphs, some graph layouts are not available for Graph
objects. You can not fix some vertex coordinates and let automatic layout do the rest. Also, layout of LayeredGraphPlot
is not available and is sometimes preferred over Graph
's LayeredDrawing
.
The way to get the best of 3 worlds is to use Graph
objects as main vehicle for graph storage and make wrappers for GraphPlot
, Combinatorica
and GraphUtilities
functions that accept Graph
objects
Some use cases:
You need some algorithm from
Combinatorica
orGraphUtilities
-- make a wrappersomeAlgorithm
that takesGraph
object, converts it to list of edges orCombinatorica
graph (GraphUtilities'ToCombinatoricaGraph
is helpful), runs the algorithm, converts it back toGraph
object, taking care to set correctGraphStyle
andVertexCoordinates
from the original graph object. Because of conflicts, make sureCombinatorica
andGraphUtilities
are not on context path, I do it using $PreYou need some custom graph plot like here, or the multi-edge graph -- make a wrapper function
someGraphPlot
that acceptsGraph
object, converts it to correct representation, then usesGraphPlot
or perhaps creates a temporaryGraph
object with custom vertex/edge shapes for the purpose of this one plot. Note that you can attach properties to edges usingSetProperty
so you can store your multigraphs inGraph
that way.You want to use one of
GraphPlot
layouts and store coordinates inGraph
-- use function like here to get vertex coordinates fromGraphPlot
layout, and store them inGraph
object usingVertexCoordinates
Here's a notebook demonstrating these use cases and a few others
这篇关于Mathematica中的多图形8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!