Advertisement
VladNitu

test vim 2

Mar 14th, 2023
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. // NACO - Nodes Ant Colony Optimisation = ACO, but the pheromones are stored on nodes, instead of on edges
  2.  
  3. def findShortestRoute(start, end): // Returns the optimal found path from start to end
  4.  
  5. initiliasePheromones() // Set the initial values of pheromones in each cell (node) to `1`
  6.  
  7. For each genertion in generations:
  8. routes = ()
  9. For each ant in ants_per_gen:
  10. route = find_path(start, end)
  11. routes.add(route)
  12. bestRoute min= route // Keep track of the shortest path found by an ant so far
  13.  
  14. updatePheromones(routes) // Update the pheromones in each cell using the formulas from the report
  15.  
  16. return bestRoute
  17.  
  18.  
  19. // Returns a path from start to end after choosing each next node in the path, using a probablity directly proportional to the pheromone values
  20. def find_path(start, end):
  21. path = ()
  22. current = start
  23. while current != end:
  24. if current does not have any neighbor that was not visited before:
  25. current = move current one step back // to the cell it came from
  26. else
  27. current = move current to the next unvisited neighbour, according to the pheromone values and formulas used in the slides
  28. path.add(current)
  29. return path
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement