def test_ac3_two(self): all_values = set() for var in self.const_problem2.get_variables(): for val in var.domain: all_values.add(val) self.assertEqual(all_values, {2, 4, 5}) res2 = csp.ac3(self.const_problem2) self.assertTrue(res2) reduced_all_values = set() for var in self.const_problem2.get_variables(): for val in var.domain: reduced_all_values.add(val) self.assertEqual(reduced_all_values, {2, 4})
"constraints_weighting", 10000, with_history=True) measure_performance(2, "n_queens_problem", n_queens_problem, "simulated_annealing", 100000, 0.5, 0.99999) measure_performance(2, "n_queens_problem", n_queens_problem, "random_restart_first_choice_hill_climbing", 100, 100, 10) general_genetic_n_queens_problem = csp.GeneralGeneticConstraintProblem( n_queens_problem, 0.1) measure_performance(2, "n_queens_problem", general_genetic_n_queens_problem, "genetic_local_search", 100, 100, 0.1) ac3_n_queens_problem = copy.deepcopy(n_queens_problem) ac3_n_queens_problem.unassign_all_variables() ac3_start_time = time.process_time() ac3_is_arc_consistent = csp.ac3(ac3_n_queens_problem) ac3_end_time = time.process_time() if ac3_is_arc_consistent: print() print() print("-" * 145) print("using ac3 as a preprocessing stage which took", ac3_end_time - ac3_start_time, "seconds") print("-" * 145) measure_performance(1, "ac3_n_queens_problem", ac3_n_queens_problem, "backtracking_search", with_history=True) measure_performance(1, "ac3_n_queens_problem",
measure_performance(2, "sudoku_problem", sudoku_problem, "simulated_annealing", 100000, 0.5, 0.99999, sudoku_start_state_generator, sudoku_successor_generator, sudoku_score_calculator, read_only_variables=read_only_variables) measure_performance(2, "sudoku_problem", sudoku_problem, "random_restart_first_choice_hill_climbing", 100, 10, 10, sudoku_start_state_generator, sudoku_successor_generator, sudoku_score_calculator, read_only_variables=read_only_variables) general_genetic_sudoku_problem = GeneticSudokuConstraintProblem(sudoku_problem, read_only_names, 0.1) measure_performance(2, "general_genetic_sudoku_problem", general_genetic_sudoku_problem, "genetic_local_search", 100, 100, 0.1, read_only_variables=read_only_variables) genetic_sudoku_problem = GeneticSudokuConstraintProblem(sudoku_problem, read_only_names, 0.1) measure_performance(2, "sudoku_genetic_sudoku_problem", genetic_sudoku_problem, "genetic_local_search", 100, 100, 0.1, read_only_variables=read_only_variables) ac3_start_time = time.process_time() ac3_is_arc_consistent = csp.ac3(ac3_sudoku_problem) ac3_end_time = time.process_time() if ac3_is_arc_consistent: print() print() print("-" * 145) print("using ac3 as a preprocessing stage which took", ac3_end_time - ac3_start_time, "seconds") print("-" * 145) measure_performance(1, "ac3_sudoku_problem", ac3_sudoku_problem, "backtracking_search", with_history=True, read_only_variables=read_only_variables) measure_performance(1, "ac3_sudoku_problem", ac3_sudoku_problem, "backtracking_search", inference=csp.forward_check, with_history=True, read_only_variables=read_only_variables) measure_performance(1, "ac3_sudoku_problem", ac3_sudoku_problem, "heuristic_backtracking_search", with_history=True, read_only_variables=read_only_variables)
10000, with_history=True) measure_performance(2, "verbal_arithmetic_problem", verbal_arithmetic_problem, "simulated_annealing", 100000, 0.5, 0.99999) measure_performance(2, "verbal_arithmetic_problem", verbal_arithmetic_problem, "random_restart_first_choice_hill_climbing", 100, 100, 10) general_genetic_verbal_arithmetic_problem = csp.GeneralGeneticConstraintProblem( verbal_arithmetic_problem, 0.1) measure_performance(2, "verbal_arithmetic_problem", general_genetic_verbal_arithmetic_problem, "genetic_local_search", 100, 100, 0.1) ac3_verbal_arithmetic_problem = copy.deepcopy(verbal_arithmetic_problem) ac3_verbal_arithmetic_problem.unassign_all_variables() ac3_start_time = time.process_time() ac3_is_arc_consistent = csp.ac3(ac3_verbal_arithmetic_problem) ac3_end_time = time.process_time() if ac3_is_arc_consistent: print() print() print("-" * 145) print("using ac3 as a preprocessing stage which took", ac3_end_time - ac3_start_time, "seconds") print("-" * 145) measure_performance(1, "ac3_verbal_arithmetic_problem", ac3_verbal_arithmetic_problem, "backtracking_search", with_history=True) measure_performance(1, "ac3_verbal_arithmetic_problem",
100000, with_history=True) measure_performance(2, "car_assembly_problem", car_assembly_problem, "simulated_annealing", 100000, 0.5, 0.99999) measure_performance(2, "car_assembly_problem", car_assembly_problem, "random_restart_first_choice_hill_climbing", 10, 10, 10) general_genetic_car_assembly_problem = csp.GeneralGeneticConstraintProblem( car_assembly_problem, 0.1) measure_performance(2, "car_assembly_problem", general_genetic_car_assembly_problem, "genetic_local_search", 100, 100, 0.1) ac3_car_assembly_problem = copy.deepcopy(car_assembly_problem) ac3_car_assembly_problem.unassign_all_variables() ac3_start_time = time.process_time() ac3_is_arc_consistent = csp.ac3(ac3_car_assembly_problem) ac3_end_time = time.process_time() if ac3_is_arc_consistent: print() print() print("-" * 145) print("using ac3 as a preprocessing stage which took", ac3_end_time - ac3_start_time, "seconds") print("-" * 145) measure_performance(1, "ac3_car_assembly_problem", ac3_car_assembly_problem, "backtracking_search", with_history=True) measure_performance(1, "ac3_car_assembly_problem",
10000, with_history=True) measure_performance(2, "map_coloring_problem", map_coloring_problem, "simulated_annealing", 100000, 0.5, 0.99999) measure_performance(2, "map_coloring_problem", map_coloring_problem, "random_restart_first_choice_hill_climbing", 100, 100, 10) general_genetic_map_coloring_problem = csp.GeneralGeneticConstraintProblem( map_coloring_problem, 0.1) measure_performance(2, "map_coloring_problem", general_genetic_map_coloring_problem, "genetic_local_search", 100, 100, 0.1) ac3_map_coloring_problem = copy.deepcopy(map_coloring_problem) ac3_map_coloring_problem.unassign_all_variables() ac3_start_time = time.process_time() ac3_is_arc_consistent = csp.ac3(ac3_map_coloring_problem) ac3_end_time = time.process_time() if ac3_is_arc_consistent: print() print() print("-" * 145) print("using ac3 as a preprocessing stage which took", ac3_end_time - ac3_start_time, "seconds") print("-" * 145) measure_performance(1, "ac3_map_coloring_problem", ac3_map_coloring_problem, "backtracking_search", with_history=True) measure_performance(1, "ac3_map_coloring_problem",
def tes_ac3_three(self): res = csp.ac3(self.const_problem3) self.assertTrue(res) wanted_reduced_domains = [[1, 2], [2, 3]] for var in self.const_problem3.get_variables(): self.assertIn(var.domain, wanted_reduced_domains)
def test_ac3_one(self): self.const_problem1.unassign_all_variables() res1 = csp.ac3(self.const_problem1) self.assertTrue(res1)
"constraints_weighting", 10000, with_history=True) measure_performance(2, "einstein_problem", einstein_problem, "simulated_annealing", 100000, 0.5, 0.99999) measure_performance(2, "einstein_problem", einstein_problem, "random_restart_first_choice_hill_climbing", 100, 100, 10) general_genetic_einstein_problem = csp.GeneralGeneticConstraintProblem( einstein_problem, 0.1) measure_performance(2, "einstein_problem", general_genetic_einstein_problem, "genetic_local_search", 100, 100, 0.1) ac3_einstein_problem = copy.deepcopy(einstein_problem) ac3_einstein_problem.unassign_all_variables() ac3_start_time = time.process_time() ac3_is_arc_consistent = csp.ac3(ac3_einstein_problem) ac3_end_time = time.process_time() if ac3_is_arc_consistent: print() print() print("-" * 145) print("using ac3 as a preprocessing stage which took", ac3_end_time - ac3_start_time, "seconds") print("-" * 145) measure_performance(1, "ac3_einstein_problem", ac3_einstein_problem, "heuristic_backtracking_search", with_history=True) measure_performance(1, "ac3_einstein_problem",
"min_conflicts", 100000, with_history=True) measure_performance(2, "magic_square_problem", magic_square_problem, "constraints_weighting", 10000, with_history=True) measure_performance(2, "magic_square_problem", magic_square_problem, "simulated_annealing", 200000, 0.5, 0.99999) measure_performance(2, "magic_square_problem", magic_square_problem, "random_restart_first_choice_hill_climbing", 100, 100, 10) general_genetic_magic_square_problem = csp.GeneralGeneticConstraintProblem(magic_square_problem, 0.1) measure_performance(2, "general_genetic_magic_square_problem", general_genetic_magic_square_problem, "genetic_local_search", 1000, 1000, 0.1) ac3_magic_square_problem = copy.deepcopy(magic_square_problem) ac3_magic_square_problem.unassign_all_variables() ac3_start_time = time.process_time() ac3_is_arc_consistent = csp.ac3(ac3_magic_square_problem) ac3_end_time = time.process_time() if ac3_is_arc_consistent: print() print() print("-" * 145) print("using ac3 as a preprocessing stage which took", ac3_end_time - ac3_start_time, "seconds") print("-" * 145) measure_performance(1, "ac3_magic_square_problem", ac3_magic_square_problem, "backtracking_search", with_history=True) measure_performance(1, "ac3_magic_square_problem", ac3_magic_square_problem, "backtracking_search", inference=csp.forward_check, with_history=True) measure_performance(1, "ac3_magic_square_problem", ac3_magic_square_problem, "heuristic_backtracking_search", with_history=True) measure_performance(1, "ac3_magic_square_problem", ac3_magic_square_problem, "heuristic_backtracking_search", inference=csp.forward_check, with_history=True)