According to WRI tech support:

Combinatorica functionality is not technically deprecated, though it is our hope that future versions of Mathematica will subsume it entirely by incorporating its functionality with the built-in Graphs & Networks functionality.

Leaving aside that this seems to conflict with MMA's documentation, eg:

Block[{$ContextPath}, Needs["Combinatorica`"]]


General::compat: Combinatorica Graph and Permutations functionality has been superseded by preloaded functionality. The package now being loaded may conflict with this. Please see the Compatibility Guide for details.

In the meantime, in order to use Combinatorica functionality like TransitiveClosure on built in Graphs, it's necessary to take a detour through Combinatorica, eg:

AdjacencyGraph[#, VertexLabels -> "Name"] &@
     Normal@AdjacencyMatrix@Graph[{"E0" -> "T0", "T0" -> "E1"}]

This yields (sorry for truncation):

enter image description here

How to recover the built in Graph's vertex names? (These are extracted from XML metadata and so it's not so convenient to project them to positional indices)

  • $\begingroup$ hmm... unless explicitly provided, PropertyValue does not return the VertexLabels or any of VertexList, EdgeList, etc. Since Graph is atomic, one can't do structural manipulations either... Do you have control over how the first Graph is created (the one with E0, T0)? I think it might be possible to project them to positional indices easily, if that's a route you'd consider. $\endgroup$
    – rm -rf
    Jul 14, 2012 at 21:42
  • $\begingroup$ It's ok to map vertex names to numbers - that's what's happening in Combinatorica's representation anyway - as long as the process is invertible. Subsequent pattern matching is done on the vertex names (which are part of Rules that map to other XML attributes etc) $\endgroup$ Jul 14, 2012 at 21:53

1 Answer 1


You can use the VertexList of the input graph as the first argument in AdjacencyGraph:

g1 = Graph[{"E0"->"T0","E0"->"E1","T0"->"E1"}, VertexLabels->"Name",ImagePadding->10];
g2 = AdjacencyGraph[#, VertexLabels -> "Name", ImagePadding -> 10] &@ AdjacencyMatrix@g1;
g3 = AdjacencyGraph[VertexList[g1], #, VertexLabels -> "Name",ImagePadding -> 10]&
Grid[{{"g1", "g2", "g3"}, {g1, g2, g3}}, Dividers -> All]

enter image description here

EDIT: Alternative methods using SetProperty and PropertyValue:

 g4 = g2; 
 PropertyValue[g4, VertexLabels] =Thread[VertexList[g4] -> VertexList[g1]];
 g5 = SetProperty[g2, VertexLabels -> Thread[VertexList[g2] -> VertexList[g1]]];
 Grid[{{"g1", "g2", "g3", "g4", "g5"}, {g1, g2, g3, g4, g5}},Dividers -> All]

enter image description here

  • $\begingroup$ This works, but I just noticed that I was sloppy w/ the specification - somehow Normal@Adjacency matrix preserves direction but Combinatorica`FromAdjacencyMatrix[#,Type->Directed] doesn't seem to work. Any ideas? $\endgroup$ Jul 15, 2012 at 1:27
  • 1
    $\begingroup$ The option value should be a string: that is, FromAdjacencyMatrix[#,Type->"Directed"][{{0, 1, 1}, {0, 0, 1}, {0, 0, 0}}] works. $\endgroup$
    – kglr
    Jul 15, 2012 at 1:53
  • $\begingroup$ I had tried "Directed" -it still yields an undirected graph. ?? $\endgroup$ Jul 15, 2012 at 2:05
  • $\begingroup$ @alancalvitti to preserve direction you could use ToCombinatoricaGraph in the GraphUtilities` package instead of Combinatorica`FromAdjacencyMatrix@Normal@Combinatorica`AdjacencyMatrix $\endgroup$
    – Heike
    Jul 15, 2012 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.