Announcements. Today s Menu

Similar documents
Heuristics and Algorithms

Announcements. Today s Menu

Lisp Basic Example Test Questions

Modern Programming Languages. Lecture LISP Programming Language An Introduction

Common LISP-Introduction

Lisp. Versions of LISP

CIS4/681 { Articial Intelligence 2 > (insert-sort '( )) ( ) 2 More Complicated Recursion So far everything we have dened requires

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

Problem Solving & Heuristic Search

Fifth Generation CS 4100 LISP. What do we need? Example LISP Program 11/13/13. Chapter 9: List Processing: LISP. Central Idea: Function Application

CSC 550: Introduction to Artificial Intelligence. Fall 2004

FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 4. LISP: PROMĚNNÉ, DALŠÍ VLASTNOSTI FUNKCÍ, BLOKY, MAPOVACÍ FUNKCIONÁLY, ITERAČNÍ CYKLY,

Search = the exploration of a search space, which is a collection of search states and connections between them, until a goal state is found

Announcement. Overview. LISP: A Quick Overview. Outline of Writing and Running Lisp.

ME512: Mobile Robotics Path Planning Algorithms. Atul Thakur, Assistant Professor Mechanical Engineering Department IIT Patna

Functional Programming. Pure Functional Languages

Symbolic Programming. Dr. Zoran Duric () Symbolic Programming 1/ 89 August 28, / 89

Recursion & Iteration

HW#1 due today. HW#2 due Monday, 9/09/13, in class Continue reading Chapter 3

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

1. Problem Representation

Functional Programming. Pure Functional Languages

(defvar *state* nil "The current state: a list of conditions.")

Functional Programming. Pure Functional Programming

Heap storage. Dynamic allocation and stacks are generally incompatible.

(defun fill-nodes (nodes texts name) (mapcar #'fill-node (replicate-nodes nodes (length texts) name) texts))

Look at the outermost list first, evaluate each of its arguments, and use the results as arguments to the outermost operator.

Sample Final Exam Questions

regsim.scm ~/umb/cs450/ch5.base/ 1 11/11/13

Homework #2. Source code with description. Tzewen Wang ECE578 Winter 2005

MORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page.

Object Oriented Programming (OOP)

Introduction to Functional Programming

Scheme Basics > (butfirst '(help!)) ()

Functional programming with Common Lisp

Informed Search. Xiaojin Zhu Computer Sciences Department University of Wisconsin, Madison

Route planning / Search Movement Group behavior Decision making

Lecture Notes on Lisp A Brief Introduction

Lecture #2 Kenneth W. Flynn RPI CS

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

CS 314 Principles of Programming Languages

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

Lists in Lisp and Scheme

Artificial Intelligence

Streams and Lazy Evaluation in Lisp

61A LECTURE 18 SCHEME. Steven Tang and Eric Tzeng July 24, 2013

LISP. Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits.

Common Lisp. Blake McBride

A Genetic Algorithm Implementation

UMBC CMSC 331 Final Exam

Artificial Intelligence (part 4c) Strategies for State Space Search. (Informed..Heuristic search)

This should prevent residual sexism, racism, favoritism lurking in the unconscious of your professor & TA from biasing grading!!

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

Delayed Expressions Fall 2017 Discussion 9: November 8, Iterables and Iterators. For Loops. Other Iterable Uses

A.I.: Informed Search Algorithms. Chapter III: Part Deux

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

Informed State Space Search B4B36ZUI, LS 2018

Today s s lecture. Lecture 2: Search - 1. Examples of toy problems. Searching for Solutions. Victor R. Lesser

ITERATORS AND STREAMS 9

Computer Science 21b (Spring Term, 2015) Structure and Interpretation of Computer Programs. Lexical addressing

1 (5pts) 2 (20 pts) 3 (20 pts) 4 (10 pts) 5 (15 pts) 6 (30 pts) Total NAME: CU ID: Recitation instructor/time

CS 314 Principles of Programming Languages. Lecture 16

UMBC CMSC 331 Final Exam

Midterm Examination (Sample Solutions), Cmput 325

INTRODUCTION TO HEURISTIC SEARCH

COMP219: Artificial Intelligence. Lecture 7: Search Strategies

Artificial Intelligence (Heuristic Search)

Path Planning. CMPS 146, Fall Josh McCoy

Below are example solutions for each of the questions. These are not the only possible answers, but they are the most common ones.

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

INF4820. Common Lisp: Closures and Macros

Department of Computer and information Science Norwegian University of Science and Technology

Imperative, OO and Functional Languages A C program is

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

INF4820: Algorithms for Artificial Intelligence and Natural Language Processing. More Common Lisp

Building a system for symbolic differentiation

Project 2: Scheme Interpreter

FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 5. LISP: MAKRA, DATOVÁ STRUKTURA ZÁZNAM

Problems 3-1, 3.3, 3.4 and 3.5 in Chapter 3 of Winston and Horn's LISP (see Below)

Functional Languages. CSE 307 Principles of Programming Languages Stony Brook University

Procedural abstraction SICP Data abstractions. The universe of procedures forsqrt. Procedural abstraction example: sqrt

CSCI 3155: Principles of Programming Languages Exam preparation #1 2007

Functional Programming. Contents

CS 480. Lisp J. Kosecka George Mason University. Lisp Slides

6.001, Spring Semester, 1998, Final Exam Solutions Your Name: 2 Part c: The procedure eval-until: (define (eval-until exp env) (let ((return (eval-seq

(Un)informed State Space Search A4B33ZUI, LS 2016

Search. CS 3793/5233 Artificial Intelligence Search 1

521495A: Artificial Intelligence

SCHEME 10 COMPUTER SCIENCE 61A. July 26, Warm Up: Conditional Expressions. 1. What does Scheme print? scm> (if (or #t (/ 1 0)) 1 (/ 1 0))

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

Announcements. Today s Menu

A little bit of Lisp

Important Example: Gene Sequence Matching. Corrigiendum. Central Dogma of Modern Biology. Genetics. How Nucleotides code for Amino Acids

CS 61A Discussion 8: Scheme. March 23, 2017

Scheme in Scheme: The Metacircular Evaluator Eval and Apply

Interpreters and Tail Calls Fall 2017 Discussion 8: November 1, 2017 Solutions. 1 Calculator. calc> (+ 2 2) 4

The goal of this assignment is to implement and test Breadth-first search (BFS) on a simple navigation problem (path-finding).

ALISP interpreter in Awk

Lisp: Question 1. Dr. Zoran Duric () Midterm Review 1 1/ 13 September 23, / 13

Transcription:

Announcements 1 Today s Menu Sample A* Problem A* Code Traveling Salesman - Brute Force {See Traveling_Salesman.ppt } 2

Heuristic Searches The following figure shows a search tree with the state indicated by the tuple inside parentheses. A letter indicates the state name and the integer indicates the estimated cost for finding a solution from that state (a cost of 0 indicates a goal state). Using the Graph-Search algorithm discussed in class, give the solution tree or steps using depthfirst search. How many nodes did depth-first expand? Repeat using breadth-first search. How many nodes did breadth-first expand? Repeat using heuristic search. How many nodes did heuristic search expand? Repeat using A * search. How many nodes did A * expand? Can any of these algorithms ever find N as a solution? Explain 3 PROCEDURE GRAPH-SEARCH 1. Create a search graph, G, consisting solely of the start node, s. Put s on a list called OPEN. 2. Create a list called CLOSED that is initially empty. 3. LOOP: if OPEN is empty, exit with failure. 4. Select the first node on OPEN, remove it from OPEN, and put it on CLOSED. Call this node n. 5. If n is a goal node, exit successfully with the solution obtained by tracing a path along the pointers from n to s in G. (see step 7.) 6. Expand node n, generating the set, M, of its successors and install them as successors of n in G. 7. Establish a pointer to n from those members of M that were not already in G (i.e., not already on either OPEN or CLOSED). Add these members of M to OPEN. For each member of M that was already on OPEN or CLOSED, decide whether or not to redirect its pointer to n. For each member of M already on CLOSED, decide for each of its descendants in G whether or not to redirect its pointer. 8. Reorder the list OPEN, either according to some arbitrary scheme or according to heuristic merit. 9. Go LOOP 4

Algorithm Details: You can use algorithm graphsearch for everything Start: Open={A} Closed={} G={A} M={} f(n)=g(n)+h(n) where g(n)=depth(n) & h(n)=heuristic fcn Breadth First: Use the function f(n)=depth(n) and append M at the end of the open list. n 1 =B; n 2 =C; Open={B,C}, Closed={A}, G={A,B,C}, f(n 1 )=1; f (n 2 )=1 2. The algorithm expands B in order to obtain M={D,E} n 3 =D; n 4 =E; Open={C,D,E}, Closed={A,B}, G={A,B,C,D,E}, f(n 3 )=1; f (n 4 )=1 3. The algorithm expands C in order to obtain M={F,G}, f(n 5 )=1; f (n 6 )=1 n 5 =F; n 6 =G; Open={D,E,F,G}, Closed={A,B,C}, G={A,B,C,C,D,E,F,G} 4. The algorithm expands D in order to obtain M={H,I}, f(n 7 )=1; f (n 8 )=1 n 7 =H; n 8 =I; Open={E,F,G,H,I}, Closed={A,B,C,D}, G={A,B,C,D,E,F,G,H,I}, 5. The algorithm expands E in order to obtain M={J,K} f(n 9 )=1; f (n 10 )=1 n 9 =J; n 10 =K; Open={F,G,H,I,J,K}, Closed={A,B,C,D,E}, G={A,B,C,D,E,F,G,H,I,J,K}, 6. The algorithm expands F in order to obtain M={L,M}, f(n 11 )=1; f (n 12 )=1, n 11 =L; n 12 =M; Open={G,H,I,J,K,L,M}, Closed={A,B,C,D,E,F}, G={A,B,C,D,E,F,G,H,I,J,K,L,M} 7. The algorithm expands G in order to obtain M={N,P}, f(n 13 )=1; f (n 14 )=1, n 13 =N; n 14 =P; Open={H,I,J,K,L,M,N,P}, G={A,B,C,D,E,F,G,H,I,J,K,L,M,N,P}, Closed={A,B,C,D,E,F,G} 8. The algorithm expands H in order to obtain M={}, G={A,B,C,D,E,F,G,H,I,J,K,L,M,N,P} Open={I,J,K,L,M,N,P}, Closed={A,B,C,D,E,F,G,H} 9. The algorithm expands I in order to obtain M={}, G={A,B,C,D,E,F,G,H,I,J,K,L,M,N,P} Open={J,K,L,M,N,P}, Closed={A,B,C,D,E,F,G,H,I} 10. The algorithm selects J. J is a goal node and the algorithm terminates. BFS expands Closed={A,B,C,D,E,F,G,H,I} 9 nodes Depth-First: Use the function f(n)=depth(n) and append M at the front of the open list. n 1 =B; n 2 =C; Open={B,C}, Closed={A}, G={A,B,C}, f(n 1 )=1; f (n 2 )=1 2. The algorithm expands B in order to obtain M={D,E} n 3 =D; n 4 =E; Open={D,E,C}, Closed={A,B}, G={A,B,C,D,E}, f(n 3 )=2; f (n 4 )=2 3. The algorithm expands D in order to obtain M={H,I} n 4 =H; n 5 =I; Open={H,I,E,C}, Closed={A,B,D}, G={A,B,C,D,E,H,I}, f(n 5 )=3; f (n 6 )=3 4. The algorithm expands H in order to obtain M={} Open={I,E,C}, Closed={A,B,D,H}, G={A,B,C,D,E,H,I} 5. The algorithm expands I in order to obtain M={}, G={A,B,C,D,E,H,I} Open={E,C}, Closed={A,B,D,H,I} 6. The algorithm expands E in order to obtain M={J,K}, f(n 9 )=3; f (n 10 )=3 n 6 =J; n 7 =K; Open={J,K,C}, Closed={A,B,D,H,I,E}, G={A,B,C,D,E,H,I,J,K}, 7. The algorithm selects J. J is a goal node and the algorithm terminates. G={A,B,C,D,E,H,I,J,K}, DFS expands Closed={A,B,D,H,I,E,} 6 nodes

Heuristic-Search: Use the function f(n)= h(n) and sort the open list using f values. n 1 =B; n 2 =C; Open={B,C}, Closed={A}, G={A,B,C}, f(n 1 )=26; f (n 2 )=13 2. The algorithm expands C in order to obtain M={F,G} n 3 =F; n 4 =G; Open={F,B,G}, Closed={A,C}, G={A,B,C,F,G}, f(n 3 )=12; f (n 4 )=27 3. The algorithm expands F in order to obtain M={L,M}, n 5 =L; n 6 =M; Open={B,G,M,L}, Closed={A,C,F}, G={A,B,C,F,G,L,M}, f(n 5 )=33; f (n 6 )=29 4. The algorithm expands B in order to obtain M={D,E}, f(n 7 )=19; f (n 8 )=16 n 7 =D; n 8 =E; Open={E,D,G,M,L}, Closed={A,C,F.B}, G={A,B,C,F,G,L,M,D,E} 5. The algorithm expands E in order to obtain M={J,K}, n 9 =J; n 10 =K; f(n 9 )=0; f (n 10 )=2 Open={J,K,D,G,M,L}, Closed={A,C,F,B,E}, G={A,B,C,F,G,L,M,D,E,J,K} 6. The algorithm selects J. J is a goal node and the algorithm terminates. Open={K,D,G,M,L}, G={A,B,C,F,G,L,M,D,E,J,K} Heuristic search expanded Closed={A,C,F,B,E} 5 nodes A* Search: Uses f(n)=g(n)+h(n) where g(n)=depth(n) & h(n)=cost and sort the open list using f n 1 =B; n 2 =C; Open={B,C}, Closed={A}, G={A,B,C}, f(n 1 )=1+26; f (n 2 )=1+13 2. The algorithm expands C in order to obtain M={F,G}, f(n 3 )=2+12; f (n 4 )=2+27 n 3 =F; n 4 =G; Open={F,B,G}, Closed={A,C}, G={A,B,C,F,G} 3. The algorithm expands F in order to obtain M={L,M}, G={A,B,C,F,G,L,M} n 5 =L; n 6 =M; Open={B,G,M,L}, Closed={A,C,F}, f(n 5 )=3+33; f (n 6 )=3+29 4. The algorithm expands B in order to obtain M={D,E}, G={A,B,C,F,G,L,M,D,E} n 7 =D; n 8 =E; Open={E,D,G,M,L}, Closed={A,C,F.B}, f(n 7 )=2+19; f (n 8 )=2+16 5. The algorithm expands E in order to obtain M={J,K}, G={A,B,C,F,G,L,M,D,E,J,K} n 9 =J; n 10 =K; Open={J,K,D,G,M,L }, Closed={A,C,F,B,E}, f(n 9 )=3+0; f (n 10 )=3+2 6. The algorithm selects J. J is a goal node and the algorithm terminates. A* search expands Closed={A,C,F,B,E} 5 nodes. G={A,B,C,F,G,L,M,D,E,J,K} N will not be found by any of the algorithms because path {A,B,E,J} is considered before {A,C,G,N} due to the fact that h(e)=16 and h(g)=27 and h(e)<h(g).

See Class 15 Notes PROCEDURE GRAPH-SEARCH 1. Create a search graph, G, consisting solely of the start node, s. Put s on a list called OPEN. 2. Create a list called CLOSED that is initially empty. 3. LOOP: if OPEN is empty, exit with failure. 4. Select the first node on OPEN, remove it from OPEN, and put it on CLOSED. Call this node n. 5. If n is a goal node, exit successfully with the solution obtained by tracing a path along the pointers from n to s in G. (see step 7.) 6. Expand node n, generating the set, M, of its successors and install them as successors of n in G. 7. Establish a pointer to n from those members of M that were not already in G (i.e., not already on either OPEN or CLOSED). Add these members of M to OPEN. For each member of M that was already on OPEN or CLOSED, decide whether or not to redirect its pointer to n. For each member of M already on CLOSED, decide for each of its descendants in G whether or not to redirect its pointer. 8. Reorder the list OPEN, either according to some arbitrary scheme or according to heuristic merit. 9. Go LOOP (defun astar (st) (prog ((OPEN (list st)) M n CLOSED (G (list st)) (e 0)) /* 1-2 */ (print (list 'OPEN '= OPEN 'CLOSED '= CLOSED)) LOOP /* 3-5 */ (cond ( (null OPEN) (return nil) ) ( (equal 0 (get (setf n (car OPEN)) 'hval)) (return (list "Expanded" e "nodes" "Solution:" (path (car OPEN)) 'g G closed CLOSED )) )) /* 6 */ (setf M (exp n) e (+ 1 e) G (append G M) CLOSED (cons n CLOSED)) /* 7 */ (dolist (sex M) (putprop sex n 'father)) /* 8 */ (setf OPEN (sort (append M (cdr OPEN)))) /* 9 */ (go LOOP) )) (defun path (end) (prog ((pth (list end)) (i end) j) LOOP (setf j (get i 'father)) (if j (setf pth (cons j pth)) (return (list 'path pth))) (setf i j) (go LOOP) )) (defun exp (node) (get node 'sons) ) (defun fval (sex) (+ (get sex 'gval) (get sex 'hval))) > (load "astarclass25.lsp") ; loading astarclass25.lsp T > (load "astar.lsp") ; loading astar.lsp T > (astar 'a) ("Expanded" 5 "nodes" "Solution:" (PATH (A B E J)) G (A B C F G L M D E J K) CLOSED (E B F C A)) 9 (putprop 'a '(b c) 'sons ) (putprop 'b '(d e) 'sons ) (putprop 'c '(f g) 'sons ) (putprop 'd '(h i) 'sons ) (putprop 'e '(j k) 'sons ) (putprop 'f '(l m) 'sons ) (putprop 'g '(n p) 'sons ) (putprop 'a 25 'hval ) (putprop 'b 26 'hval ) (putprop 'c 13 'hval ) (putprop 'd 19 'hval ) (putprop 'e 16 'hval ) (putprop 'f 12 'hval ) (putprop 'g 27 'hval ) (putprop 'h 12 'hval ) (putprop 'i 5 'hval ) (putprop 'j 0 'hval ) (putprop 'k 2 'hval ) (putprop 'l 33 'hval ) (putprop 'm 29 'hval ) (putprop 'n 0 'hval ) (putprop 'p 12 'hval ) (putprop 'a 0 'gval ) (putprop 'b 1 'gval ) (putprop 'c 1 'gval ) (putprop 'd 2 'gval ) (putprop 'e 2 'gval ) (putprop 'f 2 'gval ) (putprop 'g 2 'gval ) (putprop 'h 3 'gval ) (putprop 'i 3 'gval ) (putprop 'j 3 'gval ) (putprop 'k 3 'gval ) (putprop 'l 3 'gval ) (putprop 'm 3 'gval ) (putprop 'n 3 'gval ) (putprop 'p 3 'gval ) 10

The End! 11