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

Problem Solving

This document discusses several toy problems in artificial intelligence including the three coins problem, 8 puzzle problem, 8 queens problem, and cryptarithmetic problem. For each problem, it describes the formulation as a state space search problem including the initial state, possible actions, transition model, goal test, and path cost.

Uploaded by

Raunak Das
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Problem Solving

This document discusses several toy problems in artificial intelligence including the three coins problem, 8 puzzle problem, 8 queens problem, and cryptarithmetic problem. For each problem, it describes the formulation as a state space search problem including the initial state, possible actions, transition model, goal test, and path cost.

Uploaded by

Raunak Das
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Artificial Intelligence

PROBLEM SOLVING
What is Problem?

We have a problem and want to find a solution !


Different meanings in different contexts.
From Wikipedia (!) :
In psychology, problem solving refers to a state of desire
for reaching a definite goal from a present condition that
either is not directly moving toward the goal, is far from
it, or needs more complex logic for finding a missing
description of conditions or steps toward the goal.
In computer science problem solving is the part of
artificial intelligence that deals with algorithms,
problem solving encompasses a number of techniques
known as algorithms, heuristics, root cause analysis, etc.
Problem Solving

Problem Solving: Ideally

Problem Solving: In practice


Introduction

The method of solving problem through AI involves


the process of defining the search space, deciding start
and goal states and then finding the path from start
state to goal state through searching state space.
A state space of a problem includes
❖ A initial state

❖ one or more goal state

❖ Sequence of intermediate states through which the

system makes transition while applying various


rules.
Introduction

State space search is a process used in the field of


computer science, including artificial intelligence(AI),
in which successive configurations or states of an
instance are considered, with the aim of finding a goal
state with a desired property.
This is a one kind of goal-based agent called a
problem-solving agent.
Three Coins Problem

❖ Given three coins arranged arbitrarily, make them all


the same (i.e., either all heads or all tails), using
exactly three moves.
❖ By a move in this case is meant flipping one of the
coins over.
❖ The Three Coins Problem can be easily stated as a
state-space problem.

H H T
Three Coins Problem

The Three Coins Problem can be stated as a


state-space
problem.
A configuration of the coins is a state. Say for example
the initial state, or start state is denoted by the
expression HHT. The desired states, or goals, are TTT
and HHH.
For any given state there are three possible operators:,
"Turn the first coin (A)"; "Turn the second coin (B)";
and "Turn the third coin (C)."
A move corresponds to the choice of one of three
operators and a solution to the problem is a sequence of
Three Coins Problem

This is an example of
state space problem.
It shows the possible
states and the result for
each state of applying
each of the possible
operators to it.
Also the sequence of
moves that can be applied
to reach to the goal state
from any initial state.
state-space for the Three Coins
Problem
Problem Types

Single-state Problems : accessible world and


knowledge of its actions allow the agent to know
which state it will be in after a sequence of
actions.

Multiple-state Problems : the world is only


partially accessible, and the agent may be one of
several possible states as the outcome of a
sequence of actions.
Problem Types

Contingency Problems: at some points in the


sequence of actions, sensing may be required to
decide which action to take; this leads to a tree of
sequences.

Exploration Problems : the agent doesn’t


know the outcome of its actions, and must
experiment to discover states of the world and
outcomes of actions
Problem Solving Agent

❖ Earlier we notice that the reflex agents are the


simplest agents because they directly map states into
actions.
❖ Unfortunately, these agents fail to operate in an
environment where the mapping is too large to store
and learn.
❖ Goal-based agent, on the other hand, considers
future actions and the desired outcomes.
❖ One type of goal-based agent known as a
problem-solving agent is used to solve the problem
in artificial intelligence.
Steps performed by Problem-solving agent

Steps performed by Problem-solving agent


Goal Formulation: It is the first and simplest step in
problem-solving. It organizes the steps/sequence
required to formulate one goal out of multiple goals as
well as set of actions to achieve that goal. Goal
formulation is based on the current situation and the
agent’s performance measure.
Problem Formulation: It is the most important
step of problem-solving which decides what actions
should be taken to achieve the formulated goal.
Steps in problem formulation

There are following five components involved in


problem formulation:
Initial State: It is the starting state or initial step of the
agent towards its goal.
Actions: It is the description of the possible set of
operations available to the agent.
Transition Model: It describes what each action does.
Goal Test: It determines if the given state is a goal state.
Path cost: It assigns a numeric cost to each path that
follows the goal. The problem-solving agent selects a cost
function, which reflects its performance measure.
Obviously an optimal solution has the lowest path cost
among all the solutions.
State Space

Initial state, actions, and transition model together


define the state-space of the problem implicitly.
State-space of a problem is a set of all states which can
be reached from the initial state followed by any
sequence of actions.
The state-space forms a directed map or graph where
❖ nodes are the states,

❖ links between the nodes are actions, and

❖ the path is a sequence of states connected by the

sequence of actions.
State space approach

Problem solving may be considered as a search


problem in the state space where from the start state
we need to reach to the goal state.
Search identifies all the best possible sequence of
actions to reach the goal state from the current state. It
takes a problem as an input and returns solution as its
output.
Solution finds the best algorithm out of various
algorithms, which may be proven as the best optimal
solution.
Execution executes the best optimal solution from
the searching algorithms to reach the goal state from
Toy Problem : 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 current state
into goal state by sliding
digits into the blank space
Problem formulation: 8 Puzzle Problem

States: It describes the location of each numbered tiles


and the blank tile.
Initial State: We can start from any state as the initial
state.
Actions: Here, actions of the blank space is defined,
i.e., either left, right, up or down
Transition Model: It returns the resulting state as per
the given state and actions.
Goal test: It identifies whether we have reached the
correct goal-state.
Path cost: The path cost is the number of steps in the
path where the cost of each step is 1.
Problem formulation: 8 Puzzle Problem
Toy 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.
It is noticed from the above
figure 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
approach to the 8-queens
problem.
Toy Problem : 8-Queens Problem

For this problem, there are two main kinds of


formulation:
Incremental formulation: It starts from an empty
state where the operator augments a queen at each
step.
Complete-state formulation: It starts with all the
8-queens on the chessboard and moves them around,
saving from the attacks.
❖ States: Arrangement of all the 8 queens one per column with no
queen attacking the other queen.
❖ Actions: Move the queen at the location where it is safe from the
attacks.
Complete-state formulation is better than the
Toy Problem : 8-Queens Problem

Following steps are involved in the Incremental


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.
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: There is no need for path cost because only
final state
Toy Problem: Cryptarithmetic Problem

The Crypt-Arithmetic problem in Artificial Intelligence


is a type of encryption problem in which the written
message in an alphabetical form which is easily
readable and understandable is converted into a
numeric form which is neither easily readable nor
understandable.
In simpler words, the crypt-arithmetic problem deals
with the converting of the message from the readable
plain text to the non-readable ciphertext.
Toy Problem: Cryptarithmetic Problem

The rules or constraints on a cryptarithmetic problem


are as follows:
❖ A number 0-9 is assigned to a particular alphabet.

❖ Each different alphabet has a unique number.

❖ All the same alphabets have the same numbers.

❖ The numbers should satisfy all the operations that

any normal number does.


Let us take an
example of the
message SEND
MORE MONEY
Toy Problem: Cryptarithmetic Problem

states : puzzle with letters and digits


initial state : only letters present
Actions: Replace each letter with a unique digit
successor function (operators) : replace all
occurrences of a letter by a digit not used yet
goal test : only digits in the puzzle calculation is
correct
path cost : all solutions are equally valid
Toy Problem: Cryptarithmetic Problem

Let us take an example of the message SEND MORE


MONEY

Solution to the given Crypt-Arithmetic problem is:


S=9; E=5; N=6; D=7; M=1; O=0; R=8; Y=2
Which can be shown in layout form as:
9567
1085
-------------
10652
Missionaries and Cannibals

❖ On one bank of a river there are three missionaries


and three cannibals.
❖ There is one boat available that can hold up to two
people and that they would like to use to cross the
river.
❖ If the cannibals ever outnumber the missionaries on
either of the river’s banks, the missionaries will get
eaten.
❖ How can the boat be used to safely carry all the
missionaries and cannibals across the river?

also known as “goats and cabbage”, “wolves and


Missionaries and Cannibals

states : number of missionaries, cannibals, and boats on the


banks of a river; illegal states : missionaries are outnumbered
by cannibals on either bank
Initial states : all missionaries, cannibals, and boats are on
one bank
Action: Transport a set of 2 participant [ {1 missionary} | {
1cannibal} | {2 missionaries} | {2 cannibals} | {1 missionary
and 1 cannibal}]
Successor function (operators) : transport a set of up to
two participants to the other bank
Goal test : nobody left on the initial river bank
Path cost : number of crossings
Missionaries and Cannibals
Real World Problems: Airline Travelling
Problem
Airline Travelling Problem

States: Each is represented by a location and the current


time.
Initial State: This is specified by the problem.
Actions:
Successor Function: This returns the states resulting from
taking any scheduled flight, leaving later than the current
time plus the within airport transit time, from the current
airport to another.
Goal Test: Are we at the destination by some pre-specified
time?
Path Cost: This depends on the monetary cost, waiting
time, flight time, customs and immigration procedures,
seat quality, time of day, type of air place, frequent-flyer
Production System

Production system or production rule system is a


computer program typically used to provide some
form of artificial intelligence, which consists primarily
of a set of rules about behavior but it also includes the
mechanism necessary to follow those rules as the
system responds to states of the world.
Production System

A production system consists of four basic


components:
1. A set of rules of the form Ci → Ai where Ci is the
condition part and Ai is the action part. The condition
determines when a given rule is applied, and the action
determines what happens when it is applied.
2. One or more knowledge databases that contain
whatever information is relevant for the given
problem. Some parts of the database may be
permanent, while others may temporary and only exist
during the solution of the current problem.
Production System

3. A control strategy that determines the order in


which the rules are applied to the database, and
provides a way of resolving any conflicts that can arise
when several rules match at once.
4. A rule applier which is the computational system
that implements the control strategy and applies the
rules
Control/Search Strategies

How to decide which rule to apply next during the process


of searching for a solution to a problem.
The first requirement of a good control strategy is that
it causes motion
The second requirement of a good control strategy is
that it be systematic(need for global motion as well as
local motion)
Requirements of a good search strategy:
❖ It causes motion Otherwise, it will never lead to a

solution.
❖ It is systematic Otherwise, it may use more steps than

necessary.
❖ It is efficient to find a good, but not necessarily the best,
Production System Rules

Production rules can be categorized as


❖ Deductive inference rules (eg. Modes ponen ) or
❖ abductive inference rules
We can represent knowledge in a production system as a
set of rules of the form –
If (condition) THEN (action)
along with a control system and a database.
The production rules are also known as condition –
action, antecedent –consequent, pattern – action,
situation – response, feedback – result pairs.
For example, If (you have an exam tomorrow) THEN
(study the whole night)
Features of Production System

Some of the main features of production system are:


1. Simplicity: The structure of each sentence in a
production system is unique and uniform as they use
“IF-THEN” structure. This structure provides
simplicity in knowledge representation. This feature of
production system improves the readability of
production rules.
2. Modularity: This means production rule, code the
knowledge available in discrete pieces. Information
can be treated as a collection of independent facts
which may be added or deleted from the system with
essentially no deleterious side effects.
Features of Production System

3. Modifiability: This means the facility of modifying


rules. It allows the development of production rules in
a skeletal form first and then it is accurate to suit a
specific application.
4. Knowledge intensive: The knowledge base of
production system stores pure knowledge. This part
does not contain any type of control or programming
information. Each production rule is normally written
as an English sentence; the problem of semantics is
solved by the very structure of the representation.
Four Classes of Production System

Production systems describe the operations that can be


performed in a search for a solution to the problem.
They can be classified as follows.
1. Monotonic production system :- A system in
which the application of a rule never prevents the later
application of another rule, that could have also been
applied at the time the first rule was selected.
2. Partially commutative production system:-A
production system in which the application of a
particular sequence of rules transforms state X into
state Y, then any permutation of those rules that is
allowable also transforms state x into state Y.
Four Classes of Production System

3. Non-Monotonic Production Systems: These are


useful for solving ignorable problems. These systems
are important from an implementation standpoint
because they can be implemented without the ability to
backtrack to previous states when it is discovered that
an incorrect path was followed. This production
system increases efficiency since it is not necessary to
keep track of the changes made in the search process.
Four Classes of Production System

4. Commutative Systems: These are usually useful


for problems in which changes occur but can be
reversed and in which the order of operation is not
critical. Production systems that are not usually
partially commutative are useful for many problems in
which irreversible changes occur, such as chemical
analysis. When dealing with such systems, the order in
which operations are performed is very important and
hence correct decisions must be made at the first
attempt itself.
Advantages of production systems

1. Production systems provide an excellent tool for


structuring AI programs.
2. Production Systems are highly modular because
the individual rules can be added, removed or
modified independently.
3. The production rules are expressed in a natural
form, so the statements contained in the knowledge
base should the a recording of an expert thinking out
loud.
Disadvantages of production system

❖ It is very difficult to analyze the flow of control


within a production system
❖ It describes the operations that can be performed in a
search for a solution to the problem.
❖ There is an absence of learning due to a rule-based
production system that does not store the result of the
problem for future use.
❖ The rules in the production system should not have any
type of conflict resolution as when a new rule is added
to the database it should ensure that it does not have
any conflict with any existing rule.
Problem Characteristics

Search is a very general method applicable to a large


class of problem . It includes a variety of techniques. In
order to choose an appropriate method, it is necessary
to analyze the problem with respect to the following
considerations.
❖ Is the problem decomposable?

❖ Can solution steps be ignored or undone?

❖ Is the universe predictable?

❖ Is a good solution absolute or relative?

❖ Is the solution a state or a path?

❖ What is the role of knowledge in solution?

❖ Does the task require human-interaction?


Is the problem decomposable ?

A very large and composite problem can be easily


solved if it can be broken into smaller problems and
recursion could be used. Suppose we want to solve.

Ex:- ∫ x2 + 3x+sin2x cos 2x dx

This can be done by breaking it into three smaller


problems and solving each by applying specific rules.
Adding the results the complete solution is obtained.
Can solution steps be ignored or undone?

Problem fall under three classes ignorable , recoverable and


irrecoverable. This classification is with reference to the steps of the
solution to a problem.
Consider theorem proving. Whatever steps we follow, we may
later find that it is of no help. We then try another method. This is
an example of ignorable solutions steps.
In the 8 queens problem while we are moving from the start
state towards goal state, we may make some stupid move and later
we may backtrack and undo the unwanted move. This only involves
additional steps and the solution steps are recoverable.
In the chess game if a wrong move is made, it can neither be
ignored nor be recovered. The thing to do is to make the best use of
current situation and proceed. This is an example of an
irrecoverable/undone solution steps.
Is the Universal Predictable?

Problems can be classified into those with certain outcome i.e.


universe/output is predictable (eight puzzle and water jug
problems) and those with uncertain outcome (not
predictable)(Ex. playing cards).
In certain outcome problems, planning could be done to
generate a sequence of operators that guarantees to a lead to a
solution. Planning helps to avoid unwanted solution steps.
For uncertain outcome problems, planning can at best generate
a sequence of operators that has a good probability of leading to
a solution. The uncertain outcome problems do not guarantee a
solution and it is often very expensive since the number of
solution paths to be explored increases exponentially with the
number of points at which the outcome can not be predicted.
Is the solution a state or a path ?

There are two categories of problems.


In one, like the water jug and 8 puzzle problems, we
are satisfied with the solution, unmindful of the
solution path taken.
In the other category not just any solution is
acceptable but we want the best solution or way it is
solved; like that of traveling salesman problem, where
it is the shortest path.
Is good solution absolute or relative ?

In any path related problems, by heuristic methods


when we obtain any solution and we do not explore
alternatives. Here solution is relative.
For the best-path problems all possible paths are
explored using an exhaustive search until the best path
is obtained. This is an example of absolute solution.
What is the role of Knowledge?

Though one could have unlimited computing power,


the size of the knowledge base available for solving the
problem matters in arriving at a good solution.
Take for example the game of playing chess, just the
rules for determining legal moves and some simple
control mechanism is sufficient to arrive at a solution.
But additional knowledge about good strategy and
tactics could help to constrain the search and speed up
the execution of the program.
The solution would then be realistic.
Does the task requires human-interaction?

The problems can again be categorized under two heads.


Solitary in which the computer will be given a problem
description and will produce an answer, with no intermediate
communication and explanation of the reasoning process.
Simple theorem proving falls under this category. Given the
basic rules and laws, the theorem could be proved, if one exists.
Conversational, in which there will be intermediate
communication between a person and the computer, wheather
to provide additional assistance to the computer or to provide
additional informed information to the user, or both. Medical
diagnosis fall under this category, where people will be
unwilling to accept the verdict of the program, if they can not
follow its reasoning.
THANK YOU!!!

You might also like