def solve(self, show_progress=False, absolute_mute=False): self.show_progress = show_progress TSPSolver.start_solving(self) population = None while not TSPSolver.conditions_met(self): TSPSolver.update_progress(self) if population is None: population = self._generate_initial_population() continue new_population = [] while len(new_population) < len(population): chrom_a, chrom_b = self._select(population) if self._do_crossover(): chrom_a, chrom_b = self._crossover(chrom_a, chrom_b) if self._do_mutation(): chrom_a, chrom_b = self._mutate(chrom_a, chrom_b) new_population.append(chrom_a) new_population.append(chrom_b) population = self._complete_generation(population, new_population) TSPSolver.end_solving(self)
def solve(self, show_progress=False): self.show_progress = show_progress TSPSolver.start_solving(self) all_nodes = range(0, len(self.graph.nodes())) combinations = permutations(all_nodes) for combination in combinations: TSPSolver.update_progress(self, "Combination - %s" % (combination, )) if TSPSolver.conditions_met(self): self.solution_canceled = True break last_node = combination[0] full_route = [last_node] for i in xrange(1, len(combination)): next_node = combination[i] full_route += shortest_path(self.graph, last_node, next_node)[1:] last_node = next_node route = list(combination) route.append(combination[0]) full_route += shortest_path(self.graph, last_node, combination[0])[1:] TSPSolver.set_solution(self, route, full_route) TSPSolver.end_solving(self)
def _conditions_met_(self): if TSPSolver.conditions_met(self) is True: return True if self.t <= 1: return True return False
def _conditions_met_(self): return TSPSolver.conditions_met(self)