Message Boards Message Boards

0
|
2967 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

[?] Print indented vertex based on depth from DepthFirstScan?

Posted 6 years ago

Consider the following code:

DepthFirstScan[
        {"A" <-> "B", "A" <-> "C", "B" <-> "D", "B" <-> "E",  "C" <-> "F", "C" <-> "G"},
        "A", 
        {"PrevisitVertex" -> (Print[#] &)}
    ];

produces

A
B
D
E
C
F
G

How could one visualize this tree indented by its depth as

A
    B
        D
        E
    C
        F
        G

I am experimenting to visualize our Messaging infrastructure having thousands of vertices. Each vertex is a queue name so printing the graph would need a way to enlarge it to at least paper size A0 or allowing to print it on multiple A3 size papers. That is why I am experimenting to visualize the graph vertically indented by its depth. I plan to use specific icons for different components and adding the edges aside colored by its type.

Any help is much appreciated. Many thanks. Markus

Markus,

I would record the depth of each discovered vertex as you search and use it to alter the printing by adding spaces depending on depth. I assigned depthval[vertex] to hold the depth value as the search is conducted. Lastly, because I am overloading "depthval", I must clear it first.

ClearAll[depthval]; 
DepthFirstScan[{"A" <-> "B", "A" <-> "C", 
      "B" <-> "D", "B" <-> "E", "C" <-> "F", 
      "C" <-> "G"}, "A", {"DiscoverVertex" -> ((depthval[#1] = #3) &), 
      "PrevisitVertex" -> (Print @@ 
          Append[Table["    ", depthval[#]], #] &)}];

Regards

Neil

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract