Seach algorithms The travelling salesman problem The Towers of Hanoi Playing games. Comp24412: Symbolic AI. Lecture 4: Search. Ian Pratt-Hartmann

Similar documents
COMP219: Artificial Intelligence. Lecture 7: Search Strategies

Coping with the Limitations of Algorithm Power Exact Solution Strategies Backtracking Backtracking : A Scenario

PSD1A. DESIGN AND ANALYSIS OF ALGORITHMS Unit : I-V

Lecture 4: Linear Programming

CSC Design and Analysis of Algorithms. Lecture 4 Brute Force, Exhaustive Search, Graph Traversal Algorithms. Brute-Force Approach

Algorithm Design Techniques (III)

Search : Brute force and Heuristic

Chapter 3: Solving Problems by Searching

CS 4700: Foundations of Artificial Intelligence. Bart Selman. Search Techniques R&N: Chapter 3

Backtracking and Branch-and-Bound

Artificial Intelligence (Heuristic Search)

Spring 2007 Midterm Exam

Uninformed Search Methods

Introduction to Combinatorial Algorithms

Downloaded from ioenotes.edu.np

Computer Science 385 Design and Analysis of Algorithms Siena College Spring Topic Notes: Brute-Force Algorithms

Lecture 3. Brute Force

Computer Science and Software Engineering University of Wisconsin - Platteville. 3. Search (Part 1) CS 3030 Lecture Notes Yan Shi UW-Platteville

mywbut.com Informed Search Strategies-II

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

CMU-Q Lecture 2: Search problems Uninformed search. Teacher: Gianni A. Di Caro

1 5,9,2,7,6,10,4,3,8,1 The first number (5) is automatically the first number of the sorted list

Notes for Lecture 24

(Refer Slide Time: 01:00)

Parallel Programming. Parallel algorithms Combinatorial Search

Algorithm Design Techniques. Hwansoo Han

State Space Search. Many problems can be represented as a set of states and a set of rules of how one state is transformed to another.

Monte Carlo Methods; Combinatorial Search

Uninformed Search. Reading: Chapter 4 (Tuesday, 2/5) HW#1 due next Tuesday

Branch and Bound. Live-node: A node that has not been expanded. It is similar to backtracking technique but uses BFS-like search.

ACO and other (meta)heuristics for CO

Search EECS 395/495 Intro to Artificial Intelligence

Search EECS 348 Intro to Artificial Intelligence

HEURISTIC SEARCH. 4.3 Using Heuristics in Games 4.4 Complexity Issues 4.5 Epilogue and References 4.6 Exercises

Machine Learning for Software Engineering

Combinatorial Search; Monte Carlo Methods

Algorithms and Complexity

CSC 8301 Design and Analysis of Algorithms: Exhaustive Search

Basic Search. Fall Xin Yao. Artificial Intelligence: Basic Search

CS510 \ Lecture Ariel Stolerman

Uninformed Search. Problem-solving agents. Tree search algorithms. Single-State Problems

Artificial Intelligence

10/31/18. About A6, Prelim 2. Spanning Trees, greedy algorithms. Facts about trees. Undirected trees

Spanning Trees, greedy algorithms. Lecture 20 CS2110 Fall 2018

val(y, I) α (9.0.2) α (9.0.3)

Lecture 3: Graphs and flows

Monotonicity. Admissible Search: That finds the shortest path to the Goal. Monotonicity: local admissibility is called MONOTONICITY

Ar#ficial)Intelligence!!

Dynamic Programming Homework Problems

Chapter 6 Backtracking Algorithms. Backtracking algorithms Branch-and-bound algorithms

CSE 417 Branch & Bound (pt 4) Branch & Bound

Uninformed Search. (Textbook Chpt 3.5) Computer Science cpsc322, Lecture 5. May 18, CPSC 322, Lecture 5 Slide 1

ME/CS 132: Advanced Robotics: Navigation and Vision

3 INTEGER LINEAR PROGRAMMING

SPANNING TREES. Lecture 21 CS2110 Spring 2016

Graph Search. Adnan Aziz

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017

Search. (Textbook Chpt ) Computer Science cpsc322, Lecture 2. May, 10, CPSC 322, Lecture 2 Slide 1

CS 440 Theory of Algorithms /

CS 771 Artificial Intelligence. Problem Solving by Searching Uninformed search

ARTIFICIAL INTELLIGENCE SOLVING PROBLEMS BY SEARCHING. Chapter 3

Chapter 16. Greedy Algorithms

The Heuristic Strategy Implementation to the Hopfield -Tank TSP Neural Algorithm

12/30/2013 S. NALINI,AP/CSE

Search and Optimization

CAP 4630 Artificial Intelligence

Uninformed Search Strategies

Spanning Trees 4/19/17. Prelim 2, assignments. Undirected trees

Spanning Trees. Lecture 22 CS2110 Spring 2017

Chapter 3 Solving problems by searching

CPSC 436D Video Game Programming

done with DCL (except for the fact that we ll use it!)

Solving Problems: Blind Search

IV/IV B.Tech (Regular) DEGREE EXAMINATION. Design and Analysis of Algorithms (CS/IT 414) Scheme of Evaluation

The Simplex Algorithm for LP, and an Open Problem

Problem Solving & Heuristic Search

INF Biologically inspired computing Lecture 1: Marsland chapter 9.1, Optimization and Search Jim Tørresen

Outline. Graphs. Divide and Conquer.

Algorithmic problem-solving: Lecture 2. Algorithmic problem-solving: Tractable vs Intractable problems. Based on Part V of the course textbook.

Artificial Intelligence. Chapters Reviews. Readings: Chapters 3-8 of Russell & Norvig.

INTRODUCTION TO HEURISTIC SEARCH

Unit 8: Coping with NP-Completeness. Complexity classes Reducibility and NP-completeness proofs Coping with NP-complete problems. Y.-W.

State Space Representa,on and Search

Introduction to Optimization

Artificial Intelligence p.1/49. n-queens. Artificial Intelligence p.2/49. Initial state: the empty board or a board with n random

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment

Class Overview. Introduction to Artificial Intelligence COMP 3501 / COMP Lecture 2. Problem Solving Agents. Problem Solving Agents: Assumptions

Assignment No 2 (Group B)

CMPSCI 250: Introduction to Computation. Lecture #24: General Search, DFS, and BFS David Mix Barrington 24 March 2014

Informed search algorithms. Chapter 4

Brute Force: Selection Sort

Computational problems. Lecture 2: Combinatorial search and optimisation problems. Computational problems. Examples. Example

Graph Search Methods. Graph Search Methods

6.034 Quiz 1, Spring 2004 Solutions

Algorithm Design and Analysis

UNINFORMED SEARCH. Announcements Reading Section 3.4, especially 3.4.1, 3.4.2, 3.4.3, 3.4.5

CSCE 350: Chin-Tser Huang. University of South Carolina

Lecture 9 Graph Traversal

Chapter 8. NP-complete problems

1 Tree Search (12 points)

Transcription:

Comp24412: Symbolic AI Lecture 4: Search Ian Pratt-Hartmann Room KB2.38: email: ipratt@cs.man.ac.uk 2016 17

Outline Seach algorithms The travelling salesman problem The Towers of Hanoi Playing games

Typical planning problem Suppose we have a robot able to move blocks on a table it can only pick up one block at a time it can only pick up blocks with nothing on top it can only put blocks down where there is a free space. a c a b b c Initial situation: on(a, table) on(c, a) on(b, table) clear(b) clear(c) Goal conditions: on(a, b) on(b, c) It helps to represent the problem in terms of a tree of possible states.

In this tree, the nodes represent possible situations and the links represent actions move(c,a,table) [on(c,a),on(a,table),on(b,table)] [on(a,b),on(b,c),on(c,table)] Obviously, we do not consider paths with repeated states (going round in circles). The main problem now is that of how to search the tree.

In depth-first search, we search the tree branch-by-branch: This search strategy is sometimes referred to as chronological backtracking.

In depth-first search, we search the tree branch-by-branch: This search strategy is sometimes referred to as chronological backtracking.

In depth-first search, we search the tree branch-by-branch: This search strategy is sometimes referred to as chronological backtracking.

In depth-first search, we search the tree branch-by-branch: This search strategy is sometimes referred to as chronological backtracking.

In depth-first search, we search the tree branch-by-branch: This search strategy is sometimes referred to as chronological backtracking.

In depth-first search, we search the tree branch-by-branch: This search strategy is sometimes referred to as chronological backtracking.

In depth-first search, we search the tree branch-by-branch: This search strategy is sometimes referred to as chronological backtracking.

Pseudocode for depth-first search set Queue to be the list [StartNode] while Queue is non-empty let FirstNode be first element of Queue if FirstNode is a goal node return FirstNode else delete FirstNode from start of Queue add children of FirstNode to front of Queue return failure

This is really easy to implement in Prolog: dplan([item RestofQueue], Item):- success_node(item). dplan([item RestOfQueue], Result):- possible_moves(item, Children), append(children, RestOfQueue, NewQueue), dplan(newqueue, Result). We can then execute depth-first search with a call of the form dplan([initial node ],Result) where initial node is a data structure representing the initial node.

Knowledge about actions can be represented as a data-structure, thus: action(move(x,y,z), preconds([on(x,y),clear(x),clear(z)]) add([on(x,z),clear(y)]), delete([on(x,y),clear(z)])) The effects of an action, such as move(c,a,b), can be easily computed: [on(c,a),on(a,table),on(b,table),clear(c),clear(b)] [on(c,b),on(a,table),on(b,table),clear(c),clear(a)] c c a b a b

All the work is involved in decisions such as: how to represent the states and actions; how to compute the possible actions and their effects; eliminating already-encountered situations; recovering the plan once a goal state has been found. These things vary from problem to problem, but the basic search strategy is completely general.

Important point: the goals here are considered all together. In practical planning applications in AI, the aim is to work on goals independently, and somehow combine the results into a single plan. This is non-trivial, because planning for one goal typically undoes previously satisfied goals. Our present example is a case in point: a c a b b c Initial situation: on(a, table) on(c, a) on(b, table) clear(b) clear(c) Goal conditions: on(a, b) on(b, c)

Breadth-first search In breadth-first search, we search the tree row-by-row:

Breadth-first search In breadth-first search, we search the tree row-by-row:

Breadth-first search In breadth-first search, we search the tree row-by-row:

Breadth-first search In breadth-first search, we search the tree row-by-row:

Breadth-first search In breadth-first search, we search the tree row-by-row:

Pseudocode for breadth-first search set Queue to be the list [StartNode] while Queue is non-empty let FirstNode be first element of Queue if FirstNode is a goal node return FirstNode else delete FirstNode from start of Queue add children of FirstNode to end of Queue return failure

Hill-climbing search Usually we want to find a plan sooner rather than later. In hill-climbing search, we consider the children in order of nearness to goals. set Queue to be the list [StartNode] while Queue is non-empty let FirstNode be first element of Queue if FirstNode is a goal node return FirstNode else delete FirstNode from start of Queue order children of FirstNode with most promising first add ordered children to start of Queue return failure Note that the measure of nearness to goals will be problem-dependent.

Best-first search The strategy of best-first search is like hill-climbing, except that we order all nodes in the queue by nearness to goals. set Queue to be the list [StartNode] while Queue is non-empty let FirstNode be first element of Queue if FirstNode is a goal node return FirstNode else delete FirstNode from start of Queue add children of FirstNode to Queue re-order Queue with most promising first return failure

A search Often, we want to find a good plan, not just any plan. The A -search method gives us a simple way to do this Suppose each node has an associated Cost so far (csf) Underestimate of remaining cost (urc) The idea is then to examine nodes in increasing order of csf+urc.

Pseudocode for A search set Queue to be the list [StartNode] while Queue is non-empty let FirstNode be first element of Queue if FirstNode is a goal node return FirstNode else delete FirstNode from start of Queue add children of FirstNode to Queue re-order Queue by csf + urc return failure This algorithm is guaranteed to produce an optimal solution if a solution exists. (Assumption: finiteness.)

Outline Seach algorithms The travelling salesman problem The Towers of Hanoi Playing games

Here is a famous problem involving the search for an optimal plan. Suppose a salesman has to tour each one of n cities, with given distances between them. We would like to find a complete tour which will minimize the total distance travelled. 3 v1 v2 10 1 7 9 8 1 6 3 v0 v3 12 More formally: TSP Given: an n n symmetric matrix {c i,j } over N; Return: a sequence of indices representing a tour of minimal cost according to {c i,j }. v4

The time taken to run an exhaustive search procedure for TSP increases exponentially with n. In fact, TSP is a combinatorially hard optimization problem. Specifically, the problem TSP-feasibility Given: an n n symmetric matrix {c i,j } over N and C N. Return: Yes if there is a tour of cost < C through this matrix; No otherwise. is known to be complete for nondeterministic polynomial time, or, for short, NP-complete.

TSP is a search problem, where we seek a least-cost path to the goal. (The need to loop back to the starting point does not really change anything.) The A -method can be used for TSP: the cost-so-far is easy to calculate; various underestimates of remaining costs can be used, the most obvious being the smallest distance in the graph multiplied by the number of remaining nodes. However, A tends to be breadth-first like in its performance (guzzles memory). As an exercise, you might try to write a modified depth-first search procedure that finds an optimal path.

For large n, exhaustive search is impractical. The following approach may be used instead. Start with any old tour and improve it: 3 v1 3 v1 10 v2 1 v2 1 1 v0 6 v0 v3 12 12 v3 12 v4 v4 This transformation is seen to produce an improvement. We then do hill-climbing on this problem space until we reach a local optimum.

Outline Seach algorithms The travelling salesman problem The Towers of Hanoi Playing games

Another well-known example: the Towers of Hanoi Of course, the problem can be generalized to n discs (but always with three poles)

The states of the TOH problem (with n discs) can be represented by a data-structure of the following form: a 1,..., a n where 1 a i 3 for all i, (1 i n). If the discs are identified as 1,..., n (in increasing order of size), the semantics (meaning) of this data-structure are as follows: For all i (1 i n), disc i is on pole a i Example: [1,1,1] [2,3,1] [3,3,1]

Consider the graph of states for the 1-disc problem: [1] [2] [3]

Here is the corresponding graph for the 2-disc problem: [1,1] [1] [2,1] [3,1] [2] [3] [2,3] [3,2] [3,3] [1,3] [1,2] [2,2]

and for the 3-disc problem: [1,1,1] [1,1] [3,1] [2,1] [3,2] [2,3] [2,2,3] [2,2,1] [3,3,1] [3,3,2] [2,2] [1,2] [1,3] [3,3] [3,3,3] [1,1,3] [1,1,2] [2,2,2]

and finally for the 4-disc problem:

Every state is reachable from every other state, i.e. not like The length of the shortest path from the start state to a goal state is 2 n 1. The length of the longest path from the start state to a goal state without repetitions is 3 n 1.

Some important points about standard search methods (like dfs, bfs,... ) treated in this lecture: they are easy to implement; they are typically uncompetitive on large problem instances (cf. TSP); they use no special information about the structure of the problem (cf. TOH); sometimes, there is just no solution (cf. 9-puzzle). There is a huge literature on TSP (see further reading on website). There is a huge literature on planning in AI (specifically concerning goal interaction).

Outline Seach algorithms The travelling salesman problem The Towers of Hanoi Playing games

Search in Game-Playing white move black move white move black move Nodes of the tree represent possible board positions Links represent possible moves

Nodes are either white or black corresponding to control of moves by different players. At some point, board positions must be evaluated. This may involve cut-off. The values can be taken to represent utilities for the white player. Thus the white player (the maximizer) wants to maximize them, and the black player (the minimizer) to minimize them.

The minimax procedure determines the best move to make assuming optimal playing by the adversary begin minimax(node) if node is at limit of search tree then let utility be the utility of node return [node,utility] else if node is a white node, then apply minimax to children of node return result which has maximum utility else if node is a black node, then apply minimax to children of node return result which has minimum utility end if end minimax

The minimax procedure, as just described, invokes unnecessary searching. Consider the following search tree: n 1 n 2 n 3 n 4 n 5 n 6 n 7 n 8 1 2 6 7 3 4 5 8 9

Implementing α-β minimax At maximizing nodes Get value of β from parent Keep a parameter α set α to maximum so far returned by children Return final value of α At minimizing nodes Get value of α from parent Keep a parameter β set α to minimum so far returned by children Return final value of β When processing any node Stop if α > β.