Example #1
0
    def _remove_connection_that_introduces_cycles(
            genome: Genome, possible_connection_set: set) -> set:
        connections_to_remove = []
        for connection in possible_connection_set:
            connections = list(genome.connection_genes.keys()) + [connection]

            if exist_cycle(connections=connections):
                connections_to_remove.append(connection)
        logger.debug(
            f'connections that introduce cycles: {connections_to_remove}')
        possible_connection_set -= set(connections_to_remove)
        return possible_connection_set
Example #2
0
 def test_self_recursive_b(self):
     connections = [(-1, 1), (-1, 2), (-1, 3), (-2, 1), (-2, 2), (-2, 3),
                    (1, 0), (2, 0), (3, 0), (2, 2)]
     self.assertEqual(True, exist_cycle(connections))
Example #3
0
    def test_self_recursive(self):
        connections = [(1, 1)]

        self.assertEqual(True, exist_cycle(connections))
Example #4
0
 def test_exists_cycle_when_negative_c(self):
     connections = [(-1, 1), (-1, 2), (-1, 3), (-2, 1), (-2, 2), (-2, 3),
                    (1, 0), (2, 0), (3, 0), (1, 2)]
     self.assertEqual(False, exist_cycle(connections))
Example #5
0
    def test_exists_cycle_when_negative_b(self):
        connections = [(1, 2), (2, 3), (1, 4), (4, 3), (3, 5)]

        self.assertEqual(False, exist_cycle(connections))
Example #6
0
    def test_exists_cycle_positive_b(self):
        connections = [(1, 2), (2, 3), (1, 4), (4, 3), (3, 1)]

        self.assertEqual(True, exist_cycle(connections))