1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#from fastpair import FastPair
import random
import time
import closest_pair_of_points
import shortest_distance2
def rand_tuple():
return tuple([round(random.uniform(540000.0, 580000.0), 3),
round(random.uniform(3610000.00, 3650000.0), 3)] )
import matplotlib.pyplot as plt
tps1 = time.clock()
points = [rand_tuple() for _ in range(10000)] # 2D points
tps2 = time.clock()
print('temps de génération des points : {:.3}'.format(tps2-tps1))
tps1 = time.clock()
points.sort() #sorting points
p,q = points[0],points[1] #taking first p,q
m=shortest_distance2.lenght (points[0],points[1]) #and first distance (as current minimum)
pt,pt2,distance= shortest_distance2.search_pair(points,p,q,m) #finding and printing results
tps2 = time.clock()
print('algo search_pair : {:.3} s - dmin : {}'.format(tps2-tps1, distance))
tps1 = time.clock()
distance2 = closest_pair_of_points.closest_pair_of_points(points, len(points))
tps2 = time.clock()
print('algo closest_pair_of_points : {:.3} s - dmin : {}'.format(tps2-tps1, distance2))
#tps1 = time.clock()
#fp = FastPair().build(points)
#dist, (a, b) = fp.closest_pair()
#tps2 = time.clock()
#print('algo fast_pair : {:.3} s - dmin : {}'.format(tps2-tps1, dist))
plt.figure()
plt.scatter(*zip(*points))
plt.scatter(*zip(pt, pt2), color="red")
plt.title("Points : {:},{} \n Distance : {:.2} .".format(pt,pt2, distance))
plt.show() |