Ejemplo n.º 1
0
    def test_update_state_in_range():
        """Test update_state method where all updated values are within the
        tolerated range"""

        problem = ContinuousOpt(5, OneMax(), maximize=True,
                                min_val=0, max_val=20, step=1)

        x = np.array([0, 1, 2, 3, 4])
        problem.set_state(x)

        y = np.array([2, 4, 6, 8, 10])
        updated = problem.update_state(y)

        assert np.array_equal(updated, (x + y))
Ejemplo n.º 2
0
    def test_update_state_outside_range():
        """Test update_state method where some updated values are outside the
        tolerated range"""

        problem = ContinuousOpt(5, OneMax(), maximize=True,
                                min_val=0, max_val=5, step=1)

        x = np.array([0, 1, 2, 3, 4])
        problem.set_state(x)

        y = np.array([2, -4, 6, -8, 10])
        updated = problem.update_state(y)

        z = np.array([2, 0, 5, 0, 5])

        assert np.array_equal(updated, z)