Evolutionary Layout of UML Class Diagrams - CiteSeerX

8 downloads 3559 Views 89KB Size Report
∗email:[email protected]. †email:[email protected] mutation probability move node. 0.54 move port of an edge. 0.1 flip port ...
Evolutionary Layout of UML Class Diagrams J. Wolff v. Gudenberg∗ W¨ urzburg University Informatik D-97074 W¨ urzburg

A. Niederle W¨ urzburg University Informatik D-97074 W¨ urzburg

Abstract An evolutionary algorithm that layouts UML class diagrams is developed and described. It evolves the layout by mutating the positions of class symbols, inheritance relations, and associations. The process is controled by a fitness function that is computed from several well-known and some new layout metrics. Keywords: UML class diagrams, evolutionary algorithms, layout metrics, graph drawing

H. Eichelberger† Hildesheim University Software Engineering 31141 Hildesheim

M. Ebner W¨ urzburg University Informatik D-97074 W¨ urzburg mutation move node move port of an edge flip port of an edge move bend delete bend

probability 0.54 0.1 0.21 0.1 0.05

An operator is chosen with the given probability in an evolution step, the move nodes operator, e.g., with a probability of 0.54. This operator works as follows: 1. Choose a random node.

1

The Algorithm

A neat and aesthetic drawing of a UML class diagram supports readabilty and usability. In this paper we investigate a new lightweight evolutionary non-deterministic approach for automatic layout of UML class diagrams.

1.1

Representation

2. Move position (x , y  ) = (x, y) + (dx, dy) where dx and dy are normally distributed random numbers with standard deviation σx = 100, and σy = 50, respectively. 3. Check for overcuts of edges with the node. If necessary flip port. 4. According to its iteration probability p1 go to step 1. The other operators work similarly, all iteration probabilities are initialized with 0.7.

We represent a diagram as a set of nodes and edges. Each node has a fixed size that does not change during the course of evolution and, hence, is not stored with each diagram. A node is represented by the x and y coordinates of its upper left corner point.

1.3

An edge connects two nodes, the coordinates of the junction points are stored relatively to the top left corner of the node rectangle. Hierarchical edges are drawn directly from point to point, whereas non-hierarchical edges are drawn orthogonally and may have (orthogonal) bends. Each bend is determined by one point. Since we only attach these edges to the left or right side of the rectangle, the number of bends is always even. In our implementation we restrict the possible number of bends to two, hence it suffices to store the common abscissa.

The fitness function or error measure is computed as a linear combination of 9 metrics, each scaled to the range [0, 1].

1.2

Mutation

The following mutations are possible, each with its own stepsize and probability: ∗ email:wolff@informatik.uni-wuerzburg.de † email:[email protected]

Fitness Function

We have considered layout metrics for UML class diagrams in more detail in [Eichelberger 2005].

1. NN Overlappings of nodes are counted and scaled regressively. It was not helpful to compute the overlapping area. ρNN :=

|overlaps| |overlaps|+1

2. EN Overcuts of edges and nodes are treated analogously. |overcuts| ρEN := overcuts +1 | | 3. EE Edge crossings are counted, the current number is then divided by the upper bound of possible crossings similar to the formula suggested in [Purchase 2002]. That bound depends on the number of edges and the number of bends. eb := |edges| + 2 · |bends| 2·|crossings | ρEE := eb·(eb−1) 4. H Hierarchical edges should follow a common flow direction, from bottom to top. In our simplified view of UML class diagrams hierarchical edges means generalizations. A linear scaling is sufficient.

ρH :=

|direction misses| |generalizations|

5. GL Lengths of hierarchical edges can be preassigned, for instance depending on the size of the arrow head. This metric measures the difference to that prefered length. Shortening the length is punished harder than prolonging. 

ρGL := 1 −

g∈generalizations

mix(¯ g ,lpref )

3

|generalizations|

+ where mix : R+ → [0, 1], mix(x, y) := 0 × R und g¯ the length of g.

min(x,y) max(x,y)

6. AL Associations, i.e. non-hierarchical edges are treated similarly. We, indeed, define a prefered length for the possibly 2 horizontal pieces, and compare the pieces and the full horizontal length separately. With piece(a) := mix(¯ ah1 , lpref )+mix(¯ ah2 , l ah1 +¯ ah2 , 2·lpref ) pref )+mix(¯ we have ρAL := 1 −

piece(a)

3·|associations |

Let x the horizontal and y the vertical distance between start and end position of a hierarchical edge (x, y) → (x + x, y + y) 



ρA :=

x x+y

2

The scaled error per side is accumulated: side(k) := n k



(k¯i )2 −equi(k)

(k¯ )

2

− equi(k)

ρM P :=

side(k)

k∈nodesides

|nodesides|

9. B The number of bends should be minimal as suggested in many graph drawing publications or in [Purchase |bends| 2002]. ρB := 2· associations | | Let x be a diagram with values ρm (x) for the metric m. The fitness function is computed as a linear combination of these values.  F (x) := 9m=1 ωm · ρm m ω

2

NN 1

EN 1

EE 5

Overall, the approach was successful, we obtain acceptable layouts of UML class diagrams in reasonable time. We have developed a set of metrics that is capable of controlling the evolutionary algorithm. The overall time, however, is slower than SugiBib by a factor of about 20.

3.1

Fitness

H 10

GL 2

Lots of experiments led us to the coefficients given in the paper. It turned out that the hierarchy should be emphasized. It is much easier to fine-tune a diagram with some overlapping nodes than one with a hierarchy mismatch. Therefore the hierarchical metric got a high factor. The regressive scaling of the overlapping metrics causes relatively high values ( ≥ 0.5), hence these metrics are very frequently reduced to 0. With larger diagrams the weight for edge crossings should be increased.

|generalizations |

8. MP If multiple edges connect to the same side of a node, a balanced distribution of the edge ports is aspired. Therefore the area spanned by squares between the ports is calculated, its minimum equi(k) :=  2 ¯ nk · nk is achieved for an equidistant partition, its k ¯2 for nk = 0 where k the side of a node maximum k partioned by nk ports into nk + 1 pieces k0 , k1 , . . . , knk ¯i , i = 0, . . . , nk . with lengths k

i=0

Discussion

a∈associations

7. A The angle between a hierarchical edge and the side where it connects to a node is estimated by the ratio of the horizontal distance to the sum of distances and linearly scaled.

generalizations

and the semantics of the input, and to transform the information to a graph structure optimized for the evolutionary algorithm. Then the evolutionary algorithm is executed and finally the coordinates are handed to SugiBib. This allows us to use real coordinates for the evolutionary algorithm, and also enables the reuse of the SugiBib metrics.

AL 1

A 1

MP 0.5

B 0.5

Combination with SugiBib

The context of SugiBib[Eichelberger and von Gudenberg 2003a; Eichelberger 2005] is used to retrieve the structure

We have noticed that the consideration of subtle metrics such as the angle A improves the overall layout of a diagram a lot. So does the MP metric that is responsible for a centered position of nodes in a hierarchy.

References Eichelberger, H., and von Gudenberg, J. W. 2003. On the Visualization of Java Programs. In Software Visualization, International Seminar, Dagstuhl Castle, Germany, May 2001, Revised Papers, Springer-Verlag Inc., New York, NY, USA, S. Diehl, Ed., vol. 2269 of Lecture Notes in Computer Science, 295–306. Eichelberger, H. 2005. Aesthetics and Automatic Layout of UML Class Diagrams Ph.D. Thesis Fakult¨ at f¨ ur Mathematik und Informatik, University of W¨ urzburg Purchase, H. C. 2002. Metrics for Graph Drawing Aesthetics. Journal of Visual Languages and Computing 13, 5, 501–516. Purchase, H., Colpoys, L., Carrington, D., and McGill, M. 2003. UML Class Diagrams: An Empirical Study of Comprehension. In Software Visualization From Theory to Practice, K. Zhang, Ed. Kluwer, 149–178.

Suggest Documents