问题
I have a problem in Hill Climbing algorithm with Water Jug Problem :
Given two jugs, one of which can accommodate X liters of water and the other which can accommodate Y liters of water, determine the number of steps required to obtain exactly D liters of water in one of the jugs.
From the start state, (X,Y) = (0,0), it can generate some states :
- (X,Y) = (0,Y)
or - (X,Y) = (X,0)
And from these states, it can generate others until the end state that is either (X,D) or (D,Y).
So, Can I estimate the heuristic function for this problem? How to know which state is better than others?
Thank you everyone.
回答1:
Represent each state in the state space as (x,y) itself.
Heuristic function: h(s) for each s = (x,y) = |x-D| + |y - D| (Assuming you want to minimize h(.) )
Please consider that this is just a greedy decision that assumes if one of the jugs contains an amount of water too close too D it's a good state! Obviously this is true for the goal state but it won't assure reaching an optimal solution, as it's not expected from the HC at all!
Why this h(.)? Cause it's admissible and you can use it (probably when your teacher asks) for A* and it will give you the optimal answer.
Considering the following problems of "Hill Climbing" algorithm, don't expect too much:
- Foothill problem
Local peaks attract procedure’s attention away from trying to reach the “top” - Plateau problem
Area flat so there is very little to attract procedure to one path over another - Ridge problem
Every step is down though not at a local minimum
来源:https://stackoverflow.com/questions/22770487/heuristic-function-for-water-jug