Re: DiscreteMath question : ToAdjacencyMatrix and FromAdjacencyMatrix

*To*: mathgroup at smc.vnet.net*Subject*: [mg66072] Re: [mg66017] DiscreteMath question : ToAdjacencyMatrix and FromAdjacencyMatrix*From*: Bruce Miller <brucem at wolfram.com>*Date*: Fri, 28 Apr 2006 06:33:22 -0400 (EDT)*References*: <200604270626.CAA29179@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

M. Jaccard, FromAdjacencyMatrix defaults to an undirected graph. There is an option, Type, to control this. In[11]:= ?FromAdjacencyMatrix FromAdjacencyMatrix[m] constructs a graph from a given adjacency matrix m, using a circular embedding. FromAdjacencyMatrix[m, v] uses v as the embedding for the resulting graph. An option Type that takes on the values Directed or Undirected can be used to affect the type of graph produced. The default value of Type is Undirected. FromAdjacencyMatrix[m, EdgeWeight] interprets the entries in m as edge weights, with infinity representing missing edges, and from this constructs a weighted graph using a circular embedding. FromAdjacencyMatrix[m, v, EdgeWeight] uses v as the embedding for the resulting graph. The option Type can be used along with the EdgeWeight tag. In[1]:= $Version Out[1]= 5.2 for Mac OS X (February 24, 2006) In[2]:= <<DiscreteMath` In[3]:= paires = {{1, 2}, {2, 3}, {2, 4}, {4, 4}}; g = FromOrderedPairs[paires]; ShowGraph[g, VertexLabel -> {1, 2, 3, 4}]; In[6]:= matrice = ToAdjacencyMatrix[g] Out[6]= {{0, 1, 0, 0}, {0, 0, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 1}} In[7]:= ToAdjacencyMatrix[FromAdjacencyMatrix[matrice]] Out[7]= {{0, 1, 0, 0}, {1, 0, 1, 1}, {0, 1, 0, 0}, {0, 1, 0, 1}} In[8]:= ToAdjacencyMatrix[FromAdjacencyMatrix[matrice, Type -> Directed]] Out[8]= {{0, 1, 0, 0}, {0, 0, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 1}} Similarly for ShowGraph[FromAdjacencyMatrix[matrice]]; ShowGraph[FromAdjacencyMatrix[matrice, Type -> Directed]]; Bruce Miller Technical Support Wolfram Research, Inc. support at wolfram.com http://support.wolfram.com/ On Apr 27, 2006, at 1:26 AM, Jaccard Florian wrote: > Let us set : > > paires = {{1, 2}, {2, 3}, {2, 4}, {4, 4}} > > The graph is given by : > > g = FromOrderedPairs[paires]; > > ShowGraph[g, VertexLabel -> {1, 2, 3, 4}] > > The matrix representation of this relation is given by : > > matrice = ToAdjacencyMatrix[g] > > Why does ToAdjacencyMatrix[FromAdjacencyMatrix[matrice]] don't give the > same matrix? > > > Regards > > F.Jaccard

**References**:**DiscreteMath question : ToAdjacencyMatrix and FromAdjacencyMatrix***From:*"Jaccard Florian" <Florian.Jaccard@he-arc.ch>