Skip to content

Commit

Permalink
file and result
Browse files Browse the repository at this point in the history
  • Loading branch information
yaansz committed Oct 26, 2021
1 parent ac13923 commit a5a8916
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 16 deletions.
2 changes: 2 additions & 0 deletions week-3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ O arquivo [show.py](./show.py) contém apenas uma implementação extra para aju

Para rodar os testes automatizados é necessário rodar o script [run.sh](./run.sh). (Funcionando em Windows e Linux)

A pasta [res](./res) contém os resultados para os testes do ./run.sh

1 change: 0 additions & 1 deletion week-3/algorithms/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def dfs(initial_state, limit=-1):
neighbors = current_state.get_neighbors()[::-1]
for neighbor in neighbors:
if neighbor.key not in explored:
scanned += 1
explored.add(neighbor.key)
stack.append(neighbor)

Expand Down
25 changes: 13 additions & 12 deletions week-3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,22 @@ def main():


# Feedback
f = open("res/" + method + ".txt", "w")

current_state = feedback["state"]
print(f"Method: {method}")
print(f"Final State Found: {current_state is not None}")
f.write(f"Method: {method}")
f.write(f"Final State Found: {current_state is not None}\n")
if current_state is not None:
#print(f"Path :{current_state}")
print(f"Cost : {current_state.cost}")
print(f"Depth : {current_state.depth}")
print(f"Max_Depth : {feedback['max_depth']}")
print(f"Final_Frontier : {feedback['final_frontier']}")
print(f"Max_Frontier : {feedback['max_frontier']}")
print(f"Scanned : {feedback['scanned']}")
print(f"Elapsed_Time : {end_time - start_time} s")
print(f"RAM_Usage : {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1000.0} kb")

f.write(f"Path : {current_state}\n")
f.write(f"Cost : {current_state.cost}\n")
f.write(f"Depth : {current_state.depth}\n")
f.write(f"Max_Depth : {feedback['max_depth']}\n")
f.write(f"Final_Frontier : {feedback['final_frontier']}\n")
f.write(f"Max_Frontier : {feedback['max_frontier']}\n")
f.write(f"Scanned : {feedback['scanned']}\n")
f.write(f"Elapsed_Time : {end_time - start_time} s\n")
f.write(f"RAM_Usage : {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1000.0} kb\n")
f.close()

#traceback_board(current_state)
return
Expand Down
10 changes: 10 additions & 0 deletions week-3/res/bfs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Method: bfsFinal State Found: True
Path : up, left, up, left, down, down, right, up, up, left, down, down, right, up, up, right, down, down, left, up, up, right, down, left, up, left, down, right, down, right
Cost : 30
Depth : 30
Max_Depth : 31
Final_Frontier : 32
Max_Frontier : 24053
Scanned : 181440
Elapsed_Time : 2.552396535873413 s
RAM_Usage : 61.936 kb
10 changes: 10 additions & 0 deletions week-3/res/dfs.txt

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions week-3/res/idfs.txt

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions week-3/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ def traceback(state):
"""
Traceback function to print the path of the current state.
"""
if state.parent is None:
return ""
return traceback(state.parent) + " " + state.action
moves = []

while state.parent:
moves.append(state.action)
state = state.parent

moves.reverse()
return ", ".join(moves)

def traceback_board(state):
"""
Expand Down

0 comments on commit a5a8916

Please sign in to comment.