Вы находитесь на странице: 1из 31

Unit 2: Problem Solving

Hridaya Kandel
hridayakandel@gmail.com
AI Lecturer
BScCSIT Vth

Hridaya Kandel (AI Lecturer) 1


Objective
The students should understand the state space representation, and
gain familiarity with some common problems formulated as state
space search problems.

Given a problem description, the student should be able to formulate


it in terms of a state space search problem.

Hridaya Kandel (AI Lecturer) 2


Problem Solving
Problem solving, particularly in artificial intelligence, may be
characterized as a systematic search through a range of possible actions
in order to reach some predefined goal or solution.
1. special purpose: is tailor-made for a particular problem and often
exploits very specific features of the situation in which the problem
is embedded
2. General purpose : is applicable to a wide variety of problems One
general-purpose technique used in AI is means-end analysisa
step-by-step, or incremental, reduction of the difference between
the current state and the final goal

Hridaya Kandel (AI Lecturer) 3


Problem Solving: Steps
Steps in Problem Solving
Goal formulation
o What are the successful world states
o Goal help to organize behavior by limiting the objectives that the agent is
trying to achieve.
Problem formulation
o What actions and states to consider given the goal
Search
o Determine the possible sequence of actions that lead to the states of known
values and then choosing the best sequence.
Execute
o Give the solution perform the actions.

Hridaya Kandel (AI Lecturer) 4


What is a problem?
A problem is defined by:
An initial state: State from which agent start
Successor function: Description of possible actions available to
the agent.
Goal test: Determine whether the given state is goal state or not
Path cost: Sum of cost of each path from initial state to the given
state.

A solution is a sequence of actions from initial to goal state. Optimal


solution has the lowest path cost.

Hridaya Kandel (AI Lecturer) 5


States
Two special states are defined:
Initial state (starting point)
An initial state is the description of the starting
configuration of the agent
Final state (goal state)

Hridaya Kandel (AI Lecturer) 6


Successor Function/State Modification
A successor function is needed to move between
different states.
A successor function is a description of possible
actions, a set of operators. It is a on a state
representation, which convert it into transformation
function another state.
The successor function defines a relation of accessibility
among states.

Hridaya Kandel (AI Lecturer) 7


State Space

The state space is the set of all states reachable from


the initial state.
It forms a graph (or map) in which the nodes are states
and the arcs between nodes are actions.
A path in the state space is a sequence of states
connected by a sequence of actions.
The solution of the problem is part of the map formed
by the state space.

Hridaya Kandel (AI Lecturer) 8


Solution

A solution in the state space is a path from the initial


state to a goal state or, sometimes, just a goal state.
Path/solution cost: function that assigns a numeric cost
to each path, the cost of applying the operators to the
states
Solution quality is measured by the path cost function,
and an optimal solution has the lowest path cost among
all solutions.

Hridaya Kandel (AI Lecturer) 9


Search Problem
A search problem consists of the following:
S: the full set of states
s0 : the initial state
A:SS is a set of operators
G is the set of final states. Note that G S
The search problem is to find a sequence of actions which
transforms the agent from the initial state to a goal state gG. A
search problem is represented by a 4-tuple {S, s0, A, G}.
sequence of actions is called a solution plan. It is a path from the
initial state to a goal state. A plan P is a sequence of actions.

Hridaya Kandel (AI Lecturer) 10


Search Problem: Representation
The states are represented as nodes.
The allowed actions are represented as arcs.

Hridaya Kandel (AI Lecturer) 11


Vacuum World Problem

Hridaya Kandel (AI Lecturer) 12


Vacuum world Problem

States?? two locations with or without dirt: 2 x 22=8 states.


Initial state?? Any state can be initial
Actions?? {Left, Right, Suck}
Goal test?? Check whether squares are clean.
Path cost?? Number of actions to reach goal.

Hridaya Kandel (AI Lecturer) 13


Eight Puzzle
a) States:
Description of the eight
tiles and location of the
7 2 4
blank tile 5 6
b) Successor Function:
Generates the legal states 8 3 1
from trying the four actions
{Left, Right, Up, Down}
c) Goal Test:
Checks whether the state 1 2 3
matches the goal
configuration 4 5 6
d) Path Cost:
Each step costs 1 7 8

Hridaya Kandel (AI Lecturer) 14


Eight Queens
Place eight queens on a chess Q
board such that no queen can
attack another queen Q
Q
Q
Q
Q
Q
Q
January 26, (AI2003
Hridaya Kandel Lecturer) AI: Chapter 3:15Solving 15
Problems by Searching
Eight Queens: Problem formulation 1

States:
Any arrangement of 0 to 8
Q
queens on the board
Initial state:
Q
No queens on the board Q
Successor function:
Add a queen to an empty Q
square
Goal Test: Q
8 queens on the board and
none are attacked Q
The initial state has 64 Q
successors and 63 and 62 so
on Q
Hridaya Kandel (AI Lecturer) 16
Eight Queens: Problem formulation 2

States:
Q
Any arrangement of 8 queens
on the board Q
Initial state:
All queens are at any (say Q
column 1)
Successor function:
Q
Change the position of any Q
one queen
Goal test: Q
8 queens on the board, none
are attacked Q
Q
Hridaya Kandel (AI Lecturer) 17
Eight Queens: Problem formulation 3

States:
Q
Any arrangement of k queens
in the first k rows such that Q
none are attacked
Initial state: Q
Zero queens on the board
Successor function:
Add a queen to the (k+1)th
row so that none are attacked
Goal test:
8 queens on the board, none
are attacked

Hridaya Kandel (AI Lecturer) 18


Water Jug problem
Given a 4 gallon bucket and a 3 gallon bucket,
how can we measure exactly 2 gallons into one
bucket?
There are no markings on the bucket
You must fill each bucket completely

Hridaya Kandel (AI Lecturer) 19


Water Jug problem
Initial state: Actions and Successor Function
The buckets are empty Fill a bucket
Represented by the tuple ( 0 0 ) (x y) -> (3 y)
Goal state: (x y) -> (x 4)
One of the buckets has two Empty a bucket
gallons of water in it (x y) -> (0 y)
Represented by either ( x 2 ) or (x y) -> (x 0)
(2x) Pour contents of one bucket into
Path cost: another
1 per unit step (x y) -> (0 x+y) or (x+y-4, 4)
(x y) -> (x+y 0) or (3, x+y-3)

Hridaya Kandel (AI Lecturer) 20


Cryptarithmetic
letters stand for digits and the aim is to find a substitution of digits for letters such
that the resulting sum is arithmetically correct. Usually, each letter must stand for
a different digit. The following is a well-known example:

The following formulation is probably the simplest:


States: a cryptarithmetic puzzle with some letters replaced by digits.
Operators: replace all occurrences of a letter with a digit not already
appearing in the puzzle.
Goal test: puzzle contains only digits, and represents a correct sum.
Path cost: zero. All solutions equally valid.

Hridaya Kandel (AI Lecturer) 21


Production System
A production system (or production rule system) is a computer program typically
used to provide some form of artificial intelligence
Primarily Consist of
a set of rules about behavior called Productions
A production system provides the mechanism necessary to execute productions in
order to achieve some goal for the system.

Productions consist of two parts:


1. a sensory precondition (or "IF" statement)
2. an action (or "THEN")

If a production's precondition matches the current state of the world, then the
production is said to be triggered.
If a production's action is executed, it is said to have fired.
The underlying idea of production systems is to represent knowledge in the form
of condition-action pairs called production rules:
If the condition C is satisfied then the action A is appropriate.
Hridaya Kandel (AI Lecturer) 22
Production system is also called ruled-based system
Production system: Architecture

Short Term Memory:


Contains the description of the current
state.
Set of Production Rules:
Set of condition-action pairs and defines a
single chunk of problem solving
knowledge.
Interpreter:
A mechanism to examine the short term
memory and to determine which rules to
fire (According to some strategies such as
DFS, BFS, Priority, first encounter etc)
The execution of a production system can be defined as a series of recognize-act
cycles: Match memory contain matched against condition of production rules, this
produces a subset of production called conflict set. Conflict resolution one of the
production in the conflict set is then selected, Apply the rule.
Hridaya Kandel (AI Lecturer) 23
Production system: String Sort

Problem: Sorting a string composed of letters a, b & c.


Short Term Memory: cbaca
Production Set:

Interpreter: Choose one rule according to some strategy.

Hridaya Kandel (AI Lecturer) 24


Production System: Water Jug-Production Rules
1. Fill 4-gal jug (x,y) (4,y)
x<4
2. Fill 3-gal jug (x,y) (x,3)
y<3
3. Empty 4-gal jug on ground (x,y) (0,y)
x>0
4. Empty 3-gal jug on ground (x,y) (x,0)
y>0
5. Pour water from 3-gal jug to fill 4-gal (x,y) (4, y - (4 - x))
jug 0 < x+y 4 and y > 0
6. Pour water from 4-gal jug to fill 3-gal- (x,y) (x - (3-y), 3)
jug 0 < x+y 3 and x > 0
7. Pour all of water from 3-gal jug into (x,y) (x+y, 0)
4-gal jug 0 < x+y 4 and y 0
8. Pour all of water from 4-gal jug into (x,y) (0, x+y)
3-gal jug 0 < x+y 3 and x 0
Hridaya Kandel (AI Lecturer) 25
Production System: Water Jug-state representation

Hridaya Kandel (AI Lecturer) 26


Constraint Satisfaction Problem(CSP)
Constraint satisfaction problems or CSPs are mathematical problems where one
must find states or objects that satisfy a number of constraints or criteria.
A Constraint Satisfaction Problem is characterized by
a set of variables {x1, x2, .., xn},
for each variable xi a domain Di with the possible values for that variable,
and
a set of constraints, i.e. relations, that are assumed to hold between the
values of the variables. [These relations can be given intentionally, i.e. as a
formula, or extensionally, i.e. as a set, or procedurally, i.e. with an
appropriate generating or recognizing function.] We will only consider
constraints involving one or two variables.

The constraint satisfaction problem is to find, for each i from 1 to n, a value in


Di for xi so that all constraints are satisfied. Means that, we must find a value for
each of the variables that satisfies all of the constraints.

Hridaya Kandel (AI Lecturer) 27


Constraint Satisfaction Problem(CSP)
In a CSP, the states are defined by the values of a set of variables and the goal
test specifies a set of constraints that the values must obey.
For example, 8-queens problem as CSP
the variables are the locations of each of the eight queens; the possible
values are squares on the board; and
the constraints state that no two queens can be in the same row, column or
diagonal.
For example, all-diff(X1, X2, X3).
This constraint says that X1, X2, and X3 must take on different values. Say
that {1,2,3} is the set of values for each of these variables then:
X1=1, X2=2, X3=3 OK X1=1, X2=1,X3=3 NO

For Example, A map coloring problem


We are given a map, i.e. a planar graph, and we are told to color it using k
colors, so that no two neighboring countries have the same color. Example
of a four color map is shown below:
or diagonal.
Hridaya Kandel (AI Lecturer) 28
Constraint Satisfaction Problem(CSP)

The four color theorem states that given any plane separated into regions,
such as a political map of the countries of a state, the regions may be
colored using no more than four colors in such a way that no two adjacent
regions receive the same color.

Hridaya Kandel (AI Lecturer) 29


Constraint Satisfaction Problem(CSP)

For example, A cryptarithmetic problem


SEND
MORE
=========
MONEY

we have to replace each letter by a distinct digit so that the resulting sum is
correct. (Class Assignment)

Note:
A CS problem is usually represented as an undirected graph, called Constraint Graph where
the nodes are the variables and the edges are the binary constraints.

Hridaya Kandel (AI Lecturer) 30


Thank You

Hridaya Kandel (AI Lecturer) 31

Вам также может понравиться