From: Thomas Dowling on
Hello,

I have not been able to reproduce your problem on a Mac (Non-Intel) running
Mathematica v 7.0.0. All the code you posted works fine, but there is no
edge-order reversal,
and the final graph is the same as the one you started out with. Perhaps I
am missing something?


Edges[g2] == Edges[g]

Out[53] = True

(Loading Graphics Utilities Package)

EdgeList[g2] == EdgeList[g]

Out[54]= True

VertexList[g2] == VertexList[g]

Out[56]= True

EdgeList[ToCombinatoricaGraph] == EdgeList[g]

Out[57]= True.

mgalt = Normal(a)AdjacencyMatrix[g]

mgalt == mg

Out[63] = True

Is this a particular problem with your system, or is it peculiar to
Mathematica 7.0.1?

Tom Dowling.



On Fri, Oct 23, 2009 at 3:33 AM, Andrew <dr.a.graham(a)googlemail.com> wrote:

> Hello group,
>
> This question seems to have been touched on in the past but I'm not
> sure if it has ever been definitively answered. I would be grateful
> for some advice!
>
> I have some data that I would like to explore. It concerns a set of
> directed graphs, without edge weights. The data comes to me as the
> corresponding asymmetric adjacency matrices.
>
> I can visualise the graphs directly using the native function
> GraphPlot.
> However, I would prefer to visualise them using ShowGraph from the
> Combinatorica package - but this requires that the adjacency matrix is
> converted to the Combinatorica graph format first.
>
> The trouble is that (for directed graphs at least),
> FromAdjacencyMatrix appears to be broken.
>
> Example:
> g = Cycle[3, Type -> Directed] (*construct a simple directed graph in
> Combinatorica graph format*)
>
> Edges[g] (*List of edges*)
>
> Vertices[g] (*List of vertices*)
>
> GraphOptions[g] (*Shows the graph options*)
>
> ShowGraph[g, VertexNumber -> True] /.
> x : Arrow[__] -> {Arrowheads[{{Automatic, 0.6}}], x} (*Visualises the
> graph with ShowGraph, using a workaround to place the arrowheads mid-
> edge, as suggested Apr 2 2008 by dh*)
> GraphPlot[g, VertexLabeling -> True, DirectedEdges -> True]
> (*Visualises the graph with GraphPlot - the same outcome*)
>
> mg = ToAdjacencyMatrix[g, Type -> Directed] (*Convert to adjacency
> matrix*)
>
> mg // TableForm (*Inspect - seems appropriate*)
>
> mg // MatrixForm (*Ditto*)
>
> GraphPlot[mg, VertexLabeling -> True, DirectedEdges -> True] (*Cannot
> plot directly with ShowGraph, but with GraphPlot the graph is still
> preserved at this stage*)
>
> g2 = FromAdjacencyMatrix[mg, Type -> Directed] (*Convert back to a
> graph*)
>
> Edges[g2] (*Oh dear. The direction of edge #3 has been reversed*)
>
> Vertices[g2] (*Vertices are preserved*)
>
> GraphOptions[g2] (*Graph options are preserved*)
>
> ShowGraph[g2, VertexNumber -> True] /.
> x : Arrow[__] -> {Arrowheads[{{Automatic, 0.6}}], x}
> GraphPlot[g2, VertexLabeling -> True, DirectedEdges -> True] (*And
> visualising the graph with both ShowGraph & GraphPlot it is no longer
> the same as the graph we started out with*)
>
> The problem seems to be with FromAdjacencyMatrix
> FromAdjacencyLists shows the same problem
>
> Is there something wrong with the code above, or are these functions
> truly broken? If they are broken, can anyone help with writing a
> function that will correctly turn a directed adjacency matrix into
> Combinatorica lists of edges & vertices?
>
> Finally, if these functions are broken, can they be fixed? I have
> otherwise found Combinatorica very easy to work with & would prefer to
> stick with it rather than native functions if possible. The
> Combinatorica book has recently been republished in paperback & I have
> found it very helpful.
>
> Many thanks
>
> Andrew Graham
> Dept of Neurology
> Addenbrooke's Hospital
>
>


From: David Bevan on
I see the problem (on 32-bit Windows).

Looking at the Combinatorica code, the problem seems to be in the call to
SetGraphOptions[g, EdgeDirection -> True] which apparently normalises the edge list by sorting if the source graph is undirected before making the result directed:

In[]:= g1=Cycle[3,Type->Directed];
In[]:= List@@g1
Out[]= {{{{1,2}},{{2,3}},{{3,1}}},{{{-0.5,0.866025}},{{-0.5,-0.866025}},{{1.,0}}},EdgeDirection->True}

In[]:= g2=SetGraphOptions[g1, EdgeDirection -> False];
In[]:= List@@g2
Out[]= {{{{1,2}},{{2,3}},{{3,1}}},{{{-0.5,0.866025}},{{-0.5,-0.866025}},{{1.,0}}},EdgeDirection->False}

In[]:= g3=SetGraphOptions[g2, EdgeDirection -> False];
In[]:= List@@g3
Out[]= {{{{1,2}},{{2,3}},{{1,3}}},{{{-0.5,0.866025}},{{-0.5,-0.866025}},{{1.,0}}},EdgeDirection->False}

Note that g3 is normalised, but g2 isn't.

FromAdjacencyMatrix should really create a directed graph directly.

I can't see why different endian-ness should affect this though.

David %^>