Ai Lab Assignment-1 (22bce20065)
Ai Lab Assignment-1 (22bce20065)
LAB ASSIGNMENT – 1
Name: M.J.N.SANJAY
Reg No: 22BCE20065
Goal Formation:
Definition: Deciding on the desired final state the agent
wants to achieve.
Involves:
Identifying the objective or purpose of the task.
Specifying the desired outcome in a well-defined way.
Can be influenced by prior experience, reward models, and
external environment.
Problem Formation:
Definition: Transforming the desired goal into a well-defined
problem that can be solved.
Involves:
Identifying the initial state (current world state).
Defining the set of possible actions the agent can take.
Determining the state transitions resulting from each action.
Specifying a success criterion for achieving the goal.
Understanding with the 8 Queens Problem:
Goal formation:
The goal is to place 8 queens on a chessboard such that no
two queens can attack each other (no two queens in the
same row, column, or diagonal).
Problem formation:
The initial state is an empty chessboard.
Possible actions are placing a queen on any of the 64 squares.
State transitions involve placing a queen and updating the
board, considering queen placements as potential conflicts.
The success criterion is having all 8 queens placed without
conflicts.
By forming a clear goal and transforming it into a well-defined
problem, the AI agent can utilize search algorithms to explore
possible actions and find a sequence that achieves the
desired goal of placing all queens safely.
Importance of Interplay:
Goal formation and problem formation are interconnected
and often happen iteratively. An initial problem formulation
might reveal the need for a more specific goal, and achieving
a sub-goal might require reformulating the remaining
problem. This dynamic process allows the AI agent to adapt
and refine its approach towards achieving the overall goal.
Conclusion:
Understanding goal formation and problem formation is
crucial for comprehending how AI agents tackle complex
tasks. By defining clear goals and translating them into
actionable problems, AI can navigate complex environments
and achieve desired outcomes.
2)list different searching algorthims in AI
Ans:
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.
Uninformed/Blind Search:
The uninformed search does not contain any domain
knowledge such as closeness, the location of the goal. It
operates in a brute-force way as it only includes information
about how to traverse the tree and how to identify leaf and
goal nodes. 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.
It can be divided into five main types:
1)Breadth-first search
2)Uniform cost search
3)Depth-first search
4)Iterative deepening depth-first search
5)Bidirectional Search
Informed Search:
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.
Informed search can solve much complex problem which
could not be solved in another way.
An example of informed search algorithms is a traveling
salesman problem.
1)Greedy Search
2)A* Search
class Node:
def __init__(self, state, parent, action):
self.state = state
self.parent = parent
self.action = action
class StackFrontier:
def __init__(self):
self.frontier = []
def empty(self):
return len(self.frontier) == 0
def remove(self):
if self.empty():
raise Exception("Empty Frontier")
else:
node = self.frontier[-1]
self.frontier = self.frontier[:-1]
return node
class QueueFrontier(StackFrontier):
def remove(self):
if self.empty():
raise Exception("Empty Frontier")
else:
node = self.frontier[0]
self.frontier = self.frontier[1:]
return node
class Puzzle:
def __init__(self, start, startIndex, goal, goalIndex):
self.start = [start, startIndex]
self.goal = [goal, goalIndex]
self.solution = None
def print(self):
solution = self.solution if self.solution is not None
else None
print("Start State:\n", self.start[0], "\n")
print("Goal State:\n", self.goal[0], "\n")
print("\nStates Explored: ", self.num_explored, "\
n")
print("Solution:\n ")
for action, cell in zip(solution[0], solution[1]):
print("action: ", action, "\n", cell[0], "\n")
print("Goal Reached!!")
def solve(self):
self.num_explored = 0
start = Node(state=self.start, parent=None,
action=None)
frontier = QueueFrontier()
frontier.add(start)
self.explored = []
while True:
if frontier.empty():
raise Exception("No solution")
node = frontier.remove()
self.num_explored += 1
if (node.state[0] == self.goal[0]).all():
actions = []
cells = []
while node.parent is not None:
actions.append(node.action)
cells.append(node.state)
node = node.parent
actions.reverse()
cells.reverse()
self.solution = (actions, cells)
return
self.explored.append(node.state)
startIndex = (1, 1)
goalIndex = (1, 0)
p = Puzzle(start, startIndex, goal, goalIndex)
p.solve()
p.print()
Result:-