Exemple #1
0
 def test_successful_distance(self):
     """> Test when a distance-measure should be performed."""
     # Folder must be root to load in make_net properly
     if os.getcwd().split('\\')[-1] == 'tests': os.chdir('..')
     
     # Setup the nodes to compare
     cfg = Config()
     cfg.genome.compatibility_weight = 1
     node0 = SimpleNodeGene(key=0, cfg=cfg.genome)
     node0.bias = 0
     node1 = SimpleNodeGene(key=1, cfg=cfg.genome)
     node1.bias = 1
     conn_set1 = get_connections(receiving_key=0, sending_keys={-1, -2}, cfg=cfg.genome)
     conn_set2 = get_connections(receiving_key=1, sending_keys={-1, -2}, cfg=cfg.genome)
     
     # Create an empty NodeComparingCache
     cache = NodeComparingCache()
     
     # Fetch the result of the distance-measure
     result = cache(
             node0=node0,
             node1=node1,
             conn0=conn_set1,
             conn1=conn_set2,
             cfg=cfg.genome,
     )
     self.assertEqual(result, (True, 1.0))  # Only distance-difference is in the bias
Exemple #2
0
 def test_distance_success(self):
     """> Test if the distance-parameter is updated correctly after successful read."""
     # Folder must be root to load in make_net properly
     if os.getcwd().split('\\')[-1] == 'tests': os.chdir('..')
     
     # Setup the nodes to compare
     cfg = Config()
     cfg.genome.compatibility_weight = 1
     node0 = SimpleNodeGene(key=0, cfg=cfg.genome)
     node0.bias = 0
     node1 = SimpleNodeGene(key=1, cfg=cfg.genome)
     node1.bias = 1
     conn_set1 = get_connections(receiving_key=0, sending_keys={-1, -2}, cfg=cfg.genome)
     conn_set2 = get_connections(receiving_key=1, sending_keys={-1, -2}, cfg=cfg.genome)
     
     # Create an empty NodeComparingCache
     cache = NodeComparingCache()
     
     # Cache the result of the distance-measure
     result = cache(
             node0=node0,
             node1=node1,
             conn0=conn_set1,
             conn1=conn_set2,
             cfg=cfg.genome,
     )
     
     # Check the distance-parameter
     self.assertEqual(result, (True, 1.0))
     self.assertEqual(cache.comparable[(0, 1)], True)
     self.assertFalse((1, 0) in cache.comparable)