Planning and Search Space
Planning and Search Space
State Space is the universe of all possible configurations or situations that an agent can be in,
along with actions that lead from one state to another.
🔬 Experiment 1:
“Represent the state space for a simple robot vacuum cleaner navigating a 2x2 grid house.”
📌 Objective:
🧠 Task:
🧪 Sample Code:
import networkx as nx
import matplotlib.pyplot as plt
G = nx.DiGraph()
for state, next_states in transitions.items():
for next_state in next_states:
G.add_edge(state, next_state)
AI planners explore the state space using search techniques to find a path from the initial state to
the goal state.
🔬 Experiment 2:
📌 Objective:
🧠 Task:
🧪 Sample Code:
from collections import deque
graph = {
'Start': ['A', 'B'],
'A': ['C', 'D'],
'B': ['E'],
'C': [],
'D': ['Goal'],
'E': [],
'Goal': []
}
def bfs(start, goal):
queue = deque([[start]])
visited = set()
while queue:
path = queue.popleft()
state = path[-1]
if state == goal:
return path
elif state not in visited:
for next_state in graph[state]:
new_path = list(path)
new_path.append(next_state)
queue.append(new_path)
visited.add(state)
Goal-Oriented Planning involves finding a sequence of actions to transition from an initial state
to a goal state while obeying constraints (e.g., avoid obstacles, time limits, or required order of
actions).
🔬 Experiment 3:
“Simulate a warehouse robot that must pick up a box, avoid obstacles, and deliver it to a
specific location using planning with constraints.”
📌 Objective:
🧠 Task:
start = (0, 0)
goal = (2, 2)
obstacles = [(1, 1)]
def is_valid(pos):
x, y = pos
return 0 <= x < 3 and 0 <= y < 3 and pos not in obstacles
Problem Statement:
Design a 3x3 grid environment where each cell represents a state. Define legal moves (up, down,
left, right), and represent the state space as a graph or adjacency list.
Problem Statement:
Add at least two blocked positions (obstacles) to the grid. Redefine the state space so that
blocked cells cannot be entered or passed through. Clearly mark affected transitions.
🧪 Activity 1.3 – Model a Puzzle Problem Using State Space
Problem Statement:
Represent the state space for a simplified 3-tile sliding puzzle (e.g., tiles numbered 1–3 in a row,
with a blank space). Define all possible moves and transitions from each state.
Problem Statement:
Given a start and goal state in a tree-like structure, implement BFS to find the shortest path.
Track the order of node exploration and return the full path to the goal.
Problem Statement:
Using the same structure as Activity 2.1, apply DFS and compare the path with the result of BFS.
Analyze differences in the order of visited nodes and final path.
Problem Statement:
Create a graph with cycles. Implement a search algorithm (BFS or DFS) that avoids revisiting
the same state, thus preventing infinite loops. Use a visited list or set.
Problem Statement:
Given a medium-sized state space (at least 10 nodes), run both BFS and DFS. Record and
compare time taken, number of nodes expanded, and memory usage.
🔑 Planning Key 3: Goal-Oriented Planning with Constraints
🧪 Activity 3.1 – Plan a Path Avoiding Obstacles
Problem Statement:
In a 5x5 grid environment, define a start and goal position. Add at least three obstacles. Plan a
valid path that navigates around the obstacles using any search strategy.
Problem Statement:
Assign movement costs (e.g., 1 for horizontal, 2 for vertical, 3 for diagonal moves) in a 3x3 grid.
Use a cost-aware search algorithm like Uniform Cost Search (UCS) to find the lowest-cost path
from start to goal.
Problem Statement:
Simulate a robot that can only deliver a package if it has picked it up first. Plan a sequence of
actions where each move is only valid if its preconditions are met (e.g., deliver is only valid if
has_package = True).
Problem Statement:
Define a problem with multiple actions (e.g., clean room, move to another room, recharge). Each
action should have preconditions and effects. Write a plan that satisfies a given goal using only
legal action sequences.
Problem Statement:
Given a small problem domain (like a robot in a grid with goals), generate the planning tree up to
a depth of 3. Identify all possible plans and visually represent the tree.