0% found this document useful (0 votes)
6 views6 pages

Planning and Search Space

The document outlines key concepts in planning and search space representation, focusing on state space, search techniques, and goal-oriented planning with constraints. It includes experiments and activities for implementing state space representation, breadth-first and depth-first search algorithms, and planning with obstacles and action preconditions. Sample code and problem statements guide the reader in applying these concepts through practical exercises.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Planning and Search Space

The document outlines key concepts in planning and search space representation, focusing on state space, search techniques, and goal-oriented planning with constraints. It includes experiments and activities for implementing state space representation, breadth-first and depth-first search algorithms, and planning with obstacles and action preconditions. Sample code and problem statements guide the reader in applying these concepts through practical exercises.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Planning and Search Space

🔑 Planning Key 1: State Space Representation


🔸 Concept:

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:

 Define states based on robot location.


 Define transitions using movement actions (up, down, left, right).
 Model the state space as a graph and visualize it.

🧠 Task:

 Create a 2x2 grid with 4 positions: A1, A2, B1, B2.


 Define each state as the robot’s position.
 Write transitions as functions.
 Optionally use networkx to visualize.

🧪 Sample Code:
import networkx as nx
import matplotlib.pyplot as plt

states = ['A1', 'A2', 'B1', 'B2']


transitions = {
'A1': ['A2', 'B1'],
'A2': ['A1', 'B2'],
'B1': ['A1', 'B2'],
'B2': ['B1', 'A2']
}

G = nx.DiGraph()
for state, next_states in transitions.items():
for next_state in next_states:
G.add_edge(state, next_state)

nx.draw(G, with_labels=True, node_color='lightblue', node_size=2000,


font_size=15)
plt.title("State Space of Robot in 2x2 Grid")
plt.show()

🔑 Planning Key 2: Search Space Exploration Techniques


🔸 Concept:

AI planners explore the state space using search techniques to find a path from the initial state to
the goal state.

🔬 Experiment 2:

“Implement Breadth-First Search (BFS) and Depth-First Search (DFS) to explore a


planning search space.”

📌 Objective:

 Create a tree or graph from a state space.


 Implement BFS and DFS in Python.
 Track and compare paths found.

🧠 Task:

 Define a simple tree-like structure (states connected to successors).


 Apply BFS and DFS to find a goal node.
 Compare path lengths and visited nodes.

🧪 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)

print("BFS path to goal:", bfs("Start", "Goal"))

🔑 Planning Key 3: Goal-Oriented Planning with Constraints


🔸 Concept:

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:

 Define actions like move_forward, turn, pick_box, drop_box.


 Represent constraints (e.g., cannot move through blocked cells).
 Build a plan to reach the goal.

🧠 Task:

 Represent the warehouse as a 3x3 grid.


 Set blocked cells (obstacles).
 Allow only legal actions.
 Generate a plan from start to goal considering constraints.

🧪 Sample Code (Simplified):


grid = [
['Start', '', ''],
['', 'X', ''],
['', '', 'Goal']
]

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

def generate_path(start, goal):


from queue import Queue
q = Queue()
q.put([start])
visited = set()
while not q.empty():
path = q.get()
x, y = path[-1]
if (x, y) == goal:
return path
for dx, dy in [(0,1), (1,0), (0,-1), (-1,0)]:
new_pos = (x+dx, y+dy)
if is_valid(new_pos) and new_pos not in visited:
q.put(path + [new_pos])
visited.add(new_pos)

path = generate_path(start, goal)


print("Planned Path:", path)

🔑 Planning Key 1: State Space Representation


🧪 Activity 1.1 – Design a Grid-Based State Space

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.

🧪 Activity 1.2 – Modify the Grid to Include Obstacles

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.

🔑 Planning Key 2: Search Space Exploration


🧪 Activity 2.1 – Implement Breadth-First Search (BFS)

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.

🧪 Activity 2.2 – Implement Depth-First Search (DFS)

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.

🧪 Activity 2.3 – Avoid Loops in Cyclic Graphs

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.

🧪 Activity 2.4 – Analyze Performance of Search Strategies

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.

🧪 Activity 3.2 – Use Action Cost and Find Cheapest Path

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.

🧪 Activity 3.3 – Plan with Action Preconditions

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).

🧪 Activity 3.4 – Design a STRIPS-like Planner

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.

🧪 Activity 3.5 – Generate and Visualize a Planning Tree

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.

You might also like