| 1 | |
|---|
| 2 | :- object(hill_climbing(Threshold), |
|---|
| 3 | instantiates(heuristic_search(Threshold))). |
|---|
| 4 | |
|---|
| 5 | :- info([ |
|---|
| 6 | version is 1.2, |
|---|
| 7 | author is 'Paulo Moura', |
|---|
| 8 | date is 2008/6/9, |
|---|
| 9 | comment is 'Hill climbing heuristic state space search strategy.', |
|---|
| 10 | parnames is ['Threshold']]). |
|---|
| 11 | |
|---|
| 12 | :- uses(list, [member/2, reverse/2, sort/2]). |
|---|
| 13 | |
|---|
| 14 | search(Space, State, Threshold, Solution, Cost) :- |
|---|
| 15 | hill(Space, State, Threshold, [], Path, 0, Cost), |
|---|
| 16 | reverse(Path, Solution). |
|---|
| 17 | |
|---|
| 18 | hill(Space, State, _, Path, [State| Path], Cost, Cost) :- |
|---|
| 19 | Space::goal_state(State). |
|---|
| 20 | hill(Space, State, Threshold, Path, Solution, SoFar, Total) :- |
|---|
| 21 | findall( |
|---|
| 22 | (Estimate, Cost, Next), |
|---|
| 23 | (Space::next_state(State, Next, Cost), |
|---|
| 24 | \+ Space::member_path(Next, [State| Path]), |
|---|
| 25 | Space::heuristic(Next, Guess), |
|---|
| 26 | Estimate is Guess + Cost), |
|---|
| 27 | States), |
|---|
| 28 | sort(States, SortedStates), |
|---|
| 29 | member((_, Cost2, Next2), SortedStates), |
|---|
| 30 | SoFar2 is SoFar + Cost2, |
|---|
| 31 | SoFar2 =< Threshold, |
|---|
| 32 | hill(Space, Next2, Threshold, [State| Path], Solution, SoFar2, Total). |
|---|
| 33 | |
|---|
| 34 | :- end_object. |
|---|