Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub PerformHeuristic()
- Dim step As Integer
- Dim i As Integer
- Dim nowAt As Integer
- Dim nextAt As Integer
- Dim minDistance As Integer
- nowAt = 1
- For step = 2 To nCities
- minDistance = 10000
- For i = 2 To nCities
- If i <> nowAt And Not wasVisited(i) Then
- If distance(nowAt, i) < minDistance Then
- nextAt = i
- minDistance = distance(nowAt, nextAt)
- End If
- End If
- Next i
- route(step) = nextAt
- wasVisited(nextAt) = True
- totalDistance = totalDistance + minDistance
- nowAt = nextAt
- Next step
- totalDistance = totalDistance + distance(nowAt, 1)
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement