def from_json(config): gene = ConnectionGene() gene.connection = Connection.from_json(config['connection']) gene.innovation_number = config['innovation_number'] gene.is_enabled = config['is_enabled'] return gene
def test_connection_json(self): """Test whether a connection can be saved to and loaded from JSON.""" c = Connection(1, 0) out_file = json.dumps(c.to_json()) c_load = Connection.from_json(json.loads(out_file)) self.assertEqual(c, c_load) self.assertEqual(c.id, c_load.id) self.assertEqual(c.weight, c_load.weight)
def from_json(config): """Load a graph object from JSON. Arguments: config: the JSON dictionary loaded from file. Returns: a graph object. """ graph = Graph() graph.add_nodes([Node.from_json(node) for node in config['nodes']]) for connection in [ Connection.from_json(connection) for connection in config['connections'] ]: graph.add_connection(connection) graph.compile() return graph