Пример #1
0
 def select_cluster_combinations(
     self, cluster1: Cluster, cluster2: Cluster, genome_count: int
 ) -> List[Tuple[StorageGenome]]:
     """
     :param cluster1: Cluster to choose 1
     :param cluster2: Cluster to choose 2
     :param genome_count: int number of seats which should be filled
     :return: List[Tuple[StorageGenome]] combination from given cluster
     """
     genomes1 = self.get_genomes_in_cluster(cluster1.cluster_id)
     genomes2 = self.get_genomes_in_cluster(cluster2.cluster_id)
     g1 = weighted_choice_range(genomes1, genome_count)
     g2 = weighted_choice_range(genomes2, genome_count)
     return list(zip(g1, g2))
Пример #2
0
    def select_genomes_for_breeding(self, breeding_percentage: float) -> List[Tuple[StorageGenome, StorageGenome]]:
        """
        Selects genomes for breeding currently best two from all Clusters
        :type breeding_percentage: float
        :return: tuple(Storage)
        """
        result = []
        for cluster in self.cluster_repository.get_current_clusters():
            genome_one = self.get_genomes_in_cluster(cluster.cluster_id)
            genome_two = genome_one
            seats_to_mutation = int(cluster.offspring * breeding_percentage)
            result.extend(
                list(
                    zip(
                        weighted_choice_range(genome_one, seats_to_mutation),
                        weighted_choice_range(genome_two, seats_to_mutation),
                    )
                )
            )

        return result
Пример #3
0
    def select_genomes_for_mutation(self, mutation_percentage: float) -> List[StorageGenome]:
        """
        Selects genome for mutation currently the best from all Clusters
        :param mutation_percentage: float
        :return: StorageGenome the most fit
        """
        result = []
        for cluster in self.cluster_repository.get_current_clusters():
            step = self.get_genomes_in_cluster(cluster.cluster_id)
            seats_to_mutation = int(cluster.offspring * mutation_percentage)

            result.extend(weighted_choice_range(step, seats_to_mutation))
        return result