192 def __init__(self, problem, archive, *, initial_tours=8, seed=0):
219 def run(self, budget, *, seed_tours=()):
220 """Optionally measure caller-supplied tours before random starts and offspring."""
222 raise ValueError(
"Use an empty archive for each Traveling Thief run.")
223 budget = _positive_int(budget,
"budget")
224 rng = np.random.default_rng(self.
seed)
225 seeds = iter(islice(seed_tours, budget))
226 transitions = updates = outside = 0
228 for attempt
in range(budget):
229 tour = next(seeds,
None)
232 tour = (0, *map(int, rng.permutation(np.arange(1, cities))))
234 parent = self.
archive[int(rng.integers(len(self.
archive)))][:cities]
235 start, end = sorted(rng.choice(np.arange(1, cities), 2, replace=
False))
236 tour = (*parent[:start], *reversed(parent[start:end + 1]), *parent[end + 1:])
237 solution, count = self.
problem.solve_packing(tour)
239 features = solution.tour_length, solution.profit
240 fitness = (solution.fitness,)
241 if (self.
archive.in_bounds(features, self.
archive.features_domain)
242 and self.
archive.in_bounds(fitness, self.
archive.fitness_domain)):
248 updates += self.
archive.nb_added - before