collision-bench.py
Go to the documentation of this file.
1 import matplotlib.pyplot as plt
2 import csv, sys, numpy as np
3 from math import sqrt
4 
5 filename = sys.argv[1]
6 
7 with open(filename, "r") as file:
8  reader = csv.reader(file, strict=True)
9  fieldnames = None
10  # fieldnames = reader.fieldnames
11  converters = (str, int, int, int, float, lambda x: float(x) * 1e-3)
12 
13  for row in reader:
14  if fieldnames is None:
15  fieldnames = [n.strip() for n in row]
16  values = []
17  continue
18 
19  values.append([c(v) for v, c in zip(row, converters)])
20 
21 request1 = values[: int(len(values) / 2)]
22 request2 = values[int(len(values) / 2) :]
23 
24 Ntransforms = 1
25 while values[0][0:3] == values[Ntransforms][0:3]:
26  Ntransforms += 1
27 
28 splitMethods = ["avg", "med", "cen"]
29 type = [
30  "o",
31  "or",
32  "r",
33 ]
34 BVs = sorted(list(set([v[0] for v in request1[::Ntransforms]])))
35 xvals = [
36  BVs.index(v[0]) + len(BVs) * v[2] + 3 * len(BVs) * v[1]
37  for v in request1[::Ntransforms]
38 ]
39 cases = [
40  v[0] + " " + type[v[1]] + " " + splitMethods[v[2]] for v in request1[::Ntransforms]
41 ]
42 
43 idx_reorder = sorted(list(range(len(xvals))), key=lambda i: xvals[i])
44 
45 
46 def reorder(l):
47  return [l[i] for i in idx_reorder]
48 
49 
50 xvals_s = reorder(xvals)
51 cases_s = reorder(cases)
52 
53 onlyLB = True
54 # Time
55 plt.figure(0)
56 for i in range(Ntransforms):
57  if not onlyLB:
58  plt.plot(
59  xvals_s,
60  reorder([v[5] for v in request1[i::Ntransforms]]),
61  "-.o",
62  label=str(i),
63  )
64  plt.plot(
65  xvals_s,
66  reorder([v[5] for v in request2[i::Ntransforms]]),
67  ":+",
68  label=str(i) + "+lb",
69  )
70 
71 plt.legend()
72 plt.xticks(ticks=xvals_s, labels=cases_s, rotation=90)
73 plt.ylabel("Time (us)")
74 plt.yscale("log")
75 
76 # Time
77 plt.figure(2)
78 for k in range(0, len(request1), Ntransforms):
79  if not onlyLB:
80  plt.plot(
81  [
82  xvals[int(k / Ntransforms)],
83  ],
84  sum([v[5] for v in request1[k : k + Ntransforms]]) / Ntransforms,
85  )
86  plt.plot(
87  [
88  xvals[int(k / Ntransforms)],
89  ],
90  sum([v[5] for v in request2[k : k + Ntransforms]]) / Ntransforms,
91  )
92 
93 plt.plot(
94  xvals_s,
95  reorder(
96  [
97  sum([v[5] for v in request2[k : k + Ntransforms]]) / Ntransforms
98  for k in range(0, len(request1), Ntransforms)
99  ]
100  ),
101 )
102 
103 plt.xticks(ticks=xvals_s, labels=cases_s, rotation=90)
104 plt.ylabel("Time (us)")
105 plt.yscale("log")
106 
107 # Distance lower bound
108 plt.figure(1)
109 for i in range(Ntransforms):
110  if request2[i][3] > 0:
111  continue
112  plt.plot(
113  xvals_s,
114  reorder([v[4] for v in request2[i::Ntransforms]]),
115  ":+",
116  label=str(i) + "+lb",
117  )
118 
119 plt.legend()
120 plt.ylabel("Distance lower bound")
121 plt.xticks(ticks=xvals_s, labels=cases_s, rotation=90)
122 
123 plt.show()
const char * str()


hpp-fcl
Author(s):
autogenerated on Fri Jun 2 2023 02:39:00