Exemple #1
0
    def test_connection_gene_json(self):
        """Test whether a connection gene can be saved to and loaded from JSON.
        """
        cg = ConnectionGene(0, 1)
        dump = json.dumps(cg.to_json())
        cg_load = ConnectionGene.from_json(json.loads(dump))

        self.assertEqual(cg, cg_load)
        self.assertEqual(cg.is_enabled, cg_load.is_enabled)
Exemple #2
0
    def from_json(config):
        """Load a genome object from JSON.

        Arguments:
            config: the JSON dictionary loaded from file.

        Returns: a genome object.
        """
        genotype = Genome()
        genotype.add_genes([
            NodeGene.from_json(ng_config) for ng_config in config['node_genes']
        ])
        genotype.add_genes([
            ConnectionGene.from_json(cg_config)
            for cg_config in config['connection_genes']
        ])

        return genotype