Drawing layered graphs with port constraints

https://doi.org/10.1016/j.jvlc.2013.11.005Get rights and content

Abstract

Complex software systems are often modeled using data flow diagrams, in which nodes are connected to each other through dedicated connection points called ports. The influence a layout algorithm has on the placement of ports is determined by port constraints defined on the corresponding node.

In this paper we present approaches for integrating port constraints into the layer-based approach to graph drawing pioneered by Sugiyama et al. We show how our layout algorithm, called KLay Layered, progresses from relaxed to more restricted port constraint levels as it executes, and how established algorithms for crossing minimization and edge routing can be extended to support port constraints. Compared to the previous layout algorithms supporting ports, our algorithm produces fewer edge crossings and bends and yields pleasing results.

We also explain and evaluate how layout algorithms can be kept simple by using the concept of intermediate processors to structure them in a modular way. A case study integrating our layout algorithm into UC Berkeley's Ptolemy tool illustrates how KLay Layered can be integrated into Java-based applications.

Introduction

With up to ten million lines of code, software-based functions account for 50–70% of the effort in the development of automotive electronic control units [3]. To keep up with the growing complexity and tightening time-to-market requirements, embedded software domains such as the automotive, rail, or aerospace industries increasingly take advantage of graphical model-based development tools that follow the actor-oriented approach [19] such as Simulink (The MathWorks), SCADE (Esterel Technologies), ASCET (ETAS), or Ptolemy (UC Berkeley). Herein, graphical diagrams are used as input representations for simulators, rapid prototyping systems, and code generators. Fig. 1 shows a typical data flow diagram from Ptolemy and reveals the basic components of such a diagram, namely actors (also called blocks or operators), connections between the actors, and ports that define the interface of actors and the kind of data that is transported by connections.

While it is generally assumed that graphical diagrams are more readable than textual programs, the readability of a diagram strongly depends on its layout. Therefore, when creating or changing a model, an estimated 25% of a user's time is spent on manual layout adjustments according to Klauske [16]. Using graph layout algorithms to automate layout adjustments, this time can be better spent improving the model itself instead of its graphical representation.

Since in data flow diagrams actors are connected through ports, graph layout algorithms have to provide support for them. The position of a port relative to its actor need not even be fixed; instead, the layout algorithm can be made responsible for finding a good position. The degree of freedom it has in doing so is given by port constraints placed on the actor. Traditional layout algorithms support these requirements only in very limited ways, if at all.

Contributions: In this paper, we address the automatic layout of graphs with port constraints, building on the layer-based approach that has already proven successful in many domains but so far has received little attention with respect to port constraints. We introduce a structured way for transitioning from relaxed to restricted port constraint levels during the algorithm. We describe how the popular barycenter-based crossing minimization heuristic can be extended to support ports and compare different methods for doing so. We also introduce methods for sorting ports where their order is not fixed. We describe how inverted ports can be handled that require connected edges to be routed around a node. For handling north/south-side ports, we introduce layout units and a new flexible method for dummy node creation. We also present the concept of intermediate processors to structure layout algorithms in a modular way, including an account of our practical experience with this concept.

As explained above, the development of the methods presented here was primarily motivated by the desire for automatic layout of data flow diagrams as used in embedded software development. However, our results should be applicable to other application areas as well, such as electronic circuit diagrams or any other graph representation with port constraints.

Outline: The rest of this section defines the necessary notation, introduces the layer-based approach to graph drawing, and gives an overview of related work in this area. Section 2 describes a clean approach for handling port constraint levels in a layout algorithm. Since port constraints have large implications for crossing minimization and edge routing, the necessary modifications are described in depth in 3 Crossing minimization with port constraints, 4 Edge routing with port constraints. Shifting towards a more practical perspective, we give details on the algorithm's modular architecture and a case study describing its integration into an existing software product in Section 5. We finish with a detailed evaluation of the algorithm in Section 6 and conclude with Section 7.

Let (V,E) be a directed graph and vV. We denote the set of incoming edges of v by Ei(v) and the set of outgoing edges of v by Eo(v). The source node of an edge e=(u,u') is vs(e)=u, and its target node is vt(e)=u'. In a port-based graph each edge is connected to its source and target over specific ports. The set of ports attached to v is denoted by P(v). An edge e has a source port ps(e)P(vs(e)) and a target port pt(e)P(vt(e)). For a port pP(v) we write Ei(p) for the subset of incoming edges of v that have p as their target port, and Eo(p) for the subset of outgoing edges of v that have p as their source port. Furthermore, we define E(p)=Ei(p)Eo(p).

The drawing of a port-based graph maps each node vV to an area bounded by a rectangle with its upper left corner at pos(v)=(x,y)R2 and its bottom right corner at (x+w,y+h) with w,h>0. Likewise, each port pP(v) is mapped to a position pos(p)R2, but that position is constrained to the boundary of the bounding rectangle of v. As a consequence, p can be assigned to a side s{north,east,south,west} depending on which side of the bounding rectangle of v is chosen. The vertical axis is assumed to point downwards.

Edges are drawn with series of line segments that are each determined by a start point, an end point, and a sequence of bend points. Usually orthogonal routing is applied to port-based graphs: all line segments are aligned either horizontally or vertically.

During its execution, an algorithm may add and remove additional nodes. We distinguish such additional nodes from the nodes originally present in the graph and call them dummy nodes and regular nodes, respectively.

Many modeling applications that use ports do not allow graph drawing algorithms too modify the positions of ports relative to the node they are attached to, i.e. pos(p)pos(v) must be constant for each pP(v). Other applications allow repositioning ports within certain constraints. The port constraints model used here assigns a constraint level PC(v) to each node v, which can be chosen from five different levels:

    Free

    Ports can be placed at arbitrary positions on the boundary of node v.

    FixedSide

    A side of v, denoted by side(p){north,east,south,west}, is assigned to each port pP(v).

    FixedOrder

    The side of each port is fixed, and the ports of each side have to be placed in a specific order.

    FixedRatio

    Each port is assigned a position, relative to the containing node v; if v is resized, the position is scaled accordingly.

    FixedPos

    Each port is assigned a relative position that must not be modified by the layout algorithm.

The layer-based graph layout approach was introduced by Sugiyama et al. [26]. Given a directed acyclic graph, this approach arranges all edges in the same direction by organizing the nodes in subsequent layers, which are also called hierarchies or levels in graph drawing literature. All algorithms are described with the assumption that the main orientation of edges is from left to right, hence the nodes of each layer are arranged vertically. While this is inconsistent with most of the graph drawing literature, which assumes top-to-bottom layout [10], [26], the left-to-right layout is commonly used for data flow diagrams.

The layer-based approach solves the graph layout problem by dividing it into five consecutive phases.

  • 1.

    Elimination of cycles. Directed cycles can be eliminated by reversing a subset of the edges. The aim is to minimize this subset in order to have as many edges as possible pointing in the same direction in the final drawing. A popular algorithm for this problem is the heuristic of Eades et al. [4].

  • 2.

    Layer assignment: Nodes are assigned to layers L1,,Lk such that all edges point from layers of lower index to layers of higher index. Edges that span more than one layer (long edges) are split with dummy nodes in order to obtain a proper layering, where all edges connect nodes placed in consecutive layers. The number of required dummy nodes can be minimized efficiently with the algorithm of Gansner et al. [10].

  • 3.

    Crossing minimization: The nodes of each layer Li are ordered with the goal of minimizing the number of edge crossings that can occur between pairs of layers. The barycenter heuristic, proposed by Sugiyama et al. [26], is very simple, fast, and gives reasonably good results [15].

  • 4.

    Node placement: The nodes of each layer Li are assigned vertical positions according to the order determined in the previous step. Positions should be chosen such that the edges can be drawn as straight as possible, e.g. with the method of Sander [21] or the method of Brandes and Köpf [2].

  • 5.

    Edge routing: This final phase adds bend points to edges, depending on the desired routing style. Methods for orthogonal routing that also support hyperedges (edges connecting multiple ports) have been proposed by Eschbach et al. [7] and Sander [22].

The barycenter heuristic for crossing minimization is an important basis for the extensions proposed in this paper. It reduces the ordering problem to consider only two layers La and Lb at a time, where La is kept fixed and Lb is reordered. In the following, we assume that La is left of Lb in the ordering of layers; thus we consider only the set Ei of incoming edges of the nodes in Lb, but the symmetric case can be computed in the same way by considering the set Eo of outgoing edges of the nodes in La. For each node vLa, let r(v) be its position in the fixed order of La. The barycenter value for each node wLb is defined byb(w)=1|Ei(w)|(v,w)Ei(w)r(v),that is the average position of the connected nodes in La. The order of Lb is obtained by sorting the contained nodes by their barycenter values. The barycenter method can be used to order all layers using the layer sweep algorithm:
  • 1.

    Determine a random order for the nodes of L1.

  • 2.

    Repeat for i=2,,k: Reorder the nodes of Li to reduce the number of crossings of edges with their source in Li1 and their target in Li.

  • 3.

    Repeat for i=k1,,1: Reorder the nodes of Li to reduce the number of crossings of edges with their source in Li and their target in Li+1.

  • 4.

    Repeat steps 2 and 3 until the total number of crossings is not further reduced.

Generally the result of the layer sweep algorithm can be improved by repeating it with different random initial orderings, and then selecting the result that produced the least number of edge crossings. This selection process as well as step 4 of the layer sweep algorithm require a method for counting the number of crossings that result from a given layering. There are simple and efficient algorithms for counting crossings, e.g. the algorithm of Barth et al. [1].

More details on layer-based layout are reported by Healy and Nikolov [14].

The first contributions to the problem of integrating port constraints in the layer-based approach were motivated by the layout of data structures, where certain fields of a structure may contain pointers to other structures. Gansner et al. showed how node positioning can be extended for including offsets derived from port positions [10]. Sander introduced the idea of handling side ports by adding dummy nodes in order to route the respective edges [21]. The problem of crossing minimization with port constraints was first discussed by Waddle, who adapted the barycenter heuristic to consider port positions [28]. These contributions employ FixedPos constraints with spline curve edge routing, but they do not support inverted ports or other port constraints and are not sufficient for the layout of data flow diagrams. Basic approaches for handling multiple levels of port constraints were proposed by Spönemann et al. [25].

Schreiber proposed different solutions in the context of drawing bio-chemical networks [23]. The crossing minimization phase is adapted by inserting dummy nodes for each port and adding constraints to respect the order of ports. Side ports are handled by routing the incident edges locally for each node, which is done through transformation into a two-layer crossing minimization problem. This suffices for treating FixedPos constraints, but can lead to unpleasant layouts since the number of resulting bend points is possibly higher than necessary (see Section 4). The approach of Siebenhaller suffers from the same problem because it also routes edges of side ports locally [24]. However, it supports more flexible port constraints by associating them with individual edges. The consequence is that a node may have some edges that are constrained to ports, and some that are not. This flexibility can be useful for the layout of UML diagrams, where it is possible that only a subset of the edges is connected to fixed points of a node. The crossing minimization problem that results from this additional degree of freedom can be partly solved by reducing it to a network flow problem. The extension of our approaches to consider such mixed constraints is not required for most data flow languages and is left for future research.

Klauske and Dziobek introduced a specialized node placement for Fixed-Ratio constraints [16], [17] in the context of the Simulink modeling language. Their approach is an extension of the linear program for node placement proposed by Gansner et al. [10]. This extension does not only determine vertical positions for the nodes, but also modifies their height in order to find an optimal placement of ports.

Gutwenger et al. introduced the concept of embedding constraints for modeling the port constraints of a node [12], but that model captures only the order of ports, and not their concrete positions. Such constraints are used in the context of planarization based layout, e.g. the topology-shape-metrics approach [27]. Harrigan and Healy applied embedding constraints to level planarization [13], which consists in finding a planar subgraph respecting a given layer assignment.

Klauske et al. proposed a new approach in which edges connected to north/[0]south-side ports are routed through dummy nodes that are allowed to be interleaved with dummy nodes of long edges, giving more freedom to the edge routing [18]. However, the order of the dummy nodes is fixed and minimizes crossings only locally. This approach is compared with a new approach that does not fix the order of the dummy nodes in this paper. For handling inverted ports, Klauske et al. also introduced the concept of in-layer edges that connect two nodes in the same layer, and described the algorithmic modifications necessary to support them. Finally, Klause et al. introduced a way for structuring layout algorithms in a modular way, allowing them to dynamically adapt to different layout tasks. We follow this up in this paper with an account of our practical experience with this concept after having made extensive use of it.

Section snippets

Handling port constraint levels

Let vV be a node and PC(v) be the port constraint level of v. The basic principle for handling this constraint level is to lift it to stricter values as we progress through of the five phases of the layer-based approach. One important goal is to modify the algorithms employed in the five phases as little as possible, and to realize most of the extensions in additional preprocessing or postprocessing algorithms (see Section 5.1). This allows a modular implementation with a clear separation of

Crossing minimization with port constraints

Extending the crossing minimization phase to consider port constraints is crucial since the number of crossings does not depend only on the order of nodes, but also on the order of ports for each node. We show how to modify the barycenter heuristic used in the layer sweep algorithm [26] such that it includes the port order in its calculations.

Let La be the fixed layer and Lb be the free layer to be reordered. For each node vLa, let P'(v)P(v) be the subset of ports that have connections to

Edge routing with port constraints

The way an edge incident to a node v should be routed depends on the side to which the edge is connected, and whether it is an incoming or an outgoing edge. We call a port pP(v) regular if either side(p)=east and Ei(p)=, or side(p)=west and Eo(p)=. For instance, all ports in Fig. 7 are regular and thus conform to the left-to-right orientation of edges. In contrast, we call p an inverted port if either side(p)=east and Ei(p), or side(p)=west and Eo(p). If all ports are regular, we can

Implementation and integration

The algorithmic concepts described so far are implemented in a Java-based layout algorithm called KLay Layered. Since many popular graph layout libraries such as Graphviz1 and OGDF2 are implemented in C, the KLay project is an effort to develop layout algorithms purely in Java. The algorithms are integrated into the KIELER Infrastructure for Meta Layout (KIML),3 a framework based on Eclipse4

Experimental evaluation

The quality of layouts is usually measured through aesthetics criteria, of which the number of edge crossings and the number of bend points rank among the most important according to Purchase et al. [20], [29]. In this section, we evaluate KLay Layered regarding the number of edge crossings and bend points produced as well as its runtime performance. We also evaluate the two methods for assigning port ranks described in Section 3.1 and the two methods for handling north/south-side ports

Conclusion

A large class of graphical languages, including data flow diagrams used for embedded software development, impose port constraints on their drawings. We presented in fair detail a method for the automatic layout of such diagrams, building on the layered approach. A key element of our method is the creation and special treatment of dummy nodes. This comes at a certain cost in terms of runtime performance, but simplifies the handling of port constraints and allows the algorithm to be structured

Acknowledgments

Several people have contributed to the results presented here. We thank in particular Petra Mutzel and Lars Kristian Klauske, for valuable exchanges on the general subject of layout with port constraints, and Hauke Fuhrmann, for the first integration of KIELER layout technology into Ptolemy. We also thank Edward A. Lee, Christopher Brooks, and other members of UC Berkeley's Ptolemy group for being highly supportive of this integration effort. We also thank the users of KIELER and Ptolemy for

References (29)

  • P. Eades et al.

    A fast and effective heuristic for the feedback arc set problem

    Inf. Process. Lett.

    (1993)
  • W. Barth, M. Jünger, P. Mutzel, Simple and efficient bilayer cross counting, in: Proceedings of the 10th International...
  • U. Brandes, B. Köpf, Fast and simple horizontal coordinate assignment, in: Proceedings of the 9th International...
  • M. Broy, Challenges in automotive software engineering, in: Proceedings of the 28th International Conference on...
  • M. Eiglsperger, M. Siebenhaller, M. Kaufmann, An efficient implementation of Sugiyama's algorithm for layered graph...
  • J. Eker, J.W. Janneck, E.A. Lee, J. Liu, X. Liu, J. Ludvig, S. Neuendorffer, S. Sachs, Y. Xiong, Taming...
  • T. Eschbach et al.

    Orthogonal hypergraph drawing for improved visibility

    J. Graph Algorithms Appl.

    (2006)
  • M. Forster, A fast and simple heuristic for constrained two-level crossing reduction, in: Proceedings of the 12th...
  • E. Gamma et al.

    Design patternsabstraction and reuse of object-oriented design

  • E.R. Gansner et al.

    A technique for drawing directed graphs

    Softw. Eng.

    (1993)
  • M.R. Garey et al.

    Crossing number is NP-complete

    SIAM J. Algebr. Discret. Methods

    (1983)
  • C. Gutwenger et al.

    Planarity testing and optimal edge insertion with embedding constraints

    J. Graph Algorithms Appl.

    (2008)
  • M. Harrigan, P. Healy, Practical level planarity testing and layout with embedding constraints, in: Proceedings of the...
  • P. Healy et al.

    Hierarchical drawing algorithms

  • Cited by (0)

    This paper has been recommended for acceptance by S.-K. Chang.

    View full text