Skip to content

Commit 0419dae

Browse files
authored
Merge pull request #74 from APLA-Toolbox/add-pddl-examples-limit
Add pddl examples limit
2 parents cc7f1eb + aae4868 commit 0419dae

3 files changed

Lines changed: 57 additions & 23 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ If you want to use it by cloning the project:
5959
```shell
6060
$ git clone https://github.com/APLA-Toolbox/PythonPDDL
6161
$ cd PythonPDDL
62-
$ git submodule init
63-
$ git submodule update
62+
$ python3 -m pip install -r requirements.txt
63+
$ git submodule update --init
6464
```
6565

6666
You should have a `pddl-examples` folder containing PDDL instances.

jupyddl/data_analyst.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,25 @@ def __init__(self):
2121
logging.info("Instantiating data analyst...")
2222
self.available_heuristics = ["goal_count", "zero"]
2323

24-
def __get_all_pddl_from_data(self):
24+
def __get_all_pddl_from_data(self, max_pddl_instances=-1):
2525
tested_files = []
2626
domains_problems = []
2727
i = 0
2828
if "DISPLAY" in os.environ:
2929
for root, _, files in os.walk("pddl-examples/", topdown=False):
3030
for name in files:
31-
# if ".gitkeep" in name:
31+
# if "README" in name:
32+
# continue
33+
# if "LICENSE" in name:
34+
# continue
35+
# if ".gitignore" in name:
3236
# continue
3337
tested_files.append(os.getcwd() + "/" + os.path.join(root, name))
3438
if i % 2 != 0:
3539
domains_problems.append((tested_files[i - 1], tested_files[i]))
3640
i += 1
41+
if max_pddl_instances != -1 and i >= max_pddl_instances*2:
42+
return domains_problems
3743
return domains_problems
3844
return [
3945
("pddl-examples/flip/problem.pddl", "pddl-examples/flip/domain.pddl"),
@@ -66,12 +72,12 @@ def __scatter_data(self, times, total_nodes, plot_title):
6672
plt.show(block=False)
6773

6874
def __gather_data_astar(
69-
self, domain_path="", problem_path="", heuristic_key="goal_count"
75+
self, domain_path="", problem_path="", heuristic_key="goal_count", max_pddl_instances=-1
7076
):
7177
has_multiple_files_tested = True
7278
if not domain_path or not problem_path:
7379
metrics = dict()
74-
for problem, domain in self.__get_all_pddl_from_data():
80+
for problem, domain in self.__get_all_pddl_from_data(max_pddl_instances=max_pddl_instances):
7581
logging.debug("Loading new PDDL instance planned with A*...")
7682
logging.debug("Domain: " + domain)
7783
logging.debug("Problem: " + problem)
@@ -111,26 +117,26 @@ def __gather_data_astar(
111117
return [total_time], [opened_nodes], has_multiple_files_tested
112118
return [0], [0], has_multiple_files_tested
113119

114-
def plot_astar(self, heuristic_key="goal_count", domain="", problem=""):
120+
def plot_astar(self, heuristic_key="goal_count", domain="", problem="", max_pddl_instances=-1):
115121
if bool(not problem) != bool(not domain):
116122
logging.warning(
117123
"Either problem or domain wasn't provided, testing all files in data folder"
118124
)
119125
problem = domain = ""
120126
times, total_nodes, has_multiple_files_tested = self.__gather_data_astar(
121-
heuristic_key=heuristic_key, problem_path=problem, domain_path=domain
127+
heuristic_key=heuristic_key, problem_path=problem, domain_path=domain, max_pddl_instances=max_pddl_instances
122128
)
123129
title = "A* Statistics" + "[Heuristic: " + heuristic_key + "]"
124130
if has_multiple_files_tested:
125131
self.__plot_data(times, total_nodes, title)
126132
else:
127133
self.__scatter_data(times, total_nodes, title)
128134

129-
def __gather_data_bfs(self, domain_path="", problem_path=""):
135+
def __gather_data_bfs(self, domain_path="", problem_path="", max_pddl_instances=-1):
130136
has_multiple_files_tested = True
131137
if not domain_path or not problem_path:
132138
metrics = dict()
133-
for problem, domain in self.__get_all_pddl_from_data():
139+
for problem, domain in self.__get_all_pddl_from_data(max_pddl_instances=max_pddl_instances):
134140
logging.debug("Loading new PDDL instance planned with BFS...")
135141
logging.debug("Domain: " + domain)
136142
logging.debug("Problem: " + problem)
@@ -154,26 +160,26 @@ def __gather_data_bfs(self, domain_path="", problem_path=""):
154160
return [total_time], [opened_nodes], has_multiple_files_tested
155161
return [0], [0], has_multiple_files_tested
156162

157-
def plot_bfs(self, domain="", problem=""):
163+
def plot_bfs(self, domain="", problem="", max_pddl_instances=-1):
158164
title = "BFS Statistics"
159165
if bool(not problem) != bool(not domain):
160166
logging.warning(
161167
"Either problem or domain wasn't provided, testing all files in data folder"
162168
)
163169
problem = domain = ""
164170
times, total_nodes, has_multiple_files_tested = self.__gather_data_bfs(
165-
problem_path=problem, domain_path=domain
171+
problem_path=problem, domain_path=domain, max_pddl_instances=max_pddl_instances
166172
)
167173
if has_multiple_files_tested:
168174
self.__plot_data(times, total_nodes, title)
169175
else:
170176
self.__scatter_data(times, total_nodes, title)
171177

172-
def __gather_data_dfs(self, domain_path="", problem_path=""):
178+
def __gather_data_dfs(self, domain_path="", problem_path="", max_pddl_instances=-1):
173179
has_multiple_files_tested = True
174180
if not domain_path or not problem_path:
175181
metrics = dict()
176-
for problem, domain in self.__get_all_pddl_from_data():
182+
for problem, domain in self.__get_all_pddl_from_data(max_pddl_instances=max_pddl_instances):
177183
logging.debug("Loading new PDDL instance planned with DFS...")
178184
logging.debug("Domain: " + domain)
179185
logging.debug("Problem: " + problem)
@@ -197,26 +203,26 @@ def __gather_data_dfs(self, domain_path="", problem_path=""):
197203
return [total_time], [opened_nodes], has_multiple_files_tested
198204
return [0], [0], has_multiple_files_tested
199205

200-
def plot_dfs(self, problem="", domain=""):
206+
def plot_dfs(self, problem="", domain="", max_pddl_instances=-1):
201207
title = "DFS Statistics"
202208
if bool(not problem) != bool(not domain):
203209
logging.warning(
204210
"Either problem or domain wasn't provided, testing all files in data folder"
205211
)
206212
problem = domain = ""
207213
times, total_nodes, has_multiple_files_tested = self.__gather_data_dfs(
208-
problem_path=problem, domain_path=domain
214+
problem_path=problem, domain_path=domain, max_pddl_instances=max_pddl_instances
209215
)
210216
if has_multiple_files_tested:
211217
self.__plot_data(times, total_nodes, title)
212218
else:
213219
self.__scatter_data(times, total_nodes, title)
214220

215-
def __gather_data_dijkstra(self, domain_path="", problem_path=""):
221+
def __gather_data_dijkstra(self, domain_path="", problem_path="", max_pddl_instances=-1):
216222
has_multiple_files_tested = True
217223
if not domain_path or not problem_path:
218224
metrics = dict()
219-
for problem, domain in self.__get_all_pddl_from_data():
225+
for problem, domain in self.__get_all_pddl_from_data(max_pddl_instances=max_pddl_instances):
220226
logging.debug("Loading new PDDL instance planned with Dijkstra...")
221227
logging.debug("Domain: " + domain)
222228
logging.debug("Problem: " + problem)
@@ -240,15 +246,15 @@ def __gather_data_dijkstra(self, domain_path="", problem_path=""):
240246
return [total_time], [opened_nodes], has_multiple_files_tested
241247
return [0], [0], has_multiple_files_tested
242248

243-
def plot_dijkstra(self, problem="", domain=""):
249+
def plot_dijkstra(self, problem="", domain="", max_pddl_instances=-1):
244250
title = "Dijkstra Statistics"
245251
if bool(not problem) != bool(not domain):
246252
logging.warning(
247253
"Either problem or domain wasn't provided, testing all files in data folder"
248254
)
249255
problem = domain = ""
250256
times, total_nodes, has_multiple_files_tested = self.__gather_data_dijkstra(
251-
problem_path=problem, domain_path=domain
257+
problem_path=problem, domain_path=domain, max_pddl_instances=max_pddl_instances
252258
)
253259
if has_multiple_files_tested:
254260
self.__plot_data(times, total_nodes, title)
@@ -264,6 +270,7 @@ def __gather_data(
264270
dijkstra=True,
265271
domain="",
266272
problem="",
273+
max_pddl_instances=-1
267274
):
268275
gatherers = []
269276
xdata = dict()
@@ -287,21 +294,22 @@ def __gather_data(
287294
domain_path=domain,
288295
problem_path=problem,
289296
heuristic_key=heuristic_key,
297+
max_pddl_instances=max_pddl_instances
290298
)
291299
else:
292-
times, nodes, _ = g(domain_path=domain, problem_path=problem)
300+
times, nodes, _ = g(domain_path=domain, problem_path=problem, max_pddl_instances=max_pddl_instances)
293301
ydata[name] = times
294302
xdata[name] = nodes
295303
return xdata, ydata
296304

297-
def comparative_astar_heuristic_plot(self, domain="", problem=""):
305+
def comparative_astar_heuristic_plot(self, domain="", problem="", max_pddl_instances=-1):
298306
_, ax = plt.subplots()
299307
plt.xlabel("Number of opened nodes")
300308
plt.ylabel("Planning computation time (s)")
301309

302310
for h in self.available_heuristics:
303311
times, nodes, _ = self.__gather_data_astar(
304-
domain_path=domain, problem_path=problem, heuristic_key=h
312+
domain_path=domain, problem_path=problem, heuristic_key=h, max_pddl_instances=max_pddl_instances
305313
)
306314
data = dict()
307315
for i, val in enumerate(nodes):
@@ -334,6 +342,7 @@ def comparative_data_plot(
334342
problem="",
335343
heuristic_key="goal_count",
336344
collect_new_data=True,
345+
max_pddl_instances=-1
337346
):
338347
json_dict = {}
339348
if collect_new_data:
@@ -345,6 +354,7 @@ def comparative_data_plot(
345354
dijkstra=dijkstra,
346355
domain=domain,
347356
problem=problem,
357+
max_pddl_instances=max_pddl_instances
348358
)
349359
json_dict["xdata"] = xdata
350360
json_dict["ydata"] = ydata
@@ -363,6 +373,7 @@ def comparative_data_plot(
363373
dijkstra=dijkstra,
364374
domain=domain,
365375
problem=problem,
376+
max_pddl_instances=max_pddl_instances
366377
)
367378
json_dict["xdata"] = xdata
368379
json_dict["ydata"] = ydata

tests/test_data_analyst.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,29 @@ def test_data_analyst_plot_astar_h_goal_count():
8484
da.plot_astar()
8585
assert True
8686

87+
def test_data_analyst_plot_dfs_restricted():
88+
da = DataAnalyst()
89+
da.plot_dfs(max_pddl_instances=2)
90+
assert True
91+
92+
93+
def test_data_analyst_plot_bfs_restricted():
94+
da = DataAnalyst()
95+
da.plot_bfs(max_pddl_instances=2)
96+
assert True
97+
98+
99+
def test_data_analyst_plot_dijkstra_restricted():
100+
da = DataAnalyst()
101+
da.plot_dijkstra(max_pddl_instances=2)
102+
assert True
103+
104+
105+
def test_data_analyst_plot_astar_h_goal_count_restricted():
106+
da = DataAnalyst()
107+
da.plot_astar(max_pddl_instances=2)
108+
assert True
109+
87110

88111
def test_data_analyst_plot_astar_h_zero():
89112
da = DataAnalyst()

0 commit comments

Comments
 (0)