In: Computer Science
(Artificial Intelligence)
Write a pseudo code for the following:
Regular Hill Climbing with steepest ascent
As per the question, you have asked only the Pseudo code. So I have provided a running code which will help you to test and run the program and I have marked the main logic. Please refer to the image attached for proper indentation.
As the steepest ascent Hill Climbing is the variation of the simple hill-climbing the program is written below:
import random
import string
# Package Imported
# for the best solution to get in
def random_data(length=13):
return [random.choice(string.printable) for _ in range(length)]
#Pseudo code for the main method to get implement
def data_evaluate(solution):
outcome = list("Hill, Climb")
diff = 0
for i in range(len(outcome)):
s = solution[i]
t = outcome[i]
diff += abs(ord(s) - ord(t))
return diff
#data_evaluate provide the distance between two string --> Hill and Climb
def data_best(solution):
number = random.randint(0, len(solution) - 1)
solution[number] = random.choice(string.printable)
#basis structure or Skeleton of the code
best = random_data()
data_score_best = data_evaluate(best)
while True:
print('Best Score', data_score_best, 'Outcome', "".join(best))
if data_score_best == 0:
break
data_sol = list(best)
data_best(data_sol)
Score_output = data_evaluate(data_sol)
if data_evaluate(data_sol) < data_score_best:
best = data_sol
data_score_best = Score_output
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Hope you got it!! You can try different string for different distance. Thank you