昨天被一位老師提問了這個問題,一時沒有回答上來,后經過一番查找資料,在這里做一下筆記。
問題描述
設有兩個有限點集$u_{i}\in V_{1} (1\leq i\leq m)$和$v_{j}\in V_{2} (1\leq j\leq n)$,則兩點集中最短距離定義為$d_{min}(V_{1}, V_{2})$=$min$ $d_{u_{i}, v_{j}}$。
問題解法1:窮舉求解
直接容易想到的解法,即計算出兩點集所有點之間的距離,並尋找最小的那個。偽代碼如下:
| Algorithm 1: Brute Force Approach |
| Input: The node set $V_{1}$ and $V_{2}$ Output: The $d_{min}(V_{1}, V_{2})$ 1. for $i$ =1 to $m$ 2. for $j$ =1 to $n$ 3. Compute the distance between $u_{i}$ and $v_{j}$ 4. end for 5. end for 6. Determine the minimum distance computed along line 1 to line 5 |
易知該算法復雜度為O$(mn)$。這顯然不是一個令老師滿意的結果,於是考慮一個非窮舉的解法。
問題解法2:基於Gabriel圖的非窮舉解
經過查找資料,發現文獻"Optimal Algorithms for Computing the Minimum Distance Between Two Finite Planar Sets"(其PDF的閱讀順序應為從最后一頁向上閱讀)對此類問題提出了求解方法。原文敘述較簡略,本文在此做詳細一些的解釋。
先對兩個點集的並集做Delaunay三角剖分,然后根據Delaunay三角圖得到其對偶的Voronoi圖;若Delaunay三角圖的某條邊與其對應的Voronoi圖的邊交叉,則將其置為Gabriel圖的一條邊,如此得到Gabriel圖;尋找Gabriel圖中所有兩端點分別屬於兩不同點集的邊,並計算該邊的兩端點的距離;所有符合條件的距離中最小的那個即為所求。偽代碼如下:
| Algorithm 2: Gabriel Graph based Approach |
| Input: The node set $V_{1}$ and $V_{2}$ Output: The $d_{min}(V_{1}, V_{2})$ 01. Compute the Delaunay triangulation $DT(V)$ of $V=V_{1}\cup V_{2}$ 02. Compute the Voronoi diagram $VD(V)$ of $V$ via the Delaunay triangulation 03. if an edge in the $DT(V)$ intersects its corresponding $VD(V)$ edge 04. Put it into the Gabriel graph $GP(V)$ 05. end if 06. for each edge in the $GP(V)$ 07. if its one node $n_{i}\in V_{1}$ and another node $n_{j}\in V_{2}$ 08. Compute the distance $d_{ij}$ between $n_{i}$ and $n_{j}$ 09. end if 10. end for 11. Determine the minimum distance computed along line 6 to line 10 |
根據該文獻,算法復雜度為O$(m+n)log(mn)$,可等價為O$(n)log(n)$,是一種更為高效的算法。當然在$m$和$n$較小時,窮舉解法的表現更好。
參考
關於該解法所提到的若干概念,這里給出一些參考鏈接(不保證原鏈接所述內容的准確性),僅供參考。
- Delaunay三角剖分:可以參考“三角剖分算法(delaunay)”這篇博文;
- Voronoi圖:可以參考“泰森多邊形(Voronoi圖)的matlab繪制”這篇博文;
- Gabriel圖:可以參考“Gabriel 圖 (gabriel gragh)”這篇博文。
