From e1a7a4a5d2ec8b59c564099ac9858b6594f08d46 Mon Sep 17 00:00:00 2001 From: Michael Mutote <130656746+mr1Michael@users.noreply.github.com> Date: Wed, 25 Oct 2023 13:09:31 +0200 Subject: [PATCH] 22202956 refactored --- Breath-First Search/breadth_first_search.py | 19 --------- Depth-First Search/Depth_first.py | 0 {A-Star => Search_Algorithms}/A_Star.py | 0 Search_Algorithms/Search_Algorithms.py | 39 +++++++++++++++++++ .../Sucessors.py | 0 .../is_goal.py | 0 .../solution testing.py | 2 +- 7 files changed, 40 insertions(+), 20 deletions(-) delete mode 100644 Breath-First Search/breadth_first_search.py delete mode 100644 Depth-First Search/Depth_first.py rename {A-Star => Search_Algorithms}/A_Star.py (100%) create mode 100644 Search_Algorithms/Search_Algorithms.py rename {Breath-First Search => Search_Algorithms}/Sucessors.py (100%) rename {Breath-First Search => Search_Algorithms}/is_goal.py (100%) rename {Breath-First Search => Search_Algorithms}/solution testing.py (98%) diff --git a/Breath-First Search/breadth_first_search.py b/Breath-First Search/breadth_first_search.py deleted file mode 100644 index b24cdc9..0000000 --- a/Breath-First Search/breadth_first_search.py +++ /dev/null @@ -1,19 +0,0 @@ -import queue - - -def BreadthFirstSearch(state, successor, isgoal): - """accepts start state, Please do not change this function""" - toDo = queue.Queue() - toDo.put([state]) - explored = {state} - while not toDo.empty(): - path = toDo.get() - current = path[-1] - if isgoal(current): - return path - for next_state in successor(current): - if next_state not in explored: - explored.add(next_state) - path2 = path + [next_state] - toDo.put(path2) - return "Error Path not found" diff --git a/Depth-First Search/Depth_first.py b/Depth-First Search/Depth_first.py deleted file mode 100644 index e69de29..0000000 diff --git a/A-Star/A_Star.py b/Search_Algorithms/A_Star.py similarity index 100% rename from A-Star/A_Star.py rename to Search_Algorithms/A_Star.py diff --git a/Search_Algorithms/Search_Algorithms.py b/Search_Algorithms/Search_Algorithms.py new file mode 100644 index 0000000..dbeae12 --- /dev/null +++ b/Search_Algorithms/Search_Algorithms.py @@ -0,0 +1,39 @@ +import queue +from collections import deque + + +def BreadthFirstSearch(state, successor, isgoal): + """accepts start state, Please do not change this function""" + toDo = queue.Queue() + toDo.put([state]) + explored = {state} + while not toDo.empty(): + path = toDo.get() + current = path[-1] + if isgoal(current): + return path + for next_state in successor(current): + if next_state not in explored: + explored.add(next_state) + path2 = path + [next_state] + toDo.put(path2) + return "Error Path not found" + + +def DepthFirstSearch(state, successor, isgoal): + """accepts start state, Please do not change this function""" + toDo = deque() + toDo.append([state]) + explored = {state} + while not toDo: + path = toDo.pop() + current = path[-1] + if isgoal(current): + return path + for next_state in successor(current): + if next_state not in explored: + explored.add(next_state) + path2 = path + [next_state] + toDo.append(path2) + return "Error Path not found" + diff --git a/Breath-First Search/Sucessors.py b/Search_Algorithms/Sucessors.py similarity index 100% rename from Breath-First Search/Sucessors.py rename to Search_Algorithms/Sucessors.py diff --git a/Breath-First Search/is_goal.py b/Search_Algorithms/is_goal.py similarity index 100% rename from Breath-First Search/is_goal.py rename to Search_Algorithms/is_goal.py diff --git a/Breath-First Search/solution testing.py b/Search_Algorithms/solution testing.py similarity index 98% rename from Breath-First Search/solution testing.py rename to Search_Algorithms/solution testing.py index 971dced..669fa3d 100644 --- a/Breath-First Search/solution testing.py +++ b/Search_Algorithms/solution testing.py @@ -1,4 +1,4 @@ -import breadth_first_search +import Search_Algorithms import Sucessors import is_goal -- GitLab