我正在尝试访问某个范围内的信息Graph
Mathematica 8 中的对象。出于某种原因,Part
命令似乎不起作用。
myGraph
是我想要访问的对象。
下面的第一行显示 myGraph。其他人的作用是检查它。
myGraph
myGraph // FullForm
myGraph // InputForm
myGraph // OutputForm
myGraph[[1]]
myGraph[[2]]
为什么不myGraph[[1]]
return List[1,3,4,2,5]
?
[为了以防万一,我检查到了 2 级Graph
被一些看不见的包装物包裹着。Level[myGraph,1]
,简单地返回{}
. And FullForm[myGraph][[1]]
返回图表本身的图片。
我一定是忽略了一些显而易见的事情。
Edit
这是我用来生成图表的代码。其中大部分与当前的问题无关。
但至少您将使用我正在使用的相同代码。
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]