2Force-Directed Methods Use a physical analogy to draw graphsHow does the natural “draw” a graph?View a graph as a system of objects with forces acting between them.Assumption: a balanced system gives a good layoutSpecifically, a system configuration with locally minimal energy:The sum of the forces on each object is zero.
3Force-Directed Methods Vertex:Object of the system;Interacting with each other based on “some” force(s).Edge:A different type of object;Not interacting with each other;Add new force(s) to vertex object.Equilibrium configuration: the sum of forces on each vertex object is zero
4The model: a force system defined by vertices & edges There are many force directed methods. In general, they have two parts: model & algorithmThe model: a force system defined by vertices & edgesThe algorithm: a technique for finding an equilibrium state, that is the sum of the forces on each vertex is zero (force system); ora technique for finding a configuration with locally minimal energy (energy system)
5Spring Methods Vertex: Edge: Electrically charged particles; Repel each other.Edge:Spring that connect particles;Attraction force when longer than the natural length;Repulsion force when shorter than the natural length.1.2.
7Many Variations Spring & electrical force Barycenter method Force simulating graph theoretic distanceMagnetic fieldGeneral energy functionConstraints
81. Springs & Electrical Forces Use a combination of spring & electrical forcesEdge: modeled as springVertex: equally charged particles which repel each otherThe force on v : F(v) = Σ f u,v Σ g u,vf u,v : force on v by the spring between u an v: follow Hook’s law (proportional to the difference between the distance between u and v and the zero-energy length of the spring)g u,v : Electrical repulsion exerted on v by vertex u: follow inverse square lawE(u,v)VxV(u,v)
9d(p,q) : Euclidean distance between points p and q pv = (xv, yv): position of vertex vx component of the force on vlu,v : natural (zero energy) length of the spring between u and v: if the spring has natural length lu,v, no force is exerted;k1u,v : stiffness of the spring between u and v: the larger k1u,v , the more tendency for the distance between u and v to be close to lu,v.k2u,v : the strength of the electrical repulsion between u and v
10Aim of the force model design: Spring force: Ensure the distance between adjacent vertices u and v is approximately equal to lu,v.Electrical force:Ensure vertices not too close to each other.One may choose parameters luv k1u,v k2u,v to customize for specific applications.
11Not the fastest, but allow smooth animation. There are many technique to find an equilibrium configuration (or minimum energy).Simple algorithmInitially at random locationAt each iteration:Force F(v) on each vertex is computedEach vertex v is moved in the direction of F(v) by a small amount proportional to the magnitude of F(v)Stops when equilibrium is achieved or some conditions are met.Not the fastest, but allow smooth animation.Calculating attractive forces only between neighbors: O(|E|)Calculating repulsive forces between all pair of vertices: O(|V|2)Bottleneck of the algorithm in general
12Spring Embedder [Eades84] “Logarithmic spring”Rather than Hook’s law, the spring force is calculated as:Hook Law (linear) spring is too strong when the vertices are far
13Advantages Relatively simple & easy to implement Good flexibility Heuristic improvements easily addedHandle domain constraintsSmooth evolution of the drawing into the final configuration helps preserving the user’s mental mapCan be extended to 3DOften able to display symmetriesWorks well in practice for small graphs with regular structureShow some clustering structure
14Disadvantages Slow running time Results are acceptable, but not brilliantFew theoretical results on the quality of the drawings producedDifficult to extend to orthogonal & polyline drawingsLimited constraint satisfaction capability
152. Barycenter Method [Tutte60,63] Use springs with natural length 0, and attractive force proportional to the lengthPin down the vertices of the external face to form a given convex polygon (position constraint)Let the system go…
16luv = 0, k1u,v = 1, no electrical force Trivial solution pv = 0 for all v
17Where deg(v) is the degree of v, N0(v): set of fixed neighbor of v; Partition V into two sets: fixed vertex (at least 3, nailed down) and free vertexTo achieve equilibrium, choose pv so that Fx(v) = 0 for all free vertices;Similarly, choose pv so that Fy(v) = 0 for all free vertices.Therefore,Where deg(v) is the degree of v,N0(v): set of fixed neighbor of v;N1(v): set of free neighbor of v.
18The equations are linear. The number of equations and the number of unknownvariables are both equal to the number of free vertices.Solving them equals to placing each free vertex at the barycenter of its neighbours.So the name ‘barycenter method’.
19Algorithm Barycenter-Draw Input: partition of V, V0: at least 3 fixed verticesV1: set of free verticesStrictly convex polygon P with V0 verticesOutput: position pv1. Place each vertex u in V0 at a vertex of P and each free vertex at the origin2. RepeatFor each free vertex v doxv = S xudeg(v)yv = S yuUntil xv and yv converge for all free vertices v_____E(u,v)_____E(u,v)
213. Force Simulating Graph Theoretic Distance [Kamada Kawai 89] Model graph-theoretic distance with Euclidean distanceThe forces try to place vertices so that their geometric distance in the drawing is proportional to their graph theoretic distanceFor each pair of vertices (u, v), δ(u,v) is the graph-theoretic distance between them;Number of edges on a shortest path between u and v.Aim: find a drawing such that for each pair of vertices, the Euclidean distance d(pu, pv) is approximately proportional to δ(u,v)i.e. system has a force proportional to d(pu, pv) - d(u,v)
22Potential energy in the spring between u and v: ½ kuv (d(pu, pv) - d(u,v))2Choose stiffness parameter: springs between vertices that have small graph theoretic distance are strongerkuv = k / d(u,v)2Thus, energy in (u, v): h = k/2 (d(pu, pv)/d(u,v) – 1)2Energy in the whole drawing is the sum of individual energies:h = k/2 S (d(pu, pv)/d(u,v) – 1)2Algorithm seek a position pv=(xv, yv), for each vertex v to minimize hh / xv = 0, h / yv = 0, v V : non linear equationPartial derivatives with respect to each xv and yv are zeroEu v
23However, iterative approach can solve the equation At each step, a vertex is moved to a position that minimizes energy, while other vertices remain fixedChoose a vertex that has the largest force acting on it, that isis maximized for all v in V.
244. Magnetic Fields [SM95] Variations: 3 types of magnetic fields Some or all of the springs are magnetizedThere is a global magnetic field that acts on the springMagnetic field can be used to control the orientation of edges3 types of magnetic fieldsParallel: all magnetic forces operate in the same directionConcentric: the force operates in concentric circlesRadial: the forces operate radially outward from a point
25The three basic magnetic fields can be combined encourage orthogonal edges with a combination of parallel forces in the horizontal & vertical directionsThe springs can be magnetized in two ways:Unidirectional: the spring tends to align with direction of the magnetic fieldBidirectional: the spring tends to align with the magnetic field, but in either directionA spring may not be magnetized at all
26The magnetic field induces a torsion or rotational force on the magnetic springs. For a unidirectionally magnetized spring representing (u,v), the force is proportional to d(pu, pv) aq bd(pu, pv): Euclidean distance between pu and pvq: angle between the magnetic field and the line from pu to pva and b are constantθUnidirectional magnetic springDirection of the magnetic field
27The magnetic forces are combined with the spring & electrical force Algorithm to find equilibrium:initially random position and at each iteration move the vertex to lower energy positionCan handle directed graphs (unidirectional springs with one of the 3 fields)arcs point downward: downward parallel fieldOutward: radial fieldCounterclockwise: concentric fieldCan be applied to orthogonal drawings: combined vertical & horizontal field with bidirectional springsApplied with success to mixed graphs (graph with both directed & undirected edges)
28Two Examples Vertical and horizontal magnetic field Vertical magnetic fieldVertical and horizontal magnetic field
295. General Energy Function Most of the energy function h is a simple continuous function of the location of vertices. However, many of aesthetic criteria are not continuousIncluding discrete energy functionThe number of edge crossingsThe number of horizontal & vertical edgesThe number of bends in edgesgeneral energy functionh = l1 h1 + l2 h2 + … + lk hkhi : a measure for an aesthetic criterionMay include spring, electrical, magnetic energy
30[Davidson & Harel 96] energy function for straight line drawings = l1 h1 + l2 h2 + l3 h3 + l4 h4h1 = Su,v V (1/ (d(pu, pv))2 ) : similar to electrical repulsion (vertices do not come too close together)ru, lu, tu, bu: Euclidean distance between vertex u and the four side lines of rectangular area (vertices do not come too close to the border of the screen)h3 = S(u,v) E (d(pu, pv))2 : edges do not become too longh4 : the number of edge crossings in the drawing
31Flexibility ensures popularity Flexibility of general energy function: allow variety of aesthetics by adjusting li[BBS97]: user can choose & adjust system parameters[Mendonca94]: how these coefficients can be automatically adjusted to user’s preferenceMain problem: computationally expensive to find a minimum energy state (very slow)simulated annealing [DH96]…..Genetic algorithm [BBS97]…Flexibility ensures popularity
32[Davidson & Harel 96] simulated annealing Energy function takes into account vertex distribution, edge-lengths, and edge-crossingsGiven drawing region acts as wallSimulated annealing: flexible optimization techniqueEfficiency: very slow30 nodes and 50 edgesAble to deal with optimization problem in a discrete configuration spaceAim: to minimize (or maximize) the cost function
346. ConstraintsForce-directed methods can be extended to support several types of constraints6.1. Position constraints6.2. Fixed-subgraph constraints6.3. Constraints that can be expressed by force or energy function
356.1. Position constraintsassign to a vertex a topologically connected region where the vertex should remainSingle point: a vertex nail down at a specific locationHorizontal line: group of vertices arranged on a layerA circle: set of vertices to be restricted to a distinct region[Ostry96]: constraints vertices to curves and 3D surfaces
366.2. Fixed subgraph constraints Assign prescribed drawing to a subgraph .May be translated or rotated, but not deformed.Considering the subgraph as a rigid body.For example, barycenter method is a force-directed method that constrains a set of vertices (fixed external vertices) to a polygon.
376.3. Constraints expressed by forces Orientation of directed edges: magnetic springGeometric clustering of special set of verticesAlignment of verticesClustering can be achieved [ECH97]For each set C of vertices, add a dummy attractor vertex vCAdd attractive forces between an attractor vC and each vertex in C.Add repulsive forces between pairs of attractors and between attractors and vertices not in any cluster.
38Remark Improve the efficiency [BHR96] empirical analysis [FR91]: amenable force functions[FLM95, Tun92]: use randomization in S.A.[Ost96]: the equations describing the minimal energy states are stiff for some graphs of low connectivity.[HS95]: use combinatorial preprocessing step, good initial layout[BHR96] empirical analysis[FR91],[KK89],[DH96],[Tun92],[FLM95]No winner, try several methods and then choose the best
39Faster Spring methodsProblem: Spring methods are too slow for huge graphs1. pu = some initial position for each node u;2. Repeat2.1 Fu := 0 for each node u;2.2 For each pair u,v of nodes2.2.1 calculate the force fuv between u and v;2.2.2 Fu += fuv;2.2.3 Fv += fuv;2.3 For each node u, pu += eFu;Until pu converges for all u;Computingthe forcestakesquadratictime
40FADE [Quigley & Eades01] It is feasible to use a spring method, thena geometric clustering methodto obtain a good graph clustering.ClusteredGraphGraph
41Quadtree A tree data structure Each internal node has up to four children.Most often used to partition a two dimensionalRecursively subdividing it into four quadrants or regions.Stops when each quadrant contains one point.In general, recursively partition the space into 2d subspace equally, where d is the dimensionKnown as Octree for 3D
42Barnes-Hutt method A method of computing forces between stars. root Use Quadtree to cluster the starsUse the forces between the clusters to approximate the forces between individual stars.rootaTLBRcbBLabddcefef
43Barnes-Hutt methodThe contents of a subtree of can be approximated by a mass at the centroid.rootasTLBRcbsBLabddcefef
44Barnes-Hutt methodThe force that the subtree s exerts on the star x can approximate the sum of the forces that the nodes in s exert on x.rootaTLBRcsbsBLabddcefef
45FADETo compute the force on star x, we proceed from the root toward the leaves.ComputeForce(star x; treenode t)If the approximation is goodthen return the approximation;else return SsComputeForce(x, s), where the sum is over all children s of t.A simple method can be used to determine whether the approximation is good; it depends on the mass of nodes and the distance between x and s.w(t) / d(x,t) < c,w(t) the width of t; d(x,t) the distance between x and t, and c is a constant.
46FADE The Barnes-Hutt method is faster than the usual spring algorithm. 1. px = some initial position for each star x;2. Repeat2.1 Build the quadtree;2.2 Foreach star xComputeForce(x,root);2.3 Foreach star x, px += eFx;Until px converges for all x;In practice,computing all theforces takesO(n log n) time
47FADE 1. pu = some initial position for each node u; 2. Repeat At each iteration, the node movements introduced in the previous step improves the quadtree clusteringMakes the quadtre clustering (a geometric clustering) better reflects the graph clustering.1. pu = some initial position for each node u;2. Repeat2.1 Build the quadtree;2.2 Foreach node uComputeForce(u,root);2.3 Foreach node u, pu += eFu;Until pu converges for all u;Some nodes migrate from one cluster to the next
48FADE Observations This means that we can: The Quadtree provides a clustering of the dataIf the data is well clustered, then BH runs fasterThe approximated force is then more accurateThe spring algorithm tends to cluster the dataThis means that we can:Use Barnes-Hutt to compute the clusters as well as the drawingUse the quadtree as the clustering for the clustered graph
49Experimental Result Visual abstraction The error is the difference between the approximated force vector and the original oneVisual abstraction