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


hpp-fcl
Author(s):
autogenerated on Fri Aug 2 2024 02:45:13