I came across a puzzle a few days ago. It's solvable easily by hand. But I was trying to build an algorithm for solving it. But i dont know how I should proceed.
Here you can see that i have to connect all pairs of colored dots. For example i need to connect yellow dot to another yellow dot, green to other green, blue to blue and so on.
Here is an example of how it should be solved. if the description was not clear.
So you can see that i connected yellow dot with another yellow dot. And blue with another blue. But this causes a problem. I've blocked the path of aqua color as you can see. I hope you get the idea.
So i want to solve it. Brute force approach would work but it will take a long time and i'm not interested in that. I tried about implementing Breadth First Search, Depth First Search, and Dijkstra algorithm. But i think they won't be good in this case. Correct me please if I'm wrong. A* Search may work, but what will be the heuristic?
Can anyone give me some intuition on how to solve the problem?
The puzzle is divided into sqrt(N+1) rows and sqrt(N+1) columns. Eg. 15-Puzzle will have 4 rows and 4 columns and an 8-Puzzle will have 3 rows and 3 columns. The puzzle consists of N tiles and one empty space where the tiles can be moved.
Best-first search. First, insert the initial state (the initial board, 0 moves, and a null previous state) into a priority queue. Then, delete from the priority queue the state with the minimum priority, and insert onto the priority queue all neighboring states (those that can be reached in one move).
h4 = 5 (out of row) + 8 (out of column) = 13. optimal solution to this problem as a heuristic for the 8-puzzle. Represent the 'space' as a tile and assume you can swap any two tiles. Use the cost of the optimal solution to this problem as a heuristic for the 8-puzzle.
IDDFS will do the trick, considering the relatively limited search space of this puzzle. It would be efficient hence respond to the OP's question.
I genetic algorithm might be an appropriate means to get a solution. The fitness function and the cross-over would have to be tailored specifically for the problem.
Chromosome:
Fitness function off the top of my head
Mutation
Cross-Over / Breeding Off the top of my head
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With