예제 #1
0
    def not_same_person(val_a, val_b, name_a, name_b):
        return val_a != val_b

    for pair in all_pairs:
        constraints.append(
            BinaryConstraint(
                pair[0], pair[1], not_same_person,
                "No two seats can be occupied " + "by the same person"))
    return CSP(constraints, variables)


if __name__ == "__main__":
    if len(sys.argv) > 1:
        checker_type = sys.argv[1]
    else:
        checker_type = "dfs"

    if checker_type == "dfs":
        import lab4  # Use for speed comparison
        checker = basic_constraint_checker
    elif checker_type == "fc":
        import lab4
        checker = lab4.forward_checking
    elif checker_type == "fcps":
        import lab4
        checker = lab4.forward_checking_prop_singleton
    else:
        checker = basic_constraint_checker

    solve_csp_problem(moose_csp_problem, checker, verbose=True)
예제 #2
0
        output.append([0, 0, 0, 0, 0, 0, 0, 0, 0])
    for (name, val) in variables:
        i = int(name[0])
        j = int(name[2])
        output[i - 1][j - 1] = val

    return output


if __name__ == "__main__":
    if len(sys.argv) > 1:
        checker_type = sys.argv[1]
    else:
        checker_type = "dfs"

    if checker_type == "dfs":
        checker = basic_constraint_checker
    elif checker_type == "fc":
        import lab4
        checker = lab4.forward_checking
    elif checker_type == "fcps":
        import lab4
        checker = lab4.forward_checking_prop_singleton
    else:
        import lab4
        checker = lab4.forward_checking_prop_singleton

    sol = solve_csp_problem(sudoku_csp_problem, checker, verbose=True)
    for row in make_solution_readable(sol):
        print row
예제 #3
0
파일: moose_csp.py 프로젝트: AIRising/AI
                             "McCain, Palin can't be next to Obama, Biden"))

    # No two seats can be occupied by the same person
    def not_same_person(val_a, val_b, name_a, name_b):
        return val_a != val_b
    for pair in all_pairs:
        constraints.append(
            BinaryConstraint(pair[0], pair[1],
                             not_same_person,
                             "No two seats can be occupied by the same person"))
    return CSP(constraints, variables)

if __name__ == "__main__":
    if len(sys.argv) > 1:
        checker_type = sys.argv[1]
    else:
        checker_type = "dfs"
        
    if checker_type == "dfs":
        checker = basic_constraint_checker
    elif checker_type == "fc":
        import lab4
        checker = lab4.forward_checking
    elif checker_type == "fcps":
        import lab4
        checker = lab4.forward_checking_prop_singleton
    else:
        checker = basic_constraint_checker

    solve_csp_problem(moose_csp_problem, checker, verbose=True)
        if val_a == val_b:
            return False
        return True

    for pair in edges:
        constraints.append(
            BinaryConstraint(pair[0], pair[1],
                             conflict,
                             "Time conflict"))
    return CSP(constraints, variables)

if __name__ == "__main__":
    if len(sys.argv) > 1:
        checker_type = sys.argv[1]
    else:
        checker_type = "dfs"
        
    if checker_type == "dfs":
        checker = basic_constraint_checker
    elif checker_type == "fc":
        import lab4
        checker = lab4.forward_checking
    elif checker_type == "fcps":
        import lab4
        checker = lab4.forward_checking_prop_singleton
    else:
        import lab4
        checker = lab4.forward_checking_prop_singleton

    solve_csp_problem(time_traveling_csp_problem, checker, verbose=True)
예제 #5
0
            return False
        return True

    for pair in all_edges:
        constraints.append(
            BinaryConstraint(pair[0], pair[1], forbidden_edge,
                             "R-B, B-R, Y-Y edges are not allowed"))

    return CSP(constraints, variables)


if __name__ == "__main__":
    if len(sys.argv) > 1:
        checker_type = sys.argv[1]
    else:
        checker_type = "dfs"

    if checker_type == "dfs":
        checker = basic_constraint_checker
    elif checker_type == "fc":
        import lab4
        checker = lab4.forward_checking
    elif checker_type == "fcps":
        import lab4
        checker = lab4.forward_checking_prop_singleton
    else:
        import lab4
        checker = lab4.forward_checking_prop_singleton

    solve_csp_problem(map_coloring_csp_problem, checker, verbose=True)
예제 #6
0
        if val_a == val_b:
            return False
        return True

    for pair in edges:
        constraints.append(
            BinaryConstraint(pair[0], pair[1], conflict,
                             "TA(subject_a) != TA(subject_b) constraint"))
    return CSP(constraints, variables)


if __name__ == "__main__":
    if len(sys.argv) > 1:
        checker_type = sys.argv[1]
    else:
        checker_type = "dfs"

    if checker_type == "dfs":
        checker = basic_constraint_checker
    elif checker_type == "fc":
        import lab4
        checker = lab4.forward_checking
    elif checker_type == "fcps":
        import lab4
        checker = lab4.forward_checking_prop_singleton
    else:
        import lab4
        checker = lab4.forward_checking_prop_singleton

    solve_csp_problem(ta_scheduling_csp_problem, checker, verbose=True)
예제 #7
0
    def conflict(val_a, val_b, var_a, var_b):
        if val_a == val_b:
            return False
        return True

    for pair in edges:
        constraints.append(
            BinaryConstraint(pair[0], pair[1], conflict, "Time conflict"))
    return CSP(constraints, variables)


if __name__ == "__main__":
    if len(sys.argv) > 1:
        checker_type = sys.argv[1]
    else:
        checker_type = "dfs"

    if checker_type == "dfs":
        checker = basic_constraint_checker
    elif checker_type == "fc":
        import lab4
        checker = lab4.forward_checking
    elif checker_type == "fcps":
        import lab4
        checker = lab4.forward_checking_prop_singleton
    else:
        import lab4
        checker = lab4.forward_checking_prop_singleton

    solve_csp_problem(time_traveling_csp_problem, checker, verbose=True)
예제 #8
0
                    #print(my_constraint_var.get_domain())
                if my_constraint_var.domain_size()==0:
                    return False
        for allvar1 in state.get_all_variables():
            if allvar1.domain_size()==1:
                if allvar1 not in visited and allvar1 not in singleton_list:
                    singleton_list.append(allvar1)
    #print(state)        
    return True        
#solve_csp_problem(map_coloring_csp_problem,forward_checking_prop_singleton)
## The code here are for the tester
## Do not change.
from moose_csp import moose_csp_problem
from map_coloring_csp import map_coloring_csp_problem
#from sudoku_csp import sudoku_csp_problem
solve_csp_problem(moose_csp_problem,forward_checking_prop_singleton,True)

def csp_solver_tree(problem, checker):
    problem_func = globals()[problem]
    checker_func = globals()[checker]
    answer, search_tree = problem_func().solve(checker_func)
    return search_tree.tree_to_string(search_tree)

##
## CODE for the learning portion of lab 4.
##

### Data sets for the lab
## You will be classifying data from these sets.
senate_people = read_congress_data('S110.ord')
senate_votes = read_vote_data('S110desc.csv')
            return False
        return True

    for pair in all_edges:
        constraints.append(
            BinaryConstraint(pair[0], pair[1],
                             forbidden_edge,
                             "R-B, B-R, Y-Y edges are not allowed"))

    return CSP(constraints, variables)

if __name__ == "__main__":
    if len(sys.argv) > 1:
        checker_type = sys.argv[1]
    else:
        checker_type = "dfs"
        
    if checker_type == "dfs":
        checker = basic_constraint_checker
    elif checker_type == "fc":
        import lab4
        checker = lab4.forward_checking
    elif checker_type == "fcps":
        import lab4
        checker = lab4.forward_checking_prop_singleton
    else:
        import lab4
        checker = lab4.forward_checking_prop_singleton

    solve_csp_problem(map_coloring_csp_problem, checker, verbose=True)
    for (name,val) in variables:
        i = int(name[0])
        j = int(name[2])
        output[i-1][j-1] = val

    return output
        

if __name__ == "__main__":
    if len(sys.argv) > 1:
        checker_type = sys.argv[1]
    else:
        checker_type = "dfs"
        
    if checker_type == "dfs":
        checker = basic_constraint_checker
    elif checker_type == "fc":
        import lab4
        checker = lab4.forward_checking
    elif checker_type == "fcps":
        import lab4
        checker = lab4.forward_checking_prop_singleton
    else:
        import lab4
        checker = lab4.forward_checking_prop_singleton


    sol = solve_csp_problem(sudoku_csp_problem, checker, verbose=True)
    for row in make_solution_readable(sol):
        print row
        if val_a == val_b:
            return False
        return True

    for pair in edges:
        constraints.append(
            BinaryConstraint(pair[0], pair[1],
                             conflict,
                             "TA(subject_a) != TA(subject_b) constraint"))
    return CSP(constraints, variables)

if __name__ == "__main__":
    if len(sys.argv) > 1:
        checker_type = sys.argv[1]
    else:
        checker_type = "dfs"
        
    if checker_type == "dfs":
        checker = basic_constraint_checker
    elif checker_type == "fc":
        import lab4
        checker = lab4.forward_checking
    elif checker_type == "fcps":
        import lab4
        checker = lab4.forward_checking_prop_singleton
    else:
        import lab4
        checker = lab4.forward_checking_prop_singleton

    solve_csp_problem(ta_scheduling_csp_problem, checker, verbose=True)