Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

GraphPlot question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67308] GraphPlot question
  • From: János <janos.lobb at yale.edu>
  • Date: Sat, 17 Jun 2006 04:36:39 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

I have an nxm list called ndstr.  It is a rule based list, so the  
element at ndstr[[i,j]] looks like "a1.a2.a3.a4"->"b1.b2.b3.b4", of  
course a-s and b-s can be different for any i,j combinations.  If I  
take the GraphCoordinates of this list with coord=GarphCoordinates 
[Flatten[ndstr] ] it spits out coordinates for all vertices.  However  
the order how the nodes' coordinates appear in coord are not  
trivial.  I am guessing that is somewhat relates to Gray coding.  I  
would like to create a function f[i_,j_] that would give a color  
according to values stored in an ndstrColor table also with an nxm  
structure and use it with the EdgeStyleFunction->f fashion in  
GraphPlot.  To be able to do that I have to transform the ndstrColor  
table to have the same format as the coord table.

In my particular case nxm is 7x4, that is a matrix with seven rows  
and 4 columns  coords is a 22x2 matrix. Twentytwo is the number of  
independent vertices in the ndstr list.

Here is my example:

In[170]:=
ndstr = {{"10.84.2.31" ->
       "10.84.2.254",
      "10.84.2.254" ->
       "10.32.1.29",
      "10.32.1.29" ->
       "10.32.1.78",
      "10.32.1.78" ->
       "10.48.106.45"},
     {"10.84.2.42" ->
       "10.84.2.254",
      "10.84.2.254" ->
       "10.32.1.33",
      "10.32.1.33" ->
       "10.32.1.82",
      "10.32.1.82" ->
       "10.48.106.45"},
     {"10.84.10.116" ->
       "10.84.10.254",
      "10.84.10.254" ->
       "10.32.1.29",
      "10.32.1.29" ->
       "10.32.1.78",
      "10.32.1.78" ->
       "10.48.106.45"},
     {"10.84.20.53" ->
       "10.84.20.254",
      "10.84.20.254" ->
       "10.32.1.29",
      "10.32.1.29" ->
       "10.32.1.70",
      "10.32.1.70" ->
       "10.48.106.45"},
     {"10.84.30.16" ->
       "10.84.30.254",
      "10.84.30.254" ->
       "10.32.1.33",
      "10.32.1.33" ->
       "10.32.1.74",
      "10.32.1.74" ->
       "10.48.106.45"},
     {"10.38.155.85" ->
       "10.38.155.254",
      "10.38.155.254" ->
       "10.32.1.49",
      "10.32.1.49" ->
       "10.32.1.74",
      "10.32.1.74" ->
       "10.48.106.45"},
     {"10.40.40.23" ->
       "10.40.40.254",
      "10.40.40.254" ->
       "10.32.1.65",
      "10.32.1.65" ->
       "10.32.1.82",
      "10.32.1.82" ->
       "10.48.106.45"}};

My ndstrColor table is:
Out[182]=
{{0, 0.024187218389599533,
    0.02592719144474731, 0},
   {0, 0.37555752153893274,
    0.06459070265015886, 0},
   {0, 0.41830807973000594,
    0.040645833263024324, 0},
   {0, 0.6497291061582198,
    0.4186258636315614, 0},
   {0, 0.8477454512788037,
    0.4294219857324032, 0},
   {0, 0.037502590928314886,
    0.02630417678156069, 0},
   {0, 0.142419879665854,
    0.052516012160304604, 0}}

coord is:
In[171]:=
coord = 2*GraphCoordinates[
     Flatten[ndstr]]

other elements to the GraphPlot are"
In[161]:=
labels = VertexList[
    Flatten[ndstr]]

esf[i_, j_] := Block[{},
     {Blue, Line[{i, j}],
      Arrow[{coord[[i]],
        coord[[i]] +
         0.7*(coord[[j]] -
           coord[[i]])},
       HeadScaling ->
        Absolute]}];

The plot itself without per edge coloring is:
In[190]:=
GraphPlot[Flatten[ndstr],
    EdgeStyleFunction -> esf,
    VertexStyleFunction ->
     ({White, Disk[#1,
        {0.17, 0.05}], Black,
       Circle[#1, {0.2,
         0.05}], Red,
       Text[labels[[#1]],
        #1]} & ),
    VertexCoordinates ->
     coord, TextStyle ->
     {FontSize -> 8}];

Above in the esf function I would like to override the "Blue"  
directives with my f[i_,j_] function, or have a transformation rule  
for the ndstrColor table that makes it like the coord table.  I tried  
the following silly construct in place of the Blue:
RGBColor[ndstrColor[[,i,j]],ndstrColor[[,i,j]],ndstrColor[[,i,j]] ]
but of course it did not work because ndstrColor is not a 22x2 matrix.

Now,
In[196]:=
Show[Graphics[
    (Text[Position[coord, #1],
       #1] & ) /@ coord]]

shows the order of the nodes position and I can visually compare it  
with the GraphPlot above.  My algebra teacher - Andor Kertész - used  
to say that "from here on you just have to look it till you see it",  
but I am looking it in the last few hours and I am still not seeing  
it :)  I can see that some kind of Gray coding is involved, but I do  
not see how.

I realize that GraphCoordinates doing something like:

UnsortedUnion[Flatten[Map[{#[[1]], #[[2]]} &, Flatten[ndstr]]] ]

If I combine the two lists, that is ndstr and ndstrColor like:
In[324]:=
fcf = Flatten[
    ({{#1[[1,1]], #1[[2]]},
       {#1[[1,2]],
        #1[[2]]}} & ) /@
     Flatten[Table[Table[
        {ndstr[[j,i]],
         ndstrColor[[j,i]]},
        {i, Length[ndstr[[
           j]]]}],
       {j, Length[ndstr]}],
      1], 1]

  so that every element in ndstr is broken apart with the value  
assigned to both and try to UnsortedUnion it, I am still getting  
elements where the first part of an elemnt is the same but the second  
is not and they are more than one neighbor away.  I still  need to  
eliminate all elements whose first part was found earlier.


Thanks ahead,

János



  • Prev by Date: Re: a mahtematica newbie about FitResiduals question:
  • Next by Date: Mathematica bugs?
  • Previous by thread: Re: Unexpected condition on convergence of integral
  • Next by thread: Mathematica bugs?