public class HillClimbingSearch extends java.lang.Object implements SearchForActions, SearchForStates
function HILL-CLIMBING(problem) returns a state that is a local maximum
current <- MAKE-NODE(problem.INITIAL-STATE)
loop do
neighbor <- a highest-valued successor of current
if neighbor.VALUE <= current.VALUE then return current.STATE
current <- neighbor
Figure 4.2 The hill-climbing search algorithm, which is the most basic local
search technique. At each step the current node is replaced by the best
neighbor; in this version, that means the neighbor with the highest VALUE,
but if a heuristic cost estimate h is used, we would find the neighbor with
the lowest h.| Modifier and Type | Class and Description |
|---|---|
static class |
HillClimbingSearch.SearchOutcome |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
METRIC_NODE_VALUE |
static java.lang.String |
METRIC_NODES_EXPANDED |
| Constructor and Description |
|---|
HillClimbingSearch(HeuristicFunction hf)
Constructs a hill-climbing search from the specified heuristic function.
|
HillClimbingSearch(HeuristicFunction hf,
NodeExpander nodeExpander) |
| Modifier and Type | Method and Description |
|---|---|
java.util.List<Action> |
findActions(Problem p)
Returns a list of actions to the goal if the goal was found, a list
containing a single NoOp Action if already at the goal, or an empty list
if the goal could not be found.
|
java.lang.Object |
findState(Problem p)
Returns a state which is might be but not necessary is a goal state of
the problem.
|
java.lang.Object |
getLastSearchState()
Returns the last state from which the hill climbing search found the
local maximum.
|
Metrics |
getMetrics()
Returns all the search metrics.
|
NodeExpander |
getNodeExpander()
Returns the node expander used by the search.
|
HillClimbingSearch.SearchOutcome |
getOutcome()
Returns SOLUTION_FOUND if the local maximum is a goal state, or FAILURE
if the local maximum is not a goal state.
|
Node |
searchNode(Problem p)
Returns a list of actions to the local maximum if the local maximum was
found, a list containing a single NoOp Action if already at the local
maximum, or an empty list if the search was canceled by the user.
|
public static final java.lang.String METRIC_NODES_EXPANDED
public static final java.lang.String METRIC_NODE_VALUE
public HillClimbingSearch(HeuristicFunction hf)
hf - a heuristic functionpublic HillClimbingSearch(HeuristicFunction hf, NodeExpander nodeExpander)
public java.util.List<Action> findActions(Problem p)
SearchForActionsfindActions in interface SearchForActionsp - the search problempublic java.lang.Object findState(Problem p)
SearchForStatesfindState in interface SearchForStatesp - the search problempublic Node searchNode(Problem p)
p - the search problempublic HillClimbingSearch.SearchOutcome getOutcome()
public java.lang.Object getLastSearchState()
public NodeExpander getNodeExpander()
SearchForActionsgetNodeExpander in interface SearchForActionsgetNodeExpander in interface SearchForStatespublic Metrics getMetrics()
getMetrics in interface SearchForActionsgetMetrics in interface SearchForStates