Anda di halaman 1dari 39

SSDA

Unit 2
Problem-solving
and Building Smart
Systems

Introduction to Problem solving process


Everyone

must have felt at least once in his or


her life how wonderful it would be if we could
solve a problem at hand preferably without
much difficulty or even with some difficulties.
Unfortunately the problem solving is an art at
this point and there are no universal approaches
one can take to solving problems

PROBLEM REPRESENTATION IN AI
Define

the problem precisely :like what is


initial situation, what will be the final, what are
acceptable solutions
Analyze the problem: various possible
techniques for solving the problem
Isolate and represent the task knowledge that is
necessary to solve the problem.
Choose the best problem solving technique
and apply it

Some example problems


Toy

problems and micro-worlds

8-Puzzle
Missionaries and Cannibals
Cryptarithmetic
Remove 5 Sticks
Water Jug Problem

Real-world

problems

8-Puzzle
Given an initial configuration of 8 numbered tiles on
a 3 x 3 board, move the tiles in such a way so as to
produce a desired goal configuration of the tiles.

8-Puzzle

State Representation: 3 x 3 array configuration of the tiles on the


board. 3 x 3 array configuration of the tiles on the board.
Operators: M Move Blank Square Left, Right, Up or Down. ove Blank
Square Left, Right, Up or Down.

s a more efficient encoding of the operators than one in


which each of four possible moves for each of the 8 distinct
tiles is used.

Initial State: A A particular configuration of the board. particular


configuration of the board.
Goal: A particular configuration of the board.

The 8-Queens Problem


State Representation: ?
Initial State: ?
Operators: ?
Goal: Place eight queens on a
chessboard such that no queen
attacks any other

Missionaries and Cannibals


Three missionaries and three cannibals wish to cross the
river. They have a small boat that will carry up to two
people. Everyone can navigate the boat. If at any time the
Cannibals outnumber the Missionaries on either bank of the
river, they will eat the Missionaries. Find the smallest
number of crossings that will allow everyone to cross the
river safely.

Missionaries and Cannibals


Goal:

Move all the missionaries and


cannibals across the river.
Constraint: Missionaries can never be
outnumbered by cannibals on either side
of river, or else the missionaries are
killed.
State: configuration of missionaries and
cannibals and boat on each side of river.
Initial State: 3 missionaries, 3
cannibals and the boat are on the near
bank
Operators: Move boat containing some
set of occupants across the river (in
either direction) to the other side.

Missionaries and Cannibals Solution


NearsideFarside
0Initialsetup:MMMCCCB
1Twocannibalscrossover:MMMCBCC
2Onecomesback:MMMCCBC
3Twocannibalsgooveragain:MMMBCCC
4Onecomesback:MMMCBCC
5Twomissionariescross:MCBMMCC
6Amissionary&cannibalreturn:MMCCBMC
7Twomissionariescrossagain:CCBMMMC
8Acannibalreturns:CCCBMMM
9Twocannibalscross:CBMMMCC
10Onereturns:CCBMMMC
11Andbringsoverthethird:BMMMCCC

Water Jug Problem


Given a full 4-gallon jug and a full 5-gallon jug, fill the 2-gallon jug
with exactly 1 gallon of water.

State: ?

Initial State: ?

Operators: ?

Goal State: ?

Water Jug Problem


5

Operator table

State = (x,y), where x


is the number of
gallons of water in the
5-gallon jug and y is #
of gallons in the 2gallon jug

Name

Cond. Transition

Effect

Empty5

(x,y)(0,y)

Empty 5-gal.
jug

Empty2

(x,y)(x,0)

Empty 2-gal.
jug

5to2

x>3

(x,2)(x,2)

Pour 2-gal.
into 3-gal.

(x,0)(x-2,2)

Pour 5-gal.
into 2-gal.

Initial State = (5,2)

5to2

x2

Goal State = (*,1),


where * means any
amount

5to2part

y <= 1 (1,y)(0,y+1) Pour partial


5-gal. into 2gal.

Some more real-world problems


Route

finding
Touring (traveling salesman)
Logistics
VLSI layout
Robot navigation
Learning

Types of Problem Spaces


Problems generally represented as graphs
Problem solving ~ searching a graph
There

are several types of problem spaces:

State space
Problem Reduction Space
AND/OR Graphs

State Space
The

"state space" is the set of states of


the problem

we

can get to a state by applying


operators to that state and get a new
state.

State Space
The

states represent situations of the problem.


The operators represent actions in the world.
forward search:
search the root of the problem space represents the
start state, and the search proceeds forward to a goal state.
backward search : the root of the problem space represents the
goal state, and the search proceeds backward to the initial state.

State Space
State

space = Directed graph


Nodes ~ Problem situations
Arcs ~ Actions, legal moves
Problem

= ( State space, Start, Goal condition)


Note: several nodes may satisfy goal condition
Solving

a problem ~ Finding a path


Problem solving ~ Graph search
Problem solution ~ Path from start to a goal node

A problem from blocks world

Find a sequence of robot moves to re-arrange


blocks

Blocks world state space


Start

Goal

Examples of representing problems in state


space
Blocks

world planning
8-puzzle, 15-puzzle
8 queens
Travelling salesman
Set covering
How can these problems be represented by graphs?
Propose corresponding state spaces

8-puzzle

State spaces for optimisation problems


Optimisation:

minimise cost of solution

In

blocks world:
actions may have different costs
(blocks have different weights, ...)

Assign

costs to arcs
Cost of solution = cost of solution path

Problem Reduction Space


In

a problem reduction space, the nodes represent problems


to be solved or goals to be achieved, and the edges represent
the decomposition of the problem into subproblems.
This is best illustrated by the example of the Towers of
Hanoi problem.

AA

BB

Problem Reduction Space


The

root node, labeled 3AC represents the original


problem of transferring all 3 disks from peg A to peg C.

The

goal can be decomposed into three subgoals: 2AB,


1AC, 2BC. In order to achieve the goal, all 3 subgoals
must be achieved.
3AC

2AB

1AC

1AB

1AC

1CB

2BC

1BA

1BC

1AC

Problem Reduction Space

3AC

Problem Reduction Space

3AC

2AB

1AC

Problem Reduction Space

B
3AC

2AB

1AC

1AB

Problem Reduction Space

3AC

2AB

1AC

1AB

1CB

Problem Reduction Space

3AC

1AC

2AB

1AC

1AB

1CB

Problem Reduction Space

3AC

1AC

2AB

1AC

1AB

1CB

2BC

1BA

Problem Reduction Space

3AC

1AC

2AB

1AC

1AB

1CB

2BC

1BA

1BC

Problem Reduction Space

3AC

1AC

2AB

1AC

1AB

1CB

2BC

1BA

1BC

1AC

AND/OR Graphs
An

AND/OR graph consists of both AND nodes and OR


nodes.

One

source of AND/OR graphs is a problem where the


effect of an action cannot be predicted in advanced, as in
an interaction with the physical world.

AndOr Graph

represents the search space for solving the problem P,


using the goal-reduction methods:
P if Q and R
P if S
Q if T
Q if U

AND/OR Graphs
An

AND graph consists entirely of AND nodes, and in


order to solve a problem represented by it, you need to
solve the problems represented by all of his children (Hanoi
towers example).

An

OR graph consists entirely of OR nodes, and in order to


solve the problem represented by it, you only need to solve
the problem represented by one of his children (Eight
Puzzle Tree example).

Solution subgraph for AND/OR trees


In

general, a solution to an AND/OR graph is a


subgraph with the following properties:

It contains the root node. For every OR node included in


the solution subgraph, one child is included.
For every AND node included in the solution subgraph,
all the children are included.
Every terminal node in the solution subgraph is a solved
node.

Example:Matrix Multiplication

Example:Matrix Multiplication

Anda mungkin juga menyukai