Search code examples
artificial-intelligencegraph-algorithmheuristics

A heuristic function for 3 Water Jug


I've question to ask you guys.

I'm a newbie in Artificial Intelligence. I want to solve water jug problem(3 jugs - 3 lt, 5lt, 9lt - Trying to get 7lt) using A* search.

I need a heuristic function to implement the solution, but I can't find a good heuristic f(n) so that the algorithm will find the least steps to the solution.


Solution

  • So given your parameters the non-heuristic way of solving this problem is:

    0) Fill the 9 liter jug  
    1) Pour the 9 liter jug into the 5 liter jug, this leaves 4 liters in the 9 liter  
    2) Fill the 3 liter jug  
    3) Pour the 3 liter jug into the 9 liter jug and the problem is solved
    

    So looking at this you will have a graph that has nodes that can be in one of two states: Pour or Fill . You then assign to each node a weight that represents the amount of liquid you will get from it, 1,2,3,etc . There should be no division involved, you just need to make it "expensive" to use specific operations.