CSE473 Winter 1998 1 01/30/98 State-Space Search Administrative –Reading: Chapter 4 –PS2 on the Web now Last time –problem solving as {graph search, Lisp.

Slides:



Advertisements
Similar presentations
Cooperating Intelligent Systems
Advertisements

Recursion Chapter 14. Overview Base case and general case of recursion. A recursion is a method that calls itself. That simplifies the problem. The simpler.
ANSI Common Lisp 3. Lists 20 June Lists Conses List Functions Trees Sets Stacks Dotted Lists Assoc-lists.
Main Title Here Additional copy here, additional copy here, additional copy here, additional copy here, additional copy here. ADD YOUR WEB ADDRESS HERE.
1 Search Problems (read Chapters 3 and 4 of Russell and Norvig) Many (perhaps most) AI problems can be considered search problems. This can be modeled.
Solving Equations with variables on both sides of the Equals
CSE Winter 2008 Introduction to Program Verification refining an interface.
Generics "It is easy to study the rules of overloading and of templates without noticing that together they are one of the keys to elegant and efficient.
Project 1: Background Informed search : 8- puzzle world BFS, DFS and A* algorithms Heuristics : Manhattan distance, Number of misplaced tiles Lisp programming.
Defining functions in lisp In lisp, all programming is in terms of functions A function is something which –takes some arguments as input –does some computing.
Introduction to Artificial Intelligence Lisp Ruth Bergman Fall 2002.
(cons ) (defun pair_elements (A B) ) (cond ( (or (null A) (null B) ) ‘() ) ( t ) (list ) Pairing elements in two lists >(pair_elements ‘(jack bonnie romeo)
Imperative programming public int factorial (int N){ int F = 1; for(X=N; X>1; X-- ){ F= F*X; } return F; } Functional programming (defun factorial(N) (cond.
Introduction to Artificial Intelligence Problem Solving Ruth Bergman Fall 2002.
>(setf oldlist ) Constructing a list We know how to make a list in lisp; we simply write it: ‘4321( ) What if we want a new list with that list as a part?
Introductory Lisp Programming Lecture # 2 Main Topics –Basic Lisp data types –Lisp primitives –Details of list handling Cons cells (boxes) & their representation.
Programming in Lisp; Instructor: Alok Mehta Programming in Lisp Recursion, Data Abstraction, Mapping, Iteration.
Symbolic Expressions (S Expressions) Syntax: Opening and Closing parenthesis having elements in between. List represented in LISP: (A B2 C3 Shahid) (A.
Solving problems by searching
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
Subspaces, Basis, Dimension, Rank
CSE 341, S. Tanimoto Lisp Data Structures - 1 Data Structures in Lisp 0. Collections of associations, association lists. 1. Creating graphs with conses.
LISP 1.5 and beyond A very quick tour. Data Atoms (symbols) including numbers – All types of numbers including Roman! (well, in the early days) – Syntactically.
For Wednesday Read Chapter 4, sections 1 and 2 Homework: –Lisp handout 3.
Functional Programming
Search Much of AI has traditionally revolved around search –Search means “searching among all the possibilities for an answer” (or possibly the best answer)
Functional Programming 02 Lists
1 Othello Game Programs (human to human). 2 (defconstant all-directs '( )) ALL-DIRECTS (defconstant empty 0) EMPTY (defconstant.
Functional Programming Here we briefly look at what functional programming is and why we want to study it –a function, in the mathematical sense, is a.
1 Lisp Functions –Built-in functions –Defining functions –Function Evaluation and Special Forms defun, if Control statements –Conditional if, cond –Repetition.
Lecture 2-1CS250: Intro to AI/Lisp Intelligent Agents Lecture 3-2 October 14 th, 1999 CS250.
KU NLP Artificial Intelligence1 Ch 15. An Introduction to LISP q 15.0 Introduction q 15.1 LISP: A Brief Overview  Symbolic Expressions, the Syntactic.
Common lisp A functional programming language. Useful URL:
Structures and Strategies For Space State Search
Lecture 6-2CS250: Intro to AI/Lisp Programming in Your Favorite Language Lecture 5-2 February 11 th, 1999 CS250.
Function Design in LISP. Program Files n LISP programs are plain text –DOS extensions vary; use.lsp for this course n (load “filename.lsp”) n Can use.
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
Introduction to LISP. Lisp Extensible: It lets you define new operators yourself Lisp programs are expressed as lisp data structures –You can write programs.
UMBC CMSC Common Lisp II. UMBC CMSC Input and Output Print is the most primitive output function > (print (list 'foo 'bar)) (FOO BAR) The.
Design of Problem Solvers (PS) using Classical Problem Solving (CPS) techniques Classical Problem Solver has 2 basic components:  Search engine (uses.
Main Title Here Additional copy here, additional copy here, additional copy here, additional copy here, additional copy here. ADD YOUR WEB ADDRESS HERE.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
1 Variable Declarations Global and special variables – (defvar …) – (defparameter …) – (defconstant …) – (setq var2 (list 4 5)) – (setf …) Local variables.
September 4, Application problem 1. A guitar has 6 strings. How many strings are there on 6 guitars? Write a multiplication sentence and solve.
8puzzle in CP initial state goal state A trivial example.
Macros and general code walkers in Lisp: how useful! or, how useful? Ernst van Waning
Search as a problem solving technique. Consider an AI program that is capable of formulating a desired goal based on the analysis of the current world.
Functional Programming: Lisp MacLennan Chapter 10.
{ Module 4 Lesson 3 Model tiling with centimeter and inch unit squares as a strategy to measure area.
1 Outline Review Introduction to LISP Symbols and Numbers Lists Writing LISP Functions LISPWorks.
Engaging with Numbers   with Cary Cermak-Rudolf Roseburg Public Schools
Section 15.4, 15.6 plus other materials
Example of formula (defun roots (a b c) (list
Modern Programming Languages Lecture 20 Fakhar Lodhi
Prime and Composite.
J.E. Spragg Mitthögskolan 1997
Lisp Tutorial Click on Xlisp icon – you enter the interpreter
Iterative Deepening A* (IDA*) Search: Rough Algorithm from LISP
Modern Programming Languages Lecture 20 Fakhar Lodhi
CSE S. Tanimoto Explicit Function Application
John McCarthy Pioneer in AI Also Lisp Formalize common-sense reasoning
Area Models A strategy for Multiplication
Functional Programming: Lisp
Main Title Here ADD YOUR WEB ADDRESS HERE
Data Structures in Lisp
Data Structures in Lisp
Look back in your books to this table.
Common Lisp II.
Intersection Method of Solution
P8.py.
Presentation transcript:

CSE473 Winter /30/98 State-Space Search Administrative –Reading: Chapter 4 –PS2 on the Web now Last time –problem solving as {graph search, Lisp code} This time –Lisp code for 8-puzzle –search strategies

CSE473 Winter Puzzle, State Definition (defstruct state tiles actions) (defun copy-state-deeply (state) (make-state :tiles (copy-list (state-tiles state)) :actions (state-actions state))) (defun state-blank-pos (state) (position 0 (state-tiles state) :test '=))

CSE473 Winter Puzzle: Moving a Tile (defun state-new-pos (state dir) (let ((dimen (truncate (sqrt (length (state-tiles state))))) (blank-pos (state-blank-pos state))) (multiple-value-bind (row col) (truncate blank-pos dimen) (case dir ((:UP) (if (= row 0) NIL (+ (* dimen (- row 1)) col))) ((:DOWN) (if (= row (- dimen 1)) NIL (+ (* dimen (+ row 1)) col))) ((:LEFT) (if (= col 0) NIL (+ (* dimen row) (- col 1)))) ((:RIGHT) (if (= col (- dimen 1)) NIL (+ (* dimen row) (+ col 1))))))))

CSE473 Winter Puzzle: Utilities for Manipulating States (defun state-swap-pos (state pos1 pos2) (let* ((tiles (state-tiles state)) (temp (nth pos1 tiles))) (setf (nth pos1 tiles) (nth pos2 tiles)) (setf (nth pos2 tiles) temp))) (defun state-add-action (state action) (push action (state-actions state)))

CSE473 Winter Puzzle: Invoking the Search (defun make-initial-state (tiles) (make-state :tiles tiles :actions '())) (defun goal-state-p (state) (equal (state-tiles state) '( ))) (defun next-states (state) (remove NIL (list (move-blank state :UP) (move-blank state :DOWN) (move-blank state :LEFT) (move-blank state :RIGHT)))) (defun move-blank (state dir) (let ((blank-pos (state-blank-pos state)) (new-pos (state-new-pos state dir))) (cond ((null new-pos) NIL) (T (let ((new-state (copy-state-deeply state))) (state-swap-pos new-state blank-pos new-pos) (state-add-action new-state dir) new-state)))))