2 """Plot scenario's runs cost."""
5 from sys import argv, exit
6 import matplotlib.pyplot as plt
10 """Load scenario from file.
18 raise ValueError("File name as argument needed")
20 with open(fn, "r") as f:
24 def load_dir(dn=None, fn=None):
25 """Load scenarios from directory.
30 - `dn` -- Directory name.
33 raise ValueError("Directory name as argument needed")
36 s = load("{}/{}/{}.json".format(dn, d, fn))
44 return np.percentile(li, p) if len(li) > 0 else p
46 if __name__ == "__main__":
48 print("""Usage: ./plot_cost.py DIR FN
51 - DIR is the directory with the results.
52 - FN is the desired test filename.
57 scenarios = load_dir(result_dir, test_fn)
58 L = 1000#len(scenarios[0]["log_path_cost"])
59 err_hist = [0 for i in range(L)]
60 val_list = [[] for i in range(L)]
71 lpc = s["log_path_cost"]
76 val_list[i].append(lpc[i])
77 if min_c == 0.0 or s["goal_cc"] < min_c:
80 if s["goal_cc"] > max_c:
84 icnt_list.append(s["icnt"])
85 bcnt_list.append(s["bcnt"])
86 rcnt_list.append(s["rcnt"])
90 time_list.append(s["time"])
94 otime_list.append(s["otime"])
97 print("{} {}".format(min_s, max_s))
98 icnt_avg = np.average(icnt_list)
99 bcnt_avg = np.average(bcnt_list)
100 rcnt_avg = np.average(rcnt_list)
101 br_avg = np.average([b / r for (b, r) in zip(bcnt_list, rcnt_list)])
102 print("avg. icnt = {}".format(icnt_avg))
103 print("avg. bcnt = {}".format(bcnt_avg))
104 print("avg. rcnt = {}".format(rcnt_avg))
105 print("b/r avg. {}".format(br_avg))
107 plt.rcParams["figure.figsize"] = [12, 12]
108 plt.rcParams["font.size"] = 24
109 plt.rcParams["font.family"] = "cmr10"
110 plt.rcParams["hatch.linewidth"] = 1.0
111 plt.rcParams["lines.linewidth"] = 1.0
112 plt.rc('axes', unicode_minus=False)
114 f, ax = plt.subplots()
116 ax.set_title(scenarios[0]["fn"])
117 ax.set_xlabel("Number of iterations [-]")
118 ax.set_ylabel("Cost [m]")
119 eax.set_ylabel("Finished with no path [%]")
120 ax.set_ylim([0, 100])
121 eax.set_ylim([0, 100])
126 y2=[i for i in err_hist],
129 label="No path found",
133 "Minimum and maximum",
134 "10 % and 90 % percentile",
135 "20 % and 80 % percentile",
136 "30 % and 70 % percentile",
137 "40 % and 60 % percentile",
143 y1=[perc(val_list[i], 50 - (5-j)*10) for i in range(L)],
144 y2=[perc(val_list[i], 50 + (5-j)*10) for i in range(L)],
151 [np.average(val_list[i]) for i in range(L)],
154 label="Average cost",
158 ax.tick_params(axis='x', labelrotation=45)
159 ax.legend(loc="upper left")
160 eax.legend(loc="upper right")
161 plt.savefig("out.pdf", bbox_inches="tight")