Pathfinding. Advaith Siddharthan

Similar documents
Notes. Video Game AI: Lecture 5 Planning for Pathfinding. Lecture Overview. Knowledge vs Search. Jonathan Schaeffer this Friday

A* Algorithm BY WARREN RUSSELL

Overview. Path Cost Function. Real Life Problems. COMP219: Artificial Intelligence. Lecture 10: Heuristic Search

CS 354R: Computer Game Technology

Pathfinding Algorithms and Implementations on Grid Map

COMP219: Artificial Intelligence. Lecture 10: Heuristic Search

Route planning / Search Movement Group behavior Decision making

COMP219: Artificial Intelligence. Lecture 10: Heuristic Search

UNIVERSITY OF NORTH CAROLINA AT CHARLOTTE

Algorithms and Path Planning

Learning Objectives. c D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 3.3, Page 1

AN IMPLEMENTATION OF PATH PLANNING ALGORITHMS FOR MOBILE ROBOTS ON A GRID BASED MAP

Informed search strategies (Section ) Source: Fotolia

CMPUT 396 Sliding Tile Puzzle

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

A* optimality proof, cycle checking

Path Planning. Marcello Restelli. Dipartimento di Elettronica e Informazione Politecnico di Milano tel:

CS 331: Artificial Intelligence Informed Search. Informed Search

CS 331: Artificial Intelligence Informed Search. Informed Search

Chapter 5.4 Artificial Intelligence: Pathfinding

Motion Planning for a Point Robot (2/2) Point Robot on a Grid. Planning requires models. Point Robot on a Grid 1/18/2012.

Informed Search and Exploration for Agents

DIT411/TIN175, Artificial Intelligence. Peter Ljunglöf. 19 January, 2018

Chapter 3: Informed Search and Exploration. Dr. Daisy Tang

CS 387/680: GAME AI PATHFINDING

Informed (Heuristic) Search. Idea: be smart about what paths to try.

Informed search. Soleymani. CE417: Introduction to Artificial Intelligence Sharif University of Technology Spring 2016

Introduction to Computer Science and Programming for Astronomers

Heuristic (Informed) Search

Outline. Best-first search

Graph and A* Analysis

the gamedesigninitiative at cornell university Lecture 20 Pathfinding

CSE 473. Chapter 4 Informed Search. CSE AI Faculty. Last Time. Blind Search BFS UC-BFS DFS DLS Iterative Deepening Bidirectional Search

Uninformed Search Strategies

ME/CS 132: Advanced Robotics: Navigation and Vision

MEM380 Applied Autonomous Robots Fall Depth First Search A* and Dijkstra s Algorithm

Basic Motion Planning Algorithms

Artificial Intelligence

INTRODUCTION TO HEURISTIC SEARCH

Informed search algorithms. Chapter 4

The big picture: from Perception to Planning to Control

PATH FINDING AND GRAPH TRAVERSAL

CSE 40171: Artificial Intelligence. Informed Search: A* Search

521495A: Artificial Intelligence

Informed Search. CS 486/686 University of Waterloo May 10. cs486/686 Lecture Slides 2005 (c) K. Larson and P. Poupart

A* Optimality CS4804

Lecture 5 Heuristics. Last Time: A* Search

Path Planning. CMPS 146, Fall Josh McCoy

Informed/Heuristic Search

AI: Week 2. Tom Henderson. Fall 2014 CS 5300

CPSC 436D Video Game Programming

Course Outline. Video Game AI: Lecture 7 Heuristics & Smoothing. Finding the best location out of several. Variable size units / special movement?

TIE Graph algorithms

Search with Costs and Heuristic Search

LECTURE 17 GRAPH TRAVERSALS

Sung-Eui Yoon ( 윤성의 )

Graph and Heuristic Search. Lecture 3. Ning Xiong. Mälardalen University. Agenda

EE631 Cooperating Autonomous Mobile Robots

CSS 343 Data Structures, Algorithms, and Discrete Math II. Graphs II. Yusuf Pisan

Game AI: The set of algorithms, representations, tools, and tricks that support the creation and management of real-time digital experiences

Informed Search. Best-first search. Greedy best-first search. Intelligent Systems and HCI D7023E. Romania with step costs in km

Informed Search CS457 David Kauchak Fall 2011

Motion Planning, Part IV Graph Search Part II. Howie Choset

Heuristic (Informed) Search

Informed search methods

ARTIFICIAL INTELLIGENCE. Informed search

Informed search methods

Basic Search Algorithms

Heuristic Search and Advanced Methods

Discrete Motion Planning

Informed Search A* Algorithm

Pathfinding. Prof. Dr. Taoufik Nouri

Today. Informed Search. Graph Search. Heuristics Greedy Search A* Search

9/17/2015 7:56 AM. CSCE 625 Programing Assignment #1 due: Tues, Sep 22 (by start of class) Objective

CS-171, Intro to A.I. Mid-term Exam Fall Quarter, 2013

CS 460/560 Introduction to Computational Robotics Fall 2017, Rutgers University. Lecture 08 Extras. A* In More Detail. Instructor: Jingjin Yu

Today s s lecture. Lecture 3: Search - 2. Problem Solving by Search. Agent vs. Conventional AI View. Victor R. Lesser. CMPSCI 683 Fall 2004

Informed search algorithms. Chapter 3 (Based on Slides by Stuart Russell, Dan Klein, Richard Korf, Subbarao Kambhampati, and UW-AI faculty)

Understand graph terminology Implement graphs using

Informed Search. CS 486/686: Introduction to Artificial Intelligence Fall 2013

Heuristic Search: A* CPSC 322 Search 4 January 19, Textbook 3.6 Taught by: Vasanth

CS 5522: Artificial Intelligence II

Informed Search. CMU Snake Robot. Administrative. Uninformed search strategies. Assignment 1 was due before class how d it go?

3 SOLVING PROBLEMS BY SEARCHING

Lecture 2: Fun with Search. Rachel Greenstadt CS 510, October 5, 2017

CS 206 Introduction to Computer Science II

Lecture 6 Basic Graph Algorithms

Lesson 1 Introduction to Path Planning Graph Searches: BFS and DFS

Searching. Assume goal- or utilitybased. Next task to achieve is to determine the best path to the goal

Problem solving and search

Artificial Intelligence

Artificial Intelligence Informed search. Peter Antal

Problem Solving: Informed Search

Search and Games. Adi Botea. ANU Summer Schools in Logic and Learning February, 2009

Motion Planning. Howie CHoset

Informed (heuristic) search (cont). Constraint-satisfaction search.

Introduction to Artificial Intelligence. Informed Search

Section 08: Solutions

Outline. Informed search algorithms. Best-first search. Review: Tree search. A search Heuristics. Chapter 4, Sections 1 2 4

CS 380: Artificial Intelligence Lecture #4

Transcription:

Pathfinding Advaith Siddharthan

Context What is Intelligence? Rational? Search Optimisation Reasoning Impulsive? Quicker response Less predictable Personality/Emotions: Angry/Bored/Curious

Overview The first half of this course is about classical AI Rational behaviour based on planning, search and optimisation You've encountered decision making Next 2 weeks on Pathfinding Afterwards, Planning

Introduction to Pathfinding Perhaps the most ubiquitous task in AI games

Introduction to Pathfinding Many Algorithms exist Different levels of complexity Different quality of solutions

Pathfinding: Representations Grid representation (e.g., dungeon worlds) Can move to any of 8 neighbours at each step Which one?

Pathfinding: Representations Graph Representations (e.g., streetmaps, etc) More general: you can assign costs to edges Best path = Path with lowest cost If all edges have same cost, equivalent to grid

Pathfinding Algorithms Bug Model Naive, used in many early games Breadth First Search and Dijkstra's Algorithm expensive, but finds the shortest path Best First Search A* Search Quick, but needn't find shortest path Finds shortest path reasonably fast Most games use some variation of A*

How this course works (in theory) Lectures: Introduce and give context to algorithms Practicals: Tutorials: Implement algorithms in dungeon game Make sure you do this or you risk failing One assessment will likely be a competition of NPCs coded by you I'll give some problems on the website. Email solutions to me before the tutorial. We will discuss solutions (anonymously)

How this course works in practice Lectures and tutorials are interchangable Interaction is encouraged in BOTH

Pathfinding Algorithm Properties Completeness Optimality Efficiency Will it find a path if one exists Will it find the shortest path Time: How many nodes need to be searched? Space: How many nodes need to be stored in memory?

Pathfinding algorithms Bug models Breadth First Dijkestra's Algorithm A* Algorithm Basically, Dijkestra with Heuristics A* is the objective. You will need to understand and program this algorithm. Most games use some version of A*

Bug Models Move towards goal and circumnavigate obstacles: BugPath(start, goal) 1. current = start 2. while (current!= goal) 3. return; (a) next = next square on straight line to goal (b) if (next is in obstacle) current = circumnavigate_obstacle (current); else current = next

Bug Model 1 Circumnavigate_obstacle(current) 1. walk all around obstacle, keeping track of distance to goal 2. return the closest point to goal

Bug Model 2 Circumnavigate_obstacle (current) 1. walk around the obstacle, until you hit the original line from source to goal 2. return the point on this line

Which is better?

Which is better?

Bug models Direction towards goal is known Obstacles are avoided when encountered Unlikely to give shortest path But guaranteed to find some path (if implemented properly!)

Breadth-first Search Look at all possible moves at successive depths: BFS(start, goal) 1. Initialise: queue={start}; start->parent = NULL 2. while (queue!= {}) (a) next = pop from queue (b) if (next == goal) return path; (the path is the sequence of parents from goal) (c) Add new successors of next to queue (d) Mark next as parent of each successor 3. return no path;

Breadth-first Search Cells in Queue: Step 2

Breadth-first Search Cells in Queue: Step 3

Breadth-first Search Demo http://qiao.github.com/pathfinding.js/visual/

Breadth-first Search Completeness Optimality Efficiency Time: Space: Answers will be discussed again in tutorial next week

Breadth-first search Completeness Yes Optimality Yes, if each movement has same cost No, if different costs

Pathfinding with costs A 1 C 2 8 1 D 1 F B 1 0.5 E 1 2 G

Pathfinding with costs Breadth-first is no longer guaranteed to find shortest path (in terms of cost) Which brings us to Dijkstra's Algorithm A very important algorithm in CS Used extensively for example, in networks and routing Performs similar to breadth-first when movement costs are equal Guarantees shortest path as long as costs are non-negative

Dijkstra's Algorithm Maintains two lists: Open (nodes/squares that need to be investigated) Closed (nodes/squares that have been investigated) Maintains least cost from start to each node. This is commonly called the G-function We will use notation: g(node) Uses a greedy approach Always picks the closest (least cost from start) node to investigate next

Dijkstra's Algorithm (basics) Step 1: a) Initialise closed list to NULL b) Move start (D) to open list c) Set g(d)=0 Step 2 (repeated): (a) (a) (a) Pop lowest cost member of open list (D) Assign cost-from-source to its neighbours: g(e)=0.5, g(f)=1, g(a)=8 Move D to closed list, and E,F,A to open list (b) Set parents of E,F,A to D A 2 B 1 8 C 1 D 1 0.5 1 E F 1 2 G

Dijkstra's Algorithm (basics) Now, closed={d}, open={e,f,a} Step 2 (repeated): a) Pop lowest cost member of open list (E) b) Assign cost-from-source to its neighbours: g(b)=0.5+1, g(g)=0.5+1 a) Move E to closed list, and B,G to open list a) Set parents of B,G to E A 2 1 8 C 1 B 1 D 0.5 1 E F 1 2 G

Dijkstra's Algorithm (Basics) In Step 2b, when assigning cost-from-source: If the node is already in the open list, you need to check if you have found a less costly path to it. If yes, update that node's cost and parent to reflect the cheaper path. In Step 2b and 2c: you should ignore any neighbours that are already in the closed list (do not add members of closed list back to open list!) Algorithm ends when Goal is popped from open list in Step 2a (success) Open list is empty (no path to goal)

Dijkstra's Algorithm for Grids Dijkestra (start, goal) 1. Initialise: Closed={}; Open={start}; g(start)=0; 2. While (Open!={}) (a) current=square with minimum g-value in Open (b) If (current==goal) return Path (c) Push (Closed, current) (d) For each adjacent square X i. If (X is Obstacle OR X is in Closed) Ignore X; ii. Calculate new g(x) iii. If (X is in Open AND the new g(x) < g(x)) Change parent(x) to current and Update g(x) Else Add X to Open and change parent(x) to current 3. Return NULL

Dijkstra's Algorithm Demo http://qiao.github.com/pathfinding.js/visual/

A* Algorithm Similar to Dijkstra's Algorithm, but with a Heuristic Function: So for each node in graph (or square in grid), we associate: g(node) = Cost of path from Start to Node h(node) = An estimate of cost of path from Node to Goal f(node) = g(node) + h(node) is the estimate of the best path from Start to Goal that passes through Node Just replace g() with f() in Dijkstra to get A* Replace g() with h() to get Best First Algorithm

Heuristics In simple grid worlds, straight line distance to goal is often a sensible h() function 6 5 4 6 5 5 6 6 6 3 2 1

Heuristics for A* If h(n)=0 for all n A* is identical to Dijkstra's Algorithm If h(n) <= actual cost of moving from `n' to goal A* is guaranteed to find the shortest path The lower h(n) is, the more nodes are expanded If h(n) > than actual cost of moving from `n' to goal Longer paths can be found first (not optimal). If h(n) = actual cost of moving from `n' to goal A* will search only the shortest path and nowhere else.

Heuristics for A* A good heuristic should be Examples: Fast to compute Always less than actual cost Euclidean Diatance h(n) = sqrt((n.x-goal.x)^2 + (n.y-goal.y)^2) Manhattan Distance ( diagonals not allowed) h(n) = abs(n.x-goal.x) + abs(n.y-goal.y) Chebyshev Distance (diagonals allowed) h(n) = max(abs(n.x-goal.x), abs(n.y-goal.y))

Negative Weights E -0.29 A -0.38 D 0.51 C 0.36 0.32 B