Top Banner
CS 415 – A.I. Slide Set 5
39

CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Jan 03, 2016

Download

Documents

Justin Mathews
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

CS 415 – A.I.

Slide Set 5

Page 2: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Chapter 3

• Structures and Strategies for State Space Search– Predicate Calculus: provides a means of describing

objects and relations in a problem domain– Inference Rules: allow us to infer new knowledge

from these descriptions– Inferences and Base Rules define a space that is

searched to find a problem solution

Page 3: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Key Questions

• Is the problem solver guaranteed to find a solution?• Will the problem solver always terminate, or can it become

caught in an infinite loop?• When a solution is found, is it guaranteed optimal?• What is the complexity of the search algorithm?• How can the interpreter most effectively reduce complexity?• How can an interpreter be designed to most effectively use a

representation language?

Page 4: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Theory of State-Space Search• Primary tool for answering these questions– Represent the problems as a state-space graph– Use graph theory to analyze the structure and

complexity

• Graph = (V,E)– Vs are the particular states in a problem solving

process– Es are the transitions between states• Logical inferances or legal moves of a game

Page 5: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Euler Invents Graph Theory

• Bridges of Konigsberg

• Is there any simple path so that all 7 bridges are crossed once and then one returns to the starting point?

Page 6: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

A new formalization

What might a predicate calculus representation of this look like?

A “Eulerian Path” exists iff there are no nodes with odd degree or exactly two nodes with odd degree

Page 7: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Graph Theory• Graph = (V,E)• Labeled Graph: has labels attached to nodes

to distinguish them– Arcs (edges) are indicated by combining the labels

of the nodes on each end of the arc– Arcs may also be otherwise labeled• Indicates a named relation

• Directed graphs vs. non-directed• Path: connects successive nodes through a

series of edges

Page 8: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

A Directed Graph

Page 9: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Rooted Graphs and Trees• Rooted Graphs – a node with a “root”– Root: a node such that there is a path from the

node to all other nodes in the graph

• Tree – A graph in which two nodes have at most one path between them– Eliminates loops (cycles) in the graph–Most often trees are “rooted”– Parent, Child, and Sibling– Ancestor and Descendent

Page 10: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Example

Page 11: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Formal Definitions

Page 12: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Finite State Machine• Might be familiar to you– All modern computers and programs can be

represented as FSMs

• Finite State Machine (FSM) – a finite, directed, connected graph, having a set of states, a set of input values, and a state transition function that describes the effect that the elements of the input stream have on the state of the graph–Often used as a tool for compilers/interpreters

Page 13: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Fig 3.5 (a) The finite state graph for a flip flop and

(b) its transition matrix.

Page 14: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Fig 3.6 (a) The finite state graph and (b) the transition matrix for string recognition example

Page 15: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

The State Space Representation of Problems

• Nodes – correspond to partial problem solutions–Much like the Moore Machine FSM had nodes

that represented states of partial solutions

• Also allow the graph to define an initial condition and a goal condition– Again, much like the Moore machine

Page 16: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Formal Definition

Page 17: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Example: The Traveling Salesperson

N – all the cities A – interconnecting S – intermediate list of cities reached and total

cost GD – State where all cities have been reached

and we have returned home WITH the minimum possible cost of all such paths

Must be able to compare to all possible costs

Page 18: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

State Space?

Note: the notion of “dead end” states

Page 19: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Dealing with Huge State Spaces

The only way to be guaranteed to find the answer is to find all the possibilities

In some cases, we have provable algorithms that solve the problem without doing so

Any ideas for “general rules”?

Page 20: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Nearest Neighbor

Page 21: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Strategies for State Space Search

Data-driven and Goal-driven Search Data-driven (forward chaining)

Begin with given facts and set of legal moves

Continually apply rules to facts to create new facts

Goal-driven (backward chaining) Begin with the goal Work backwards based on applying

rules in reverse Work back to the start state

Page 22: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

When Goal-Driven Search?

1. A goal is given or can easily by formulated

2. A large number of rules that match the facts of the problem, and thus create an increasing number of goals

Early selection of a goal eliminates most of the branches

3. Problem data are not given Goal-driven search can direct problem

data acquisition (i.e. – medical examiner)

Page 23: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

When Data-Driven Search?

All (or most) of the data in initial problem statement

Interpretation problems, etc. There are a large number of potential

goals, but only a few ways to use the facts and given information of a problem instance

It is difficult to form a goal or hypothesis

Page 24: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Implementing Graph Search

Backtracking Begin at a start state and pursue path

until dead-end or goal If dead-end backtrack to most recent

node in path with unexamined siblings depth-first search

Going to be implemented recursively

Page 25: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Function Backtrack Algorithm

Notation SL – state list, lists the states in the

current path, if goal is found, SL lists solution

NSL – new state list, contains nodes whose descendants have not been generated/searched

DE – dead end, lists states whose descendents have failed to contain goal

CS – current state

Page 26: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

For graphs (not just trees) need to prevent loops

Test each new node to see if it is in any set

If so, ignore it Why is it ok to ignore a state once visited?

Function continues until goal or exhausts state-space

Page 27: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Function backtrack algorithm

Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 16

Page 28: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005

Fig 3.14 Backtracking search of a hypothetical state space space.

18

Page 29: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

A trace of backtrack on the graph of figure 3.14

Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 17

Page 30: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Data or Goal-Driven?

Currently, this is a data-driven search Takes the root as a start state and

evaluates its children Could be implemented as goal-driven

Let the goal be the root, evaluate descendants backward until a start-state is found

Page 31: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

DFS and BFS

2 Design Considerations Data-driven or goal-driven Depth-first or breadth-first

Going to give general DFS and BFS algorithms that don’t store paths

Each can be augmented easily to do so Look at Figure 3.15-on next slide

Page 32: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005

Fig 3.15 Graph for breadth - and depth - first search examples.

19

• DFS – A,B,E,K,S,L,T,F,M,C,G,N,H,O,P,U,D,I,Q,J,R

• BFS – A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U

Page 33: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Implementing BFS

Use lists closed – keeps track of states that are

already examined The union of dead end (DE) and state list

(SL) open – keeps track of nodes that have

children that have not been visited Note: the order in which nodes are

removed from open determines the order of the search

Algorithm on next slide

Page 34: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Function breadth_first search algorithm

Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 20

Page 35: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

A trace of breadth_first_search on the graph of Figure 3.15

Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 21

• Also, look at Fig. 3.17 to see the BFS search solution to an instance of the 8-puzzle (next slide)

Page 36: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005

Fig 3.17 Breadth-first search of the 8-puzzle, showing order in which states were removed from open.

5

Page 37: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

DFS Algorithm

Simplification of the backtrack algorithm

No ancestor information is stored Use open and closed lists as before

open list must be implemented as a stack rather than a queue as in the case of BFS

Remember, the order in which items are removed from open determines the structure of the search

Page 38: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Function depth_first_search algorithm

Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 3

Page 39: CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.

Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005

Fig 3.19 Depth-first search of the 8-puzzle with a depth bound of 5.

7

How far down do we go?

How many states were we required to visit? What about with BFS?