Mathematica中的多图8

时间:2011-03-30 10:59:26

标签: graph wolfram-mathematica

我花了几个小时试图转换some old code使用Mathematica 7的GraphPlot来使用新的Mathematica 8 Graph函数。这似乎是明智的,因为新的图形绘制更好,内置了AdjacencyMatrixKirchhoffMatrix

问题是我无法弄清楚如何让多边的图形在Mma 8中工作。

我用作规范示例的Feynman图是双回路真空图

GraphPlot[{1 -> 2, 1 -> 2, 1 -> 2}, MultiedgeStyle -> .5, 
          DirectedEdges -> True, VertexCoordinateRules -> {{-1, 0}, {1, 0}}]

two-loop vacuum sunset graph

尝试在Mma 8中制作类似的图表

Graph[{DirectedEdge[1, 2], DirectedEdge[1, 2], DirectedEdge[1, 2]}, 
      VertexCoordinates -> {{-1, 0}, {1, 0}}]

产生错误消息

Graph::supp: Mixed graphs and multigraphs are not supported. >>

如何使用Mathematica 8的Graph[]对象构建(和使用)类似的图形?

编辑:Mathematica 9中仍存在此问题

3 个答案:

答案 0 :(得分:15)

我经历了类似的过程,尝试将Graph用于所有内容,并发现它不会取代CombinatoricaGraphPlotGraph的最佳用途是将其用作存储顶点+边+坐标的容器类型。

例如,Combinatorica教程的“算法图论”中的大多数函数不适用于新的Graph对象。当我在Graph项目上与WRI开发人员交谈时,我的理解是提供Combinatorica的所有Graph函数不是优先事项,因为设计目标是提供解算算法任务的方法不可知论的方式。例如,您可能有方法为新Graph对象找到顶点覆盖和图形着色,但对于像Brelaz着色和贪婪顶点覆盖这样的算法特定任务,您可能始终必须遵从Combinatorica。< / p>

除了多图形之外,某些图形布局不适用于Graph个对象。你不能修复一些顶点坐标,让自动布局完成剩下的工作。此外,LayeredGraphPlot的布局不可用,有时preferred超过Graph的{​​{1}}。

充分利用3个世界的方法是使用LayeredDrawing个对象作为图形存储的主要工具,并为GraphGraphPlotCombinatorica函数创建包装器接受GraphUtilities个对象

一些用例:

  • 您需要GraphCombinatorica中的某种算法 - 制作一个包含GraphUtilities对象的包装器someAlgorithm,将其转换为边缘列表或{{ 1}}图表(Graph很有用),运行算法,将其转换回Combinatorica对象,注意从原始图表对象设置正确的GraphUtilities'ToCombinatoricaGraphGraph 。由于存在冲突,请确保GraphStyleVertexCoordinates不在上下文路径中,do it使用$ Pre

  • 您需要一些自定义图表,如here或多边图 - 制作一个接受Combinatorica对象的包装函数GraphUtilities,将其转换为正确的表示形式,然后使用someGraphPlot或者创建一个具有自定义顶点/边缘形状的临时Graph对象,用于此一个图的目的。请注意,您可以使用GraphPlot将属性附加到边缘,以便以Graph的方式存储多图。

  • 您希望在SetProperty中使用Graph布局之一并存储坐标 - 使用here之类的函数来获取GraphPlot布局的顶点坐标,以及使用Graph

  • 将它们存储在GraphPlot对象中

这是展示这些用例和其他几个用户的notebook

答案 1 :(得分:9)

GraphPlot函数仍然可以在mma 8中运行。

Combinatorica的功能也不支持多图。在adjecency矩阵中也很难实现。也许使用EdgeWeight可能会在计算中起作用?

为了绘制多个链接,我可以想象'EdgeShapeFunction'可以帮助你。

ef[pts_List, e_] :=
 Block[{g1 = 
    Insert[pts, (pts[[1]] + pts[[-1]])/
      2 + ({x, y}/5 /. 
        Solve[{Norm[{x, y}] == 1, (pts[[1]] - pts[[-1]]).{x, y} == 
            0}, {x, y}][[1]]), Round[(Length[pts] + 1)/2]],
   g2 = Insert[
     pts, (pts[[1]] + pts[[-1]])/
      2 + (-{x, y}/5 /. 
        Solve[{Norm[{x, y}] == 1, (pts[[1]] - pts[[-1]]).{x, y} == 
            0}, {x, y}][[1]]), Round[(Length[pts] + 1)/2]]}, {Arrow[
    BSplineCurve[g1]], Arrow[BSplineCurve[g2]], Arrow[pts]}]

Graph[{1 \[DirectedEdge] 2, 2 \[DirectedEdge] 3, 3 \[DirectedEdge] 1},
  EdgeShapeFunction -> ef]

enter image description here

或选定的边缘:

Graph[{1 \[DirectedEdge] 2, 2 \[DirectedEdge] 3, 3 \[DirectedEdge] 1},
  EdgeShapeFunction -> {3 \[DirectedEdge] 1 -> ef}]

enter image description here

函数ef可以很容易地根据要绘制的边数进行参数化。

答案 2 :(得分:2)

我猜这些还不支持:

In[201]:= AdjacencyGraph[{{0, 3}, {0, 0}}]

During evaluation of In[201]:= Graph::supp: Mixed graphs and multigraphs are not supported. >>

Out[201]= AdjacencyGraph[{{0, 3}, {0, 0}}]

虽然这可能不是你希望得到的答案。