2 """Plot scenario's runs cost."""
5 from sys import argv, exit
6 import matplotlib.pyplot as plt
14 """Load scenario from file.
22 raise ValueError("File name as argument needed")
24 with open(fn, "r") as f:
28 def load_dir(dn=None, fn=None):
29 """Load scenarios from directory.
34 - `dn` -- Directory name.
37 raise ValueError("Directory name as argument needed")
42 s = load("{}/{}/{}.json".format(dn, d, fn))
50 return np.percentile(li, p) if len(li) > 0 else p
52 if __name__ == "__main__":
62 "OSP-WK + cost heur.",
68 # "No cost heuristics",
70 # "No path optimization",
71 # "Out-of-slot planner"]
74 "Average final path cost",
75 "Maximum final path cost"]
77 plt.rcParams["figure.figsize"] = [14, 7]
78 plt.rcParams["font.size"] = 24
79 plt.rcParams["font.family"] = "cmr10"
80 plt.rcParams["hatch.linewidth"] = 1.0
81 plt.rcParams["lines.linewidth"] = 1.0
82 plt.rc('axes', unicode_minus=False)
84 f, ax = plt.subplots()
85 ax.grid(which="major", linestyle=":", color="tab:gray")
88 #ax.set_title("Scenario 3: {}".format(titles[WHAT_PLOT - 1]))
89 #ax.set_title("Scenario 3: {}".format(titles[WHAT_PLOT - 1]))
91 #ax.set_title("Scenario 8: Final path cost after optimization")
92 #ax.set_title("Scenario 2: Final path cost after optimization")
93 #ax.set_title("Scenario 7: Final path cost after optimization")
94 ax.set_xlabel("Number of iterations [-]")
96 ax.set_ylabel("Failure rate [%]")
98 ax.set_ylabel("Cost [m]")
99 #ax.set_ylim([20.1, 57]) # scenario 7
100 #ax.set_ylim([18, 43]) # scenario 2
102 ax.set_ylim([10, 40])
103 #ax.set_ylim([0, 100])
110 result_dir = "rwps-additional/rwps-1"
112 "test54-no-improvement",
113 "test54-w-cost-heuristics",
114 "test54-w-goal-zone",
118 scenarios = load_dir(result_dir, test_fn)
120 err_hist = [0 for i in range(L)]
121 val_list = [[] for i in range(L)]
132 lpc = s["log_path_cost"]
139 val_list[i].append(lpc[i])
140 if min_c == 0.0 or s["goal_cc"] < min_c:
143 if s["goal_cc"] > max_c:
147 icnt_list.append(s["icnt"])
148 bcnt_list.append(s["bcnt"])
149 rcnt_list.append(s["rcnt"])
153 time_list.append(s["time"])
157 otime_list.append(s["otime"])
160 o_err_hist = list(err_hist)
161 err_hist = [i * 100.0 / RUNS for i in o_err_hist]
162 #print("{} {}".format(min_s, max_s))
163 icnt_avg = np.average(icnt_list)
164 bcnt_avg = np.average(bcnt_list)
165 rcnt_avg = np.average(rcnt_list)
166 br_avg = np.average([b / r for (b, r) in zip(bcnt_list, rcnt_list)])
167 #print("avg. icnt = {}".format(icnt_avg))
168 #print("avg. bcnt = {}".format(bcnt_avg))
169 #print("avg. rcnt = {}".format(rcnt_avg))
170 #print("b/r avg. {}".format(br_avg))
171 print("last avg. cost = {}".format(np.average(val_list[-1])))
172 #print("last max. cost = {}".format(perc(val_list[-1], 100)))
173 print("failure rate = {}".format(err_hist[-1]))
174 for i in range(len(err_hist)):
182 # y2=[i for i in err_hist],
185 # label="Succes rate {}".format(ci),
190 [i for i in err_hist],
194 linestyle=(0, (5, 5)) if ci == 0 else "solid",
199 [np.average(val_list[i]) for i in range(L)],
203 linestyle=(0, (5, 5)) if ci == 0 else "solid",
208 [perc(val_list[i], 100) for i in range(L)],
212 linestyle=(0, (5, 5)) if ci == 0 else "solid",
216 ax.tick_params(axis='x', labelrotation=45)
217 h1, la1 = ax.get_legend_handles_labels()
218 #h2, la2 = eax.get_legend_handles_labels()
223 ax.legend(h, la, loc="upper right", ncol=1)
225 ax.legend(h, la, loc="upper right", ncol=2)
226 plt.savefig("out.pdf", bbox_inches="tight")