Unit 2 AI
Unit 2 AI
Formulating Problems :
• 8 Puzzle Problem
• More precisely, an agent is an entity that perceives its environment through sensors and
acts on the environment through actuators.
Sense: It perceives the current state of the world with its sensors.
Model: It constructs an internal model of the world from what it sees.
Reason: It uses its model of the world to decide how to act based on a set of predefined rules or heuristics.
Act: The agent carries out the action that it has chosen.
Goal - Based Agents
• Use information from their environment to achieve specific goals.
• They employ search algorithms to find the most efficient path towards their objectives within a given
environment.
• These agents are also known as rule-based agents, as they follow predefined rules to accomplish their goals
and take specific actions based on certain conditions.
The working pattern of the goal-based agent can be
divided into five steps:
Perception: The agent perceives its environment using
sensors or other input devices to collect information about
its surroundings.
Reasoning: The agent analyzes the information collected
and decides on the best course of action to achieve its
goal.
Action: The agent takes actions to achieve its goal, such
as moving or manipulating objects in the environment.
Evaluation: After taking action, the agent evaluates its
progress towards the goal and adjusts its actions, if
necessary.
Goal Completion: Once the agent has achieved its goal, it
Utility - Based Agents
• Utility-based agents are often used in
applications where they have to
compare and select among multiple
options, such as resource allocation,
scheduling, and game-playing.
A utility-based agent aims to choose actions that lead to a high utility state.
To achieve this, it needs to model its environment, which can be simple or complex.
Then, it evaluates the expected utility of each possible outcome based on the probability distribution and the utility
function.
Finally, it selects the action with the highest expected utility and repeats this process at each time step.
Learning Agents
• An AI learning agent is a software agent that can learn from past experiences and improve its performance. It
initially acts with basic knowledge and adapts automatically through machine learning.
• Learning Element: It is responsible for learning and making improvements based on the experiences it gains
from its environment.
• Citric: It provides feedback to the learning element by the agent’s performance for a predefined standard.
• Performance Element: It selects and executes external actions based on the information from the learning
element and the critic.
• Problem Generator: It suggests actions to create new and informative experiences for the learning element to
improve its performance.
Rule for AI Agents
Problem Solving
• First, the problem which can be solved by using
Deterministic Procedure and the success is guaranteed.
Deterministic
• But most real-world problems can be solved only by
searching a solution. Problem Solving
• AI is concerned with these second types of problems Search
solving.
To build a system to solve a problem, we need to
Define the problem precisely-find initial and final configuration for acceptable solution to the
problem.
Analyse the problem-find few important features that may have impact on the appropriateness of
various possible techniques for solving the problem
Choose the best problem-solving technique(s) and apply it to the particular problem
Problem Formulation
• To provide a formal description of a problem, we need to do the following:
• Define a state space that contains all the possible configurations of the
relevant objects.
• Specify one or more states that describe possible situations, from which the
problem solving process may start. These states are called initial states.
• Defining a set of rules for the actions (operators) that can be taken.
• Problem formulation is the process of deciding what actions and states to consider,
given a goal.
• The process of looking for a sequence of actions that reaches the goal is called
search.
• A search algorithm takes a problem as input and returns a solution in the form of
an action sequence.
• Once a solution is found, the carrying actions it recommends is called the
execution phase.
Formulating Problem
• A problem space is represented by a directed graph,
where nodes represent search state and paths represent
the operators applied to change the state.
• To simplify search algorithms, it is often convenient to
logically and programmatically represent a problem
space as a tree.
• A tree usually decreases the complexity of a search at a
cost. GRAPH TREE
• A tree is a graph in which any two vertices are
connected by exactly one path.
• Alternatively, any connected graph with no cycles is a
tree.
Water Jug Problem
• Problem statement:
• Given two jugs, a 4-gallon and a 3-gallon, both of which do not have measuring
indicators on them. The jugs can be filled with water with the help of a pump that is
available
• The question is “how can you get exactly 2 gallons of water into 4-gallon jug”.
• The state space or production rule of this problem can be defined as a collection of
ordered pairs of integers:
• (x,y) where x=0,1,2,3,4 and y= 0,1,2,or 3.
• In the order pair (x,y),
• x is the amount of water in four-gallon jug
• y is the amount of water in the three-gallon jug.
• State space: all possible combination of (x,y)
• Start state Is: (0,0) and
• Goal state Is: (2, 𝑛)
• 𝑤ℎ𝑒𝑟𝑒 𝑛 = 0,1,2,3
Production Rules
The following table-1 shows the set of production rules (actions) that can be used to change one state to another.
Water Jug Problem: Solution 1
The following 2 solutions are found for the problem “how can you get exactly 2 gallons of water into 4-gallon jug”,
as shown in Table-2 and in Table-3.
Water Jug Problem: Solution 2
The following 2 solutions are found for the problem “how can you get exactly 2 gallons of water into 4-gallon jug”,
as shown in Table-2 and in Table-3.
8 Puzzle Problem
• The eight-tile puzzle consists of a 3-by-3 (3 × 3) square frame board which holds eight (8) movable tiles
numbered as 1 to 8.
• One square is empty, allowing the adjacent tiles to be shifted.
• The objective of the puzzle is to find a sequence of tile movements that leads from a starting configuration to a
goal configuration
• Given a 3 × 3 grid with 8 sliding tiles and one “blank”
• Initial State: some other configuration of the tiles, for example
• Goal State:
• Operators: : Slide tiles (Move Blank) to reach the goal (as shown below).
• There are 4 operators that is, “Moving the blank”:
• Move the blank UP
• Move the blank DOWN
• Move the blank LEFT
• Move the blank RIGHT
8 Puzzle Problem
Path Cost: Sum of of the cost of each path from initial state to goal state.
Here cost of each action (blank move) = 1,
So cost of a Sequence of Actions= the number of Actions.
A optimal solution is one which has a lowest cost path.
State-Space Search Tree for 8-Puzzle problem: The predecessor reference connects the search nodes, creating a
data structure known as a tree.
https://www.youtube.com/watch?v=laLS8gHzROg
Start state:(3,3,0)
Goal State: (0,0,1)