Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: graph

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125358] Re: graph
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Fri, 9 Mar 2012 06:08:35 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201203080940.EAA14251@smc.vnet.net>

data = {
   {1, {11, 6, 13, 22}},
   {2, {35, 10, 12, 8, 28}},
   {3, {23, 31, 19, 14, 11}},
   {4, {9, 15, 7, 13, 33, 19}},
   {5, {28, 8, 32, 34}},
   {6, {27, 13, 1, 11, 20}},
   {7, {13, 4, 15, 17, 21, 32, 8}},
   {8, {7, 32, 5, 28, 2, 12}}};

adjMatrix = With[{m = Max[data]},
   SparseArray[
    Join @@
     (Thread[Thread[{#[[1]], #[[2]]}] -> 1] & /@ data),
    {m, m}]];

adjGraph = AdjacencyGraph[adjMatrix,
  VertexLabels -> "Name", ImageSize -> 600]


Bob Hanlon


On Thu, Mar 8, 2012 at 4:40 AM, clansa <dauphinester at gmail.com> wrote:
> I have this kind of data
> {{1, {11, 6, 13, 22}}, {2, {35, 10, 12, 8, 28}}, {3, {23, 31, 19, 14,
>   11}}, {4, {9, 15, 7, 13, 33, 19}}, {5, {28, 8, 32, 34}}, {6, {27,
>   13, 1, 11, 20}}, {7, {13, 4, 15, 17, 21, 32, 8}}, {8, {7, 32, 5,
>   28, 2, 12}}}
> The node 1 is connected to nodes 11, 6, 13 and 22
> the node 2 is connected to nodes 35,10,12,8 and 28
>
> I want to make a graph gr
> and then to obtain adjency matrix with AdjacencyMatrix[gr]
>
> I work with many nodes (>250
>
> Thanks
> Andrew



  • References:
    • graph
      • From: clansa <dauphinester@gmail.com>
  • Prev by Date: possible an error in Mathematica or a book proof
  • Next by Date: Re: Using Mathematica to typeset books
  • Previous by thread: Re: graph
  • Next by thread: Using Throw/Catch in MeshFunctions doesn't work? (8.0.4)