Two Friends Meeting in Saudi Arabia πŸ‡ΈπŸ‡¦

Multi-Agent Search Problem with Real-World Context

Coordination, heuristic analysis, and graph theory application

Problem Statement

Two friends live in different cities on a map of Saudi Arabia and want to meet as quickly as possible.

R
β€”
M
β€”
D


J
β€”
K
β€”
A

R=Riyadh, M=Mecca, D=Dammam, J=Jeddah, A=Abha, K=Khobar
Rules
  • Simultaneous movement: Each turn, both move to neighboring cities
  • Turn time: Max of both travel times (slower sets pace)
  • Goal: Meet in same city as quickly as possible
Learning Outcomes

By completing this exercise, you will be able to:

  • Formulate multi-agent problems with states, actions, and coordination costs
  • Analyze heuristic admissibility using lower bounds and mathematical reasoning
  • Apply graph theory to determine solution existence and revisit requirements
How to Use This Exercise

Each question provides two levels of explanation:

  • πŸ”΅ Simple Response: Easy-to-understand explanation using everyday language and examples
  • πŸ”§ Technical Solution: Detailed mathematical analysis with formal proofs and step-by-step reasoning
Choose the level that matches your comfort with technical details!
  • Question: Formulate as a search problem: state, actions, transition model, step cost, goal test?
Simple Response

Think of this like planning a meetup with GPS tracking:

  • State = Where are both friends right now? Like "(Ahmed in Riyadh, Kamal in Jeddah)"
  • Actions = Where can they go next? Each friend picks a neighboring city to drive to
  • Cost = How long does each round take? Wait for the slower friend (if Ahmed takes 2 hours, Kamal takes 3 hours, then this round takes 3 hours)
  • Goal = When are they done? When both friends are in the same city
  • Problem size = All possible combinations If there are 10 cities, there are 10Γ—10 = 100 possible "where both friends are" situations
Technical Solution - Search Formulation
1 State: $(a, b)$ where $a, b$ = current cities of friends A & B
2 Actions: $(a', b')$ where $a' \in N(a), b' \in N(b)$ (joint moves to neighbors)
3 Step cost: $c = \max\{d(a,a'), d(b,b')\}$ (slower traveler sets turn time)
4 Goal test: $a = b$ (same city) | State space: $|V|^2$ states
Explanation - Multi-Agent Problem Formulation

Think of this as coordinating two people with GPS tracking:

🏠 State like a "snapshot":
  • State (Riyadh, Jeddah): "Ahmed is in Riyadh, Kamal is in Jeddah right now"
  • State (Mecca, Mecca): "Both are in Mecca - they've met!" (Goal achieved)
  • Why pairs?: You need to know where BOTH friends are to plan the meeting
πŸš— Actions like "travel plans":
  • Action (Mecca, Dammam): "Ahmed goes to Mecca, Kamal goes to Dammam"
  • Neighbors only: You can only drive to directly connected cities
  • Joint decision: Both friends decide their next city together
⏱️ Why "max" cost makes sense:
Example: Ahmed takes 2 hours (Riyadh→Mecca), Kamal takes 3 hours (Jeddah→Taif). They agreed to coordinate, so Ahmed waits 1 hour in Mecca until Kamal arrives in Taif. Total turn time = 3 hours (the slower one).
🎯 How to solve similar problems:
1. State = all information needed to make decisions
2. Actions = what can change in one step
3. Cost = what you're trying to minimize (here: meeting time)
4. Goal = when you're done (here: same location)
  • Question: Given straight-line distance $D(i,j)$, which are admissible: $h_1 = D(i,j)$, $h_2 = 2D(i,j)$, $h_3 = D(i,j)/2$?
Simple Response

Think of heuristics like GPS time estimates - they should never lie by saying "too easy":

  • Best case scenario: Friends run directly toward each other in a straight line
  • Meeting time: They meet halfway, so each travels half the distance
  • Why h₁ = D fails: Says "it takes the FULL distance time" but friends help each other by moving toward each other
  • Why hβ‚‚ = 2D fails: Even worse - says it takes TWICE the full distance (way too pessimistic!)
  • Why h₃ = D/2 works: Says "at least half-distance time" which is true - they might take longer due to roads, but never less than this

Answer: Only h₃ = D/2 is admissible because it never underestimates the meeting time.

Technical Solution - Admissibility Analysis
1 Admissibility requirement: A heuristic $h(s)$ is admissible if $h(s) \leq h^*(s)$ for all states $s$
Where $h^*(s)$ = true optimal cost from state $s$ to goal
2 Physical lower bound derivation:
Consider friends at cities $i$ and $j$ with straight-line distance $D(i,j)$
Best case scenario: Both move directly toward each other at maximum speed
Meeting point: Halfway between $i$ and $j$
Distance per friend: $D(i,j)/2$
Therefore: $h^*(i,j) \geq D(i,j)/2$ (fundamental physical constraint)
3 Analysis of $h_1 = D(i,j)$:
Claim: Not admissible
Strategy: To prove non-admissibility, we need to show there exists at least one case where $h_1 > h^*$ (the heuristic overestimates the true cost).
Proof by counterexample:
β€’ What we have: $h_1(i,j) = D(i,j)$ and we established $h^*(i,j) \geq D(i,j)/2$
β€’ What we need for admissibility: $h_1 \leq h^*$, which means $D(i,j) \leq h^*(i,j)$
β€’ The problem: Our lower bound tells us $h^*(i,j)$ could be as small as $D(i,j)/2$
β€’ Counterexample scenario: Consider the ideal case where friends meet exactly halfway
  - True optimal cost: $h^*(i,j) = D(i,j)/2$ (each friend travels half the distance)
  - Our heuristic predicts: $h_1 = D(i,j) = 2 \cdot D(i,j)/2 = 2 \cdot h^*(i,j)$
β€’ Mathematical violation: $h_1 = D(i,j) > D(i,j)/2 = h^*(i,j)$
β€’ Conclusion: Since we found a case where $h_1 > h^*$, heuristic $h_1$ is not admissible
4 Analysis of $h_2 = 2D(i,j)$:
Claim: Not admissible
Intuition: If $h_1 = D(i,j)$ already overestimates, then $h_2 = 2D(i,j)$ (twice as large) will overestimate even more severely.
Proof by direct comparison:
β€’ Given: $h_2(i,j) = 2D(i,j)$ and we know $h^*(i,j) \geq D(i,j)/2$
β€’ Admissibility requires: $h_2 \leq h^*$, which means $2D(i,j) \leq h^*(i,j)$
β€’ The gap analysis: We need to check if this inequality can ever be violated
β€’ Critical observation: Our physical constraint only guarantees $h^*(i,j) \geq D(i,j)/2$
β€’ Worst-case scenario: When friends meet optimally at the halfway point
  - True optimal cost: $h^*(i,j) = D(i,j)/2$
  - Heuristic prediction: $h_2 = 2D(i,j)$
  - Ratio comparison: $h_2/h^* = 2D(i,j) / (D(i,j)/2) = 4$
β€’ Mathematical violation: $h_2 = 2D(i,j) = 4 \cdot D(i,j)/2 = 4 \cdot h^*(i,j) > h^*(i,j)$
β€’ Conclusion: $h_2$ overestimates by a factor of 4, making it severely non-admissible
5 Analysis of $h_3 = D(i,j)/2$:
Claim: Admissible
Strategy: To prove admissibility, we must show $h_3 \leq h^*$ holds for ALL possible states. We'll use our established lower bound.
Proof by universal inequality:
β€’ What we established in Step 2: $h^*(i,j) \geq D(i,j)/2$ (this is our fundamental physical constraint)
β€’ What our heuristic predicts: $h_3(i,j) = D(i,j)/2$
β€’ The key insight: Our heuristic exactly matches the lower bound we derived
β€’ Mathematical relationship: $h_3(i,j) = D(i,j)/2 \leq h^*(i,j)$ for all states $(i,j)$
β€’ Why this works:
  - In the best case: $h^*(i,j) = D(i,j)/2$ exactly β†’ $h_3 = h^*$ (perfect estimate)
  - In realistic cases: $h^*(i,j) > D(i,j)/2$ β†’ $h_3 < h^*$ (conservative estimate)
  - Never happens: $h^*(i,j) < D(i,j)/2$ β†’ impossible due to physics
β€’ Admissibility verification: Since $h_3 \leq h^*$ always holds, $h_3$ satisfies the admissibility condition
β€’ Conclusion: $h_3$ is a valid admissible heuristic that provides a safe lower bound
6 Final Summary and Comparison:
Remember: Admissibility means the heuristic never overestimates. Even one counterexample breaks admissibility!
Results overview:
β€’ $h_1 = D(i,j)$: ❌ Not admissible
  - Problem: Overestimates by factor of 2 in optimal scenarios
  - Why it fails: Assumes one friend travels the full distance (ignores simultaneous movement)
β€’ $h_2 = 2D(i,j)$: ❌ Not admissible
  - Problem: Overestimates by factor of 4 in optimal scenarios
  - Why it fails: Even worse than $h_1$, completely ignores coordination benefits
β€’ $h_3 = D(i,j)/2$: βœ… Admissible
  - Success: Matches the fundamental physical lower bound
  - Why it works: Represents the best-case scenario (perfect coordination)
Key insight: The only admissible heuristic is the one that equals our derived lower bound: $h_3 = D(i,j)/2$
h₁ = D(i,j)
❌ Not Admissible
Often overestimates
hβ‚‚ = 2D(i,j)
❌ Not Admissible
Even worse overestimate
h₃ = D(i,j)/2
βœ… Admissible
Safe lower bound
Explanation - Understanding Heuristic Admissibility

Think of admissibility as "never lying about how easy the problem is":

πŸƒβ€β™‚οΈ The physics argument for D/2:
  • Best case scenario: Friends run directly toward each other in a straight line
  • Meeting point: They meet exactly halfway between their starting points
  • Time needed: Each travels distance D/2, so meeting time = D/2
  • Reality check: Roads aren't straight lines, so real time β‰₯ D/2
❌ Why h₁ = D fails:
  • Problem: Says meeting takes D time (full distance)
  • Reality: Both friends move toward each other simultaneously
  • Example: Riyadh-Jeddah distance = 1000km. h₁ = 1000km, but they can meet in Mecca (500km each) much faster
🧭 Navigation GPS analogy:
A good heuristic is like GPS estimated time: it might say "at least 30 minutes" and you actually take 35 minutes (fine!). But if GPS said "at least 60 minutes" when you actually take 35, you'd be frustrated - that's an overestimate like h₁ and hβ‚‚.
🎯 How to design admissible heuristics:
1. Find physical constraints: What's the absolute best case?
2. Use straight-line distances: Reality can only be equal or worse
3. Consider simultaneous movement: Don't forget both agents move together
4. Test with examples: Can you find any case where h > actual cost?
  • Question: Could there be a connected road map where no meeting is possible?
Simple Response

Think of this like asking "Can you drive between any two places?"

  • Connected road map: You can drive from anywhere to anywhere else (maybe not directly, but through other cities)
  • Can friends always meet? YES! Here's why:
    • Pick any city as the meeting spot (say, Riyadh)
    • Since roads connect everything, both friends can drive to Riyadh
    • They coordinate to arrive at the same time - meeting successful!
  • When is meeting impossible? Only when roads are broken/missing between friend locations
  • Example: Ahmed in mainland Saudi, Kamal on an island with no bridge - they literally can't reach each other

Answer: No, there cannot be a connected road map where meeting is impossible. Connected = meeting always possible!

Technical Solution - Graph Connectivity Analysis
1 Setup: Graph $G = (V, E)$ where $V$ = cities, $E$ = roads
Question: Given connected $G$, can friends always meet?
2 Claim: If $G$ is connected, meeting is always possible
Constructive proof:
β€’ Choose any rendezvous city $r \in V$
β€’ Since $G$ connected: paths $P_A: a_0 \leadsto r$ and $P_B: b_0 \leadsto r$ exist
β€’ Friends coordinate to both reach $r$ (possibly with detours for synchronization)
β€’ ∴ Solution exists
3 When meeting is impossible:
Disconnected case:
β€’ Friends in different components $C_i, C_j$ where $C_i \cap C_j = \emptyset$
β€’ No path between components β†’ No common reachable city
β€’ ∴ Meeting impossible
4 Answer: No - connected graphs always allow meetings
Verification: Run BFS from $a_0$. If $b_0$ reachable β†’ meeting possible. Complexity: $O(|V| + |E|)$
Explanation - Graph Connectivity and Solution Existence

Think of connectivity as "can you drive from anywhere to anywhere else?":

πŸ—ΊοΈ Connected graph = guaranteed meeting:
  • Proof by example: Pick any city as meeting point (say, Riyadh)
  • Friend A's path: Since graph is connected, there's a route from A's city β†’ Riyadh
  • Friend B's path: Since graph is connected, there's a route from B's city β†’ Riyadh
  • Coordination: They can synchronize to both arrive at Riyadh
🏝️ Disconnected = impossible meeting:
  • Island scenario: Ahmed in mainland Saudi Arabia, Kamal on an island with no bridge
  • Different components: No path exists between their locations
  • Result: No matter how they move, they can never reach the same city
πŸ” How to check connectivity:
Algorithm: Start from Friend A's location, use BFS/DFS to explore all reachable cities. If you can reach Friend B's location, they're in the same connected component β†’ meeting is possible!
🎯 Real-world examples:
β€’ Saudi Arabia: Highly connected road network β†’ meetings always possible
β€’ Island nations: Without ferries/bridges, some meetings impossible
β€’ War zones: Destroyed roads can create disconnected regions
β€’ Internet routing: Same principle applies to data packet delivery
  • Question: Must one friend visit the same city twice before meeting?
Simple Response

Think of this like coordinating two people who must move at the same time:

  • The setup: Hub city H with 3 side streets (L₁, Lβ‚‚, L₃). Ahmed starts at H, Kamal starts at L₁
  • The goal: Both arrive at the same place after the same number of moves
  • The problem: Kamal needs 1 move (L₁→H), but Ahmed can't just wait at H!
  • The solution: Ahmed must "waste time" by going Hβ†’Lβ‚‚β†’H (2 moves) while Kamal goes L₁→Hβ†’somewhereβ†’H (2 moves)
  • The result: Ahmed visited H twice (start and end)!
  • Why this happens: When you can't wait and need to synchronize timing, sometimes you must backtrack
  • Real-world: People can usually wait, so this isn't common in real life

Answer: Yes, sometimes one friend must revisit cities - but only when "waiting" isn't allowed and timing needs to be synchronized.

Technical Solution - City Revisit Analysis
1 Key modeling choice: Answer depends on whether "wait" actions are allowed
β€’ Model A: Wait action allowed
β€’ Model B: No wait (must move every turn)
We'll prove Model B can require revisits
2 Counterexample construction:
Star graph: Hub $H$ connected to leaves $L_1, L_2, L_3$
Initial positions: Friend A at $H$, Friend B at $L_1$
Constraint: Both must move simultaneously with equal total moves
3 Movement sequence forcing revisit:
Strategy: Both make 2 moves to meet at hub $H$
β€’ Solution sequence:
  - A: $H \rightarrow L_2 \rightarrow H$ (2 moves)
  - B: $L_1 \rightarrow H \rightarrow H$ (but can't wait, so needs alternative)
β€’ Result: A visits $H$ twice (start and end) to enable synchronization
4 General condition: Revisits required when:
$|d_A - d_B| > 0 \land \text{no wait} \land \text{limited connectivity}$
Model comparison: With waiting: A stays at $H$, B moves $L_1 \rightarrow H$ (no revisits). Without waiting: synchronization forces detours.
Answer: Yes - revisits necessary under restrictive action models
H

L₁
β€”
Lβ‚‚
β€”
L₃

Star: requires timing coordination
Explanation - The Synchronization Dilemma

Think of this as a timing coordination problem:

⏰ The timing mismatch problem:
  • Friend B needs 1 move: L₁ β†’ H (arrives at Hub in 1 turn)
  • Friend A is already at H: If A just waits, they could meet immediately
  • But "wait" isn't allowed: A must move every turn (game rules)
  • A's solution: Go H β†’ Lβ‚‚ β†’ H (takes 2 turns, same as B)
πŸ”„ Why revisit happens:
  • Turn 1: A: Hβ†’Lβ‚‚, B: L₁→H (A visits Lβ‚‚, B reaches H)
  • Turn 2: A: Lβ‚‚β†’H, B: already at H (A revisits H, they meet!)
  • Result: A visited H twice (start + end)
🎭 Dancing analogy:
Imagine two dancers who must move to the same beat. If one dancer needs 1 step to reach the center and the other is already there, the one at the center must "mark time" by stepping away and back, so they both arrive simultaneously.
πŸ”§ Modeling choice impact:
β€’ With "wait" action: A stays at H, B comes to H β†’ No revisits needed
β€’ Without "wait" action: Must move every turn β†’ Revisits for synchronization
β€’ Real world: People can usually wait, so revisits are often unnecessary
β€’ Game/robotics: Sometimes continuous movement is required
πŸ“ Problem-solving tip:
When analyzing multi-agent problems, always consider: Can agents wait? Can they move at different speeds? These modeling choices drastically affect solution complexity.

Continue Learning

Robot Navigation Heuristics A* Search Maze Exercise