Exemple #1
0
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())
Exemple #2
0
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())
Exemple #3
0
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())
Exemple #4
0
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())
Exemple #5
0
 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)
Exemple #6
0
 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
Exemple #7
0
 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
Exemple #8
0
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)
Exemple #9
0
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()
Exemple #10
0
 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