ShowGraph [{{e1,e2},{e1,e3}},{e1,e2,e3}]; // 这里有什么问题? [英] ShowGraph[ { {e1,e2}, {e1, e3} }, {e1,e2,e3} ]; // what is the problem here?

查看:121
本文介绍了ShowGraph [{{e1,e2},{e1,e3}},{e1,e2,e3}]; // 这里有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mathematica Graph Theory软件包'Combinatorica'中没有显示指定的图形。

解决方案

好的,谢谢大家。让我收拾一下这些讨论。首先,Janus提到,在Mathematica中绘制图有两种方法。首先,Combinatorica的方式,作为一个附加。第二,GraphPlot的方式,这是一个本地的Mathematica实现绘制图形。 GraphPlot采用Spring布局绘制图形。正如dreeves所说,我们使用ShowGraph []以Combinatorica的方式绘制图形。

为了理解为什么上述代码不起作用,我们必须很好地理解ShowGraph []命令。 Mathematica 7定义,


ShowGraph [g]显示图形g。


现在,什么是图?


图[e,v,opts]表示图形对象,其中 e 是使用图形选项注释的边缘列表, v 是使用图形选项注释的顶点列表, opts 是一组全局图形选项


问题是Combinatorica似乎无法完全按照上面定义的方式工作。让我们来检查...假设你已经创建一个名为 g 的Combinatorica图,现在 g [[0]] 会打印 g [[1]] 会打印边缘列表, g [[2]] 会打印 opts 。顶点列表在哪里



正如您在上面看到的,您可以手动创建 g [[1]] g [[2]] 并将它提供给Graph,让我们创建它:

  e = {{1,2},{{1,3}}} 
opts = {{{0,0}},{{ 5,5}},{{5,5}}}
g =图表[e,opts]

这将创建一个顶点1,2和3的图形。现在,你怎么能标记它们?在Combinatorica中,您可以使用ShowGraph []的VertexLabel选项执行此操作。如果您使用VertexLabel-> True,它将仅显示默认标签,即此处的1,2和3。要使用自己的标签,请执行以下操作:

  ShowGraph [g,VertexLabel-> {a,b,c}] 

有趣的,对吗? :)。



现在回答我的问题的确切答案。所提到的代码的问题是由于使用文字值而不是整数。 Combinatorica仅将整数值视为边或顶点列表。



请记住,虽然这是可能的,但它仅用于创建小图。对于更大的图形,您应该使用默认图形生成器来创建图形。就像一个随机图表一样:

  g =随机[10,0.23] 

将创建一个包含10个顶点的图,边缘概率为0.23。



< waka,

这次是Combinatorica!

doesn't show specified graph in Mathematica Graph Theory package 'Combinatorica'.

解决方案

Ok, thanks all. Let me pack up all these discussions. First of all as Janus mentioned, there are two ways to draw graphs in Mathematica. Firstly, Combinatorica way, which comes as an add in. Secondly, GraphPlot way which is a native Mathematica implementation to draw graphs. GraphPlot employs Spring layout to draw graphs. As dreeves said we use ShowGraph[] to draw graphs in Combinatorica way.

To understand why the mentioned code doesn't work we have to understand ShowGraph[] command very well. Mathematica 7 defines,

ShowGraph[g] displays the graph g.

Now, what is graph?

Graph[e , v, opts] represents a graph object where e is the list of edges annotated with graphics options, v is a list of vertices annotated with graphics options, and opts is a set of global graph options"

The problem is Combinatorica doesn't seem to work exactly the above defined way. Let's examine... suppose you've created a Combinatorica graph named g. Now g[[0]] would print Graph, g[[1]] would print list of edges, g[[2]] would print opts. Where is list of vertices??

As you can see above, you can manually create g[[1]], and g[[2]] and feed it to Graph. Let's create it:

e = {{1,2}, {{1,3}}}
opts = {{{0,0}}, {{-5,5}}, {{5,5}}}
g = Graph[e, opts]

This will create a graph with vertices 1, 2 and 3. Now, how can you label them? In Combinatorica, you do this using VertexLabel option of ShowGraph[]. If you use VertexLabel->True it will only show default labels, that is 1, 2 and 3 here. To use your own labels do the following:

ShowGraph[g, VertexLabel->{a,b,c}]

Interesting, right? :).

Now to the exact answer of my question. The problem of the mentioned code is due to the use of literal values instead of integers. Combinatorica only excepts integer values as edge or vertex list.

Remember, although it is possible it is only useful to create small graphs. For larger graphs you should use default graph generators to create your graph. Like, for a random graph use:

g = Random[10, 0.23]

Will create a graph with 10 vertices, with edge probability of 0.23.

Waka, waka,
this time for Combinatorica!

这篇关于ShowGraph [{{e1,e2},{e1,e3}},{e1,e2,e3}]; // 这里有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆