-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
81 lines (68 loc) · 2.63 KB
/
main.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from time import time
from datasets import square, circle, triangle, hull
import graham_scan
import jarvis_march
def add(algorithm, points):
for p in points:
algorithm.add(p)
def run_algorithms(dataset, size, show_progress):
graham = graham_scan.GrahamScan()
jarvis = jarvis_march.JarvisMarch()
if dataset == 1:
start = time()
square(graham, size)
total = (time() - start)
print("Graham's scan execution time: {} seconds").format(total)
start = time()
square(jarvis, size)
total = (time() - start)
print("Jarvis's march execution time: {} seconds").format(total)
elif dataset == 2:
start = time()
points = circle(graham, size)
total = (time() - start)
print("Graham's scan execution time: {} seconds").format(total)
start = time()
add(jarvis, points)
total = (time() - start)
print("Jarvis's march execution time: {} seconds").format(total)
elif dataset == 3:
start = time()
points = triangle(graham, size)
total = (time() - start)
print("Graham's scan execution time: {} seconds").format(total)
start = time()
add(jarvis, points)
total = (time() - start)
print("Jarvis's march execution time: {} seconds").format(total)
elif dataset == 4:
start = time()
points = hull(graham, size)
total = (time() - start)
print("Graham's scan execution time: {} seconds").format(total)
add(jarvis, points)
total = (time() - start)
print("Jarvis's march execution time: {} seconds").format(total)
else:
square(graham, size)
square(jarvis, size)
print("Convex Hull:", graham.get_hull_points(show_progress))
print("Convex Hull:", jarvis.get_hull_points(show_progress))
graham.display()
jarvis.display()
def main():
# size of the set of input points
input_size = 100
# set to 'True' to display convex hull construction
show_progress = False
normal_dataset = 1 # points distributed over square-shaped interval
circle_dataset = 2 # points distributed over circle-shaped interval
triangle_dataset = 3 # points distributed over triangle-shaped interval
hull_dataset = 4 # all points distributed on the hull
# run the algorithms (one at a time)
run_algorithms(normal_dataset, input_size, show_progress)
# run_algorithms(circle_dataset, input_size, show_progress)
# run_algorithms(triangle_dataset, input_size, show_progress)
# run_algorithms(hull_dataset, input_size, show_progress)
if __name__ == "__main__":
main()