EuroCG 2016, Lugano, Switzerland, March 30–April 1, 2016

A New Modular Parametric Search Framework

Christian Knauer∗ David K¨ubel† Fabian Stehn∗

Abstract values, representing k comparisons to λopt. Exploiting the monotonicity of P , all comparisons of a batch can Parametric search is a technique to develop efficient be resolved by O (log k) calls to As. After resolving deterministic for optimization problems. a batch of critical values, each process can continue The strategy requires an for the decision until a new batch of k comparisons is collected and variant of the problem at hand. Given this decision resolved in the same way. algorithm, the strategy can be seen as a black box Throughout this process, an I = (λ−,λ+] is that does not really exploit characteristics of the un- maintained, where λ− is the largest value encountered derlying problem: It computes an optimal solution by so far such that dec (λ−) = false and λ+ is the keeping track of the values that appear in comparisons P smallest value encountered so far with dec (λ+) = of the decision algorithm. P true; this implies that λ ∈ I. Through the course In this abstract, we present a new parametric search opt of this process, at least one instance of the parallel framework written in Java. We show how parametric algorithm A has to carry out a comparison with the search based algorithms can be implemented and ex- p actual optimal value λ , which implies that λ will plored with the framework. It allows to quickly spec- opt opt appear as a critical value. Since P is a minimization ify or change crucial functionalities which influence problem, we have that λ = λ+ after all processes of the specific behaviour (and performance) of the re- opt A terminated. This gives a combined minimization sulting optimization algorithm. We focus on a trans- p algorithm C that computes λ in O(T ·(k+T ·log k)) parent, simple-to-use, and modular design, and dis- opt p s deterministic time; see [6] for details. cuss the implementation of a specific algorithm that computes an optimal shortcut of a polygonal curve.

1 Introduction 1.1 Applications

Parametric search is a powerful and fairly general The technique has been applied to a wide range of method to compute the (exact) optimal solution λopt problems. In the field of , of an optimization problem P in one variable. Let P e.g., the technique has been used to compute the be a minimization problem whose objective function Fr´echet Distance [2] between two polygonal curves. is monotone, that is, for the decision variant decP of Recently, Große et al. [4] showed how to efficiently P there is a value λopt such that decP (λ) = true ⇔ compute a diameter-optimal shortcut between ver- λ ≥ λopt. In oder to apply Megiddo’s [6] parametric tices of a polygonal curve. Agarwal et al. [1] present search technique, two ingredients are required: several applications in context of geometric optimiza- tion. 1. A sequential algorithm As that solves decP for any value λ in Ts time, and 2. a parallel algorithm Ap using k processes, solving decP for an unknown value of λopt in Tp time. 1.2 Related work

Ap is an algorithm that uses k (independent) pro- cesses whose control-flow depends on the outcome of The first implementations of parametric search algo- comparisons. Each comparison can be resolved by re- rithms are due to Toledo [9] (solving extremal lating a value that is derived from the input to the placement problems) and Schwerdt et al. [8] (comput- (unknown) value of λopt. The basic idea is to fol- ing the diameter of moving points) roughly twenty low the control-flow of each process until it requires years ago. Van Oostrum and Veltkamp [7] were the the solution to such a comparison and to collect these first to provide a general framework, written in C++. comparisons in batches (these collected values are usu- Their framework includes a detailed documentation as ally called critical values). A batch hence consists of k well as two reference implementations to compute the Median of Lines [6] and the Fr´echetdistance between ∗ Institut f¨ur Informatik, Universit¨at Bayreuth, two polygonal curves [2]. They experimented with dif- {christian.knauer, fabian.stehn}@uni-bayreuth.de, †Institut f¨urInformatik, Abteilung I, Universit¨at Bonn, ferent sorting algorithms and showed that [email protected] can replace a parallel in practice.

This is an extended abstract of a presentation given at EuroCG 2016. It has been made public for the benefit of the community and should be considered a preprint rather than a formally reviewed paper. Thus, this work is expected to appear in a conference with formal proceedings and/or in a journal. 32nd European Workshop on Computational Geometry, 2016

1.3 Contribution backs: It forces the developer to scatter code to sched- uled methods which makes the parallel algorithm even In Chapter 2, we present a new general parametric harder to read, understand or debug. Realizing com- search framework. Two (geometric) algorithms that plex parallel algorithms is considerably more involved have been realized in this framework are discussed in with this design. Moreover, the developer has no Chapter 3. chance to control or influence the parallel steps and The framework can be used as a black box to imple- the evaluation of batches separately. ment efficient optimization algorithms (based on de- With our framework we offer the chance to hook cision algorithms) with minimal adaptation effort for into the scheduling or the handling of critical val- the task at hand. It is designed to provide the capabil- ues, if desired or necessary. Both frameworks share ity to easily exchange not only the sorting algorithm (conceptually) similar components, e.g., a scheduler, (a central component of the parametric search tech- processes or a decision algorithm. However, the de- nique) but also the strategy that is used to solve the sign of our framework meets additional requirements. comparisons of a batch, or the scheduler that man- The most striking difference is that we separate the ages the (simulated) parallel execution of the individ- scheduling component from the management of crit- ual processes. Standard performance enhancements, ical values. We provide ready-to-use functionalities such as “Cole’s trick” [3] are built in along with other to reduce the implementation effort; c.f. Section 2.2. optimizations. Several parameters can be used to fine- Among these are different strategies to resolve criti- tune the performance of the final algorithm. cal values of a batch which can be easily exchanged to From this point of view, our approach is twofold: study their impact on the overall performance. This On the one hand, the framework can be used as provides an insight into how critical values are pro- a black box that merely requires to provide an im- cessed in a certain application and may reveal char- plementation of the corresponding decision algorithm acteristics of the underlying problem. and parts of Ap that determine and organize critical The core components of the framework have already values. On the other hand, it allows a deeper look been released online [10]. The code of the whole para- “under the hood” of the general mechanism of para- metric search framework together with the demo ap- metric search in order to study, analyse and compare plications will be released as a part of a larger frame- an algorithm and to gain deeper insight into the orig- work within this year. inal problem. In Chapter 3, we discuss how a recent algorithm for computing shortcuts has been realized with the 2.1 Design Choices framework, and we show how the framework allows to Our framework is written in Java and consists of four study the effect of optimization strategies on the ac- components. A single responsibility is assigned to tual computation times. Numerical effects which may each component in order to (re-)use or interchange arise in practical applications are discussed briefly. them independently. In the following, we briefly de- scribe these components and their role within the 2 The Framework framework. One component is the serial decision algorithm As In this section, we describe the general structure of which has to be provided by the developer. The im- our framework and discuss where and why it differs plementation has to support a method to decide decP from the reference framework by van Oostrum et al. for any given value λ ≥ 0. The outcome of a call to [7]. To keep the implementation effort as small as pos- As is a boolean value; either true (if λ ≥ λopt) or sible, van Oostrum et al. identify essential parts of the false (if λ < λopt). technique so that certain components can be reused The remaining three components constitute the in different implementations. Their framework pro- parallel algorithm Ap. We aim to restrict the ac- vides Quicksort and Bitonicsort together with an au- cess to the decision algorithm during the execution tomated organization of the comparisons in a batch. of Ap. Whenever decP needs to be solved for a con- The framework encapsulates and hides the scheduling crete value λ, the component Oracle has to be asked: of comparisons and the management of critical val- In contrast to As, the oracle may also return the value ues. In case that Ap is a parallel sorting algorithm, unknown, implying that λ ∈ I, which forces the call- it is certainly a benefit to hide all this complexity ing process to wait. This allows us to delay a single which reduces the implementation effort considerably. evaluation of the decision problem and to batch sev- If, however, Ap is not a sorting algorithm, the de- eral critical values. Of course, at some points during veloper has to use “lower-level facilities for batching the execution of Ap it will be necessary to evaluate comparisons and suspending/resuming computation” the decision problem for (some of) the batched values, instead which enforces the use of a rigid mechanism e.g., when Ap has to continue with its next parallel specified by their framework. This has certain draw- step. At this point, the oracle will apply a strategy EuroCG 2016, Lugano, Switzerland, March 30–April 1, 2016

to resolve the comparisons of the current batch. 3 Computing Optimal Shortcuts The flow of control of the parallel algorithm branches at certain points. This is realized by in- In this section we briefly discuss two proof-of-concept stances of Process, which allows for pausing and re- implementations. Due to space limitations, we merely suming, depending on the outcome to the calls to the state the first implementation, the computation of the oracle. Fr´echet Distance between two polygonal curves (c.f. The component that manages the (virtual) paral- [2]). For this implementation, Bitonicsort has been chosen to realize the parallel part of the algorithm; lel execution of Ap is the Scheduler: It assures that the oracle and all processes are triggered when nec- the corresponding decision problem was solved in a essary. After a certain number of parallel steps, all standard fashion via the use of free space diagrams. processes will terminate; as soon as the last processes The initial motivation that led to the design of becomes inactive, the scheduler and with it the entire this new framework is the problem of computing a algorithm will terminate. diameter-optimal shortcut of a polygonal curve: A shortcut (a non-edge between two vertices of the path) is considered diameter-optimal if no other shortcut 2.2 Functionality and Oracle Strategies added to the curve results in a graph with smaller di- ameter. Große et al. [4] present a parametric search With the framework we provide a parallel sorting al- algorithm for this problem. In contrast to the com- gorithm based on a bitonic sorting network. It can be putation of the Fr´echet distance, their approach does used to implement sorting based parametric search not involve a sorting algorithm for Ap. algorithms. The Scheduler is realized by a simple serial round-robin strategy. To experiment with dif- Some Details ferent strategies of the Oracle component, we imple- mented the following strategies: Let λopt denote the diameter induced by an optimal shortcut. The main idea of the concrete decision al- 1. Brute force. This strategy does not store λ and gorithm As is to check for every possible start vertex solves the decision problem, at once. We do not s of the shortcut whether there exists a feasible end maintain I. Consequently every request causes vertex e. The vertex range of candidates for e is effi- an evaluation of As. ciently restricted through binary searches. As returns 2. Monotonicity. This strategy only exploits the true exactly if a feasible pair (s,e) was found. monotonicity of decP : The decision problem is Große et al. suggest to implement the decision algo- only evaluated if λ ∈ I. Otherwise, the outcome rithm in a generic and parallel fashion to get Ap. This is determined according to the position of λ ac- implies that each comparison in a binary search has cording to I in constant time. to be deduced from the result of the decision problem 3. Parametric Search. If λ lies in I, we store it in at a critical value. For every candidate start vertex a list and return unknown. When the oracle is s, the search for a feasible e is independent and can triggered via the method resolveCollectedValues, be assigned to a separate parallel process. Conse- all stored values are resolved in a binary search quently, Cole’s weighting scheme [3] can be applied to fashion as suggested by Megiddo [6]. reduce the theoretical worst-case running time by a 4. Cole (unweighted). In contrast to the previous log-factor. 10 strategy, the oracle evaluates decP only for the We generated 1000 polygonal curves of 2 vertices median the of stored values. Afterwards, half each, where the coordinates of the vertices were cho- of the critical values can be resolved in constant sen uniformly at random within a square. For each time. The corresponding processes are called to curve, we computed the diameter-optimal shortcut us- produce additional critical values. ing each of the five oracle strategies discussed above. 5. Cole (weighted). To guarantee that no processes As stated earlier, the number of calls to As is used has to wait for a result for too long, a critical to measure the performance of the individual strate- value is stored together with a certain weight. gies. Table 1 lists the outcome of the experiments, In contrast to the previous strategy, the decision ordered by oracle strategy as discussed in Section 2.2. problem is now evaluated for the weighted half of As expected, all strategies but the first (brute force), the stored values and not just for the median. require a small number of evaluations of As. With regard to the average number of calls, Strategy 2 per- Depending on the specific application at hand, other forms best by only exploiting the monotonicity of the strategies to handle and resolve batches can be real- decision problem. As the last row of Table 1 reveals, ized or combined with these strategies. As a measure- Strategy 5, known as “Cole’s trick” (which reduces ment for the performance we suggest to look at the the theoretical worst-case runtime by a log-factor), re- total number of evaluations of As. quires more calls to the decision problem than Strate- 32nd European Workshop on Computational Geometry, 2016

Strategy of the oracle 4 Conclusion & future work 1 2 3 4 5 With the presented framework it is possible to take µ ∼ 13,872 19.43 19.66 20.32 20.05 a closer look into the details and the specific be- σ ∼ 658 3.88 2.28 1.94 2.96 haviour of parametric search algorithms. Different oracle strategies allow for quantified experiments un- max 18,538 36 26 25 59 der different optimization variants with no additional min 12,965 12 12 12 12 implementation effort. The outcome of these exper- iments might lead to a deeper understanding of the Table 1: Experimental results by oracle strategy. µ: structure of the underlying problem. average number of calls to A ; σ standard deviation; s Future versions of the framework might include the max (min): maximum (minimum) number of calls option to trace and visualize critical values through- to A . s out the parallel steps. In case of the shortcut problem, this would help to study the distribution of critical values around λopt and to understand under which gies 2 − 4 for some instances. conditions which parallel step calls As with the opti- The fact that Strategy 2 performs well is probably mal value. due to the order in which critical values are computed by Ap. All distances from the first vertex to other References vertices along the curve are critical values of the first batch (see [4] for details). Consequently, the interval [1] Pankaj K. Agarwal, Micha Sharir and Sivan Toledo. I is already narrowed down right after the first batch Applications of Parametric Searching in Geometric has been resolved. The higher number of evaluations Optimization, J. of Algorithms 17(3):292–318, 1994. for Cole’s weighing scheme in some instances might be [2] Helmut Alt and Michael Godau. Computing the due to the fact that this strategy calls As for values Fr´echet distance between two polygonal curves. Int. of λ that are far from λopt, as critical values of previ- J. of Comp. Geom. & App. 5:75–91, 1995. ous parallel steps are favoured over critical values of [3] Richard Cole. Slowing down sorting networks to ob- processes that have proceeded further. tain faster sorting algorithms. J. ACM 34(1):200–208, It turns out that for the problem of computing an 1987. optimal shortcut, the critical values of the first batch [4] Ulrike Große, Joachim Gudmundsson, Christian are the key to achieve a small overall number of eval- Knauer, Michiel H. M. Smid and Fabian Stehn. uations. The order in which critical values are com- Fast Algorithms for Diameter-Optimally Augmenting puted and resolved plays an important role for the Paths. Proceedings, Part I, ICALP (1) 2015: 678– actual performance of a parametric search algorithm. 688. [5] Prosenjit Gupta, Ravi Janardan and Michiel H. M. Smid. Fast Algorithms for Collision and Proximity Problems Involving Moving Geometric Objects. Com- 3.1 Numerical Issues put. Geom. 6: 371-391, 1996. As for the built-in components of our framework, [6] Nimrod Megiddo. Applying Parallel Computation Al- gorithms in the Design of Serial Algorithms. J. ACM critical values are currently represented as double- 30(4): 852–865, 1983. precision numbers. The following problem can arise when representing critical values as finite-precision [7] Ren´evan Oostrum and Remco C. Veltkamp. Para- floats: The floating point representation of the op- metric search made practical. Comput. Geom. 28(2- 3): 75–88, 2004. timal solution λopt is slightly smaller than the ac- [8] J¨org Schwerdt, Michiel H. M. Smid and Stefan tual value of λopt. As a consequence, As rejects this value and it will be stored as the lower bound of Schirra. Computing the Minimum Diameter for Mov- I = (λ−,λ+]. If the algorithm outputs λ+ as sug- ing Points: An Exact Implementation Using Para- metric Search. Proceedings of the Thirteenth Annual gested above, the error can be huge. To address this Symposium on Computational Geometry, pages 466- problem, we can perform a final call to As with the 468, 1997. center of I. If the center is a valid solution, we con- clude that λ− is closer to λ than λ+. [9] Sivan Toledo. Extremal Polygon Containment Prob- opt lems and other issues in parametric searching. Mas- We are currently working on a solution to integrate ter’s Thesis, Tel-Aviv University, 1991. and provide types that allow comparisons with arbi- [10] Source Code: Modular Parametric Search Frame- trary precision. Note that the general framework does work (in Java) https://[email protected]/- not depend on specific numerical data-types. The davidkuebel/modularparametricsearchframework.git specification and treatment of critical values has to be handled by the developer in a concrete application.