22import glob
33import matplotlib as mpl
44import logging
5+
56mpl .use ("TkAgg" )
67mpl .set_loglevel ("WARNING" )
78import matplotlib .pyplot as plt
9+
810plt .style .use ("ggplot" )
911from .automated_planner import AutomatedPlanner
1012from os import path
1113import json
1214
15+
1316class DataAnalyst :
1417 def __init__ (self ):
1518 logging .info ("Instantiating data analyst..." )
1619
17-
1820 def __get_all_pddl_from_data (self ):
1921 tested_files = []
2022 domains_problems = []
@@ -29,29 +31,29 @@ def __get_all_pddl_from_data(self):
2931 i += 1
3032 return domains_problems
3133
32-
3334 def __plot_data (self , times , total_nodes , plot_title ):
3435 plt .plot (total_nodes , times , "b:o" )
3536 plt .xlabel ("Number of opened nodes" )
3637 plt .ylabel ("Planning computation time" )
3738 plt .title (plot_title )
38- plt .xscale (' symlog' )
39- plt .yscale (' log' )
39+ plt .xscale (" symlog" )
40+ plt .yscale (" log" )
4041 plt .grid (True )
4142 plt .show (block = False )
4243
43-
4444 def __scatter_data (self , times , total_nodes , plot_title ):
4545 plt .scatter (total_nodes , times )
4646 plt .xlabel ("Number of opened nodes" )
4747 plt .ylabel ("Planning computation time" )
4848 plt .title (plot_title )
49- plt .xscale (' symlog' )
50- plt .yscale (' log' )
49+ plt .xscale (" symlog" )
50+ plt .yscale (" log" )
5151 plt .grid (True )
5252 plt .show (block = False )
5353
54- def __gather_data_astar (self , domain_path = "" , problem_path = "" , heuristic_key = "goal_count" ):
54+ def __gather_data_astar (
55+ self , domain_path = "" , problem_path = "" , heuristic_key = "goal_count"
56+ ):
5557 has_multiple_files_tested = True
5658 if not domain_path and not problem_path :
5759 has_multiple_files_tested = False
@@ -90,7 +92,6 @@ def __gather_data_astar(self, domain_path="", problem_path="", heuristic_key="go
9092 return [0 ], [0 ], has_multiple_files_tested
9193 return [total_time ], [total_nodes ], has_multiple_files_tested
9294
93-
9495 def plot_astar_data (self , heuristic_key = "goal_count" , domain = "" , problem = "" ):
9596 if bool (not problem ) != bool (not domain ):
9697 logging .warning (
@@ -106,7 +107,6 @@ def plot_astar_data(self, heuristic_key="goal_count", domain="", problem=""):
106107 else :
107108 self .__scatter_data (times , total_nodes , title )
108109
109-
110110 def __gather_data_bfs (self , domain_path = "" , problem_path = "" ):
111111 has_multiple_files_tested = True
112112 if not domain_path and not problem_path :
@@ -130,7 +130,6 @@ def __gather_data_bfs(self, domain_path="", problem_path=""):
130130 _ , total_time , opened_nodes = apla .breadth_first_search ()
131131 return [total_time ], [total_nodes ], has_multiple_files_tested
132132
133-
134133 def plot_bfs (self , domain = "" , problem = "" ):
135134 title = "BFS Statistics"
136135 if bool (not problem ) != bool (not domain ):
@@ -146,7 +145,6 @@ def plot_bfs(self, domain="", problem=""):
146145 else :
147146 self .__scatter_data (times , total_nodes , title )
148147
149-
150148 def __gather_data_dfs (self , domain_path = "" , problem_path = "" ):
151149 has_multiple_files_tested = True
152150 if not domain_path and not problem_path :
@@ -170,7 +168,6 @@ def __gather_data_dfs(self, domain_path="", problem_path=""):
170168 _ , total_time , opened_nodes = apla .depth_first_search ()
171169 return [total_time ], [total_nodes ], has_multiple_files_tested
172170
173-
174171 def plot_dfs (self , problem = "" , domain = "" ):
175172 title = "DFS Statistics"
176173 if bool (not problem ) != bool (not domain ):
@@ -209,7 +206,6 @@ def __gather_data_dijkstra(self, domain_path="", problem_path=""):
209206 _ , total_time , opened_nodes = apla .dijktra_best_first_search ()
210207 return [total_time ], [total_nodes ], has_multiple_files_tested
211208
212-
213209 def plot_dijkstra (self , problem = "" , domain = "" ):
214210 title = "Dijkstra Statistics"
215211 if bool (not problem ) != bool (not domain ):
@@ -225,7 +221,6 @@ def plot_dijkstra(self, problem="", domain=""):
225221 else :
226222 self .__scatter_data (times , total_nodes , title )
227223
228-
229224 def __gather_data (
230225 self ,
231226 heuristic_key = "goal_count" ,
@@ -239,7 +234,7 @@ def __gather_data(
239234 gatherers = []
240235 xdata = dict ()
241236 ydata = dict ()
242-
237+
243238 if bfs :
244239 gatherers .append (("BFS" , self .__gather_data_bfs ))
245240 if dfs :
@@ -249,19 +244,22 @@ def __gather_data(
249244 if astar :
250245 gatherers .append (("A*" , self .__gather_data_astar ))
251246
252- _ , _ , _ = self .__gather_data_bfs (domain_path = domain , problem_path = problem ) # Dummy line to do first parsing and get rid of static loading
247+ _ , _ , _ = self .__gather_data_bfs (
248+ domain_path = domain , problem_path = problem
249+ ) # Dummy line to do first parsing and get rid of static loading
253250 for name , g in gatherers :
254251 if g == self .__gather_data_astar :
255252 times , nodes , _ = self .__gather_data_astar (
256- domain_path = domain , problem_path = problem , heuristic_key = heuristic_key
253+ domain_path = domain ,
254+ problem_path = problem ,
255+ heuristic_key = heuristic_key ,
257256 )
258257 else :
259258 times , nodes , _ = g (domain_path = domain , problem_path = problem )
260259 ydata [name ] = times
261260 xdata [name ] = nodes
262261 return xdata , ydata
263262
264-
265263 def comparative_data_plot (
266264 self ,
267265 astar = True ,
@@ -317,11 +315,14 @@ def comparative_data_plot(
317315 plt .ylabel ("Planning computation time (s)" )
318316 for planner in json_dict ["xdata" ].keys ():
319317 ax .plot (
320- sorted (json_dict ["xdata" ][planner ]), sorted (json_dict ["ydata" ][planner ]), '-o' , label = planner
318+ sorted (json_dict ["xdata" ][planner ]),
319+ sorted (json_dict ["ydata" ][planner ]),
320+ "-o" ,
321+ label = planner ,
321322 )
322323 plt .title ("Planners complexity comparison" )
323324 plt .legend (loc = "upper left" )
324- plt .xscale (' symlog' )
325- plt .yscale (' log' )
325+ plt .xscale (" symlog" )
326+ plt .yscale (" log" )
326327 plt .grid (True )
327328 plt .show (block = False )
0 commit comments