A fix for the blind. Jesus be praised!

This commit is contained in:
Casper 2018-10-21 20:28:35 +02:00
parent d7b3d75e0f
commit 5e9cb0e943
No known key found for this signature in database
GPG Key ID: B1156723DB3BDDA8
4 changed files with 9 additions and 9 deletions

View File

@ -3,7 +3,7 @@ from profile import Profiler
from util import gen_point, Side, display
@Profiler("calculating sidedness")
@Profiler("calc sidedness")
def sidedness(p1, p2, p3, eps=0.0000001):
# Find line from p1 to p2, ask where p3 is in relation to this
@ -28,7 +28,7 @@ def graham_scan(points):
sorted_points = sorted(points)
UH = sorted_points[:2]
with Profiler("iterating points", excluded=("calculating sidedness",)):
with Profiler("iterating points", excluded=("calc sidedness",)):
for s in sorted_points[2:]:
while len(UH) > 1 and (sidedness(UH[-2], UH[-1], s) != Side.ABOVE):
del UH[-1]
@ -38,7 +38,7 @@ def graham_scan(points):
reversed_list.append(UH[0])
LH = reversed_list[:2]
with Profiler("iterating points", excluded=("calculating sidedness",)):
with Profiler("iterating points", excluded=("calc sidedness",)):
for s in reversed_list[2:]:
while len(LH) > 1 and (sidedness(LH[-2], LH[-1], s) != Side.ABOVE):
del LH[-1]

View File

@ -44,7 +44,7 @@ def find_hull(points: Set[Point], p: Point, q: Point, hull: Set[Point]):
if not points:
return
with Profiler("finding farthest point from line"):
with Profiler("find farthest point"):
farthest = max(points, key=lambda point: abs(distance(p, q, point)))
hull.add(farthest)
points.remove(farthest)

View File

@ -163,7 +163,7 @@ def plot_graham(result, ax):
"other",
"sorting points",
"iterating points",
"calculating sidedness",
"calc sidedness",
)
util.stacked_bar(ax=ax,
data=[[result["times"][step] * 1000] for step in steps],
@ -189,7 +189,7 @@ def plot_quick(result, ax):
steps = (
"other",
"partitioning set",
"finding farthest point from line",
"find farthest point",
)
util.stacked_bar(ax=ax,
data=[[result["times"][step] * 1000] for step in steps],
@ -200,7 +200,8 @@ def plot_quick(result, ax):
def do_profile():
num_points = 60_000
results = do_one_profile(num_points)
#results = do_one_profile(num_points)
results = {"graham_scan": {"times": {"sorting points": 0.039986371994018555, "calc sidedness": 0.20061016082763672, "iterating points": 0.1414051055908203, "graham_scan": 0.48474693298339844, "other": 0.10274529457092285}, "total": 0.48474693298339844, "total_profiled": 0.3820016384124756, "unaccounted": 0.10274529457092285}, "quick_hull": {"times": {"partitioning set": 0.1488804817199707, "find farthest point": 0.0767507553100586, "quick_hull": 0.24364948272705078, "other": 0.018018245697021484}, "total": 0.24364948272705078, "total_profiled": 0.2256312370300293, "unaccounted": 0.018018245697021484}, "mbc": {"times": {"finding median": 0.008962392807006836, "partitioning set": 0.08010172843933105, "building constraints": 0.14875221252441406, "shuffling constraints": 0.08788180351257324, "solving LP": 0.14783930778503418, "finding bridge points": 0.06223654747009277, "pruning between line points": 0.05157780647277832, "mbc": 0.625605583190918, "other": 0.0382537841796875}, "total": 0.625605583190918, "total_profiled": 0.5873517990112305, "unaccounted": 0.0382537841796875}, "mbc_no_shuffle": {"times": {"finding median": 0.007230997085571289, "partitioning set": 0.06375980377197266, "building constraints": 0.12821173667907715, "solving LP": 0.06401801109313965, "finding bridge points": 0.05544614791870117, "pruning between line points": 0.042369842529296875, "mbc_no_shuffle": 0.3726029396057129, "other": 0.011566400527954102}, "total": 0.3726029396057129, "total_profiled": 0.3610365390777588, "unaccounted": 0.011566400527954102}, "mbc2": {"times": {"extra pruning step": 0.15880751609802246, "finding median": 0.0018236637115478516, "partitioning set": 0.022843599319458008, "building constraints": 0.04632830619812012, "shuffling constraints": 0.02962517738342285, "solving LP": 0.05501532554626465, "finding bridge points": 0.02581334114074707, "pruning between line points": 0.015393733978271484, "mbc2": 0.36753416061401367, "other": 0.01188349723815918}, "total": 0.36753416061401367, "total_profiled": 0.3556506633758545, "unaccounted": 0.01188349723815918}, "mbc2_no_shuffle": {"times": {"extra pruning step": 0.15827727317810059, "finding median": 0.0018894672393798828, "partitioning set": 0.0220644474029541, "building constraints": 0.04755878448486328, "solving LP": 0.026836633682250977, "finding bridge points": 0.023386240005493164, "pruning between line points": 0.01653766632080078, "mbc2_no_shuffle": 0.30204010009765625, "other": 0.0054895877838134766}, "total": 0.30204010009765625, "total_profiled": 0.2965505123138428, "unaccounted": 0.0054895877838134766}}
print("================== RESULTS ==================")
print(json.dumps(results))

View File

@ -171,8 +171,7 @@ def stacked_bar(ax, data, series_labels, category_labels=None,
category_labels = reversed(category_labels)
for i, row_data in enumerate(data):
axes.append(ax.bar(ind, row_data, bottom=cum_size,
label=series_labels[i]))
axes.append(ax.bar(ind, row_data, bottom=cum_size, label=series_labels[i]))
cum_size += row_data
if category_labels: