Пример #1
0
    def test_genome_json(self):
        """Test whether genome objects can be saved to and loaded from JSON."""
        genome = GenomeUnitTest.generate_genome()

        dump = json.dumps(genome.to_json())
        genome_load = Genome.from_json(json.loads(dump))

        self.assertEqual(len(genome), len(genome_load))
        self.assertEqual(
            genome.connection_genes.union(genome_load.connection_genes),
            genome.connection_genes)
Пример #2
0
    def from_json(config):
        """Load a gene object from JSON.

        Arguments:
            config: the JSON dictionary loaded from file.

        Returns: a gene object.
        """
        creature = Creature()
        creature.genotype = Genome.from_json(config['genotype'])
        creature.age = config['age']
        creature.fitness = config['fitness']
        creature.raw_fitness = config['raw_fitness']
        creature.name_suffix = config['name_suffix']
        # TODO: Restore creature's species.
        creature.past_species = config['past_species']

        creature.phenotype = Phenotype(creature.genotype)

        return creature