Mathematica 8 中的多重图
我刚刚花了几个小时尝试转换使用 Mathematica 7 的 GraphPlot一些旧代码 /code> 使用新的 Mathematica 8 图形函数。这似乎是明智的,因为新的图形绘制更好,并且它具有诸如 AdjacencyMatrix
和 KirchhoffMatrix 内置。
问题是我无法弄清楚如何让具有多个边的图在 Mma 8 中工作。
我用作规范的费曼图示例是双环真空图
GraphPlot[{1 -> 2, 1 -> 2, 1 -> 2}, MultiedgeStyle -> .5,
DirectedEdges -> True, VertexCoordinateRules -> {{-1, 0}, {1, 0}}]
尝试在 Mma 8 中制作类似的图
Graph[{DirectedEdge[1, 2], DirectedEdge[1, 2], DirectedEdge[1, 2]},
VertexCoordinates -> {{-1, 0}, {1, 0}}]
会产生错误message
Graph::supp: Mixed graphs and multigraphs are not supported. >>
如何使用 Mathematica 8 的 Graph[] 对象构建(并使用)类似的图形?
编辑:这个问题在 Mathematica 9 中仍然存在
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我经历了类似的过程,尝试使用 Graph 来处理所有事情,发现它并不能取代 Combinatorica 和 GraphPlot。
Graph
的最佳用途是将其用作存储顶点+边+坐标的容器类型。例如,
Combinatorica
教程的“算法图论”中的大多数函数不适用于新的Graph
对象。当我与 WRI 开发人员讨论Graph
项目时,我的理解是为Graph
提供所有Combinatorica
功能并不是优先考虑的事情,因为设计目标是提供以与算法无关的方式解决任务的方法。例如,您可能有方法为新的Graph
对象查找顶点覆盖和图形着色,但对于 Brelaz 着色和贪婪顶点覆盖等算法特定任务,您可能始终必须遵循 Combinatorica 。除了多图之外,某些图形布局不适用于 Graph 对象。您无法修复某些顶点坐标并让自动布局完成其余的工作。此外,
LayeredGraphPlot
的布局不可用,有时优于Graph
的LayeredDrawing
。充分利用这三个世界的方法是使用 Graph 对象作为图形存储的主要工具,并为 GraphPlot、Combinatorica 和
Combinatorica 制作包装器。接受
函数Graph
对象的 code>GraphUtilities一些用例:
您需要
Combinatorica
或GraphUtilities
中的一些算法 --制作一个包装器someAlgorithm
,它接受Graph
对象,将其转换为边列表或Combinatorica
图(GraphUtilities'ToCombinatoricaGraph
很有帮助),运行算法,将其转换回 Graph 对象,注意从原始图形对象中设置正确的 GraphStyle 和 VertexCoordinates 。由于存在冲突,请确保Combinatorica
和GraphUtilities
不在上下文路径上,我 使用 $Pre 进行操作您需要一些自定义图表,例如 这里,或者多边图——制作一个包装函数
someGraphPlot
接受 Graph 对象,将其转换为正确的表示,然后使用 GraphPlot 或创建一个带有自定义顶点的临时 Graph 对象/用于这一图的边缘形状。请注意,您可以使用SetProperty
将属性附加到边缘,这样您就可以以这种方式将多重图存储在Graph
中。您想要使用
GraphPlot
布局之一并将坐标存储在Graph
中 - 使用类似 此处从GraphPlot
布局中获取顶点坐标,并将其存储在Graph<中使用
VertexCoordinates
的 /code> 对象
,这是一个 笔记本 演示这些用例和其他一些用例
I went through a similar process of trying to use
Graph
for everything, and found that it it does not replaceCombinatorica
andGraphPlot
. The best use forGraph
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 newGraph
objects. When I talked with a WRI developer onGraph
project, my understanding was providing all ofCombinatorica
functions forGraph
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 newGraph
object, but for algorithmic specific tasks like Brelaz coloring and Greedy Vertex Cover, you may always have to defer toCombinatorica
.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 ofLayeredGraphPlot
is not available and is sometimes preferred overGraph
'sLayeredDrawing
.The way to get the best of 3 worlds is to use
Graph
objects as main vehicle for graph storage and make wrappers forGraphPlot
,Combinatorica
andGraphUtilities
functions that acceptGraph
objectsSome 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
GraphPlot 函数在 mma 8 中仍然有效。Combinatorica
的函数也不支持多重图。在邻接矩阵中实现起来也相当困难。也许使用
EdgeWeight
可以在计算中发挥作用?对于绘制多个链接,我可以想象“EdgeShapeFunction”可能会帮助您。
或对于选定的边缘:
可以轻松地对函数 ef 进行参数化以获取要绘制的边数。
The GraphPlot function still works in mma 8.
Multigraphs weren't supported in Combinatorica's functions either. Pretty difficult to implement in an adjecency matrix too. Perhaps working with
EdgeWeight
may work in calculations?For drawing multiple links I can imagine that 'EdgeShapeFunction' may help you.
or for selected edges :
The function ef can be easily parametrized for the number of edges to draw.
我猜这些尚未得到支持:
尽管这可能不是您希望得到的答案。
These are not yet supported, I guess:
although this might not be the answer you hope to get.