Exemple #1
0
def test_update_gbest_neighborhood(swarm, p, r):
    """Test if update_gbest_neighborhood gives the expected return values"""
    topology = VonNeumann()
    pos, cost = topology.compute_gbest(swarm, p=p, r=r)
    expected_pos = np.array([9.90438476e-01, 2.50379538e-03, 1.87405987e-05])
    expected_cost = 1.0002528364353296
    assert cost == pytest.approx(expected_cost)
    assert pos == pytest.approx(expected_pos)
Exemple #2
0
def test_neighbor_idx(swarm, p, r):
    """Test if the neighbor_idx attribute is assigned"""
    topology = VonNeumann()
    topology.compute_gbest(swarm, p=p, r=r)
    assert topology.neighbor_idx is not None