def test_2d_box_constraints_entire_line(self):
        # Both constraints are active
        ta, tb, intersect = box_sphere_intersections([1, 1], [-2, 2], [-1, -2],
                                                     [1, 2],
                                                     2,
                                                     entire_line=True)
        assert_array_almost_equal([ta, tb], [0, 0.5])
        assert_equal(intersect, True)

        # None of the contraints are active
        ta, tb, intersect = box_sphere_intersections([1, 1], [-1, 1], [-1, -3],
                                                     [1, 3],
                                                     10,
                                                     entire_line=True)
        assert_array_almost_equal([ta, tb], [0, 2])
        assert_equal(intersect, True)

        # Box Constraints are active
        ta, tb, intersect = box_sphere_intersections([1, 1], [-4, 4], [-1, -3],
                                                     [1, 3],
                                                     10,
                                                     entire_line=True)
        assert_array_almost_equal([ta, tb], [0, 0.5])
        assert_equal(intersect, True)

        # Spherical Constraints are active
        ta, tb, intersect = box_sphere_intersections([1, 1], [-4, 4], [-1, -3],
                                                     [1, 3],
                                                     2,
                                                     entire_line=True)
        assert_array_almost_equal([ta, tb], [0, 0.25])
        assert_equal(intersect, True)

        # Infeasible problems
        ta, tb, intersect = box_sphere_intersections([2, 2], [-4, 4], [-1, -3],
                                                     [1, 3],
                                                     2,
                                                     entire_line=True)
        assert_equal(intersect, False)
        ta, tb, intersect = box_sphere_intersections([1, 1], [-4, 4], [2, 4],
                                                     [2, 4],
                                                     2,
                                                     entire_line=True)
        assert_equal(intersect, False)
Ejemplo n.º 2
0
    def test_2d_box_constraints_entire_line(self):
        # Both constraints are active
        ta, tb, intersect = box_sphere_intersections([1, 1], [-2, 2],
                                                     [-1, -2], [1, 2], 2,
                                                     entire_line=True)
        assert_array_almost_equal([ta, tb], [0, 0.5])
        assert_equal(intersect, True)

        # None of the constraints are active
        ta, tb, intersect = box_sphere_intersections([1, 1], [-1, 1],
                                                     [-1, -3], [1, 3], 10,
                                                     entire_line=True)
        assert_array_almost_equal([ta, tb], [0, 2])
        assert_equal(intersect, True)

        # Box Constraints are active
        ta, tb, intersect = box_sphere_intersections([1, 1], [-4, 4],
                                                     [-1, -3], [1, 3], 10,
                                                     entire_line=True)
        assert_array_almost_equal([ta, tb], [0, 0.5])
        assert_equal(intersect, True)

        # Spherical Constraints are active
        ta, tb, intersect = box_sphere_intersections([1, 1], [-4, 4],
                                                     [-1, -3], [1, 3], 2,
                                                     entire_line=True)
        assert_array_almost_equal([ta, tb], [0, 0.25])
        assert_equal(intersect, True)

        # Infeasible problems
        ta, tb, intersect = box_sphere_intersections([2, 2], [-4, 4],
                                                     [-1, -3], [1, 3], 2,
                                                     entire_line=True)
        assert_equal(intersect, False)
        ta, tb, intersect = box_sphere_intersections([1, 1], [-4, 4],
                                                     [2, 4], [2, 4], 2,
                                                     entire_line=True)
        assert_equal(intersect, False)