Skip to content

Instantly share code, notes, and snippets.

@BrendanBenshoof
Created December 10, 2015 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrendanBenshoof/af5ddae03ac04784b2ff to your computer and use it in GitHub Desktop.
Save BrendanBenshoof/af5ddae03ac04784b2ff to your computer and use it in GitHub Desktop.
Implementation of DGVH algorithm
def getApproxDelaunayPeers(candidates,center):
"""
This is the Distrubuted Greedy Voronoi Heuristic.
center is some point in a space (we don't really care which) and the
heuristic decides which of the candidates are members of Delaunay
Triangulations with the center point.
This allows a node located at center to quickly figure out its
Voronoi region.
Error rate: Our heuristic underestimates approximately edge per node
"""
if len(candidates) < 2:
return candidates
sortedCandidates = sorted(candidates,key=lambda x: distance(x,center))
peers = [sortedCandidates[0]] #create a new list, initialized closest peer
sortedCandidates = sortedCandidates[1:]
for c in sortedCandidates:
accept = True
for p in peers:
if distance(c,p) < distance(c,center): # if occluded by previous peer
accept = False
break
if accept:
peers.append(c)
return peers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment