Beispiel #1
0
def test_node_count_CBJ():
    csp = sudoku_csp_5()
    make_arc_consistent(csp)
    _, n0 = solve(SolverType.BT, csp)
    _, n1 = solve(SolverType.BJ, csp)
    _, n2 = solve(SolverType.CBJ, csp)
    assert n2 < n1 < n0
    assert n0 == 520
    assert n1 == 504
    assert n2 == 496
Beispiel #2
0
def test_arc_consistency():
    all_puzz = get_all_puzzles()
    all_puzz.extend(
        [sudoku_csp_1(),
         sudoku_csp_2(),
         sudoku_csp_3(),
         sudoku_csp_4()])
    for csp in all_puzz:
        make_arc_consistent(csp)
        for i in range(csp.num_variables()):
            for a in csp.get_domain(i):
                for j in csp.get_vars_in_contraint_with(i):
                    dj = csp.get_domain(j)
                    assert len(dj) != 0
                    assert len(dj) > 1 or a not in dj
    # AC3 should "solve" the easy one
    csp = sudoku_csp_1()
    make_arc_consistent(csp)
    for i in range(81):
        assert len(csp.get_domain(i)) == 1
Beispiel #3
0
def test_test_suites_with_ac3():
    for i, sud in enumerate(t_suites):
        g1 = gen_csp_from_board(list(map(int, sud)))
        g2 = gen_csp_from_board(list(map(int, sud)))
        g3 = gen_csp_from_board(list(map(int, sud)))
        make_arc_consistent(g1)
        make_arc_consistent(g2)
        make_arc_consistent(g3)
        s1, n1 = solve(SolverType.BT, g1)
        s2, n2 = solve(SolverType.BJ, g2)
        s3, n3 = solve(SolverType.CBJ, g3)
        if i == 11:
            assert n1 > n2 > n3
            assert n1 == 427 or n1 == 427 + 1
            assert n2 == 353 or n2 == 353 + 1
            assert n3 == 316 or n3 == 316 + 1
        else:
            assert n1 == n2 == n3 == 81
        s4 = fetch_sudoku_solution(sud)
        assert s1 == s2 == s3 == s4
Beispiel #4
0
def test_correct_solution_CBJ_with_AC3():
    expected = list(map(int, x3))
    csp = sudoku_csp_3()
    make_arc_consistent(csp)
    sol, _ = solve(SolverType.CBJ, csp)
    assert sol == expected