How to Achieve Deterministic Graph Layout
Applies to: yFiles for Java 2.8, 2.7, 2.6, 2.5, 2.4, 2.3, 2.2, 2.1, 2.0; yFiles.NET 2.4, 2.3, 2.2 print article email article

Type: Questions & Answers

Categories this article belongs to:
yFiles for Java > yFiles Layout > Automatic Graph Layout

Achieving deterministic graph layout depends on a number of factors in different scenarios.

As a general precondition to facilitate deterministic graph layout in different scenarios, the graph structure should remain unaltered between algorithm runs. This includes the following items (most relevant first):
  1. The sequence of nodes and also the sequence of edges should not be changed.
  2. The sequence of edges at the nodes should not be changed either.
  3. In scenarios where (strong) port constraints are obeyed, they should remain unchanged, too.
The sections below describe common scenarios where non-deterministic layout results can arise, and offer practical solutions.

Multiple Subsequent Runs of a Layout Algorithm

To get deterministic layout results from multiple subsequent runs of a layout algorithm on a given graph, it is important that the graph structure itself remains unaltered. However, a number of algorithms actually do change the graph structure when they perform their computations.

The solution then, is to use class BufferedLayouter to perform the layout. Class BufferedLayouter creates a copy of the given graph structure, and thereafter invokes the original layout algorithm on that copy. As a consequence, the original graph structure remains unaltered.

// 'myLayouter' is of type y.layout.Layouter. 

new y.layout.BufferedLayouter(myLayouter).doLayout(graph);

Switching to Deterministic Mode with Some Layout Algorithms

Normally, classes OrganicLayouter and SmartOrganicLayouter use randomization when computing a layout.

To get deterministic results this behavior can be changed by using methods OrganicLayouter.setActivateDeterministicMode(boolean) and SmartOrganicLayouter.setDeterministic(boolean).

Analogously, to obtain deterministic results for the OrthogonalLayouter the randomization has to be disabled using method OrthogonalLayouter.setUseRandomization(boolean).

"As Is" Layout

The layout algorithms provided by classes HierarchicLayouter (HierarchicGroupLayouter) and OrganicLayouter support layout computation based on a given node placement. This feature is referred to as "As Is" layout.

Of course, the main precondition for determinstic layout using a given node placement is the placement to remain unaltered when running the layout multiple times.

Setting (Increasing) the Time Limit

With huge graphs or really slow computers there is the possibility to reach a computation time limit. Reaching the time limit enforces the computation to end, returning its current result. Clearly, with modern operating system this result is not guaranteed to be deterministic at all.

Hence, to achieve deterministic results the time limit should offer enough room for a normal end of computation.


Keywords: BufferedLayouter - time - limit - deterministic - layout - As - Is

Provide feedback:
How useful was this article?    less 1 2 3 4 5 more
Email address (optional):
COPYRIGHT © 2012 yWorks · ALL RIGHTS RESERVED imprint | terms of use | privacy policy | home