示例#1
0
    def test_mutate_add_connection(self):
        g = Genome(3, 1)
        g.connect_nodes_by_id(1, 4, 1)
        g.connect_nodes_by_id(2, 4, 2)
        g.connect_nodes_by_id(3, 4, 3)
        g.create_node_between(2, 4, 5, 4)
        g.connect_nodes_by_id(1, 5, 6)

        self.assertEqual(True, g.select_node_by_id(1).is_connected_to_next_by_id(4))
        self.assertEqual(True, g.select_node_by_id(4).is_connected_to_prev_by_id(1))
        self.assertEqual(True, g.select_node_by_id(1).is_connected_to_next_by_id(5))
        self.assertEqual(True, g.select_node_by_id(2).is_connected_to_next_by_id(5))
        self.assertEqual(True, g.select_node_by_id(5).is_connected_to_next_by_id(4))
        self.assertEqual(True, g.select_node_by_id(3).is_connected_to_next_by_id(4))

        g.connect_nodes_by_id(3, 5, 7)
        self.assertEqual(True, g.select_node_by_id(3).is_connected_to_next_by_id(5))
示例#2
0
    def test_create_node_between(self):
        g = Genome(1, 1)

        g.create_node_between(1, 2, 3, 1)
        self.assertEqual(2, len(g.connections))
        self.assertEqual(1, g.connections[0].get_innovation())
        self.assertEqual(2, g.connections[1].get_innovation())

        g.create_node_between(3, 2, 4, 3, g.select_connection_by_innovation(2))

        self.assertEqual(3, len(g.connections))

        current_node = g.nodes[0]
        self.assertEqual(1, g.nodes[0].get_innovation())

        current_node = current_node.get_next_connections()[0].get_next_node()
        self.assertEqual(3, current_node.get_innovation())

        current_node = current_node.get_next_connections()[0].get_next_node()
        self.assertEqual(4, current_node.get_innovation())

        current_node = current_node.get_next_connections()[0].get_next_node()
        self.assertEqual(2, current_node.get_innovation())
示例#3
0
 def test_get_next_nodes(self):
     g = Genome(1, 1)
     g.create_node_between(1, 2, 3, 1)
     self.assertEqual([3], [n.get_innovation() for n in g.select_node_by_id(1).get_next_nodes()])