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

Method get_neighbors

searches/hill_climbing.py:37–59  ·  view source on GitHub ↗

Returns a list of coordinates of neighbors adjacent to the current coordinates. Neighbors: | 0 | 1 | 2 | | 3 | _ | 4 | | 5 | 6 | 7 |

(self)

Source from the content-addressed store, hash-verified

35 return self.function(self.x, self.y)
36
37 def get_neighbors(self):
38 """
39 Returns a list of coordinates of neighbors adjacent to the current coordinates.
40
41 Neighbors:
42 | 0 | 1 | 2 |
43 | 3 | _ | 4 |
44 | 5 | 6 | 7 |
45 """
46 step_size = self.step_size
47 return [
48 SearchProblem(x, y, step_size, self.function)
49 for x, y in (
50 (self.x - step_size, self.y - step_size),
51 (self.x - step_size, self.y),
52 (self.x - step_size, self.y + step_size),
53 (self.x, self.y - step_size),
54 (self.x, self.y + step_size),
55 (self.x + step_size, self.y - step_size),
56 (self.x + step_size, self.y),
57 (self.x + step_size, self.y + step_size),
58 )
59 ]
60
61 def __hash__(self):
62 """

Callers 2

simulated_annealingFunction · 0.80
hill_climbingFunction · 0.80

Calls 1

SearchProblemClass · 0.85

Tested by

no test coverage detected