Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview Search for #TODO tags to quickly find the functions you are required to implement. Descriptions and pseudocode for each function are provided in the

Overview
Search for #TODO tags to quickly find the functions you are required to implement. Descriptions and pseudocode for each function are provided in the notebook, along with links to external readings.
Complete the TravelingSalesmanProblem class by implementing the successors(), get_successor(), and __get_value() methods
Complete the HillClimbingSolver class
Complete the LocalBeamSolver class
Complete the SimulatedAnnealingSolver class
Complete the LAHCSolver class
In []:
import json
import math # contains sqrt, exp, pow, etc.
import random
import time
from collections import deque
from helpers import *
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
%matplotlib inlineI. Hill Climbing
Next, complete the solve() method for the HillClimbingSolver class below.
The hill-climbing search algorithm is the most basic local search technique. At each step the current node is replaced by the neighbor with the highest value. [AIMA 3rd ed, Chapter 4]
Pseudocode for the hill climbing function from the AIMA textbook. Note that our Problem class is already a "node", so the MAKE-NODE line is not required.
In []:
class HillClimbingSolver:
"""
Parameters
----------
epochs : int
The upper limit on the number of rounds to perform hill climbing; the
algorithm terminates and returns the best observed result when this
iteration limit is exceeded.
"""
def __init__(self, epochs=100):
self.epochs = epochs
def solve(self, problem):
""" Optimize the input problem by applying greedy hill climbing.
Parameters
----------
problem : Problem
An initialized instance of an optimization problem. The Problem class
interface must implement a callable method "successors()" which returns
a iterable sequence (i.e., a list or generator) of the states in the
neighborhood of the current state, and a property "utility" which returns
a fitness score for the state. (See the `TravelingSalesmanProblem` class
for more details.)
Returns
-------
Problem
The resulting approximate solution state of the optimization problem
Notes
-----
(1) DO NOT include the MAKE-NODE line from the AIMA pseudocode
"""
# TODO: Implement this function!
for _ in (3):
neihbor = max(problem.successors(),)
if(neihbor.some < problem.something):
raise NotImplementedError
Run the Hill Climbing Solver
In []:
solver = HillClimbingSolver(epochs=100)
start_time = time.perf_counter()
result = solver.solve(capitals_tsp)
stop_time = time.perf_counter()
print("solution_time: {:.2f} milliseconds".format((stop_time - start_time)*1000))
print("Initial path length: {:.2f}".format(-capitals_tsp.utility))
print("Final path length: {:.2f}".format(-result.utility))
print(result.path)
show_path(result.coords, starting_city)

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_2

Step: 3

blur-text-image_3

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

Building The Data Lakehouse

Authors: Bill Inmon ,Mary Levins ,Ranjeet Srivastava

1st Edition

1634629663, 978-1634629669

More Books

Students also viewed these Databases questions

Question

Find the derivative. f(x) 8 3 4 mix X O 4 x32 4 x32 3 -4x - x2

Answered: 1 week ago

Question

Organize and support your main points

Answered: 1 week ago

Question

Move smoothly from point to point

Answered: 1 week ago

Question

Outlining Your Speech?

Answered: 1 week ago