Exemple #1
0
def test_penalty_custom_with_bounds_failing_min_bound(value):
    def custom_with_bounds(ocp, nlp, t, x, u, p):
        my_values = DM.zeros((12, 1)) + x[0]
        return -10, my_values, 10

    ocp = prepare_test_ocp()
    x = [DM.ones((12, 1)) * value]

    penalty_type = ConstraintFcn.CUSTOM
    penalty = Constraint(penalty_type)

    penalty.min_bound = 0
    penalty.custom_function = custom_with_bounds

    with pytest.raises(RuntimeError):
        penalty_type.value[0](penalty, ocp, ocp.nlp[0], [], x, [], [])
Exemple #2
0
def test_penalty_custom_with_bounds_failing_min_bound(value):
    def custom_with_bounds(pn):
        return -10, pn.nlp.states["q"].cx, 10

    ocp = prepare_test_ocp()
    t = [0]
    x = [DM.ones((12, 1)) * value]
    u = [0]

    penalty_type = ConstraintFcn.CUSTOM
    penalty = Constraint(penalty_type)

    penalty.min_bound = 0
    penalty.custom_function = custom_with_bounds

    with pytest.raises(RuntimeError):
        penalty_type.value[0](penalty,
                              PenaltyNodeList(ocp, ocp.nlp[0], t, x, [], []))