Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I'm stuck in this question. Can you help me to solve with code using Python. Pls make sure to run the test cases first.

Hello, I'm stuck in this question. Can you help me to solve with code using Python. Pls make sure to run the test cases first. Thank you so much for the help!!

image text in transcribedimage text in transcribedimage text in transcribed

Task 2.6: Implement hill-climbing Using your representation above, implement the hill-climbing algorithm hill_climbing(cities, distances), which takes in the number of cities and the list of distances, and returns the shortest route as a list of cities. 1. Local search algorithms move from a candidate solution to another in the search space by applying local changes (with the help of a transition function), until an optimal solution is found. 2. The hill-climbing approach is a local search algorithm which starts with a randomly-inifialised state and continuously selects the next candidate solution that locally maximizes the reduction of the heuristic function. 3. The algorithm terminates when a (local) maxima is reached, i.e. a solution that cannot be improved further by looking at the next candidate solutions. 4. Unlike previous search algorithms you have implemented, hill-climbing only keeps a single current state. As such, it does not involve a search tree/graph. Backtracking is also not possible. An implementation for heuristic (cities, distances, route) has been provided on Coursemology for this section, in case you were unable to come up with a good heuristic and transition function. Locally, you can test your hill-climbing implementation using the functions you defined in Task 2.3. def hill_climbing(cities: int, distances: List[Tuple[int]]): r"*n Hill climbing finds the solution to reach the goal from the initial. Args: cities (int): The number of cities to be visited distances (List[Tuple[int]]): The list of distances between every two cities Each distance is represented as a tuple in the form of (c1,c2,d), where c1 and c2 are the two cities and d is the distance between them. The length of the list should be equal to cities * (cities - 1)/2. Returns: route (List[int]): The shortest route, represented by a list of cities in the order to be traversed. route =[] END YOUR CODE HERE " return route

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions