Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) LayeredLayout speed (Read 4874 times)
tom_w
Junior Member
**
Offline


Swimlanes made our dreams
come true :-)

Posts: 79
Joined: Oct 20th, 2008
LayeredLayout speed
Sep 27th, 2012 at 10:51am
Print Post  
Hi

Our layered layout diagrams are proving slow to arrange when there are hundreds of nodes (five to ten minutes). I'm guessing I simply need to change some settings for layout? The code currently looks like this:

Code
Select All
        Dim layout = New LayeredLayout()

        layout.StartNode = Me.RootNode

        layout.Anchoring = Anchoring.Ignore
        layout.Direction = Direction.Straight  'get P0 to the top
        layout.IgnoreNodeSize = True  ' false makes it slower
        layout.LayerDistance = Me.VerticalNodeSpacing  'default is 25 - this is the distance between the vert node bands
        layout.LinksCompactFactor = 0.5

        layout.NodeDistance = HorizontalNodeSpacing  'distance between adjacent nodes in the layer
        layout.Orientation = MindFusion.Diagramming.Layout.Orientation.Vertical
        layout.SplitLayers = False  ' split layers that are much wider than others
        layout.StableSort = True 'ensures the nodes always appear in the same position on each run
        layout.StraightenLongLinks = Me.StraightenLongLinks   'true makes it wider as has to arrange for only 2 bends on links that cross 2 or more layers
        layout.SwapPairsIterations = 2 ' default is 5, higher no. = less crossing links
        layout.TimeLimit = 10 ' 10 secs, should be more than enough.

        Debug.Print(Now.ToLongTimeString)

        layout.Arrange(diagram)

        Debug.Print(Now.ToLongTimeString)
 



I was under the impression that the TimeLimit property would limit how long the arrange routine ran for, but setting it to 10 (assuming units of seconds) or 10000 (assuming units of milliseconds as per the documentation) doesn't seem to make any difference. Is TimeLimit only working on part of the arrange?

Thanks, Tom
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: LayeredLayout speed
Reply #1 - Sep 27th, 2012 at 10:58am
Print Post  
TimeLimit limits only a path-finding part of the algorithm, where it looks for a very long path whose nodes determine the number of layers (to make layers narrower). You could avoid that part completely by specifying StartNode and EndNode, or by setting EnforceLinkFlow, so it might get faster with any of these options. I think it works faster also if StraightenLongLinks is enabled.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
tom_w
Junior Member
**
Offline


Swimlanes made our dreams
come true :-)

Posts: 79
Joined: Oct 20th, 2008
Re: LayeredLayout speed
Reply #2 - Sep 27th, 2012 at 11:11am
Print Post  
Thanks Stoyan, I'll give those a go.
  
Back to top
 
IP Logged
 
tom_w
Junior Member
**
Offline


Swimlanes made our dreams
come true :-)

Posts: 79
Joined: Oct 20th, 2008
Re: LayeredLayout speed
Reply #3 - Sep 27th, 2012 at 2:07pm
Print Post  
Hi Stoyan

Will setting the end node work in the scenario where there are multiple nodes at the same end level?  If so do I just pick any one that is at the bottom of the pyramid?

The other settings didn't speed things up particularly unfortunately.
  
Back to top
 
IP Logged
 
tom_w
Junior Member
**
Offline


Swimlanes made our dreams
come true :-)

Posts: 79
Joined: Oct 20th, 2008
Re: LayeredLayout speed
Reply #4 - Sep 28th, 2012 at 7:34am
Print Post  
Hi Stoyan

Is there any chance you could load the attached and see if there is anything slowing down the arrange?  The layout.Arrange(diagram) code takes about six minutes to run for this diagram on my system.

What's odd is that if I filter down the nodes to display a sub selection of the full set of nodes (say all the nodes from 10005 down) then the arrange is basically instant, but when I arrange from the very top down it takes much longer? 

Thanks, Tom
  

FullProcessHierarchyDiagram.zip (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: LayeredLayout speed
Reply #5 - Sep 28th, 2012 at 11:25am
Print Post  
Try this code with root set to the P0 node, it completes for 2-3 seconds:

Code
Select All
foreach (DiagramLink link in root.GetAllLinks())
	link.IgnoreLayout = true;

LayeredLayout ll = new LayeredLayout();
ll.StraightenLongLinks = true;
ll.EnforceLinkFlow = true;
ll.Arrange(diagram);

RectangleF r = RectangleF.Empty;
foreach (DiagramLink link in root.GetAllLinks())
{
	DiagramNode neighbor = GetOtherEnd(link, root);
	if (r.IsEmpty)
		r = neighbor.Bounds;
	else
		r = RectangleF.Union(r, neighbor.Bounds);
}
root.Move(
	r.X + r.Width / 2 - root.Bounds.Width / 2,
	r.Y - root.Bounds.Height - 30);

diagram.ResizeToFitItems(5); 



Setting IgnoreLayout on the root's links will divide the graph into several subsets, each arranged independently from the others. Since LayeredLayout is polynomial time algorithm, it will run much faster this way. E.g. instead of 1000*1000*1000 steps, it will execute in 10*100*100*100 steps if a graph having 1000 nodes is divided into 10 equal parts, so that will be 100 times faster for O(n^3) complexity (I think LayeredLayout is even more complex).

Also with version 6 of the control, the subsets can be arranged in parallel on separate processor cores when running on .NET 4 with EnableParallelism property set to true.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
tom_w
Junior Member
**
Offline


Swimlanes made our dreams
come true :-)

Posts: 79
Joined: Oct 20th, 2008
Re: LayeredLayout speed
Reply #6 - Oct 3rd, 2012 at 1:33pm
Print Post  
Thanks Stoyan, I'll give that a go.  What is the GetOtherEnd method in that code - could you provide the code for it?

Thanks, Tom
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: LayeredLayout speed
Reply #7 - Oct 3rd, 2012 at 2:47pm
Print Post  
You can find it here:
http://mindfusion.eu/Forum/YaBB.pl?num=1273515591/1#1

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
tom_w
Junior Member
**
Offline


Swimlanes made our dreams
come true :-)

Posts: 79
Joined: Oct 20th, 2008
Re: LayeredLayout speed
Reply #8 - Oct 3rd, 2012 at 2:49pm
Print Post  
I engaged my brain and guessed that the GetOtherEnd method simply returns whichever node connected to the link that isn't the root which got things working.

The code is really fast now  Smiley, but each of the subgraphs is 'upside down' for us, i.e. the arrows go up rather than down for the nodes in the subgraph.  I tried setting ll.Direction = Direction.Straight but that didn't work.  I'm guessing I'm missing something obvious?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: LayeredLayout speed
Reply #9 - Oct 3rd, 2012 at 5:08pm
Print Post  
Have you tried setting ll.Direction = Direction.Reversed? That should reverse the directions of subgraphs you are getting currently.
  
Back to top
 
IP Logged
 
tom_w
Junior Member
**
Offline


Swimlanes made our dreams
come true :-)

Posts: 79
Joined: Oct 20th, 2008
Re: LayeredLayout speed
Reply #10 - Oct 8th, 2012 at 5:24pm
Print Post  
Hi Stoyan

Direction.Reversed got it going in the right direction, thanks for that.

I noticed a few more issues that I have tried to illustrate in the attached word doc. The questions I have are:

-      Is there any way to change the order of the sub graph placement so that it is NON, P06, P1, P2 as per the original? Not massively important if not.

-      How can we make the sub graph spacing equal and bigger in the case of e.g. P1 to P2 and P2 to P0 in Figure 4?

-      After we move the P0 node it leaves P0’s links needing to be refreshed so they join centre to centre again between P0 and P1/P2/P06/NON. Think I just need to loop root’s links and call something, but link.Route gave me right angle connector links rather than the diagonal lines link arrows. What am I doing wrong?

Thanks, Tom
  

Sub_graph_layout_questions_for_MindFusion.docx (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: LayeredLayout speed
Reply #11 - Oct 9th, 2012 at 6:42am
Print Post  
Hi Tom,

Quote:
Is there any way to change the order of the sub graph placement so that it is NON, P06, P1, P2 as per the original?  Not massively important if not.


By default the subgraphs will appear in the order in which the algorithm finds their first nodes, so you might try adding the subgraph roots first in the required order when building the diagram. If by chance the required order corresponds to the size of subgraphs, try using the HorizontalSortAscending or HorizontalSortDescending options for MultipleGraphsPlacement.

Quote:
How can we make the sub graph spacing equal and bigger in the case of e.g. P1 to P2 and P2 to P0 in Figure 4


Set the Layout.Margins property.

Quote:
After we move the P0 node it leaves P0’s links needing to be refreshed so they join centre to centre again between P0 and P1/P2/P06/NON.  Think I just need to loop root’s links and call something, but link.Route gave me right angle connector links rather than the diagonal lines link arrows.  What am I doing wrong?


Try setting the links' SegmentCount to 1 and calling ReassignAnchorPoints.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
tom_w
Junior Member
**
Offline


Swimlanes made our dreams
come true :-)

Posts: 79
Joined: Oct 20th, 2008
Re: LayeredLayout speed
Reply #12 - Oct 9th, 2012 at 8:12am
Print Post  
Hi Stoyan

That all worked really well, many thanks.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint