-
Notifications
You must be signed in to change notification settings - Fork 20.8k
Description
What would you like to Propose?
Implementing Hill Climbing Algorithm
The provided Java program implements the Hill Climbing algorithm, a local search technique for finding the maximum value of a mathematical function within a specified range.
The program starts from a random initial solution, iteratively explores nearby solutions, and updates the current solution if a better one is found.
After a set number of iterations, the program outputs the best solution it found along with its corresponding function value.
Note that Hill Climbing is a local search method and may not always find the global maximum if multiple peaks exist in the function's landscape.
Issue details
The algorithm starts from a randomly chosen initial solution within the defined search space and proceeds as follows:
- Initialization:
Choose a random initial solution within the search space, setting it as the current solution.
- Evaluation:
Calculate the value of the objective function for the current solution.
- Local Search:
Generate a neighboring solution by perturbing the current solution. In this program, the perturbation is performed by adding a random value to the current solution. Ensure that the neighboring solution remains within the predefined search space boundaries (between LOWER_LIMIT and UPPER_LIMIT).
Calculate the value of the objective function for the neighboring solution.
- Comparison:
Compare the value of the objective function for the current solution with that of the neighboring solution. If the neighboring solution has a higher objective function value (i.e., it is better), update the current solution to the neighboring solution.
- Termination:
Repeat steps 3 and 4 for a specified number of iterations (defined by MAX_ITERATIONS).
- Output:
After the specified number of iterations, or when no better neighboring solution can be found, the algorithm terminates. The current solution represents the locally optimal solution found within the search space.
- Display
Result: Display the best solution found (value of currentAnswer) and its corresponding objective function value (value of currentValue).
Additional Information
No response