The lecture continues the exploration of optimization and introduces how agents handle uncertainty and structural constraints. It marks a significant evolution in how we represent the "world" the AI is operating in.


1. Local Search in Continuous Spaces

Previous algorithms assumed a discrete environment (like moving on a grid). However, most real-world environments are continuous, meaning the branching factor is infinite.

When you are architecting base estimators for modular machine learning libraries from scratch, this is exactly the type of optimization you are dealing with—finding the minimum of a continuous loss function.


2. Searching with Nondeterministic Actions

In the real world, actions don't always have guaranteed outcomes. If an environment is partially observable or nondeterministic, a single sequence of actions will inevitably fail when something unexpected happens.

To truly grasp AND-OR trees, we have to abandon the idea of finding a "path" and instead think about finding a "strategy."

In deterministic environments (like the 8-puzzle or the Missionaries and Cannibals problem), the agent is in complete control. If it decides to move a tile, the tile moves. The solution is just a linear list of steps: [Up, Left, Down, Right].

But what happens when the agent doesn't have total control?

The Structure of an AND-OR Tree

When an environment is nondeterministic (unpredictable) or adversarial (involving an opponent), a linear plan will instantly break the moment the environment does something unexpected. To survive, the agent must build a tree of contingency plans.

This tree alternates between two types of nodes:

1. OR Nodes (The Agent's Choices)

2. AND Nodes (The Environment's/Opponent's Responses)

A Concrete Example

When structuring the logic for a chess engine—especially when calculating complex combinations that involve forced moves, castling, or pawn promotion—a standard search path completely fails. You cannot plan a linear 5-move sequence to achieve checkmate because the opponent is actively trying to ruin it.

In this context, the search tree is perfectly modeled by AND-OR logic (often formalized as Minimax in adversarial games):

What does a "Solution" look like?

In a standard search, the solution is a line from start to finish.

In an AND-OR search, the solution is a subtree containing nested if-then-else rules.

If we mapped out a plan, it would look like this:

  1. [OR] I will play Knight to f7.

  2. [AND] * If the environment (opponent) plays Rook takes Knight [OR] I will play Queen to e8 (Checkmate).

    • If the environment (opponent) plays King moves to g8 [OR] I will play Knight to h6 (Checkmate).

Because you have an answer for every branch of the AND node, the strategy is completely watertight.


Interactive AND-OR Strategy Builder

The hardest part of implementing this logic is understanding how the "Goal" propagates back up the tree.

Try to find the guaranteed winning strategy in the abstract widget below.

Pasted image 20260512181551.png


To find the solution for the erratic vacuum cleaner, we have to trace the execution of the AND-OR-GRAPH-SEARCH algorithm provided in your lecture over the tree structure shown on Slide 15.

Because the vacuum is erratic, an action like Suck in State 1 is nondeterministic—it might clean the dirt and transition to State 7, or it might fail and transition to State 5. Therefore, the algorithm cannot return a simple sequence of actions; it must return a contingency plan consisting of if-then-else rules.

Here is the step-by-step application of "finding the solution," following the successful path (highlighted in red on your slide).

Pasted image 20260512182014.png

The Step-by-Step Search Trace

1. The Root Choice (OR Node: State 1) The agent begins at State 1 and must choose an action (Right or Suck). The algorithm explores Suck.

2. The Environment's Response (AND Node) Because the environment is nondeterministic, the Suck action branches into an AND node with two possible outcomes: State 7 and State 5. To successfully validate the initial Suck command, the AND-SEARCH function dictates that the agent must find a winning path for both outcomes.

3. Solving Outcome A: State 7 The algorithm evaluates State 7 and recognizes it as a GOAL. According to the algorithm, if the state passes the goal test, it returns an empty plan ([]). This branch of the AND node is successfully resolved.

4. Solving Outcome B: State 5 (OR Node)

State 5 is not a goal, so the agent must choose a new action to continue the plan.

5. Continuing from State 6 (OR Node)

State 6 is not a goal. The agent must choose again.

6. State 8 (Goal) The algorithm evaluates State 8 and recognizes it as a GOAL. The algorithm returns an empty plan ([]).


Constructing the Final Strategy

Because a successful path was found for every possible outcome of the initial Suck command, the root node is considered solved. As the recursive functions return back up the tree, the AND-SEARCH algorithm stitches the successful branches together using if-then-else logic.

The final solution returned by the algorithm is a robust contingency strategy:

Action 1: [Suck]

Condition: [if State=7 then [] else if State=5 then [Right, Suck]]


3. Constraint Satisfaction Problems (CSPs)

This is a massive paradigm shift in state representation. Previously, algorithms treated states as Atomic—a "black box" with no internal structure where you just ask "Is this the goal?".

CSPs use a Factored representation. A state is now a set of variables, and the problem is solved by assigning values to these variables without breaking the rules.


Interactive Concept: CSP Map Coloring

The lecture uses the map of Australia as a classic CSP example.

Pasted image 20260512173806.png