Problem Solving Agent Artificial Intelligence

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

Problem Solving Agent

Artificial intelligence
• 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.
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.
Following steps are involved in this 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.
In this formulation, there is approximately 64*63*62….*57= 1.8
x 10^14 possible sequence to investigate.
Complete-state formulation: It starts with all the 8-queens
on the chessboard and moves them around, saving from the
attacks.
Following steps are involved in this formulation:
•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.
•This formulation is better than the incremental formulation as
it reduces the state space from 1.8 x 10^14 to 2057, and it is
easy to find the solutions.
Toy problem
Problem formulation
• States: The state is determined by both the agent location and the
dirt locations. The agent is in one of two locations, each of which
might or might not contain dirt. There are 8 possible world states.
A larger environment with n locations has n × 𝑛states.
• Initial state: Any state can be designated as the initial state.
• Actions: each state has just three actions: Left, Right, and Suck.
• Transition model: The actions have their expected effects, except
that moving Left in the leftmost square, moving Right in the
rightmost square, and Sucking in a clean square have no effect. The
complete state space is shown in Figure 3.3.
• Goal test: This checks whether all the squares are clean.
• Path cost: Each step costs 1, so the path cost is the number of
steps in the path.
• Solution quality is measure by the path cost
function, and an optimal solution has the
lowest cost among all solution.
8-Puzzle problem
Problem formulation
• Initial state= Arad
– In(Arad)
• Action: from the state In(Arad), the applicable actions are
– { Go(Sibiu), Go(Timisoara), Go(Zerind) }.
• Transition model: specified by a function RESULT(s, a) that returns
the state that results from doing action a in state s.
– RESULT(In(Arad),Go(Zerind)) = In(Zerind)
• Path: A path in the state space is a sequence of states connected by a
sequence of actions.
• Goal Test: which determines whether a given state is a goal state
– {In(Bucharest )}.
• Path cost: A path cost function that assigns a numeric cost to each
path.
Some Real-world problems:
•Traveling salesperson problem(TSP): It is a touring
problem where the salesman can visit each city only
once. The objective is to find the shortest tour and
sell-out the stuff in each city.

•VLSI Layout problem: In this problem, millions of


components and connections are positioned on a chip
in order to minimize the area, circuit-delays, stray-
capacitances, and maximizing the manufacturing yield.
Water jug problem

• Statement: we are given three water jugs (A,


B, C) with the capacities 8, 5, 3 liters
respectively. All these jugs do not have any
other measuring mark on it. Initially these
jugs have water 6, 2, 0 liters, how can you get
water in these three jugs 1, 4, 3 liter
respectively?
Water jug problem

• Initial state
– {6,2,0}
• Final state
– {1,4,3}
• Set of action
– {ab, ac, ba, bc, ca, cb}
{6,2,0}
{6,2,0} CA or CB

AB BA
AC BC
{6,2,0}

{3,5,0} {3,2,3} {6,0,2} {8,0,0}


{6,2,0}

AB BA
AC BC

{3,5,0} {3,2,3} {6,0,2} {8,0,0}


AB, AC,BA,BC

{}{0,5,3}{8,0,0}{3,2,3}
Rep Rep
{6,2,0}

AB BA
AC BC

{3,5,0} {3,2,3} {6,0,2} {8,0,0}


AB, AC,BA,BC AB,AC,BA,BC,CA,CB

{}{0,5,3}{8,0,0}{3,2,3}
Rep Rep

{0,5,3}{}{5,0,3}{}{6,2,0}{3,5,0}
{6,2,0}

AB BA
AC BC

{3,5,0} {3,2,3} {6,0,2} {8,0,0}


AB, AC,BA,BC AB,AC,BA,BC,CA,CB AB,AC,CA,CB

{1,5,2}{5,0,3}{8,0,0}{6,2,0}
{}{0,5,3}{8,0,0}{3,2,3}
Rep Rep

{0,5,3}{}{5,0,3}{}{6,2,0}{3,5,0}
{6,2,0}

AB BA
AC BC

{3,5,0} {3,2,3} {6,0,2} {8,0,0}


AB, AC,BA,BC AB,AC,BA,BC,CA,CB AB,AC,CA,CB AB,AC

{1,5,2}{5,0,3}{8,0,0}{6,2,0}
{}{0,5,3}{8,0,0}{3,2,3} Rep Rep
{3,5,0}{5,0,3}
Rep Rep
Rep
{0,5,3}{}{5,0,3}{}{6,2,0}{3,5,0}
Rep Rep
{6,2,0}

AB BA
AC BC

{3,5,0} {3,2,3} {6,0,2} {8,0,0}


AC AB, BA AB,AC AC

{0,5,3} {0,5,3} {5,0,3} {1,5,2}{5,0,3} {5,0,3}


{6,2,0}

AB BA
AC BC

{3,5,0} {3,2,3} {6,0,2} {8,0,0}


AC AB, BA AB,AC AC

{0,5,3} {0,5,3} {5,0,3} {1,5,2}{5,0,3} {5,0,3}


BA,CA

{5,0,3}{3,5,0}
Rep Rep
{6,2,0}

AB BA
AC BC

{3,5,0} {3,2,3} {6,0,2} {8,0,0}


AC AB, BA AB,AC AC

{0,5,3} {0,5,3} {5,0,3} {1,5,2}{5,0,3} {5,0,3}


BA,CA BA,CA

{5,0,3}{3,5,0} {5,0,3}{3,5,0}
Rep Rep Rep Rep
{6,2,0}

AB BA
AC BC

{3,5,0} {3,2,3} {6,0,2} {8,0,0}


AC AB, BA AB,AC AC

{0,5,3} {0,5,3} {5,0,3} {1,5,2}{5,0,3} {5,0,3}


BA,CA BA,CA AB,CA,CB

{5,0,3}{3,5,0} {5,0,3}{3,5,0} {0,5,3}{8,0,0}{5,3,0}


Rep Rep Rep Rep Rep Rep Rep
{6,2,0}

AB BA
AC BC

{3,5,0} {3,2,3} {6,0,2} {8,0,0}


AC AB, BA AB,AC AC

{0,5,3} {0,5,3} {5,0,3} {1,5,2} {5,0,3} {5,0,3}


BA,CA BA,CA AB,CA,CB BC

{5,0,3}{3,5,0} {5,0,3}{3,5,0} {0,5,3}{8,0,0}{5,3,0}


Rep Rep
{1,4,3}
Rep Rep Rep Rep Rep
Water jug problem

• Statement: we are given three water jugs (A,


B, C) with the capacities 8, 5, 3 liters
respectively. All these jugs do not have any
other measuring mark on it. Initially these
jugs have water 8, 0, 0 liters, how can you get
water in these three jugs 1, 4, 3 liter
respectively?
Types of problem
• Well defined problem
– Which have Problem formulation
• Initial state
• Goal state
• Set of actions
• Ill defined problem
Search Algorithm Terminologies:
• Search: Searching is a step by step procedure to
solve a search-problem in a given search space. A
search problem can have three main factors:
• Search Space: Search space represents a set of
possible solutions, which a system may have.
• Start State: It is a state from where agent begins the
search.
• Goal test: It is a function which observe the current
state and returns whether the goal state is achieved
or not.
Properties of Search Algorithm :
• Completeness: A search algorithm is said to be
complete if it guarantees to return a solution if at least
any solution exists for any random input.
• Optimality: If a solution found for an algorithm is
guaranteed to be the best solution (lowest path cost)
among all other solutions, then such a solution for is
said to be an optimal solution.
• Time Complexity: Time complexity is a measure of
time for an algorithm to complete its task.
• Space Complexity: It is the maximum storage space
required at any point during the search, as the
complexity of the problem.
Types of search algorithms
• Based on the search problems we can classify the search
algorithms into uninformed (Blind search) search and
informed search (Heuristic search) algorithms
• Types of search technique
– Uninformed
• BFS
• DFS
• DFID
– Informed
• Greedy best first search
• A* search
Uninformed and Informed search
• Uninformed search applies a way in which search tree is
searched without any information about the search space
like initial state operators and test for the goal, so it is also
called blind search. It examines each node of the tree until
it achieves the goal node.
• Informed search algorithms use domain knowledge. In an
informed search, problem information is available which
can guide the search. Informed search strategies can find a
solution more efficiently than an uninformed search
strategy. Informed search is also called a Heuristic search.
• A heuristic is a way which might not always be guaranteed
for best solutions but guaranteed to find a good solution in
reasonable time.

You might also like