How to Achieve Deterministic Graph Layout |
| Applies to: yFiles 2.4, yFiles 2.3, yFiles 2.2, yFiles 2.1, yFiles 2.0, yFiles.NET 2.4, yFiles.NET 2.3, yFiles.NET 2.2 |
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):
and SmartOrganicLayouter
use randomization when computing a layout.
(HierarchicGroupLayouter
) and OrganicLayouter
support layout computation based on a given node placement.
This feature is referred to as "As Is" layout.
- The sequence of nodes and also the sequence of edges should not be changed.
- The sequence of edges at the nodes should not be changed either.
- In scenarios where (strong) port constraints are obeyed, they should remain unchanged, too.
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
To get deterministic results this behavior can be changed by using methods OrganicLayouter.setActivateDeterministicMode(boolean)
and SmartOrganicLayouter.setDeterministic(boolean)
.
"As Is" Layout
The layout algorithms provided by classes HierarchicLayouterOf 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 |


