예제 #1
0
파일: test_dtmc.py 프로젝트: graps1/switss
def test_prmin_prmax():
    for dtmc in dtmcs:
        reach_form ,_,_ = ReachabilityForm.reduce(dtmc,"init","target")
        for solver in solvers:
            m_z_st = reach_form.max_z_state(solver=solver)
            m_z_st_act = reach_form.max_z_state_action(solver=solver)
            m_y_st_act = reach_form.max_y_state_action(solver=solver)
            m_y_st = reach_form.max_y_state(solver=solver)

            for vec in [m_z_st,m_z_st_act,m_y_st,m_y_st_act]:
                assert (vec >= -1e-8).all()

            for vec in [m_z_st,m_z_st_act]:
                assert (vec <= 1+1e-8).all()

            pr_min = reach_form.pr_min()
            pr_max = reach_form.pr_max()

            for vec in [pr_min,pr_max]:
                assert (vec <= 1).all() and (vec >= 0).all()

            assert (pr_min == pr_max).all()

            pr_min_at_init = pr_min[reach_form.initial]
            pr_max_at_init = pr_max[reach_form.initial]

            # we find farkas certificates for pr_min and pr_max
            fark_cert_min = generate_farkas_certificate(
                reach_form,"min",">=",pr_min_at_init - 1e-8)
            fark_cert_max = generate_farkas_certificate(
                reach_form,"max",">=",pr_max_at_init - 1e-8)

            assert (fark_cert_min is not None) and (fark_cert_max is not None)
예제 #2
0
def test_certificates():
    for dtmc in dtmcs:
        reach_form, _, _ = ReachabilityForm.reduce(dtmc, "init", "target")
        for sense in ["<", "<=", ">", ">="]:
            for threshold in [
                    0.1, 0.2, 0.3, 0.4, 0.5, 0.66, 0.7, 0.88, 0.9, 0.999, 1,
                    0.9999999999
            ]:
                fark_cert_min = generate_farkas_certificate(
                    reach_form, "min", sense, threshold)
                fark_cert_max = generate_farkas_certificate(
                    reach_form, "max", sense, threshold)
                assert (fark_cert_max is None) == (fark_cert_min is None)
                if fark_cert_max is not None:
                    check_min = check_farkas_certificate(reach_form,
                                                         "min",
                                                         sense,
                                                         threshold,
                                                         fark_cert_min,
                                                         tol=1e-5)
                    check_max = check_farkas_certificate(reach_form,
                                                         "max",
                                                         sense,
                                                         threshold,
                                                         fark_cert_max,
                                                         tol=1e-5)
                    assert check_min
                    assert check_max
예제 #3
0
def test_certificates():
    for mdp in mdps:
        reach_form, _, _ = ReachabilityForm.reduce(mdp, "init", "target")
        for sense in ["<", "<=", ">", ">="]:
            for threshold in [
                    0.1, 0.2, 0.3, 0.4, 0.5, 0.66, 0.7, 0.88, 0.9, 0.999, 1
            ]:
                print(mdp)
                print(threshold)
                fark_cert_min = generate_farkas_certificate(
                    reach_form, "min", sense, threshold)
                fark_cert_max = generate_farkas_certificate(
                    reach_form, "max", sense, threshold)
                # if the sense is >= or > and there is a certificate for pr_min, then there is one for pr_max
                if sense in [">", ">="]:
                    assert (fark_cert_min is None) or (fark_cert_max
                                                       is not None)
                # and dually:
                if sense in ["<", "<="]:
                    assert (fark_cert_max is None) or (fark_cert_min
                                                       is not None)
                if sense in [">", ">="] and fark_cert_min is not None:
                    check_min = check_farkas_certificate(reach_form,
                                                         "min",
                                                         sense,
                                                         threshold,
                                                         fark_cert_min,
                                                         tol=1e-5)
                    check_max = check_farkas_certificate(reach_form,
                                                         "max",
                                                         sense,
                                                         threshold,
                                                         fark_cert_max,
                                                         tol=1e-5)
                    assert check_min
                    assert check_max
                if sense in ["<", "<="] and fark_cert_max is not None:
                    check_min = check_farkas_certificate(reach_form,
                                                         "min",
                                                         sense,
                                                         threshold,
                                                         fark_cert_min,
                                                         tol=1e-5)
                    check_max = check_farkas_certificate(reach_form,
                                                         "max",
                                                         sense,
                                                         threshold,
                                                         fark_cert_max,
                                                         tol=1e-5)
                    assert check_min
                    assert check_max