Problem 605679 · medium · Level 06 Heuristics & Optimization

Hut-to-Hut Hiking Loop

ant colony optimisation · pheromone · evaporation · asymmetric travelling salesman

A hiking club plans a loop through n mountain huts: start at any hut, visit every hut exactly once and walk back to the start. Walking uphill is slower than walking downhill, so the time from hut i to hut j is not the same as from j to i, and walking a loop the other way round changes its total time.

Write hut_tour(huts) that returns the order of the visits as a list of hut indices (every index from 0 to n - 1 exactly once) with a total walking time as short as you can make it.

huts is a list of (x, y, height) triples in kilometres. The tests build them with hut_map(n, seed). walk_minutes(huts, i, j) gives the minutes from hut i to hut j, and loop_minutes(huts, route) the total for a closed loop. All three are available in your code.

How this problem is scored

A loop passes if it is valid and no slower than the loop you get by starting at hut 0 and always walking to the unvisited hut that is quickest to reach. Its quality (0 to 100) is the share of the gap between that loop and the fastest loop we know that you close.

Examples

Input:  huts = hut_map(14, 1)
Output: a list such as [0, 9, 4, 12, 1, 7, 3, 11, 2, 13, 6, 10, 5, 8]
        any order of 0..13 that is no slower than the quickest-next-hut loop passes

Constraints

  • 14 <= n <= 60
  • Each test must finish in well under a second in your browser. Limit your loops by a number of rounds, not by the clock, so the result is the same on every run.

Goals

  • Build many routes at random, biased by what earlier routes learned
  • Balance pheromone (experience) against short steps (greed)
  • Handle travel times that differ with the direction of travel
Starting Python…