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

Simple AI Problem 2

Artificial intelligence problems with water and jug problems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views6 pages

Simple AI Problem 2

Artificial intelligence problems with water and jug problems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

8-Tile Puzzle

The 8-Tile Puzzle (also known as the Sliding Puzzle) is a classic problem in AI
and search algorithms. The objective is to arrange a 3x3 grid of numbered tiles
into a specific order by sliding the tiles into an empty space.
Problem Definition
1. Grid Representation: The puzzle consists of 8 numbered tiles (1-8) and
one empty space.
2. Goal State: The goal is to rearrange the tiles into a specific order (e.g.,
the above arrangement).
Allowed Moves
You can slide a tile into the empty space (the position of _) from one of the four
adjacent positions (up, down, left, right).
State Representation
A state can be represented as a 3x3 matrix or a one-dimensional array. The
position of the empty space is crucial for determining valid moves.
Example:

(Starting State) (Goal State)


Solving the Puzzle
1. Initial State: Represent the puzzle state.
2. Generate Possible Moves: Create new states by sliding tiles into the
empty space.
3. Check for Goal State: If the new state matches the goal configuration,
the puzzle is solved.
4. Explore States: Use BFS or A* to explore the state space, keeping track
of visited states to avoid loops.
Solution using Breadth-First Search (BFS)

Start State: This can be represented as: (1, 2, 3, 4, 5, 6, 0, 7, 8) where 0


represents the blank tile (_).

Goal State: This can be represented as: (1, 2, 3, 4, 5, 6, 7, 8, 0).

Step-by-Step Execution of BFS:


Step 1: Initial State: Current State: (1, 2, 3, 4, 5, 6, 0, 7, 8)
Possible Moves:
 Up: Swap blank (index 6) with (index 3): This state is: (1, 2, 3, 0, 5, 6, 4, 7, 8)
 Down: No valid move (blank is already on the bottom row).
 Left: No valid move (blank is already on the left edge).
 Right: Swap blank with (index 7): This state is: (1, 2, 3, 4, 5, 6, 7, 0, 8)
Enqueue the valid states:
Queue: [(1, 2, 3, 0, 5, 6, 4, 7, 8), (1, 2, 3, 4, 5, 6, 7, 0, 8)]

Step 2: Dequeue the first state (1, 2, 3, 0, 5, 6, 4, 7, 8)


Possible Moves:
 Up: Swap blank (index 3) with (index 0): This state is: (0, 2, 3, 1, 5, 6, 4, 7, 8)
 Down: Swap blank (index 3) with (index 6): This is the original state, already visited.
 Left: No valid move (blank is already on the left edge).
 Right: Swap blank (index 3) with (index 4): This state is: (1, 2, 3, 5, 0, 6, 4, 7, 8)
Enqueue the new states:
Queue: [(1, 2, 3, 4, 5, 6, 7, 0, 8), (0, 2, 3, 1, 5, 6, 4, 7, 8), (1, 2, 3, 5, 0, 6, 4, 7,
8)]

Step 3: Dequeue the next state (1, 2, 3, 4, 5, 6, 7, 0, 8)


Possible Moves:
 Up: Swap blank (index 7) with (index 4):This state is: (1, 2, 3, 4, 0, 6, 7, 5, 8)
 Down: No valid move (blank is already on the bottom row).
 Left: Swap blank with (index 6): This is the original state, already visited.
 Right: Swap blank with (index 8): This is the Goal State: (1, 2, 3, 4, 5, 6, 7, 8, 0)
 BFS stops here as the goal state is found.
Solution Path:
 Start State: (1, 2, 3, 4, 5, 6, 0, 7, 8)
 Move the blank tile Right to get to (1, 2, 3, 4, 5, 6, 7, 0, 8)
 Move the blank tile Right again to reach the Goal State: (1, 2, 3, 4, 5, 6, 7, 8, 0)
 This is the shortest path found by BFS in two moves.
Key Insights
 Solvability: Not all configurations are solvable. The solvability can be
determined by the number of inversions (pairs of tiles that are out of
order). A configuration is solvable if the number of inversions is even.
 State Space Complexity: The total number of configurations is 9!
(factorial of 9) divided by 2 (for solvability), leading to about 181,440
reachable states.
Applications
 Game design (creating puzzle games)
 Robotics (path planning)
 Artificial intelligence (state-space search problems)
Traveling Salesman Problem (TSP)
The Traveling Salesman Problem (TSP) is a classic optimization problem
where a salesman must visit a set of cities, each exactly once, and return to the
starting city while minimizing the total travel distance (or cost). The challenge
is to find the shortest possible route that visits every city and returns to the
original city.
Problem Definition
 Input: A set of cities and the distances between each pair of cities
(usually represented in a matrix).
 Output: The shortest possible route that visits all cities once and returns
to the starting point.
 Goal: Minimize the total travel cost (distance or time).
Example
Consider a simple example with four cities:
 Cities: A, B, C, D
 Distance Matrix:
A B C D
A 0 10 15 20
B 10 0 35 25
C 15 35 0 30
D 20 25 30 0

Possible Routes
The TSP can be visualized through permutations of cities. For four cities, the
possible routes include:
 A→ B → C → D →A
 A→ B → D → C →A
 A→ C → B → D →A
 etc.
Greedy First Approach: In the greedy approach, at each step, the algorithm
selects the nearest (shortest distance) unvisited city. It does not consider the
overall optimal route but only looks at the immediate best choice.
Step-by-Step Solution:
1. Start at City A

 Possible choices from A:


o A → B: Distance = 10
o A → C: Distance = 15
o A → D: Distance = 20
 Greedy choice: Go to the nearest city, which is B (Distance = 10).

2. Current City: B

 Possible choices from B:


o B → C: Distance = 35
o B → D: Distance = 25
 Greedy choice: Go to the nearest city, which is D (Distance = 25).

3. Current City: D

 Possible choice from D:


o D → C: Distance = 30
 Greedy choice: Go to city C (Distance = 30).

4. Return to Start City A

 Possible choice from C:


o C → A: Distance = 15

Final Route and Total Distance:

 Route: A → B → D → C → A
 Total distance traveled: A → B (10) + B → D (25) + D → C (30) + C →
A (15) = 80

Conclusion: Using the Greedy First approach, the salesman travels the route A
→ B → D → C → A with a total distance of 80 units. While this approach is
fast and straightforward, it does not guarantee the optimal solution (which might
be shorter with another route).
Key Insights
 Complexity: As number of cities grows, the number of possible tours
increases factorially.
 Applications: TSP has practical applications in logistics, manufacturing,
and circuit design, where efficient routing is crucial.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy