• Keine Ergebnisse gefunden

Routing Algorithms

6.1 Bezier Routing

The basic idea of this algorithm is to draw a connection just like a person would do it on a piece of paper: Whenever a straight line is possible without any node intersections, just draw it. Otherwise draw a curve with as few direction changes as possible avoiding obstacles. This sounds quite easy to do for a person, for a computer it is however quite a complicated task. The following subsections describe the algorithm step by step.

6.1.1 Intial Routing

The algorithm works on a polyline which starts as a straight line from the start node to the end node and is improved stepwise. Figure 6.1 shows the initial routing. As the example of this chapter, the connection between B0 and B1 is illustrated.

Figure 6.1: Initial routing.

If there are no intersections between nodes and the polyline, the algorithm ends here and sets the straight line as the routing.

6.1.2 Evade Obstacles

Now the algorithm iteratively tries to avoid intersections between the polyline and nodes.

Currently there is an intersection with B2 and B3. An additional bendpoint is inserted to avoid the intersection with B2, the resulting polyline is shown in Figure 6.2.

Figure 6.2: After first iteration step.

Chapter 6. Routing Algorithms

In the example, after evading blockB2, there is still an intersection between the poly-line and B3. Therefore the algorithm will insert additional intermediate points and the resulting line will avoid intersecting B3 too (see Figure 6.3).

Figure 6.3: After second iteration step.

Points are added to the polyline until there are no more intersections or a fixed num-ber of iterations is exceeded. The second case was introduced to avoid endless routing calculcations and to improve the performance. In most cases, ten intersections will not be exceeded. But how does the algorithm choose the additional points for avoiding in-tersections? Figure 6.4 shows all possibilities tried by this specific implementation. The rectangle in the middle stands for the obstacle that must be avoided. First, nine single points are sampled (left part of the figure), additionally four possibilities which add two points (right part) are tested.

Figure 6.4: All possible evasion points.

For every possible evasion the costs are calculated. In this implementation, this is equal to the number of intersections between the polyline and any other line or node. As an additional criteria, the angles between the introduced points and their neighbors are taken into account. Note that customizing this cost function greatly affects the quality of the result. In Figure 6.3 for example the cost function is responsible that two points to the right of B3 are inserted. Inserting two points to the left of B3 would lead to an intersection with the edge going from B2 to B3.

When counting the intersections with other edges, only the intersections with their approximation, a straight line between start and end node, are counted. This is done for performance reasons and because certain connections may be still unrouted while processing the current edge.

Chapter 6. Routing Algorithms

Initial line First possibility Second possibility

Figure 6.5: Two examples for adding intermediate points.

Figure 6.5 shows an example line and two possibilities to add extra points. In this case the algorithm selects the second possibility because in contrary to the first one the resulting polyline does not intersect the node.

6.1.3 Simplify Polygon

After evading obstacles many times, the resulting line can be more complex than necessary.

Even in our simple example, after two iterations, the polyline contains one needless point.

This is why there is an additional simplification step.

In this part of the algorithm, every possible pair of non-succeeding points is tested.

Whenever there are no intersections between those points, all intermediate points can be deleted safely without degrading the result.

Figure 6.6: After simplification step.

Figure 6.6 shows the polyline after the simplification step. The point next to B2 was removed. Now the line is simpler and does not have a bend to the left followed by a bend to the right.

6.1.4 Create Curves

Finally many intermediate points are added to make the polyline look like a smooth curve.

Lots of graph visualization programs use b-splines, which approximate polylines. For this

Chapter 6. Routing Algorithms

algorithm it is however important that the curve goes through all points, otherwise many additional intersections could be introduced in this step. For this reason cubic Bezier curves are the better choice in this case. The equation for the approximation points of the cubic Bezier curve is as follows:

C(t) =P0(1−t)3 + 3P1t(1−t)2+ 3P2t2(1−t) +P3t3

In addition to the two endpoints P0 and P3, two interpolation points P1 and P2 are needed. Figure 6.7 shows how the application calculates those two points. For the whole curve to look smooth, it is important that each point and its two neighboring interpolation points lie exactly on a straight line.

P0

Figure 6.7: Calculating the two interpolation points.

This is ensured by putting the interpolation point ofP0 for example on a line which is parallel to the line going through the previous and the next point in the polyline (Pbef ore and P3). The line itself has to go through P0, see the second image of Figure 6.7 for the result. The offset between P0 and its interpolation pointP1 is calculated by multiplying the offset between P0 and P3 with a constant factor. A value of 0.3 for the factor seems to be appropriate. Figure 6.8 shows the example control flow graph after the Bezier algorithm made the polyline between B0 and B1 look smooth.

6.1.5 Results

This algorithm leads to good results in the common case, especially for small to medium sized methods. Very important is a good heuristic for the cost function to choose the right points when evading an obstacle.

Chapter 6. Routing Algorithms

Figure 6.8: After Bezier creation.