我正在尝试在Mathematica 8中访问Graph
对象内的信息。由于某种原因,Part
命令似乎无法正常工作。
myGraph
是我想要访问的对象。
下面的第一行显示了我的Graph对象。其他行用于检查它。
myGraph
myGraph // FullForm
myGraph // InputForm
myGraph // OutputForm
myGraph[[1]]
myGraph[[2]]
为什么myGraph[[1]]
不能返回List[1,3,4,2,5]
?
(我检查了两层级别,以防万一Graph
被某些隐藏的包装器包裹。 Level [myGraph,1]
只返回{}
。 而FullForm [myGraph] [[1]]
返回图形本身的图片。
我一定是忽略了一些显而易见的东西。
编辑
这是我用来产生图形的代码。 其中大部分与手头的问题无关。 但至少您将使用我正在使用的相同代码。
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]