本文介绍了如何在Mathematica 8中以编程方式访问有关“图形"对象的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问Mathematica 8中Graph对象中的信息.由于某些原因,Part命令似乎不起作用.

I'm trying to access information within a Graph object in Mathematica 8. For some reason, the Part command does not seem to work.

myGraph是我要访问的对象.

下面的第一行显示myGraph.其他人则负责检查.

The first line below displays myGraph. The others serve to inspect it.

myGraph

myGraph // FullForm  
myGraph // InputForm  
myGraph // OutputForm    
myGraph[[1]]
myGraph[[2]]  

为什么myGraph[[1]]不返回List[1,3,4,2,5]?[我检查了第2级,以防Graph被某些不可见的包装器包裹. Level[myGraph,1],只需返回{}.然后FullForm[myGraph][[1]]返回图形本身的图片.

Why doesn't myGraph[[1]] return List[1,3,4,2,5] ?[I checked to level 2 just in case Graph were wrapped by some invisible wrapper. Level[myGraph,1], simply returns {}. And FullForm[myGraph][[1]] returns a picture of the graph itself.

我必须忽略一些明显的东西.

I must be overlooking something obvious.

编辑

这是我用来生成图形的代码.大多数问题与眼前的问题无关.但是至少您将使用与我正在使用的相同的代码.

Here's the code I used to produce the graph. Most of it is irrelevant to the issue at hand. But at least you'll be working with the same code I am using.

ClearAll[edges, compatibleQ, adjacentCourses, g];
edges[w_, b_] := 
 Most /@ Accumulate /@ 
   Flatten[Permutations[#] & /@ IntegerPartitions[w, All, b], 1]

compatibleQ[j_, k_, edg_] := 
 If[Intersection[edg[[j]], edg[[k]]] == {}, {j, k}, False]

adjacentCourses[edg_] := 
 Module[{len = Length[edg]},
  Cases[Flatten[Table[compatibleQ[j, k, edg], {j, len}, {k, j, len}], 
    1], {v_, w_} :>  v \[UndirectedEdge] w]]

myGraph =  Graph[adjacentCourses[edges[9, {2, 3}]], VertexLabels -> "Name", 
ImagePadding -> 10]

推荐答案

尽管外观如此,但在Mathematica 8中引入的图形对象并不是正常"符号表达式.以下SO问题详细讨论了此问题以及其他此类问题,包括提取图定义部分的方法:

Despite appearances, the graph objects introduced in Mathematica 8 are not "normal" symbolic expressions. The following SO question discusses this and other such problems in detail, including ways to extract parts of the graph definition:

Mathematica 8.0中的新图形

这篇关于如何在Mathematica 8中以编程方式访问有关“图形"对象的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 01:59