def large(): city_map = Map.from_atsp('atsp/tests/test_data/rbg403.atsp') solver = SimulatedAnnealing(city_map, cooling_factor=0.999) for _ in range(10): solver.solve(timeout=121, print_timeout=5) print(solver.log.time_summary()) print(solver.log.best_summary())
def small(): city_map = Map.from_atsp('atsp/tests/test_data/ftv47.atsp') solver = SimulatedAnnealing(city_map, cooling_factor=0.99997) for _ in range(10): solver.solve(timeout=31, print_timeout=5) print(solver.log.time_summary()) print(solver.log.best_summary())
def medium(): city_map = Map.from_atsp('../atsp/tests/test_data/ftv170.atsp') solver = new_solver(city_map) for _ in range(10): solver.solve(timeout=63, print_timeout=5) print(solver.log.time_summary()) print(solver.log.best_summary())
def large(): city_map = Map.from_atsp('../atsp/tests/test_data/rbg403.atsp') solver = new_solver(city_map) for _ in range(10): solver.solve(timeout=125, print_timeout=5) print(solver.log.time_summary()) print(solver.log.best_summary())
def measure_brute_force(self): values = [] for _ in range(self.repetitions): city_map = Map.from_random_matrix(size=self.size) atsp = Atsp(city_map) start = time.time() atsp.brute_force() time_taken = time.time() - start values.append(time_taken) # logger.debug(time_taken) return sum(values) / len(values)
def __init__(self, file_path, known_best_value, population_size, repetitions=10, timeout=30): city_map = Map.from_atsp(file_path) self.known_best_value = known_best_value self.solver = GeneticSolver(city_map, population_size=population_size, crossover_coefficient=0.8, mutation_coefficient=0.1) self.repetitions = repetitions self.timeout = timeout
def _measure(self, action): values = [] timeouts = 0 for _ in range(self.repetitions): city_map = Map.from_random_matrix(size=self.size) start = time.time() try: action(city_map, self.timeout) time_taken = time.time() - start except TimeoutError: time_taken = self.timeout timeouts += 1 values.append(time_taken) # logger.debug(time_taken) return sum(values) / len(values), timeouts
def city_map(test_set): test_set_path = os.path.join(os.path.dirname(__file__), 'test_data', '{}.txt'.format(test_set)) return Map.from_file(test_set_path)
def load(file_path): city_map = Map.from_file(file_path) if file_path.endswith( 'txt') else Map.from_atsp(file_path) menu = MainMenu(city_map) menu.display()
def __init__(self, file_path, known_best_value, cooling_factor, repetitions=10, timeout=30): city_map = Map.from_atsp(file_path) self.known_best_value = known_best_value self.solver = SimulatedAnnealing(city_map, cooling_factor=cooling_factor) self.repetitions = repetitions self.timeout = timeout