我正在尝试访问Graph
Mathematica 8 中的对象内的信息。由于某种原因,该Part
命令似乎不起作用。
myGraph
是我想要访问的对象。
下面的第一行显示 myGraph。其他人负责检查它。
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]]
返回图形本身的图片。
我必须忽略一些明显的东西。
编辑
这是我用来生成图表的代码。其中大部分与手头的问题无关。但至少您将使用我正在使用的相同代码。
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]