Skip to content

Commit

Permalink
Using sets to lower complexity on general pruning (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoRibeiroRodrigues authored Sep 4, 2024
1 parent 9130d0b commit a3335a6
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions aigyminsper/search/SearchAlgorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def search (self, initialState, pruning='without', trace=False):
if pruning not in valid_pruning_options:
raise ValueError(f"Invalid pruning option: {pruning}. Valid options are {valid_pruning_options}")

# List to keep track of the visited nodes
states = []
# Set to keep track of the visited nodes
states = set()
#Creating a Queue
open = deque()
open.append(Node(initialState, None))
Expand All @@ -75,7 +75,7 @@ def search (self, initialState, pruning='without', trace=False):
# general pruning
elif pruning == "general" and (new_n.state.env() not in states):
open.append(new_n)
states.append(new_n.state.env())
states.add(new_n.state.env())
return None


Expand All @@ -90,8 +90,8 @@ def search (self, initialState, m, pruning='without', trace=False):
if pruning not in valid_pruning_options:
raise ValueError(f"Invalid pruning option: {pruning}. Valid options are {valid_pruning_options}")

# List to keep track of the visited nodes
states = []
# Set to keep track of the visited nodes
states = set()
#Using list as stack
open = []
open.append(Node(initialState, None))
Expand All @@ -113,7 +113,7 @@ def search (self, initialState, m, pruning='without', trace=False):
# general pruning
elif pruning == "general" and (new_n.state.env() not in states):
open.append(new_n)
states.append(new_n.state.env())
states.add(new_n.state.env())
return None

class BuscaProfundidadeIterativa (SearchAlgorithm):
Expand Down Expand Up @@ -142,8 +142,8 @@ def search (self, initialState, pruning='without', trace=False):
if pruning not in valid_pruning_options:
raise ValueError(f"Invalid pruning option: {pruning}. Valid options are {valid_pruning_options}")

# List to keep track of the visited nodes
states = []
# Set to keep track of the visited nodes
states = set()
open = []
new_n = Node(initialState, None)
open.append((new_n, new_n.g))
Expand All @@ -166,7 +166,7 @@ def search (self, initialState, pruning='without', trace=False):
# general pruning
elif pruning == "general" and (new_n.state.env() not in states):
open.append((new_n, new_n.g))
states.append(new_n.state.env())
states.add(new_n.state.env())
return None


Expand All @@ -181,8 +181,8 @@ def search (self, initialState, pruning='without', trace=False):
if pruning not in valid_pruning_options:
raise ValueError(f"Invalid pruning option: {pruning}. Valid options are {valid_pruning_options}")

# List to keep track of the visited nodes
states = []
# Set to keep track of the visited nodes
states = set()
open = []
new_n = Node(initialState, None)
open.append((new_n, new_n.h()))
Expand All @@ -205,7 +205,7 @@ def search (self, initialState, pruning='without', trace=False):
# general pruning
elif pruning == "general" and (new_n.state.env() not in states):
open.append((new_n, new_n.h()))
states.append(new_n.state.env())
states.add(new_n.state.env())
return None


Expand All @@ -220,8 +220,8 @@ def search (self, initialState, pruning='without', trace=False):
if pruning not in valid_pruning_options:
raise ValueError(f"Invalid pruning option: {pruning}. Valid options are {valid_pruning_options}")

# List to keep track of the visited nodes
states = []
# Set to keep track of the visited nodes
states = set()
open = []
new_n = Node(initialState, None)
open.append((new_n, new_n.f()))
Expand All @@ -248,5 +248,5 @@ def search (self, initialState, pruning='without', trace=False):
open.append((new_n,new_n.f()))
# nao eh adiciona o estado ao vetor.
# eh adicionado o conteudo
states.append(new_n.state.env())
states.add(new_n.state.env())
return None

0 comments on commit a3335a6

Please sign in to comment.