Advertisement
Avish_05

Untitled

Jan 12th, 2023
1,786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub PerformHeuristic()
  2. Dim step As Integer
  3. Dim i As Integer
  4. Dim nowAt As Integer
  5. Dim nextAt As Integer
  6. Dim minDistance As Integer
  7.  
  8. nowAt = 1
  9.  
  10. For step = 2 To nCities
  11. minDistance = 10000
  12.  
  13. For i = 2 To nCities
  14.  
  15. If i <> nowAt And Not wasVisited(i) Then
  16.  
  17. If distance(nowAt, i) < minDistance Then
  18.  
  19. nextAt = i
  20.  
  21. minDistance = distance(nowAt, nextAt)
  22. End If
  23. End If
  24. Next i
  25. route(step) = nextAt
  26. wasVisited(nextAt) = True
  27. totalDistance = totalDistance + minDistance
  28. nowAt = nextAt
  29. Next step
  30. totalDistance = totalDistance + distance(nowAt, 1)
  31. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement