Exemple #1
0
    def born_wolf(self, wolf1, wolf2):
        print "wolves #: %d" % len(self.wolves)
        if len(self.wolves) >= Environ.MAX_WOLVES:
            return

        genotype = Genotype.npoint_crossover(3, wolf1.genotype, wolf2.genotype)
        genotype = Genotype.npoint_random_mutation(2, genotype)
        self.wolf_genotypes.append(genotype)

        wolf = breve.createInstances(Wolf, 1)
        wolf.generation = max(wolf1.generation, wolf2.generation) + 1
        wolf.initWith(genotype)
        wolf.move(wolf1.getLocation())

        self.__on_new_wolf(wolf)
Exemple #2
0
    def born_rabbit(self, rabbit1, rabbit2):
        print "rabbits #: %d" % len(self.rabbits)
        if len(self.rabbits) >= Environ.MAX_RABBITS:
            return

        g1 = rabbit1.genotype
        g2 = rabbit2.genotype

        genotype = Genotype.npoint_crossover(2, g1, g2)
        genotype = Genotype.npoint_random_mutation(2, genotype)
        self.rabbit_genotypes.append(genotype)

        rabbit = breve.createInstances(Rabbit, 1)
        rabbit.generation = max(rabbit1.generation, rabbit2.generation) + 1
        rabbit.initWith(genotype)
        rabbit.move(rabbit1.getLocation())

        self.__on_new_rabit(rabbit)