Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Hill Climbing Algorithm

AIM: To implement Hill Climbing Algorithm using Python

DESCRIPTION:

Hill Climbing Algorithm commonly used Heuristic search technique in the field of artificial
intelligence. The heuristic technique is a criterion for choosing which of multiple options will be
most successful in accomplishing a particular goal. Hill climbing comes from quality
measurement in Depth-First search (a variant of generating and test strategy). It is an
optimization strategy that is a part of the local search family.
It is a fairly straightforward implementation strategy as a popular first option is explored. There
are instances where hill climbing is effective, even though more complex algorithms may
produce greater benefits.

Hill climbing can solve problems with many solutions but where some solutions are better than
others. The traveling salesman problem can be solved with hill climbing. It is simple to locate a
solution that visits every city, but this solution is likely to be subpar compared to the ideal one.

Search efficiency may be increased if there is a technique to arrange the options so that the most
promising node is explored first. Hill Climbing progresses through a tree of paths in depth-first
order, but the options are arranged in accordance with some heuristic value (ie, a measure of
remaining cost from current to goal state).

Types of Hill Climbing Algorithm

Simple Hill Climbing: The simplest method of climbing a hill is called simple hill climbing. The
goal is to ascend to the mountain’s highest peak. Here, the climber’s steps and moves determine
how he moves. He continues to move if he thinks his next step will be better than the one before
it, or if he stays in the same position. This search is just concerned with his previous and
subsequent actions.
Steepest-ascent Hill Climbing: In contrast to a straightforward hill-climbing search, it compares
all of the succeeding nodes and selects the one that is closest to the answer. Because it
concentrates on each node rather than just one, the steepest hill-climbing search is comparable to
the best-first search.
Stochastic hill climbing: The nodes are not all concentrated on in stochastic hill climbing. It
chooses one node at random and then determines whether to enlarge it or look for a better one.
Random-restart Hill Climbing: Try-and-try approach is the foundation of the random-restart
algorithm. Up till the target is not reached, it iteratively searches the node and chooses the best
candidate at each stage. Success is frequently determined by the hill’s form. It is simpler to get
there if there aren’t many ridges, plateaus, or local maxima.
IMPLEMENTATION OF HILL CLIMBING

To understand the concept in a better way, let’s try to implement the problem of a traveling
salesman using the hill climbing algorithm. A description of the problem is given below.

Finding the shortest path between a number of points and places that must be visited is the goal
of the algorithmic problem known as the “traveling salesman problem” (TSP). The input here is
a 2D array of coordinates of cities and the output is a list of integers that indicates the numbers
of cities in order(starting from zero)

OUTPUT
The solution is

[2, 4, 8, 3, 7, 5, 0, 6, 9, 10, 1]

You might also like