Exemplo n.º 1
0
    def test_node_gene_json(self):
        """Test whether a node gene can be saved to and loaded from JSON."""
        ng = NodeGene(Hidden())
        dump = json.dumps(ng.to_json())
        ng_load = NodeGene.from_json(json.loads(dump))

        self.assertEqual(ng, ng_load)
Exemplo n.º 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