Introduction to
Artificial Intelligence
Assoc. Prof. Osama fathy
Problems, Problem space
and Search
Some AI task Domains
Mundane tasks:
Natural language: generation, understanding,
translation,
Perception: vision, smelling, hearing,
Robot control
Commonsense reasoning: is a reasoning about
physical object and their relation ships to each
other , reasoning about actions and reaction
3
Some AI task Domains
Formal tasks:
Math : logic, geometry, integral calculus,.. ,
Games : chess, checkers, backgammon, ..
Expert tasks:
Engineering: design, fault finding
manufacturing planning
Analysis: Scientific, Military, Medical,
Financial .
4
AI What AI can do?
Intelligence systems can help experts to solve
difficult analysis problems (military, financial, ..)
Intelligence systems can help to design new
devices (car's, airplane, .)
Intelligence systems can learn from examples
(artificial neural networks , expert sys's)
Intelligence systems can provide answer to
English questions using both structured data and
free text (Asimo. politic, )
5
Script problem
Draw a script (is a structure that represents the
system's knowledge about a subject) of
shopping text. Then, write an algorithm to
solve the questions.
Script problem
Mary went to store.
Mary went shopping for a new coat.
Mary walked up to sales person.
She asked her if she needed any help.
She asked where the coat department.
She found a red one she really liked.
When she got it home, she discovered that it went
perfectly with here favorite dress
7
Script problem
Q1: What did Mary go shopping for?
Q2: What did Mary find that she liked?
Q3: Did Mary buy any thing?
Solution
1. Arrange actions Time.
2. Coding:
C...customer
Sstore
Psales person
M.......merchandize
Dmoney
Rcolor
T.department
9
1- C enter S
3. Script:
2- C looking around
3- C looks for a specific M
4- C looks for interesting M
5- C ask P for help
6-
7- C find M
9- C buy m
8- C fails to find M
10- C leaves s
11- C leaves s
12- C go to step 2
13- C takes M
14- C leaves S
10
4. Algorithms:
11
Assignment-2:
Prepare two different texts about two different
subjects, and three questions about each one then:
Draw a script for each one
Write an algorithm to solve the questions
for each one
Note: Last date to receipt (hard & soft copy the assignments,
next --------------
12
Problem representation
State space representation:
Problem reduction representation:
States.
Operators.
Initial and goal states.
Initial problem description.
Set of operators for transforming problems to sub
problems.
Set of primitive problem description.
Game tree.
13
A-State space representation:
Define the state space that contain all the possible
configurations of the relevant objects.
Specify one or more states within that space from
which the problem solving process will start
(initial states).
Specify one or more states that would be
acceptable as solution to the problem (goal state).
Specify a set of rules that describe the actions
(operators) available.
14
Example: Water Jug Problem:
You are given to jugs 4-gallon one and 3-gallon
one, neither has measuring markers on it. There
is a pump that can be used to fill the jugs with
water. How can you get exactly 2-gallon of
water into the 4-gallon jug?
4-G
3-G
15
In order to solve the problem:
Define the problem state space including the
start and the goal states and a set of operators
for moving in that space.
The problem can then be solved by searching
for a path through the space from the initial
state to the goal state, So the process of search
is fundamental to the problem solving process.
Examples of basic search techniques:
Breadth-first search.
Depth-first search.
16
Example: Water Jug Problem
Solution:
State Space: order pairs of integers (x, y) such
that x = 0, 1, 2, 3, 4 and y = 0, 1, 2, 3.
Start state: is (0, 0).
Goal state: is (2, n) for any value of n.
17
Example: Water Jug Problem
Operators:
# Current
State
New
State
Condition
Description
(x, y)
(4, y)
x<4
Fill 4-G jug
(x, y)
(x, 3)
y<3
Fill 3-G jug
(x, y)
(x-d, y)
x>0
Pour some water
from the 4-G jug
(x, y)
(x, y-d)
y>0
Pour some water
from the 3-G jug
18
Example: Water Jug Problem
# Current
State
New
State
Condition
Description
(x, y)
(0, y)
x>0
Empty the 4-G jug
on the ground
(x, y)
(x, 0)
y>0
Empty the 3-G jug
on the ground
(x, y)
(4,y-(4-x))
x+y4 &
y>0
pour water from
3-G jug into 4-G
jug until it is full
19
Example: Water Jug Problem
# Current
State
New
State
Condition
Description
(x, y)
(x-(3-y),3)
x+y3 &
x>0
pour water from
4-G jug into 3-G
jug until it is full
(x, y)
(x+y,0)
x+y4 &
y>0
pour all the water
from 3-G jug into
4-G jug
10
(x, y)
(0, x+y)
x+y3 &
x>0
pour all the water
from 4-G jug into
3-G jug
20
Example: Water Jug Problem
Tree:
(0,0)
(0,3)
(4,0)
(4,3)
(0,3)
(0,0)
(1,0)
(2,0)
(4,3)
(1,3)
(4,0)
(0,0)
(3,0)
(4,3)
(2,3)
21
Example: travel salesman problem
A sales man has a list of cites, each of which he
must visit once. There are direct roads between
each pair of cites. Find the route the salesman
should follow for the shortest possible round
trip.
S,G
22
Example: travel salesman problem
State space for the problem:
A simple control structure solve the problem so
it will simply explore all paths in the tree and
return the shortest one.
If there are N cites, the number of different
paths among them is (N-1)!
if N= 10 cites, then different paths = 9!=362880
So, the time required to perform this search is
proportional to N!
if N= 10 cites, then time = 10!=3628800 which
is very large
23
Example: travel salesman problem
A
AB
AD
AC
ABC
ABD
ACB
ACD
ADB
ADC
ABCD
ABDC
ACBD
ACDB
ADBC
ADCB
N= 4 cites, then different paths = 3!=6
D
C
24
Problem representation
State space representation:
Problem reduction representation:
States.
Operators.
Initial and goal states.
Initial problem description.
Set of operators for transforming problems to sub
problems.
Set of primitive problem description.
Game tree.
25
B- Problem reduction representation
In this approach the initial problem description is
given and it is solved by a sequence of
transformations (operators) that changes it into a set
of sub-problems whose solutions are immediate
(primitive problems).
Problem representation:
Initial problem description.
A set of operators for transforming problem to
sub-problems.
A set of primitive problem descriptions.
26
Example: Tower of Hanoi puzzle
A
B
C
A
B
C
1
initial state
3
final state
There are three pegs, 1, 2 and 3, and three disks, a, b and c
(a being the smallest and c being the biggest). Initially, all
the disks are stacked on peg 1. The problem is to transfer
them all on to peg 3. Only one disk can be moved at a time,
and no disk can ever be placed on top of a smaller disk.
27
Example: Tower of Hanoi puzzle
The problem of moving a stack of size N from peg
(1) to peg (3) can replaced by three problems:
Moving a stack of size (n-1) from (1)
(2).
Moving a stack of size (1) from (1)
(3).
Moving a stack of size (n-1) from (2)
(3).
Primitive problem:
Moving a single disk from one peg to another
provided no smaller disk is on the receiving peg.
28
An animated solution of the Tower of Hanoi puzzle
for T(4,3)
29
A model set of the Towers of Hanoi (with 8 disks)
30
The state-space for the Eight -Puzzle problem
31
Example: Measuring problem!
9l
3l
5l
Problem : You are given three jugs 3-liter, 5-liter and
9-liter one, neither has measuring markers on it. There
is a pump that can be used to fill the jugs with water.
How can you get exactly 7-liter of water into the 9liter jug?
32
Which solution do we prefer?
Solution 1:
a
0
3
0
3
0
3
0
3
1
0
Solution 2:
b
0
0
0
0
0
0
3
3
5
5
c
0
0
3
3
6
6
6
6
6
7
start
goal
a
0
0
3
3
3
3
b
0
5
2
0
5
0
c
0
0
0
2
2
7
start
goal
33