340 likes | 474 Views
Announcements. Department Picnic: today, after class Lab 0 due today Homework 2 due Tuesday, 9/18 Lab 1 due Thursday, 9/20 Autumn – Current Event Tuesday. Search. Lecture 4. What is search?. Getting from Arad to Bucharest. ?. ?. Timisoara. Sibiu. Arad. Zerind. ?.
E N D
Announcements • Department Picnic: today, after class • Lab 0 due today • Homework 2 due Tuesday, 9/18 • Lab 1 due Thursday, 9/20 • Autumn – Current Event Tuesday CS 484 – Artificial Intelligence
Search Lecture 4
What is search? • Getting from Arad to Bucharest ? ? Timisoara Sibiu Arad Zerind ? CS 484 – Artificial Intelligence
Brute Force Search • exhaustive - examines every node in the search tree. • Generate and test is simplest: • Generate possible solutions to the problem. • Test if valid solution. • Stop when a valid solution is found. • The method used to generate possible solutions must be carefully chosen. CS 484 – Artificial Intelligence
Depth-First Search • DFS - exhaustive search • Follows each path to its deepest node, before backtracking to try the next path. CS 484 – Artificial Intelligence
Breadth-First Search • BFS - exhaustive search • Follows each path to a given depth before moving on to the next depth. CS 484 – Artificial Intelligence
Comparison of Depth-First and Breadth-First Search • Choose search method wisely • Depth first search may never find the answer. Why? CS 484 – Artificial Intelligence
Properties of Search Methods • Complexity • Time and memory • Completeness • Guaranteed to find a goal if one exists. • Optimality & Admissibility • Guaranteed to find the best path to the goal. • Irrevocability • Never back-tracks CS 484 – Artificial Intelligence
Implementations • DSF implemented using a stack to store states • Recursive function • BFS implementations are almost identical to depth-first • Difference: use queue rather than a stack. CS 484 – Artificial Intelligence
Depth-First Iterative Deepening • Combo of DFS and BFS exhaustive search • DFS to depth of 1, then to depth of 2, 3, … until a goal reached. • Efficient in memory use • Copes with infinitely long branches. • Not as inefficient in time as it might appear, • Only examines the largest row (the last one) once. CS 484 – Artificial Intelligence
Find shortest path from A to F Edges: length of roads Modified Traveling Salesman Problem B 10 A 3 3 3 C D 6 4 3 F 12 E A C B E D C B E D F E F D D F E F C F B F F CS 484 – Artificial Intelligence F
Heuristics • Heuristic: a rule used to make search more efficient or effective. • Use a heuristic evaluation function, f(n): • f(n) is the approximate distance of a node, n, from a goal node. • For two node m and n, if f(m) < f(n), than m is more likely to be on an optimal path • f(n) may not be 100% accurate, but it should give better results than pure guesswork. CS 484 – Artificial Intelligence
Heuristics – how informed? • The more informed a heuristic is, the better it will perform. • Heuristic h is more informed than j, if: • h(n) j(n) for all nodes n. • A search method using h will search more efficiently than one using j. • A heuristic should reduce the number of nodes that need to be examined. CS 484 – Artificial Intelligence
Choosing Good Heuristics • Right heuristic can have a significant impact in the time required to solve the problem • Should reduce the number of nodes that need to be searched • The heuristic cannot take too long to calculate CS 484 – Artificial Intelligence
8-puzzle Start State Goal State • States: location of each of the eight tiles and the blank one • Initial State: Any state can be designated so • Successor function: Generates legal states that result from trying 4 actions • Goal test: Checks whether state matches goal state • Path cost: Each step costs 1, total cost == length of path CS 484 – Artificial Intelligence
8-puzzle Start State Goal State • Game Properties • Typically 20 moves to get from random start to goal state • Branching Factor: • Search tree examines 320 states (3.5 billion) • Use heuristics to reduce states that are searched • How many states is a given state from the goal? CS 484 – Artificial Intelligence
Admissible Heuristics • Admissible heuristic: • Possible 8-puzzle admissible heuristics CS 484 – Artificial Intelligence
Hill Climbing • Think of it as finding the highest point in a three dimensional search space: • Check the height one foot away from your current location in each direction; North, South, East and West. • Find a higher position, move to that location, and restart the algorithm. • An informed, irrevocable search method. CS 484 – Artificial Intelligence
Foothills • Cause difficulties for hill-climbing methods. • A foothill is a local maximum. CS 484 – Artificial Intelligence
Plateaus • Cause difficulties for hill-climbing methods. • Flat areas that make it hard to find where to go next. CS 484 – Artificial Intelligence
Ridges • Cause difficulties for hill-climbing methods • B is higher than A. • At C, the hill-climber can’t find a higher point North, South, East or West, so it stops. CS 484 – Artificial Intelligence
Function hill() { queue = []; state = root_node; while (true) { if is_goal(state) return SUCCESS; else { sort(successor(state)); add_to_front_of_queue (successor(state)); } if queue == [] return FAILURE; state = queue[0]; remove_first_item (queue); } } Hill Climbing Algorithm CS 484 – Artificial Intelligence
Find shortest path from A to F Solve using hill climbing Modified Traveling Salesman Problem distance as the crow flies B 8 25 A 6 C D 20 What happens now? F E 12 CS 484 – Artificial Intelligence
Best-First Search • Like hill-climbing: • Picks the most likely path (based on heuristic value) from the partially expanded tree • Tends to find a shorter1 path than depth-first or breadth-first search, but does not guarantee to find the best path. 1 depends how shorter is defined CS 484 – Artificial Intelligence
Function hill() { queue = []; state = root_node; while (true) { if is_goal(state) return SUCCESS; else { sort(successor(state)); add_to_front_of_queue (successor(state)); } if queue == [] return FAILURE; state = queue[0]; remove_first_item (queue); } } Hill Climbing Algorithm CS 484 – Artificial Intelligence
Function best() { queue = []; state = root_node; while (true) { if is_goal(state) return SUCCESS; else { add_to_front_of_queue (successor(state)); sort(queue); } if queue == [] return FAILURE; state = queue[0]; remove_first_item (queue); } } Best-Search Algorithm CS 484 – Artificial Intelligence
Optimal Paths • An optimal path - shortest possible path from root to goal (i.e lowest cost) • not necessarily at the shallowest depth, if edges have costs • The British Museum procedure finds an optimal path by examining every possible path, and selecting the one with the least cost. • There are more efficient ways. CS 484 – Artificial Intelligence
A* Algorithms • Uses the cost function: • f(node) = g(node) + h(node). • g(node) is the cost of the path so far leading to the node. • h(node) is an underestimate of how far node is from a goal state. • f is a path-based evaluation function. • An A* algorithm expands paths from nodes that have the lowest f value. CS 484 – Artificial Intelligence
A* Algorithms (continued) • A* algorithms are optimal: • They are guaranteed to find the shortest path • Provided h(node) is always an underestimate. (h is an admissible heuristic). • A* methods are also optimally efficient – they expand the fewest possible paths to find the right one. • If h is not admissible, the method is called A, rather than A*. CS 484 – Artificial Intelligence
Get from A to F using shortest path Solve using A* g(n) – cost so far h(n) – heuristic Modified Traveling Salesman Problem h(n) = distance as the crow flies B 8 7 15 A 6 5 2 6 C D 14 6 6 3 F 11 E 11 CS 484 – Artificial Intelligence
Uniform Cost Search • Also known as branch and bound. • Like A*, but uses: • f(node) = g(node). • g(node) is the cost of the path leading up to node. • Optimal as long as all paths have a positive weight CS 484 – Artificial Intelligence
Greedy Search • Like A*, but uses: • f(node) = h(node). • Hence, always expands the node that appears to be closest to a goal, regardless of what has gone before. • Not optimal, and not guaranteed to find a solution at all. • Can easily be fooled into taking poor paths. CS 484 – Artificial Intelligence
Real World Search Problem • Route-finding Problem • States: represented by location and current time • Initial State: Specified by problem • Successor function: returns states resulting from taking any scheduled flight leaving later than current time plus transit time • Goal test: arrived at destination by prescribed time • Path cost: monetary cost, waiting time, flight time, seat quality, time of day, etc. CS 484 – Artificial Intelligence