More tests

This commit is contained in:
Alexander Munch-Hansen 2018-10-18 11:53:43 +02:00
parent d580ea4c89
commit c6d4af33bd
3 changed files with 53 additions and 9 deletions

View File

@ -190,15 +190,15 @@ def mbc_ch(points: Set[Point], flipper: callable) -> Set[Point]:
#left_point = min(on)
#right_point = max(on)
dist_to_line = lambda p: abs(intercept + slope * p.x - p.y)/sqrt(1 + slope**2)
left_point = min(pl, key = dist_to_line)
right_point = min(pr, key=dist_to_line)
#dist_to_line = lambda p: abs(intercept + slope * p.x - p.y)/sqrt(1 + slope**2)
#left_point = min(pl, key = dist_to_line)
#right_point = min(pr, key=dist_to_line)
#display_line_only(points, slope, intercept, [left_point, right_point])
#left_point = next(p for p in pl if sidedness(slope, intercept, p, flipper) == Side.ON)
#right_point = next(p for p in pr if sidedness(slope, intercept, p, flipper) == Side.ON)
left_point = next(p for p in pl if sidedness(slope, intercept, p, flipper) == Side.ON)
right_point = next(p for p in pr if sidedness(slope, intercept, p, flipper) == Side.ON)

View File

@ -13,7 +13,7 @@ import os.path
TimedResult = namedtuple("TimedResult", "algorithm points running_time")
def time_it(f: callable, args: tuple = (), iterations=20):
def time_it(f: callable, args: tuple = (), iterations=1):
start = time()
for i in range(iterations):
f(*args)
@ -128,5 +128,6 @@ print("quick:", time_it(quick_hull, args=(points,)))
print("mbch:", time_it(mbc, args=(points,)))
"""
do_square_tests(50)
do_square_tests(100)
if __name__ == '__main__':
for i in range(50, 1000, 50):
do_square_tests(i)

View File

@ -1,5 +1,5 @@
import random
from collections import namedtuple
from collections import namedtuple, defaultdict
from enum import Enum, auto
from typing import Set
from math import cos, sin, sqrt, pi
@ -53,6 +53,49 @@ def gen_weird_point(lower : int = 0, upper: int = 10) -> Point:
return Point(random.uniform(-x, x), y)
def read_and_prep_data(filename):
data = open(filename).read()
lines = data.split('\n')
data = defaultdict(list)
for line in lines[1:]:
all_vars = line.split("\t\t")
name, points, time = all_vars
data[name.strip()].append([points, time[:8]])
return data
def gen_graph(data):
graham = data['graham']
quick = data['quick']
mbch = data['mbch']
gift = data['gift']
graham_x = [p[0] for p in graham]
graham_y = [p[1] for p in graham]
quick_x = [p[0] for p in quick]
quick_y = [p[1] for p in quick]
mbch_x = [p[0] for p in mbch]
mbch_y = [p[1] for p in mbch]
gift_x = [p[0] for p in gift]
gift_y = [p[1] for p in gift]
plt.plot(graham_x, graham_y)
plt.plot(quick_x, quick_y)
plt.plot(mbch_x, mbch_y)
plt.plot(gift_x, gift_y)
plt.legend(['graham', 'quick', 'mbch', 'gift'], loc='upper left')
plt.show()
def gen_triangular_point(left : Point, right : Point, top : Point):
r1 = random.uniform(0,1)
r2 = random.uniform(0,1)