Question: Informed Search Part 1 : Problem representation In this part, you have to define ( represent ) the problem, that is to tell
Informed Search
Part : Problem representation
In this part, you have to define represent the problem, that is to tell the computer what the problem look like. For example, your representaion should be able to express the location of the nodes, and the travel cost between connected nodes. Also don't forget to define the grid world, you may need it for the heuristic.
# Define the graph
graph
# Your code here.
# hint: A: BCD
positions
# Your code here.
# hint: A:
Part : Heuristic
In this part, define a admissible heuristic function for this problem.
# Your code here
def heuristicnode goal, positions:
# Define a heuristic function that estimates the cost from node to goal
# Your code here.
pass
Part : Greedy Best First Search
In this part, implement a function doing the Greedy best first search to find the solution for the problem. To reduce the difficulty, I have given you most code, you only need to fillin a couple of lines to make this function working.
from queue import PriorityQueue
def greedybestfirstsearchgraph positions, start, goal:
visited set
pq PriorityQueue
pqput start# heuristic value, node
parent # stores the parent node of each visited node
while not pqempty:
currentnode pqget
visited.addcurrentnode
if currentnode goal:
break
for neighbor, weight in graphcurrentnode:
if neighbor not in visited:
# Your code here.
pass
# Reconstruct the path from the goal to the start
path
node goal
while node start:
path.appendnode
node parentnode
path.appendstart
# Reverse the path to get it from start to goal
path.reverse
return path
Part : A search
In this part, implement the A function to solve the problem. hint: you can seek inspiration from the greedy best first search implementation
def astarsearchgraph positions, start, goal:
# Your code here.
pass
Part : Main function
This part is the main function to run your search functions.
def printpathpath:
# Print the resulting path
if path:
printPath found:", joinpath
else:
printNo path found."
def main:
# Run the Greedy BestFirst Search algorithm
startnode A
goalnode I
pathgbf greedybestfirstsearchgraph positions, startnode, goalnode
pathastar astarsearchgraph positions, startnode, goalnode
# Print the resulting path
printGreedy Best First Search:
printpathpathgbf
printA Search:
printpathpathastar
main
Please help me with this; follow the instructions carefully, please!
Thank you!!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
