Exemple #1
0
def test_crowding_distance_assignment():
    pareto = _tuples_to_NSGAMeta([(3, 5), (5, 3), (4, 4)])
    three_five, five_three, four_four = pareto
    crowding_distance_assignment(pareto)

    assert three_five.distance == float('inf')
    assert five_three.distance == float('inf')
    assert four_four.distance == 2
Exemple #2
0
def test_crowd_compare():
    pareto = _tuples_to_NSGAMeta([(3, 5), (5, 3), (4, 4), (4.01, 3.99),
                                  (4.5, 3.5)])
    three_five, five_three, four_four, approx_four_four, half_half = pareto
    fast_non_dominated_sort(pareto)  # assigns rank
    crowding_distance_assignment(pareto)  # assigns distance

    assert all([three_five.crowd_compare(other) == -1 for other in pareto[2:]])
    assert all([five_three.crowd_compare(other) == -1 for other in pareto[2:]])
Exemple #3
0
def test_crowding_distance_assignment_inf():
    pareto = _tuples_to_NSGAMeta([(3, float('inf')), (5, 3), (4, 4)])
    three_inf, five_three, four_four = pareto
    crowding_distance_assignment(pareto)

    assert three_inf.distance == float('inf')
    assert five_three.distance == float('inf')
    #  In our implementation, we ignore 'axis' that contain inf values.
    assert four_four.distance == 1