def naiveDivideConquer(points): if len(points) <= 3: return brute.bruteForce(points); middle = int(len(points)/2) (bestDistanceLeft, bestPairsLeft) = naiveDivideConquer(points[:middle]) (bestDistanceRight, bestPairsright) = naiveDivideConquer(points[middle+1:]) (minDistance, minPairs) = general.getDelta(bestDistanceLeft, bestPairsLeft, bestDistanceRight, bestPairsright) hotStripper = general.getPntsInDelta(minDistance, points) stripSortedByY = general.sortY(hotStripper) (stripMinDistance , stripMinPairs) = general.GetShortestInSortedStrip(stripSortedByY) return general.getDelta(minDistance, minPairs, stripMinDistance , stripMinPairs)
def EnhancedDivideConquer(points, sortedByY): if len(points) <= 3: return brute.bruteForce(points) ###################################################### middle = int(len(points) / 2) midVal = points[middle][0] sortedByYLeft = [] sortedByYRight = [] for x in sortedByY: if x[0] <= midVal: sortedByYLeft.append(x) else: sortedByYRight.append(x) ###################################################### (bestDistanceLeft, bestPairsLeft) = EnhancedDivideConquer(points[:middle], sortedByYLeft) (bestDistanceRight, bestPairsright) = EnhancedDivideConquer(points[middle + 1:], sortedByYRight) (minDistance, minPairs) = general.getDelta(bestDistanceLeft, bestPairsLeft, bestDistanceRight, bestPairsright) #hotStripper = general.getPntsInDelta(minDistance, points) stripSortedByY = [] for x in sortedByY: if x[0] >= (midVal - minDistance) and x[0] <= (midVal + minDistance): stripSortedByY.append(x) (stripMinDistance, stripMinPairs) = general.GetShortestInSortedStrip(stripSortedByY) return general.getDelta(minDistance, minPairs, stripMinDistance, stripMinPairs)