Ejemplo n.º 1
0
 def test_i_consistency_one(self):
     rand_var = random.choice(tuple(self.const_problem1.get_variables()))
     rand_var.assign(random.choice(rand_var.domain))
     self.assertRaises(AssertionError, csp.i_consistency,
                       self.const_problem1, 17)
     self.const_problem1.unassign_all_variables()
     res = csp.i_consistency(self.const_problem1, 1)
     self.assertTrue(res)
Ejemplo n.º 2
0
                        with_history=True)
    measure_performance(2, "pc2_n_queens_problem", pc2_n_queens_problem,
                        "simulated_annealing", 100000, 0.5, 0.99999)
    measure_performance(2, "pc2_n_queens_problem", pc2_n_queens_problem,
                        "random_restart_first_choice_hill_climbing", 100, 100,
                        10)
    general_genetic_n_queens_problem = csp.GeneralGeneticConstraintProblem(
        pc2_n_queens_problem, 0.1)
    measure_performance(2, "pc2_n_queens_problem",
                        general_genetic_n_queens_problem,
                        "genetic_local_search", 100, 100, 0.1)

two_consistency_n_queens_problem = copy.deepcopy(n_queens_problem)
two_consistency_n_queens_problem.unassign_all_variables()
two_consistency_start_time = time.process_time()
is_two_consistent = csp.i_consistency(two_consistency_n_queens_problem, 2)
two_consistency_end_time = time.process_time()
if is_two_consistent:
    print()
    print()
    print("-" * 145)
    print("using 2-consistency as a preprocessing stage which took",
          two_consistency_end_time - two_consistency_start_time, "seconds")
    print("-" * 145)
    measure_performance(1,
                        "two_consistency_n_queens_problem",
                        two_consistency_n_queens_problem,
                        "backtracking_search",
                        with_history=True)
    measure_performance(1,
                        "two_consistency_n_queens_problem",
Ejemplo n.º 3
0
                        100000, 0.5, 0.99999)
    measure_performance(2, "pc2_verbal_arithmetic_problem",
                        pc2_verbal_arithmetic_problem,
                        "random_restart_first_choice_hill_climbing", 100, 100,
                        10)
    general_genetic_verbal_arithmetic_problem = csp.GeneralGeneticConstraintProblem(
        pc2_verbal_arithmetic_problem, 0.1)
    measure_performance(2, "pc2_verbal_arithmetic_problem",
                        general_genetic_verbal_arithmetic_problem,
                        "genetic_local_search", 100, 100, 0.1)

two_consistency_verbal_arithmetic_problem = copy.deepcopy(
    verbal_arithmetic_problem)
two_consistency_verbal_arithmetic_problem.unassign_all_variables()
two_consistency_start_time = time.process_time()
is_two_consistent = csp.i_consistency(
    two_consistency_verbal_arithmetic_problem, 2)
two_consistency_end_time = time.process_time()
if is_two_consistent:
    print()
    print()
    print("-" * 145)
    print("using 2-consistency as a preprocessing stage which took",
          two_consistency_end_time - two_consistency_start_time, "seconds")
    print("-" * 145)
    measure_performance(1,
                        "two_consistency_verbal_arithmetic_problem",
                        two_consistency_verbal_arithmetic_problem,
                        "backtracking_search",
                        with_history=True)
    measure_performance(1,
                        "two_consistency_verbal_arithmetic_problem",
Ejemplo n.º 4
0
                        pc2_car_assembly_problem, "simulated_annealing",
                        100000, 0.5, 0.99999)
    measure_performance(2, "pc2_car_assembly_problem",
                        pc2_car_assembly_problem,
                        "random_restart_first_choice_hill_climbing", 10, 10,
                        10)
    general_genetic_car_assembly_problem = csp.GeneralGeneticConstraintProblem(
        pc2_car_assembly_problem, 0.1)
    measure_performance(2, "pc2_car_assembly_problem",
                        general_genetic_car_assembly_problem,
                        "genetic_local_search", 100, 100, 0.1)

two_consistency_car_assembly_problem = copy.deepcopy(car_assembly_problem)
two_consistency_car_assembly_problem.unassign_all_variables()
two_consistency_start_time = time.process_time()
is_two_consistent = csp.i_consistency(two_consistency_car_assembly_problem, 2)
two_consistency_end_time = time.process_time()
if is_two_consistent:
    print()
    print()
    print("-" * 145)
    print("using 2-consistency as a preprocessing stage which took",
          two_consistency_end_time - two_consistency_start_time, "seconds")
    print("-" * 145)
    measure_performance(1,
                        "two_consistency_car_assembly_problem",
                        two_consistency_car_assembly_problem,
                        "backtracking_search",
                        with_history=True)
    measure_performance(1,
                        "two_consistency_car_assembly_problem",
Ejemplo n.º 5
0
                        pc2_map_coloring_problem, "simulated_annealing",
                        100000, 0.5, 0.99999)
    measure_performance(2, "pc2_map_coloring_problem",
                        pc2_map_coloring_problem,
                        "random_restart_first_choice_hill_climbing", 100, 100,
                        10)
    general_genetic_map_coloring_problem = csp.GeneralGeneticConstraintProblem(
        pc2_map_coloring_problem, 0.1)
    measure_performance(2, "pc2_map_coloring_problem",
                        general_genetic_map_coloring_problem,
                        "genetic_local_search", 100, 100, 0.1)

two_consistency_map_coloring_problem = copy.deepcopy(map_coloring_problem)
two_consistency_map_coloring_problem.unassign_all_variables()
two_consistency_start_time = time.process_time()
is_two_consistent = csp.i_consistency(two_consistency_map_coloring_problem, 2)
two_consistency_end_time = time.process_time()
if is_two_consistent:
    print()
    print()
    print("-" * 145)
    print("using 2-consistency as a preprocessing stage which took",
          two_consistency_end_time - two_consistency_start_time, "seconds")
    print("-" * 145)
    measure_performance(1,
                        "two_consistency_map_coloring_problem",
                        two_consistency_map_coloring_problem,
                        "backtracking_search",
                        with_history=True)
    measure_performance(1,
                        "two_consistency_map_coloring_problem",
Ejemplo n.º 6
0
 def test_i_consistency_seven(self):
     res = csp.i_consistency(self.const_problem3, 2)
     self.assertTrue(res)
Ejemplo n.º 7
0
 def test_i_consistency_five(self):
     res = csp.i_consistency(self.const_problem2, 2)
     self.assertFalse(res)
Ejemplo n.º 8
0
 def test_i_consistency_four(self):
     res = csp.i_consistency(self.const_problem2, 1)
     self.assertTrue(res)
Ejemplo n.º 9
0
 def test_i_consistency_three(self):
     res = csp.i_consistency(self.const_problem1, 3)
     self.assertFalse(res)
                        with_history=True)
    measure_performance(2, "pc2_einstein_problem", pc2_einstein_problem,
                        "simulated_annealing", 100000, 0.5, 0.99999)
    measure_performance(2, "pc2_einstein_problem", pc2_einstein_problem,
                        "random_restart_first_choice_hill_climbing", 100, 100,
                        10)
    general_genetic_pc2_einstein_problem = csp.GeneralGeneticConstraintProblem(
        pc2_einstein_problem, 0.1)
    measure_performance(2, "pc2_einstein_problem",
                        general_genetic_pc2_einstein_problem,
                        "genetic_local_search", 100, 100, 0.1)

two_consistency_einstein_problem = copy.deepcopy(einstein_problem)
two_consistency_einstein_problem.unassign_all_variables()
two_consistency_start_time = time.process_time()
is_two_consistent = csp.i_consistency(two_consistency_einstein_problem, 2)
two_consistency_end_time = time.process_time()
if is_two_consistent:
    print()
    print()
    print("-" * 145)
    print("using 2-consistency as a preprocessing stage which took",
          two_consistency_end_time - two_consistency_start_time, "seconds")
    print("-" * 145)
    measure_performance(1,
                        "two_consistency_einstein_problem",
                        two_consistency_einstein_problem,
                        "backtracking_search",
                        with_history=True)
    measure_performance(1,
                        "two_consistency_einstein_problem",
Ejemplo n.º 11
0
    measure_performance(2, "pc2_magic_square_problem", pc2_magic_square_problem,
                        "min_conflicts", 100000, with_history=True)
    measure_performance(2, "pc2_magic_square_problem", pc2_magic_square_problem,
                        "constraints_weighting", 10000, with_history=True)
    measure_performance(2, "pc2_magic_square_problem", pc2_magic_square_problem,
                        "simulated_annealing", 100000, 0.5, 0.99999)
    measure_performance(2, "pc2_magic_square_problem", pc2_magic_square_problem,
                        "random_restart_first_choice_hill_climbing", 100, 100, 10)
    general_genetic_pc2_magic_square_problem = csp.GeneralGeneticConstraintProblem(pc2_magic_square_problem, 0.1)
    measure_performance(2, "general_genetic_pc2_magic_square_problem", general_genetic_pc2_magic_square_problem,
                        "genetic_local_search", 1000, 1000, 0.1)

two_consistency_magic_square_problem = copy.deepcopy(magic_square_problem)
two_consistency_magic_square_problem.unassign_all_variables()
two_consistency_start_time = time.process_time()
is_two_consistent = csp.i_consistency(two_consistency_magic_square_problem, 2)
two_consistency_end_time = time.process_time()
if is_two_consistent:
    print()
    print()
    print("-" * 145)
    print("using 2-consistency as a preprocessing stage which took",
          two_consistency_end_time - two_consistency_start_time, "seconds")
    print("-" * 145)
    measure_performance(1, "two_consistency_magic_square_problem", two_consistency_magic_square_problem,
                        "backtracking_search", with_history=True)
    measure_performance(1, "two_consistency_magic_square_problem", two_consistency_magic_square_problem,
                        "backtracking_search", inference=csp.forward_check, with_history=True)
    measure_performance(1, "two_consistency_magic_square_problem", two_consistency_magic_square_problem,
                        "heuristic_backtracking_search", with_history=True)
    measure_performance(1, "two_consistency_magic_square_problem", two_consistency_magic_square_problem,