MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / search

Method search

graphs/greedy_best_first.py:119–145  ·  view source on GitHub ↗

Search for the path, if a path is not found, only the starting position is returned

(self)

Source from the content-addressed store, hash-verified

117 self.reached = False
118
119 def search(self) -> Path | None:
120 """
121 Search for the path,
122 if a path is not found, only the starting position is returned
123 """
124 while self.open_nodes:
125 # Open Nodes are sorted using __lt__
126 self.open_nodes.sort()
127 current_node = self.open_nodes.pop(0)
128
129 if current_node.pos == self.target.pos:
130 self.reached = True
131 return self.retrace_path(current_node)
132
133 self.closed_nodes.append(current_node)
134 successors = self.get_successors(current_node)
135
136 for child_node in successors:
137 if child_node in self.closed_nodes:
138 continue
139
140 if child_node not in self.open_nodes:
141 self.open_nodes.append(child_node)
142
143 if not self.reached:
144 return [self.start.pos]
145 return None
146
147 def get_successors(self, parent: Node) -> list[Node]:
148 """

Callers 1

Calls 5

retrace_pathMethod · 0.95
get_successorsMethod · 0.95
sortMethod · 0.80
popMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected