Skip to content

Commit ab6f622

Browse files
committed
trimmed trailing whitespaces
1 parent 8f8e9c0 commit ab6f622

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

PathPlanning/AntColonyOptimization/ant_colony_optimization.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
See Wikipedia article (https://en.wikipedia.org/wiki/Ant_colony_optimization_algorithms)
77
88
References:
9-
- Dorigo, M.; Maniezzo, V.; Colorni, A. (1996). "Ant system: optimization by a
10-
colony of cooperating agents". IEEE Transactions on Systems, Man, and
9+
- Dorigo, M.; Maniezzo, V.; Colorni, A. (1996). "Ant system: optimization by a
10+
colony of cooperating agents". IEEE Transactions on Systems, Man, and
1111
Cybernetics, Part B. 26 (1): 29–41.
1212
- Dorigo, M.; Stützle, T. (2004). "Ant Colony Optimization". MIT Press.
1313
@@ -55,12 +55,12 @@ def __hash__(self):
5555
class ACOPathPlanner:
5656
"""
5757
Ant Colony Optimization path planner for grid-based environments.
58-
58+
5959
ACO simulates the behavior of real ants searching for food. Ants deposit
6060
pheromones on paths they traverse, and other ants are attracted to paths
6161
with higher pheromone concentrations. Over time, shorter paths accumulate
6262
more pheromones, leading the colony to converge on optimal solutions.
63-
63+
6464
Attributes:
6565
resolution: Grid resolution in meters
6666
min_x, max_x: X-axis boundaries
@@ -75,7 +75,7 @@ class ACOPathPlanner:
7575
def __init__(self, ox, oy, resolution, start, goal):
7676
"""
7777
Initialize ACO planner.
78-
78+
7979
Args:
8080
ox: List of x positions of obstacles [m]
8181
oy: List of y positions of obstacles [m]
@@ -113,7 +113,7 @@ def __init__(self, ox, oy, resolution, start, goal):
113113
def planning(self):
114114
"""
115115
Execute ACO path planning algorithm.
116-
116+
117117
Returns:
118118
rx: List of x positions along the path
119119
ry: List of y positions along the path
@@ -158,7 +158,7 @@ def planning(self):
158158
def construct_solution(self):
159159
"""
160160
Construct a solution path for one ant using probabilistic state transition.
161-
161+
162162
Returns:
163163
path: List of nodes representing the path, or None if no path found
164164
"""
@@ -197,11 +197,11 @@ def construct_solution(self):
197197
def get_neighbors(self, node, visited):
198198
"""
199199
Get valid neighboring nodes (not visited, not obstacles, within bounds).
200-
200+
201201
Args:
202202
node: Current node
203203
visited: Set of visited node coordinates
204-
204+
205205
Returns:
206206
neighbors: List of valid neighbor nodes
207207
"""
@@ -230,14 +230,14 @@ def get_neighbors(self, node, visited):
230230
def select_next_node(self, current, neighbors):
231231
"""
232232
Select next node based on pheromone trail and heuristic information.
233-
233+
234234
Uses the ACO probability formula:
235235
P[i,j] = (tau[i,j]^alpha * eta[i,j]^beta) / sum(tau^alpha * eta^beta)
236-
236+
237237
Args:
238238
current: Current node
239239
neighbors: List of candidate neighbor nodes
240-
240+
241241
Returns:
242242
selected_node: Next node to visit
243243
"""
@@ -273,10 +273,10 @@ def select_next_node(self, current, neighbors):
273273
def calc_heuristic(self, node):
274274
"""
275275
Calculate heuristic value (Euclidean distance to goal).
276-
276+
277277
Args:
278278
node: Node to evaluate
279-
279+
280280
Returns:
281281
distance: Euclidean distance to goal node
282282
"""
@@ -285,10 +285,10 @@ def calc_heuristic(self, node):
285285
def update_pheromones(self, all_paths, all_path_lengths):
286286
"""
287287
Update pheromone levels: evaporation + deposition.
288-
288+
289289
Pheromone update rule:
290290
tau[i,j] = (1 - rho) * tau[i,j] + sum(delta_tau[i,j])
291-
291+
292292
Args:
293293
all_paths: List of paths found by all ants
294294
all_path_lengths: Corresponding path lengths
@@ -307,10 +307,10 @@ def update_pheromones(self, all_paths, all_path_lengths):
307307
def calc_path_length(self, path):
308308
"""
309309
Calculate total Euclidean path length.
310-
310+
311311
Args:
312312
path: List of nodes
313-
313+
314314
Returns:
315315
length: Total path length in grid units
316316
"""
@@ -332,11 +332,11 @@ def calc_position(self, index, min_pos):
332332
def get_obstacle_map(self, ox, oy):
333333
"""
334334
Create 2D boolean obstacle map from obstacle coordinates.
335-
335+
336336
Args:
337337
ox: List of obstacle x coordinates
338338
oy: List of obstacle y coordinates
339-
339+
340340
Returns:
341341
obstacle_map: 2D boolean array
342342
"""
@@ -356,7 +356,7 @@ def get_obstacle_map(self, ox, oy):
356356
def get_motion_model():
357357
"""
358358
Define 8-directional movement model.
359-
359+
360360
Returns:
361361
motion: List of [dx, dy] movement vectors
362362
"""
@@ -375,7 +375,7 @@ def get_motion_model():
375375
def plot_pheromone_map(self, iteration):
376376
"""
377377
Visualize pheromone distribution as heatmap.
378-
378+
379379
Args:
380380
iteration: Current iteration number
381381
"""

0 commit comments

Comments
 (0)