Group Abstract Group Abstract

Message Boards Message Boards

0
|
9.8K Views
|
5 Replies
|
8 Total Likes
View groups...
Share
Share this post:

Lists of vertices by level from "LayeredEmbedding"?

Posted 6 years ago

When a Graph is generated with layout "LayeredEmbedding", is there a built-in means of obtaining lists of vertices per layer, in horizontal order (e.g. left to right)? enter image description here

POSTED BY: Richard Frost
5 Replies
Posted 6 years ago

You can just do some sorting and grouping with vertex coordinates.

g = TreeGraph[
  RandomInteger[#] \[UndirectedEdge] # + 1 & /@ Range[0, 30], 
  VertexLabels -> Automatic]

coord = Thread[VertexList[g] -> GraphEmbedding[g]];

layers = (SortBy[#, #[[2, 1]] &] & /@ 
     GatherBy[Reverse[SortBy[coord, #[[2, 2]] &]], #[[2, 2]] &])[[All,
     All, 1]];

Column[layers]
POSTED BY: Jaebum Jung

Thank you Jaebum Jung. I have used your technique to extract vertices by layer, then alternated the label positions Above and Below left to right in each layer. This, along with reducing the precision in the edgeweights has greatly improved the legibility of the graph. I'm very happy to achieve this in an automated way!

POSTED BY: Richard Frost

Hi Richard, I don't know (I'm not an expert alas). There should be :)

Anyway I always thought that for the LayeredEmbedding the RootVertex chosen was one of the Vertexes with the lowest VertexEccentricity.

Playing with the random graph written by @Jaebum Jung this might be right.

{VertexEccentricity[LEgPP, #], #} & /@ VertexList[LEgPP] //Sort // First // Last

seems to do the trick for your graph and a couple of the randomgraphs I tried. Using on Graphs with some disconnected Vertex will not work (unless you cast out the ones with 0 Eccentricity first). I think that Jaebum's way will be the fastest way of sorting it out anyway. But if you Use the option GraphLayout -> {"LayeredEmbedding", "Orientation" -> Left} it will fail and mine will still work. Obviously Jaebum's way will work with changing the sorting order.

POSTED BY: l van Veen
POSTED BY: l van Veen
POSTED BY: Richard Frost
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard