Skip to content

Commit 40b3802

Browse files
authored
Merge pull request #26 from APLA-Toolbox/remove-docs
Workon Issue #22 - Use logger instead of prints
2 parents bcde50e + 6847c9a commit 40b3802

File tree

8 files changed

+31
-8
lines changed

8 files changed

+31
-8
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,7 @@ dmypy.json
132132

133133
# Pyre type checker
134134
.pyre/
135+
136+
# Logs
137+
logs/*
138+
!logs/.gitkeep

logs/.gitkeep

Whitespace-only changes.

main.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import src.automated_planner as parser
22
import argparse
3+
import logging
4+
import os
35

46

57
def main():
@@ -11,10 +13,22 @@ def main():
1113
args_parser.add_argument("problem", type=str, help="PDDL problem file")
1214
args_parser.add_argument("-v", "--verbose", help="Increases the output's verbosity")
1315
args = args_parser.parse_args()
16+
logging.basicConfig(
17+
filename="logs/main.log",
18+
format="%(levelname)s:%(message)s",
19+
filemode="w",
20+
level=logging.INFO,
21+
) # Creates the log file
1422
apla_tbx = parser.AutomatedPlanner(args.domain, args.problem)
23+
logging.info("Starting the tool")
1524
path, time = apla_tbx.depth_first_search(time_it=True)
16-
print(apla_tbx.get_actions_from_path(path))
17-
print("Computation time: %.2f" % time)
25+
logging.info(apla_tbx.get_actions_from_path(path))
26+
logging.info("Computation time: %.2f seconds" % time)
27+
logging.info("Tool finished")
28+
# Output the log (to show something in the output screen)
29+
logfile = open("logs/main.log", "r")
30+
print(logfile.read())
31+
logfile.close()
1832

1933

2034
if __name__ == "__main__":

src/automated_planner.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from .bfs import BreadthFirstSearch
33
from .dfs import DepthFirstSearch
44
from .dijkstra import DijkstraBestFirstSearch
5+
import logging
56

67
UI = False
78

@@ -49,7 +50,7 @@ def __retrace_path(self, node):
4950

5051
def get_actions_from_path(self, path):
5152
if not path:
52-
print("Path is empty, can't operate...")
53+
logging.warning("Path is empty, can't operate...")
5354
return []
5455
actions = []
5556
for node in path:
@@ -63,7 +64,7 @@ def get_actions_from_path(self, path):
6364

6465
def get_state_def_from_path(self, path):
6566
if not path:
66-
print("Path is empty, can't operate...")
67+
logging.warning("Path is empty, can't operate...")
6768
return []
6869
trimmed_path = []
6970
for node in path:

src/bfs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .node import Node
2+
import logging
23

34

45
class BreadthFirstSearch:
@@ -32,5 +33,5 @@ def search(self):
3233
if child in self.visited:
3334
continue
3435
self.queue.append(child)
35-
print("!!! No path found !!!")
36+
logging.warning("!!! No path found !!!")
3637
return None

src/dfs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from .node import Node
2+
import logging
3+
24

35
class DepthFirstSearch:
46
def __init__(self, automated_planner):
@@ -31,5 +33,5 @@ def search(self):
3133
if child in self.visited:
3234
continue
3335
self.stack.append(child)
34-
print("!!! No path found !!!")
36+
logging.warning("!!! No path found !!!")
3537
return None

src/dijkstra.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from .heuristics import zero_heuristic
12
from .node import Node
3+
import logging
24
import math
3-
from .heuristics import zero_heuristic
45

56

67
class DijkstraBestFirstSearch:
@@ -64,5 +65,5 @@ def search(self):
6465
else:
6566
self.nodes[child_hash] = child
6667
self.open_nodes_n += 1
67-
print("!!! No path found !!!")
68+
logging.warning("!!! No path found !!!")
6869
return None

tests/test_dfs.py

Whitespace-only changes.

0 commit comments

Comments
 (0)