Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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`"]]

warns:

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"] &@
 Combinatorica`ToAdjacencyMatrix@
  Combinatorica`RemoveSelfLoops@
   Combinatorica`TransitiveClosure@
    Combinatorica`FromAdjacencyMatrix@
     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)

share|improve this question
    
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. –  rm -rf Jul 14 '12 at 21:42
    
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) –  alancalvitti Jul 14 '12 at 21:53
add comment

1 Answer

up vote 3 down vote accepted

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]&
     @AdjacencyMatrix@g1;
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

share|improve this answer
    
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? –  alancalvitti Jul 15 '12 at 1:27
    
The option value should be a string: that is, FromAdjacencyMatrix[#,Type->"Directed"][{{0, 1, 1}, {0, 0, 1}, {0, 0, 0}}] works. –  kguler Jul 15 '12 at 1:53
    
I had tried "Directed" -it still yields an undirected graph. ?? –  alancalvitti Jul 15 '12 at 2:05
    
@alancalvitti to preserve direction you could use ToCombinatoricaGraph in the GraphUtilities` package instead of Combinatorica`FromAdjacencyMatrix@Normal@Combinatorica`AdjacencyMatrix –  Heike Jul 15 '12 at 7:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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