🔮 Interactive Agent Simulation
Prerequisites
- Agents & Environments — Vacuum world, percepts, actions
- Agent Types — Simple reflex, model-based agents
🎯 Learning Objectives
- Observe how different agent types behave in the vacuum-cleaner world
- Compare performance of random, simple reflex, and model-based agents
- Build intuition for percept sequences, actions, and performance scores
1. Vacuum-Cleaner World Simulation
This interactive demo simulates the classic 2-square vacuum-cleaner world. Select an agent type, then use Step to advance one time step at a time, or Auto Run to watch the agent work automatically. Observe how agent percepts, actions, and scores differ across agent types.
2. Agent Pseudocode
Random Agent
function RANDOM-AGENT(percept):
return random choice from {Left, Right, Suck, NoOp}
The random agent picks an action uniformly at random. It serves as a baseline—any real agent should outperform it.
Simple Reflex Agent
function SIMPLE-REFLEX-AGENT(percept):
location, status = percept
if status == Dirty:
return Suck
else if location == A:
return Right
else:
return Left
Ignores percept history. Reacts only to current percept. Works well in the simple vacuum world but oscillates forever once both squares are clean.
Model-Based Agent
// Internal state: remembers status of both squares
state = {A: unknown, B: unknown}
function MODEL-BASED-AGENT(percept):
location, status = percept
state[location] = status // Update internal model
if status == Dirty:
return Suck
else if state[A] == Clean AND state[B] == Clean:
return NoOp // Both clean → stop!
else if location == A:
return Right
else:
return Left
Maintains internal state tracking both squares. Once both are confirmed clean, it stops—unlike the simple reflex agent which oscillates forever. This is strictly more efficient.
3. What to Observe
- Random agent: Erratic behavior. Sometimes cleans, sometimes moves uselessly. Low score. May take many steps to clean both squares (or might never clean them efficiently).
- Simple reflex agent: Cleans efficiently at first, then oscillates between A and B forever. Score keeps climbing (1 point per clean square per step) but wastes energy moving.
- Model-based agent: Cleans both squares, then stops (NoOp). Most efficient—achieves maximum cleanliness in minimum steps and then rests.
This simulation demonstrates a core GATE concept: the same task environment can yield different performance depending on the agent architecture. The model-based agent’s internal state allows it to know when to stop, which the simple reflex agent cannot do.
4. Exercises
- Run each agent type for 20 steps. Record the final score. Which agent has the highest score?
- Modify the scenario in your mind: what if dirt randomly reappeared? Would the model-based agent’s “stop” behavior still be rational? (Answer: No, because it would need to keep checking.)
- How would you design a goal-based agent for this world? What would the goal be? (Answer: “Both squares clean.” The agent would plan a sequence: clean A, move to B, clean B, stop.)
- Could a utility-based agent outperform the model-based agent here? (Answer: In this simple world, no. Utility-based agents shine when trade-offs are needed—e.g., faster cleaning vs. lower energy consumption.)