MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: FromAdjacencyMatrix / FromAdjacencyLists - broken?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg104220] Re: [mg104192] FromAdjacencyMatrix / FromAdjacencyLists - broken?
  • From: Thomas Dowling <thomasgdowling at gmail.com>
  • Date: Sat, 24 Oct 2009 02:38:59 -0400 (EDT)
  • References: <200910230233.WAA27768@smc.vnet.net>

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[mg]] == EdgeList[g]

Out[57]= True.

mgalt = Normal@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 at 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
>
>



  • Prev by Date: Re: OpenerView, multiple sub cells and Notebook1Write...
  • Next by Date: Re: OpenerView, multiple sub cells and Notebook1Write...
  • Previous by thread: FromAdjacencyMatrix / FromAdjacencyLists - broken? Workaround?
  • Next by thread: Re: Re: FromAdjacencyMatrix /