0% found this document useful (0 votes)
9 views

CH 3 Problem Solving and Search Algorithms Part I

The document discusses problem solving and search algorithms in artificial intelligence, focusing on the role of problem-solving agents that utilize search strategies to achieve goals. It outlines the problem-solving process, including goal formulation, problem formulation, search, and execution, while providing examples such as tic-tac-toe and the vacuum world problem. Additionally, it distinguishes between well-defined and ill-defined problems, emphasizing the importance of clear goals and strategies in problem formulation.

Uploaded by

hidn2016
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

CH 3 Problem Solving and Search Algorithms Part I

The document discusses problem solving and search algorithms in artificial intelligence, focusing on the role of problem-solving agents that utilize search strategies to achieve goals. It outlines the problem-solving process, including goal formulation, problem formulation, search, and execution, while providing examples such as tic-tac-toe and the vacuum world problem. Additionally, it distinguishes between well-defined and ill-defined problems, emphasizing the importance of clear goals and strategies in problem formulation.

Uploaded by

hidn2016
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

3.

Problem Solving and Search Algorithms


Artificial Intelligence (AI)

Part I
Dr. Udaya Raj Dhungana
Assist. Professor
Pokhara University, Nepal
Guest Faculty
Hochschule Darmstadt University of Applied Sciences, Germany
E-mail: [email protected] and [email protected]

1
Overview
3.Problem Solving and Search Algorithms (10 hrs)
3.1.Problem Solving
3.1.1.Problem Solving Agents
3.1.2.Problem solving process
3.1.3.Production System
3.1.4.Well-defined and ill-defined problems
3.1.5.Problem formulation

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 2


Solving Problem by Searching
• In previous chapter you studied the intelligent agents.

• In this chapter, we see how an agent can look ahead to nd a sequence of


actions that will eventually achieve its goal.

• When the correct action to take is not immediately clear, an agent may need to
plan ahead to nd a sequence of actions that form a path to a goal state. Such
an agent is called a problem-solving agent and the computational process it
undertakes is called search.

• In this chapter, we consider only the simplest environments:

• episodic, single agent, fully observable, deterministic, static, discrete, and


known

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 3


fi
fi
Solving Problem by Searching
Players: X and O
A tic-tac-toe Game

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 4


Solving Problem by Searching
Initial State
Players: X and O
A tic-tac-toe Game

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 5


Solving Problem by Searching
Initial State
Players: X and O
A tic-tac-toe Game

Goal State of Player X

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 6


Solving Problem by Searching
Initial State
Players: X and O
A tic-tac-toe Game

Goal State of Player X

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 7


Solving Problem by Searching
Initial State
Players: X and O
A tic-tac-toe Game

A Path is a sequence of actions.


A solution is a path that leads from
initial state to the goal state.

Goal State of Player X

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 8


Solving Problem by Searching
• A search problem can be de ned as follows:

• A set of possible states that the environment can be in. It is called a state space of the
problem.
• An initial state that the agent starts in. For example, an empty board in tic-tac-toe game.
• A set of one or more goal states.
• A set of actions available to the agent. For example, the vacuum-cleaner world has four
actions- Right, Left, suck and NoOP.
• A transition model which describes what each action does.
• A path is a sequence of states. A solution is a path from initial state to the goal state.
• An action cost which gives the numeric cost of applying action. Total cost of the solution
is given by the summation of the cost of each action in the path that lead to the goal
State. An optimal solution has the lowest path cost among all solutions.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 9


fi
Solving Problem by Searching
• Search is a fundamental approach to problem solving in AI.

• Problem solving by searching involves systematically exploring a state space to nd a


sequence of actions that leads from the initial state to the goal state.

• The state space is represented as a graph where:

• Nodes represent states.

• Edges represent actions that transition between states

• Examples of Search Problems

• Path Finding: Finding simply a route or the shortest route on a map.

• Puzzle Solving: Arranging tiles in a speci c order. For example: 8 Puzzle problem, 8
Queen problem, Water-Jug problem

• Game Playing: Making strategic moves in a competitive environment. For example: tic-
tac-toe, chess
Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 10
fi
fi
Solving Problem by Searching
• A wide range of problems can be formulated as searches
– as the process of searching for a sequence of actions that take
you from an initial state to a goal state

Initial state Goal state

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 11


Solving Problem by Searching
• State-Space Search
go(X,X,[X]).
link(g,h). go(X,Y,[X|T]):-
link(g,d). link(X,Z),
link(e,d). go(Z,Y,T).
link(h,f).
link(e,f). Simple search algorithm
link(a,e).
link(a,b).
link(b,f). | ?- go(a,c,X).
link(b,c). X = [a,e,f,c] ? ;
link(f,c). X = [a,b,f,c] ? ;
X = [a,b,c] ? ;
State-Space no
Check in prolog Consultation

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 12


Problem Solving Agent
• Problem: You are at Arad and you want to go to Bucharest.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 13


Problem Solving Agent
• If the agent has no additional information (i.e. if the environment is unknown) then the
agent can do no better than to execute one of the actions at random.

• A problem-solving agent is an intelligent agent that uses search strategies to


determine a sequence of actions to reach to the goal state(s).

• Our assumption: our agents always have access to information about the world,
such as the map in previous slide.

• Then the agent can follow this four-phase problem-solving process to solve the
problem:

1. Goal Formulation

2. Problem Formulation

3. Search

4. Execution

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 14


Problem Solving Process
1. Goal Formulation

• The agent de nes the desired goal to achieve. For instance, the agent adopts the goal of
reaching Bucharest in the problem to reach to Bucharest from Arad.

2. Problem Formulation

• The agent de nes the problem in terms of initial state, goal state, actions necessary to reach the
goal.

3. Search

• The agent simulates sequences of actions in its model, searching until it nds a sequence of
actions that reaches the goal (solution).

• The agent might have to simulate multiple sequences that do not reach the goal, but eventually it
will nd a solution (such as going from Arad to Sibiu to Fagaras to Bucharest), or it will nd that no
solution is possible.

4. Execution

• The agent can now execute the actions in the solution, one at a time.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 15


fi
fi
fi
fi
fi
Problem Solving Agent
• It is a model-based, goal-based agent.

• It works as follows:
1. It first formulates a goal and a problem,

2. Start its search with an current state (initial state).

3. Searches for a sequence of actions that lead to the goal


state.

4. Executes the sequence of actions one at a time.

5. When this is complete, it formulates another goal and starts


over.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 16


Problem Solving Agent

# SEARCH

# SOLUTION

# EXECUTION
A simple problem-solving agent.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 17


Problem Solving Agent
• Assumes the problem environment is:
• Static
– The plan remains the same

• Observable
– Agent knows the initial state

• Discrete
– Agent can enumerate the choices

• Deterministic
– Agent can plan a sequence of actions such that each will lead to
an intermediate state

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 18


Problem Formulation
• Problem formulation is the process of defining a problem in a way that it can be
solved by a search algorithm.

• This involves identifying the state space, initial state, actions, transition model, goal
test, and path cost function. A problem can be formulated by the following
components:

1. State Space: The set of all possible states that the problem can have.

2. Initial state: the state where the agent starts in

3. Actions: all actions that the agent can apply to reach from one state to another

4. Transition Model: A description of what each action does

5. Goal Test: determines whether a current state is a goal state.

6. Path Cost function: assigns a numeric cost to the path that leads to the goal
state.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 19


Problem Formulation- Vacuum World Problem

– States:
• In a two-square version, the agent can be in either of the two squares, and
each square can either contain dirt or not, so there are 2*2*2 = 8 states.
– Initial state:
• Any state can be designated as the initial state.
– Actions:
• Left, Right Suck and NoOP
– Transition model: Initial state
• Left- move the vacuum cleaner to the left
• Right- move the vacuum cleaner to the right
• Suck- suck the dirt
• NoOP- No operation
– Goal test:
• This checks whether all the squares are clean.
– Path cost: Goal state
• Each action costs 1, so the path cost is the number of actions in the path.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 20


Problem Formulation- Vacuum World Problem

The state-space graph for the two-square vacuum world. There are 8 states and three actions for each
state: L = Left, R = Right, S = Suck. The links denotes actions.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 21


Problem Formulation- Sliding-tile Puzzle

• 8-Puzzle Problem:
– Best known variant of sliding-tile puzzle is 8 puzzle problem.

– Here, we have a 3×3 matrix with movable tiles numbered

from 1 to 8 with a blank space. The tile adjacent to the blank

space can slide into that space. The objective is to reach a

specified goal state similar to the goal state, as shown in the

below figure.

– In the figure, our task is to convert the start state into goal

state by sliding digits into the blank space.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 22


Problem Formulation- 8 Puzzle Problem
– States:
– A state description specifies the location of each of the tiles
– Initial state:
• Any state can be designated as the initial state.
– Actions:
• movements of the blank space Left, Right, Up, or Down
• If the blank is at an edge or corner then not all actions will be applicable.
– Transition model:
• Given a state and action, this returns the resulting state
• if we apply Left to the given start state, the resulting state has the 5 and the
blank switched.
– Goal test:
• This checks whether the state matches the goal configuration. It can have
multiple goal states where the numbers are in order.
• We typically specify a state with the numbers in order as specified in goal state.
– Path cost:
• Each action costs 1.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 23


Types of Problems
One way is to divide problem types: Based on information available about the
problem can be divided into:

• A well-defined problem

• is one that has a clear goal or solution, and problem solving strategies
are easily developed.

• A poorly-defined problem (Ill-defined problem)

• is one that is unclear, abstract, or confusing, and that does not have a
clear problem solving strategy.

• to solve different types of problems needs different types of solution


strategies.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 24


Well-Defined Problem
• Have:

• Have a clear goal state

• Have a clear initial state

• Have a set of rules for solving

• Well defined evaluation function

• Examples:

• Games (Sudoku, chess, checkers)

• Logical puzzles

• Geometry proofs

• Some well defended problems can appear ill-defined by the size of the problem
space (for example chess)

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 25


Ill-Defined Problem
• Have:
• Ill-defined goal state
• Ill-defined problem state
• Ill-defined evaluation function
• Ill defined operators to manipulate problem state

• Examples:
• Design a fuel efficient car
• Design software
• Write a paper
• Finding a perfect mate

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 26


Well-Defined Problems
• Well-de ned problem is a problem that provide complete
information at the phase of problem formulation and goal
formulation

• They can be solved by un-informed search strategies

• If the problem provide additional information (heuristic), it can also


be solved by informed search strategies

• Example of well de ned problem:

• Vacuum cleaner problem

• Road map problem

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 27


fi
fi
Well-Defined Problems
• Solution for well de ned problem is either

• a sequence of world state in which the nal state satisfy the goal or

• a sequence of action in which the last action will result the goal
state.

• Each action change one state to the next state of the world

• A search algorithm take a problem as input and returns a solution in the


form of action or state sequence.

• To achieve the goal, the action sequences must be executed


accordingly

• Follow the general “formulate-search-execute” algorithm

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 28


fi
fi
Problem Formulation- 8 Queens Problem
8-queens problem:

The aim of this problem is to place eight


queens on a chessboard in an order where
no queen may attack another. A queen can
attack other queens either diagonally or in
same row and column.

From the following gure, we can understand


the problem as well as its correct solution.

It is noticed from the above gure that each


queen is set into the chessboard in a position
where no other queen is placed diagonally, in
same row or column. Therefore, it is one right Goal State
solution to the 8-queens problem.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 29


fi
fi
Problem Formulation- 8 Queens Problem
8-queens problem Formulation:
• States: Arrangement of any 0 to 8 queens on the
chessboard.

• Initial State: An empty chessboard

• Actions: Add a queen to any empty box so that no queen in Initial State
the board attack each other.

• Transition model: Returns the chessboard with the queen


added in a box.

• Goal test: Checks whether 8-queens are placed on the


chessboard without any attack.

• Path cost: Each action cost 1. Goal State

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 30


Problem Formulation- Water-Jug Problem

Description of Water Jug Problem: You are given two jugs, a 4-liters and a 3-liters
one. Neither has any measuring mark on it. There is a tap with unlimited water supply
capacity and it can be used to ll the jugs with water. Each jug can be lled to its full
capacity. Each jug can be emptied completely. Each jug can be poured into the other jug
until either the rst jug is empty or the second jug is full. No other intermediate
measurement is allowed.
Problem: How can you get exactly 2 liters of water using these two jugs?

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 31


fi
fi
fi
Problem Formulation- Water-Jug Problem
Solution:
Let the state of the two jugs be represented as the set of ordered pairs of integers (x, y)
where x represents the amount of water in the 4-liter jug (x= 0,1,2,3,4) and y represents the
amount of water in 3-liter jug (y=0,1,2,3).
Problem Formulation
1. Initial State: Both jugs are empty i.e. (0,0).
2.Actions:
1. Fill jug 1: ( x , y ) → ( C1 , y ) // C1 = 4
2. Fill jug 2: ( x , y ) → ( x , C2 ) // C2 = 3
3. Empty jug 1: ( x , y ) → ( 0 , y )
4. Empty jug 2: ( x , y ) → ( x , 0 )
5. Pour from jug 1 to jug 2: ( x , y ) → ( max ( 0 , x − ( C 2 − y ) ) , min ( C 2 , x + y ) )
6. Pour from jug 2 to jug 1: ( x , y ) → ( min ( C 1 , x + y ) , max ( 0 , y − ( C 1 − x ) )
3. Goal State: One of the jug contains exactly 2 liters of water i.e. (2, 0) or (0, 2)
4. Path Cost: Each action costs 1.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 32


Problem Formulation- Water-Jug Problem
The sequence of actions that lead to the goal state:

1. Initial State: Both jugs are empty i.e. (0,0).

2. Fill jug 1: ( 4 , 0 )

3. Pour from jug 1 to jug 2: ( 1 , 3). Jug 2 is now full and Jug 1 contains exactly 1 liter.

4. Empty jug 2: ( 1 , 0 ). Jug 2 is now empty and Jug 1 still contains exactly 1 liter.

5. Pour from jug 1 to jug 2: ( 0 , 1 ). Now Jug 1 is empty and Jug 2 contains exactly 1
liter.

6. Fill jug 1: ( 4 , 1). Now Jug 1 contains 4 liter and Jug 2 contains 1 liter.

7. Pour from jug 1 to jug 2: ( 2 , 3 ). Now Jug 1 contains exactly 2 liters and Jug 3
contains exactly 3 liters.

8. Goal state is reached. You got exactly the 2 liters water in Jug 1.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 33


Problem Formulation
The Farmer, Wolf, Goat and Cabbage Problem:
A farmer with his wolf, goat, and cabbage come to the
edge of a river they wish to cross. There is a boat at the
river's edge, but, of course, only the farmer can row. The
boat also can carry only two things (including the rower)
at a time. If the wolf is ever left alone with the goat, the
wolf will eat the goat; similarly, if the goat is left alone
with the cabbage, the goat will eat the cabbage.
Devise a sequence of crossings of the river so that all
four characters arrive safely on the other side of the river.
A) Solve the above problem by nding a path from the
start state to the goal state.
B) Discuss the advantage of breadth- rst and depth- rst {Farmer, Wolf, Goat, Cabbage}
search for this problem.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 34


fi
fi
fi
Problem Formulation

The Farmer, Wolf, Goat and Cabbage Problem:

Solution of B: Solution of A
Since the goal node is at the bottom of the
tree, it is faster for the depth-first search to
reach it. The breath-first search will have to
search more nodes before it reaches the
goal node.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 35


Well-Defined Problems
Search Tree (for The Farmer, Wolf, Duck and Corn Problem)

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 36


Well-Defined Problems
Route Planning:

• Initial State
– e.g. “At Arad”

• Successor Function
– A set of action state pairs
– S(Arad) = {(Arad->Zerind, Zerind), …}

• Goal Test
– e.g. x = “at Bucharest”

• Path Cost
– sum of the distances traveled

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 37


Production Systems
Production systems provide appropriate structures for performing and describing
search processes. A production system has four basic components as enumerated
below.

1. A set of rules each consisting of a left side that determines the applicability of
the rule and a right side that describes the operation to be performed if the
rule is applied.

2. One or more knowledge/databases that contain whatever information is


appropriate for the particular task.

3. A control strategy that specifies the order in which the rules will be compared
with facts in the database and also specifies how to resolve conflicts in
selection of several rules or selection of more facts.

4. A rule applier which is the computational system that implements the control
strategy and applies the rules.

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 38


Control Strategies
• Search proceeds with different types of ‘search control strategies’.

• A search control strategy is de ned by picking the order in which the nodes expand.

• The Search strategies are evaluated along the following dimensions:

• Completeness,

• Time complexity,

• Space complexity,

• Optimality

Dr. Udaya R. Dhungana, Pokhara University, Nepal. [email protected] 39


fi
THANK YOU

End of Chapter

40

You might also like