Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 5. Advanced Search

Similar presentations


Presentation on theme: "Chapter 5. Advanced Search"— Presentation transcript:

1 Chapter 5. Advanced Search
Comp3710 Artificial Intelligence Computing Science Thompson Rivers University

2 Course Outline Part I – Introduction to Artificial Intelligence
Part II – Classical Artificial Intelligence, and Searching Knowledge Representation Searching Search Methodologies Advanced Search Genetic Algorithms (relatively new study area) Knowledge Represenation and Automated Reasoning Propositinoal and Predicate Logic Inference and Resolution for Problem Solving Rules and Expert Systems Part III – Machine Learning Part IV – Advanced Topics TRU-COMP3710 Advanced Search

3 Chapter Objectives Given a contraint satisfaction algorithm, define variables and constraints. Use of Most-Constrained Variable and Most-Constraining Variable heuristics for the 8-queens problem and the map coloring problem. Use of Least-Constraining Variable heuristic for the 8-queens problem and the map coloring problem. Use of Heuristic Repair for the 8-queens problem. ... TRU-COMP3710 Advanced Search

4 Chapter Outline Constraint Satisfaction Search
Forward Checking Most-Constrained Variable First Least-Constraining Variable First Heuristic Repair Combinatorial Optimization Problems How to use greedy approach – Local Search How to improve local search Exchanging Heuristic Iterated Local Search Simulated Annealing Parallel Search Genetic Algorithms for Search TRU-COMP3710 Advanced Search

5 Two types of search problems
Goal is known. A solution is to find a best path from the initial node to a goal node. Type 2 Goal is not known. A solution is to find a goal. Type 1 Type 2 Is a goal known? Yes No What is a solution? A best path from the initial node to a goal node. A goal node Examples 3 missionaries and 3 cannibals, The tower of Hanoi Algorithm A* TRU-COMP3710 Search Methodologies

6 1. Constraint Satisfaction Problems
Problem: Put n queens on an n × n board with no two queens on the same row, column, or diagonal. [Q] How to solve? Generic search with heuristics? [Q] Local search? From an initial board, which one do we need to move first? TRU-COMP3710 Heuristic Search

7 Example: The 8-queens problem
Combinatorial optimization problems involve assigning values to a number of variables. A constraint satisfaction problem (CSP) is a combinatorial optimization problem with a set of constraints. Example: The 8-queens problem Eight queens must be placed on a chess board in such a way that no two queens are on the same diagonal, row, or column [Q] How to model the problem? 8 variables, a through h, with domain {0, 1, 2, …, 8} Each variable can have a value 0 to 8. The values must satisfy the constraints. [Q] Meaning is? TRU-COMP3710 Advanced Search

8 Example: The 8-queens problem
Combinatorial optimization problems involve assigning values to a number of variables. A constraint satisfaction problem (CSP) is a combinatorial optimization problem with a set of constraints. Example: The 8-queens problem Eight queens must be placed on a chess board in such a way that no two queens are on the same diagonal, row, or column [Q] How to solve? [Q] Can be solved using generic search? BFS? DFS? A*? Local search? What kind of search tree? Huge space? What is the complexity? With many variables it is essential to use heuristics. TRU-COMP3710 Advanced Search

9 1.1 Forward Checking with Heuristics
Huge search tree? [Q] Do we have to visit any choice (, i.e., state or node in the search,) that conflicts with constraints? To delete, from the set of possible future choices, any that have been rendered impossible by placing the queen on that square If placing a queen on the board results in removing all remaining squares, then backtracking immediately. (Not like hill climbing. Difference?) [Q] How about to use heuristics to choose the next node? Most-Constrained Variable First Least-Constraining Variable First Not local search, rather similar to DFS TRU-COMP3710 Advanced Search

10 1.2 Most-Constrained Variables
Most-Constrained Variable First heuristic: At each stage of the search, this heuristic involves working with the variable that has the least possible number of valid choices. In the example of the 8-queens problem, assigning a value to 8 variables, a through h E.g., currently a = 1; b = 3; c = 5, then d has 3 choices. e has 3 choices. f has 1 choice. g has 3 choices. h has 3 choices. The next move is to place a queen in column f, not d. TRU-COMP3710 Advanced Search

11 Next move? a -> b -> c -> f d has 2 choices. e has 2 choices.
g has 2 choices. h has 1 choices. The next move is to place a queen in column h. TRU-COMP3710 Advanced Search

12 Next move? a -> b -> c -> f -> h d has 1 choices.
e has 2 choices. g has 1 choices. The next move is to place a queen in column d. TRU-COMP3710 Advanced Search

13 Next move? a -> b -> c -> f -> h -> d e has 1 choices.
g has 1 choices. The next move is to place a queen in column e. TRU-COMP3710 Advanced Search

14 Next move? a -> b -> c -> f -> h -> d -> e
g has 0 choice. Ooops! Then backtracking TRU-COMP3710 Advanced Search

15 Next move? a -> b -> c -> f -> h -> d
e has 1 choices. (Failed) g has 1 choices. The next move is to place a queen in column g. TRU-COMP3710 Advanced Search

16 Next move? a -> b -> c -> f -> h -> d ->g
e has 0 choice. Backtracking a -> b -> c -> f -> h -> d => a -> b -> c -> f -> h a -> b -> c -> f -> h -> g TRU-COMP3710 Advanced Search

17 [Q] Is it guaranteed to find a solution? [Q] How to implement?
Term project? [Q] Is it guaranteed to find a solution? [Q] How to implement? [Q] How to represent the problem? 1×(n+1) array for a state n(n+1) different states The start state – [0, 0, …, 0] A goal state ??? [Q] The generic search framework would not work??? The number of possible states from the start state is n × n. DFS with the selection strategy of the heuristic You may use recursion. TRU-COMP3710 Advanced Search

18 [Q] What is the next choice?
[Q] What if there are ties? Then, most-constraining variable heuristic for breaking the tie. To assign a value to the variable that places the greatest number of constraints on future variables. E.g., map coloring problem with only 3 colors [Q] What is the next choice? [Q] Which province is most constrained? [Q] Is it guaranteed to find a solution? TRU-COMP3710 Advanced Search

19 1.3 Least-Constraining Variables
Instead of the previous two heuristics – “most-constrained variable first”, and “most-constraining variable” to break ties, “Least-Constraining Variable First” heuristic To assign a value to a variable that leaves the greatest number of choices for other variables. More intuitive? Tie breaker? Stop and backtracking [Q] Is it guaranteed to find a solution? TRU-COMP3710 Advanced Search

20 This heuristic makes n-queens problems with extremely large values of n, e.g., 1000, quite solvable.
Can you try with n=8? #constraingCells(a:1) = … = #constraingCells(a:8) = 14 #constraingCells(b) = 14 #constraingCells(h) = 14 a = 1; Next move? TRU-COMP3710 Advanced Search

21 #constraingCells(a:1) = 14 #constraingCells(b) = 14 …
Term project? #constraingCells(a:1) = 14 #constraingCells(b) = 14 #constraingCells(h) = 14 a = 1; Next move? b:3 -> 10 b:4 -> 9 b:5 -> 8 b:6 -> 7 b:7 -> 6 b:8 -> 5 c:2 -> 11 c:4 -> 9 c:5 -> 8 TRU-COMP3710 Advanced Search

22 Project idea The n-queens problem with the “least constraining variable first” heuristic, or with the “most constrained variable first” heuristic Class scheduling problem TRU-COMP3710 Advanced Search

23 1.4 Heuristic Repair In the previous slides, general searching is used. A heuristic method for solving CSPs: Generate a possible solution (randomly, or using a heuristic to generate a position that is close to a solution), and then make small changes to bring it closer to satisfying constraints. [Q] Local search? TRU-COMP3710 Advanced Search

24 Heuristic Repair for the 8-Queens Problem
Initial state – one queen is conflicting with another. We’ll now move that queen to the square with the fewest conflicts. TRU-COMP3710 Advanced Search

25 Second state – now the queen on the f column is conflicting, so we’ll move it to the square with fewest conflicts. TRU-COMP3710 Advanced Search

26 [Q] Is it guaranteed to find a solution with the heuristic repair?
Units [Q] Is it guaranteed to find a solution with the heuristic repair? TRU-COMP3710 Advanced Search

27 2. Combinatorial Optimization Problems
[Wikipedia] In applied mathematics and theoretical computer science, combinatorial optimization is a topic that consists of finding an optimal object from a finite set of objects.  In many such problems, exhaustive search is not feasible. It operates on the domain of those optimization problems, in which the set of feasible solutions is discrete or can be reduced to discrete, and in which the goal is to find the best solution. Some common problems involving combinatorial optimization are the traveling salesman problem ("TSP") and the minimum spanning tree problem ("MST"). Combinatorial optimization is a subset of mathematical optimization that is related to operations research, algorithm theory, and computational complexity theory. It has important applications in several fields, including artificial intelligence, machine learning, mathematics, auction theory, and software engineering. TRU-COMP3710 Advanced Search

28 [Q] How to solve combinatorial optimization problems?
Units Let’s start discussing the type 2 problems that we do NOT know even how to test a goal. Not like n-queens problem. [Q] How to solve combinatorial optimization problems? From greedy approach – local search To advanced local search algorithms TRU-COMP3710 Advanced Search

29 2.1 Local Search Like heuristic repair, local search methods start from a random state, and make small changes (improvement) until a goal state is achieved. Most local search methods are susceptible to local maxima, like hill-climbing. Especially when we do NOT know what is the optimal. Local search methods are known as metaheuristics. Here are very important local search methods. Simulated annealing Genetic algorithms Colony optimization Neural networks We will discuss some ideas of how to improve local search in the following slides. TRU-COMP3710 Advanced Search

30 Cumulative improvement
Initial state A bit better state [Q] How to evaluate? Cumulative improvement A bit better state [Q] How to solve? A bit better state Susceptable to local maxima TRU-COMP3710 Advanced Search

31 How to Improve Local Search
Units How to Improve Local Search [Q] Any good idea? Keep cumulative improvement Give more diversity while keeping stability to search better local optimal solutions Give some random walks to get out of local optimal solutions so that better solutions can be found. TRU-COMP3710 Advanced Search

32 2.2 Exchanging Heuristics
A simple local search method. Heuristic repair is an example of an exchanging heuristic. Involves exchanging one or more variables at each step by giving them different values Exchanging variables until the new state becomes better Repeat this step until a solution is found A k-exchange involves swapping the values of k variables. Can be used to solve the traveling salesman problem. TRU-COMP3710 Advanced Search

33 Ramdom choice -> Diversity Cumulative improvement
Units Initial state A bit better state A bit better state Ramdom choice -> Diversity A bit better state A bit better state Cumulative improvement A bit better state A bit better state TRU-COMP3710 Advanced Search

34 Units 2.3 Iterated Local Search A local search is applied repeatedly from different initial states. Useful in cases where the search space is extremely large, and exhaustive search will not be possible. TRU-COMP3710 Advanced Search

35 2.4 Simulated Annealing A method based on the way in which metal is heated and then cooled very slowly in order to make it extremely strong. Aims at obtaining a minimum value for some function of a large number of variables. This value is known as the energy of the system. Based on metropolis Monte Carlo Simulation. Simple Monte Carlo Simulation: a method of learning information about the shape of a search space. E.g., a square partially contained within a circle. How to identify what proportion of the square is within the circle? By random sampling TRU-COMP3710 Advanced Search

36 Algorithm: A random initial state is selected
A small random change is made. To select a new state that makes a small change to the current state If this change lowers the system energy, it is accepted. If it increases the energy, it may be accepted, depending on a probability called the Boltzmann acceptance criteria: e(-dE/T) , where T is the current temperature, and dE is the increase in energey that has been produced by moving the previous state to the new state. TRU-COMP3710 Advanced Search

37 To determine whether to move to a higher energy state or not,
e(-dE/T) , where T is the current temperature, and dE is the increase in energey that has been produced by moving the previous state to the new state. To determine whether to move to a higher energy state or not, if a random number within (0, 1) < the probability above, then move. When the process starts, T is high, meaning increases in energy are relatively likely to happen. Over successive iterations, T lowers and increases in energy become less likely. P T (decreasing) TRU-COMP3710 Advanced Search

38 TRU-COMP3710 Ramdom choice -> better diversity
Initial state Ramdom choice -> better diversity A bit better state A bit better state A bit better state A bit worse state A bit better state A bit worse state A bit better state A bit worse state A bit better state Cumulative improvement Diversity is gradually becoming less effective. -> better stability A bit better state A bit better state TRU-COMP3710 Advanced Search

39 [Q] Why is Simulated Annealing good?
Units [Q] Why is Simulated Annealing good? Because the energy of the system is allowed to increase by using random selection, simulated annealing may be able to escape from local minima. Simulated annealing is a widely used local search method for solving problems with very large number of variables. For example: scheduling problems, traveling salesman, placing VLSI (chip) components. [Q] How to improve? Combination of iterated local search and simulated annealing? TRU-COMP3710 Advanced Search

40 Units 2.5 Parallel Search Some search methods can be easily split into tasks which can be solved in parallel. -> improved diversity Important concepts to consider are: Divide and conquer? Task distribution Load balancing Tree ordering TRU-COMP3710 Advanced Search

41 2.6 Genetic Algorithms A method based on biological evolution.
Create chromosomes which represent possible solutions to a problem. The best chromosomes in each generation are bred with each other to produce a new generation. Much more detail on this later. A form of local search, which has Cumulative improvement Better diversity Better stability Randomness Quick searching Advanced form of the combination of iterated local search and simulated annealing TRU-COMP3710 Advanced Search

42 Start with k randomly generated states (population) – 1st generation
A state is represented as a string over a finite alphabet (often a string of 0s and 1s) (encoding) Evaluation function (fitness function). Higher values for better states. Multiple states (also called individuals) -> diversity (Possibly better) Next generation A successor state is generated by combining two parent states. Produce the next generation of states by selection according to the evaluation with fitness function, crossover, and mutation. Selection -> cumulative improvement Population, Crossover -> diversity Mutation -> random walk . . . . . . . . . TRU-COMP3710 Advanced Search

43 [Q] How to represent the left individual (, i.e., state)?
List of column values, e.g., (3, 1, 7, 5, 8, 6, 4, 6) Fitness function: number of non-attacking pairs of queens (min = 0, max = 8 × 7 / 2 = 28). The larger, the better, in this example. [Q] Fitness values of the next states? TRU-COMP3710 Advanced Search

44 The fitness value: 23 (= 28 – 5) The fitness value: 24
The fitness value: 23 (= 28 – 5) The fitness value: 24 The fitness value: 23 TRU-COMP3710 Advanced Search

45 Can you evaluate them? Fitness function: number of non-attacking pairs of queens (min = 0, max = 8 × 7/2 = 28) 24/( ) = 31% 23/( ) = 29% etc TRU-COMP3710 Advanced Search

46 Two types of search problems
Goal is known. A solution is to find a best path from the initial node to a goal node. Type 2 Goal is not known. A solution is to find a goal. Sometimes we do not know how to test. Type 1 Type 2 Is a goal known? Yes No What is a solution? A best path from the initial node to a goal node. A goal node Examples 3 missionaries and 3 cannibals, The tower of Hanoi n-Queens TSP Algorithm A* CSP heuristics Genetic algorithms TRU-COMP3710 Search Methodologies

47 Project idea Units Local search for CSP heuristics for
The traveling salesman problem CSP heuristics for The n-queens problem Genetic algorithm for The class scheduling problem TRU-COMP3710 Advanced Search


Download ppt "Chapter 5. Advanced Search"

Similar presentations


Ads by Google