0% found this document useful (0 votes)
237 views29 pages

1.2 Problem Solving - State Space Search (AIML)

The document discusses problem solving through search techniques in artificial intelligence. It defines four key steps to general problem solving: goal formulation, problem formulation, search, and execution. Problem solving is formulated as a state space search, where the problem is to find a path from an initial state to a goal state. Several examples are provided to illustrate this formulation, including the 8-puzzle, missionaries and cannibals problem, and the water jug problem.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
237 views29 pages

1.2 Problem Solving - State Space Search (AIML)

The document discusses problem solving through search techniques in artificial intelligence. It defines four key steps to general problem solving: goal formulation, problem formulation, search, and execution. Problem solving is formulated as a state space search, where the problem is to find a path from an initial state to a goal state. Several examples are provided to illustrate this formulation, including the 8-puzzle, missionaries and cannibals problem, and the water jug problem.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Problem solving by search

What is an AI Technique?
• Artificial intelligence problems span a very broad spectrum. They
appear to have very little in common except that they are hard.
• Are there any techniques that are appropriate for the solution of a
variety of these problems?
• One of the few hard and fast results to come out of the first three
decades of AI research is the realization that
Intelligence requires knowledge
What is an AI Technique?

AI Technique is a method that exploits knowledge and should be


represented in such a way that:

- knowledge captures generalization


- understood by the people who provide it
- easily be modified
- used to help overcome its own sheer bulk
What is an AI Technique?

To build a system to solve a particular problem, we need four things:


1. Define the problem precisely
2. Analyze the problem
3. Isolate and represent the task knowledge
4. Choose the best problem-solving techniques
General Problem Solving
• An intelligent agents act to increase their performance measure. Some do this by adopting a goal.

• Four general steps in general problem solving:


Goal formulation – deciding on what the goal states are
– based on current situation and agent’s performance measure
– What are the successful world states
Problem formulation -
– how can we get to the goal, without getting bogged down in the detail of the world. Walking robot
- not concerned about moving one inch ahead, but, in general concerned about moving ahead.
– What actions and states to consider given the goal
– state the problem in such a way that we can make efficient progress toward a goal state.
Search
– Determine the possible sequence of actions that lead to the states of known values and then
choose the best sequence.
– Search algorithms – input is a problem, output is a solution (action
sequence)
Execute
– Given the solution, perform the actions
Problem Solving Agent

- An agent that tries to come up with a sequence of actions that will bring the
environment into a desired state.
-Special type of goal-based agent
Environment –
static – agent assumes that in the time it takes to formulate and solve the problem the
environment doesn’t change
observable – initial state and current state is known
discrete – more than one solution possible
deterministic – the solution, when executed will work!!
Deterministic, fully observable => single state problem
– Agent knows exactly which state it will be in;
A path sequence is an ordered listing of states and actions used in achieving a goal.
solution is a sequence
SIMPLE PROBLEM-SOLVING AGENT

A simple problem-solving agent. It first formulates a goal and a problem, searches for a sequence of
actions that would solve the problem, and then executes the actions one at a time. When this is
complete, it formulates another goal and starts over
Problem solving as state space search

Problem-solving task can be formulated as search in state


space
• A state space consists of all states of the domain and set of
operators that change one state into another.
• The states can be best thought of to be as nodes in a connected
graph and operators as edges.
• Certain nodes are designated as goal nodes, and a problem is said
to be solved when a path from an initial state to a goal state has
been found
Problem Solving as State Space Search

Basic Search Problem:


Given: [S, s, O, G], where
• S is the (implicitly specified) set of states
• s is the start state
• O is the set of state transition operators
• G is the set of goal states
Task: To find a sequence of state-transitions (or Operators) leading
from s to a goal state g ∈ G
State space search

Search algorithms

Apply

Real- Search
State space Goal
world ?
problem

unfold (using O)

Mathematically
workable specification
Formalizing search in a state space

Problem solving as state space search can be abstracted to


the mathematical problem of finding a path from the start
node to a goal node in a directed graph
Formalizing search in a state space

• A state space is a graph (V, E) where


• V is a set of nodes and
• E is the set of arcs, and each arc is directed from a node to
another node
• Each node is a data structure that contains a state description
plus other information such as parent of the node, operator
that generated that node from that parent and other
bookkeeping data
• Each arc corresponds to an instance of one of the operators
Formalizing search in a state space

• Each arc has a fixed, positive cost associated with it, corresponding to
the cost of the operator
• Each node has a set of successor nodes corresponding to all of the
legal operators that can be applied to the applied at the source node’s
state
• The process of expanding a node means to generate all of the successor
nodes and add them and their associated arcs to the state-space graph
• One or more nodes are designated as the start nodes
• A goal test predicate is applied to a state to determine if its associated
node is a goal node
Formalizing search in a state space

• A solution is a sequence of operators that is associated with


a path in a state space from a start node to a goal node
• The cost of a solution is the sum of the arc costs on the
solution path
• If all the arcs have the same (unit) cost, then the solution cost is
just the length of the solution ( number of steps / state transitions)
Formalizing search in a state space
• State-space search is the process of searching
through a state space for a solution by making
explicit a sufficient portion of an implicit state
space graph to find a goal node
• For large state spaces, it isn't practical to
represent the whole space
• Initially V = {S}, where S is the start node;
• When S is expanded, Its successors are generated and
those nodes are added to V and the associated arcs
are added to E.
• This process continues until a goal node is found
Formalizing search in a state space

• State-space search is the process of searching through a


state space for a solution by making explicit a sufficient
portion of an implicit state space graph to find a goal node
• Each node implicitly or explicitly represents a partial solution
path (and the cost of the partial solution path) from the start
node to the given node
• In general, from this node there are many possible paths ( and
therefore solutions ) that have this partial path as a prefix
Problem formulation: 8-puzzle
• State description (S) 2 8 3
• Location of each of the eight tiles (and the blank)
1 6 4
• Start state (s)
• The starting configuration (given) 7 5
• [2,8,3,1,6,4,7,_,5]
Start
• Operators (O)
• Four operators, for moving the blank left, right, up or down1 2 3
• O = {L,R,U,D}
8 4
• Goals (G)
7 6 5
• One or more goal configurations (given)
• [1,2,3,8,_,4,7,6,5]
Goal
8-Puzzle Problem Space
A depiction of the 8-puzzle problem space and
complete tree solution
Problem formulation: 8-queens
Placing 8 queens on a chess board, so that none attacks the other
• Formulation – I
• A state is any arrangement of 0 to 8 queens on board
• Operators add a queen to any square
• Formulation – II
• A state is any arrangement of 8 queens, one in each column
• Operators move an attacked queen to another square in the same column
Example problem: Missionaries and cannibals(M-C)

• Three missionaries and three cannibals are on one side of a river, along with a boat
that can hold one or two people. Find a way to get everyone to the other side, without
ever leaving a group of missionaries outnumbered by cannibals.
PROBLEM FORMULATION
• State: (#m, #c, 1/0)
- #m denotes the number of missionaries in the first bank
- #c denotes the number of cannibals in the first bank
- The last bit indicates whether the boat is in the first bank.
• Starting state: (3, 3, 1)
• Goal state: (0, 0, 0)
• Operators: Boat carries (#m, #c): {(1, 0), (0, 1), (1, 1), (2, 0), (0, 2)}
MC State space
M-C search graph

# SOLUTIONS = 02
COST = # operations = 11
Water Jug Problem

Problem statement: “You are given two jugs, a 4-litre one and a 3-litre one. Neither
has any measuring markers on it. There is a pump that can be used to fill the jugs
with water. How can you get exactly 2 litres of water into 4-litre jug.”

Problem formulation
• State: (x, y) where x = 0, 1, 2, 3, or 4; y = 0, 1, 2, 3
• Start state: (0, 0).
• Goal state: (2, n) for any n such that n<=3
• Attempting to end up in a goal state.
Water Jug Problem

Operators
1. (x, y) → (4, y) Fill the 4-gallon jug
if x > 4
2. (x, y) → (x, 3) Fill the 3-gallon jug
if y < 3
3. (x, y) → (x - d, y) Pour some water out of the 4-gallon jug
if x > 0
4. (x, y) → (x, y - d) Pour some water out of the 3-gallon jug
if y > 0
5. (x, y) → (0, y) Empty the 4-gallon jug on the ground
if x > 0
6. (x, y) → (x, 0) Empty the 3-gallon jug on the ground
if y > 0
Water Jug Problem
7. (x, y) → (4, y - (4 - x)) Pour water from the 3-gallon jug into the
if x + y ≥ 4, y > 0 4- gallon jug until the 4-gallon jug is full.
8. (x, y) → ( x - (3 - y), 3) Pour water from the 4-gallon jug into the 3-
if x + y ≥ 3, x > 0 gallon jug until the 3-gallon jug is full.
9. (x, y) → (x + y, 0) Pour all the water from the 3-
if x + y ≤ 4, y > 0 gallon jug into the 4-gallon jug
10. (x, y) → (0, x + y) Pour all the water from the 4-
if x + y ≤ 3, x > 0 gallon jug into the 3-gallon jug
11. ( 0, 2) → (2, 0) Pour 2-gallons from the 3-gallon
jug into the 4-gallon jug
12. (2, y) → (0, y) Empty the 2-gallons in the 4-
gallon jug on the ground
Search Tree for Water Jug (4l-3l) Problem
Water Jug Problem
One solution to the water jug problem

Gallons in the Gallons in the Rule Applied


4-gallon jug 3-gallon jug
0 0 2
0 3 9
3 0 2
3 3 7
4 2 5 or 12
0 2 9 or 11
2 0
Try it out: Problem 2

Problem statement : we have 2 jugs, a 5-gallon (5-g) and the other


3-gallon (3-g) with no measuring marker on them. There is endless
supply of water through tap. our task is to get 4-gallon of water in the
5-g jug
Task: (i) write rules /operators for the problem
(ii) draw search tree
(iii) find solution(s)
Try it out: Problem 3
There is a large bucket B full of water and Two (02) jugs, J1 of volume 3
litre and J2 of volume 5 litre. You are allowed to fill up any empty jug
from the bucket, pour all water back to the bucket from a jug or pour
from one jug to another. The goal is to have jug J1 with exactly one (1)
litre of water.

Task: (i) write rules /operators for the problem


(ii) draw search tree
(iii) find solution(s)

You might also like