wolfram-mathematicamathematica-8

How can I programmatically access information about a 'Graph` object in Mathematica 8?


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 is the object I want to gain access to.

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

myGraph

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

myGraph

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.


Edit

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]

Solution

  • 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:

    new Graph in Mathematica 8.0