Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // NACO - Nodes Ant Colony Optimisation = ACO, but the pheromones are stored on nodes, instead of on edges
- def findShortestRoute(start, end): // Returns the optimal found path from start to end
- initiliasePheromones() // Set the initial values of pheromones in each cell (node) to `1`
- For each genertion in generations:
- routes = ()
- For each ant in ants_per_gen:
- route = find_path(start, end)
- routes.add(route)
- bestRoute min= route // Keep track of the shortest path found by an ant so far
- updatePheromones(routes) // Update the pheromones in each cell using the formulas from the report
- return bestRoute
- // Returns a path from start to end after choosing each next node in the path, using a probablity directly proportional to the pheromone values
- def find_path(start, end):
- path = ()
- current = start
- while current != end:
- if current does not have any neighbor that was not visited before:
- current = move current one step back // to the cell it came from
- else
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement