PYTHON CODING This function takes a list of points and then returns a new list of points, which starts with the first point that was given in the list, and then followed by points closest to the start point.  Example: points = [a, b, c, d, e, f, g] point a is the strating point soe the new list must start with a. we then use the fistance function to calculate which points will be closest to a. lets say f is closest to a, therefore, second point in the new list will be f. Next we find which point is closest to f, lets say b is closest, therefore b is the next point in our new list, and so on. new list = [a, f, b, ......] ------- Here is the function that needs to be created: def solution_path(points) :     # insert code here     return path Please use any of the following function to develop the solution_path function Distance function - calculates the distance between two points def distance(p1, p2) :     distance = sqrt (((p1 [0] - p2 [0]) **2) + ((p1 [1] - p2 [1]) **2))     return (distance)   Find_closest function - calculates the closest point to the starting point def find_closest(start_point, remaining_points):           closest_distance = 99999           for coordinate in remaining_points:         dist = distance(start_point, coordinate)          if(dist < closest_distance):             closest_distance = dist             closest_point = coordinate         return closest_point   Path_distance function - calculates the total distance between all points def path_distance(path) :     total_distance = 0     for element in range(0, len(path) - 1):         total_distance += distance(path[element], path[element + 1])     return total_distance     Note: the function should return a new list, not modify the existing list. Hint: use a while loop to repeat while the list of remaining points is not empty   Here is an exmaple of the input and output of the function: points = [(5, 8), (5.5,3), (3.5,1.5), (2.5,3.5), (7.5,9), (1,3), (7,9.5), (9,2), (1,0), (6,8), (3,7.5), (8,2.5)] path = solution_path(points) print(path) # the first point in the input list is (5, 8), so that appears first in our output list, # the closest point to our start point (5, 8) is (6, 8), so (6, 8) appears second in our list, # the closest remaining point to (6, 8) is (7.5, 9), so (7.5, 9) appears third in our list, # and so on. So the best path should be # [(5, 8), (6, 8), (7.5, 9), (7, 9.5), (3, 7.5), (2.5, 3.5), (1, 3), (3.5, 1.5), (5.5, 3), (8, 2.5), (9, 2), (1, 0)]

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

PYTHON CODING

This function takes a list of points and then returns a new list of points, which starts with the first point that was given in the list, and then followed by points closest to the start point. 

Example:

points = [a, b, c, d, e, f, g]

point a is the strating point soe the new list must start with a. we then use the fistance function to calculate which points will be closest to a. lets say f is closest to a, therefore, second point in the new list will be f. Next we find which point is closest to f, lets say b is closest, therefore b is the next point in our new list, and so on.

new list = [a, f, b, ......]

-------

Here is the function that needs to be created:

def solution_path(points) :
    # insert code here
    return path

Please use any of the following function to develop the solution_path function

Distance function - calculates the distance between two points

def distance(p1, p2) :
    distance = sqrt (((p1 [0] - p2 [0]) **2) + ((p1 [1] - p2 [1]) **2))
    return (distance)

 

Find_closest function - calculates the closest point to the starting point

def find_closest(start_point, remaining_points):
     
    closest_distance = 99999 
    
    for coordinate in remaining_points:
        dist = distance(start_point, coordinate) 
        if(dist < closest_distance):
            closest_distance = dist
            closest_point = coordinate
   
    return closest_point

 

Path_distance function - calculates the total distance between all points

def path_distance(path) :
    total_distance = 0
    for element in range(0, len(path) - 1):
        total_distance += distance(path[element], path[element + 1])
    return total_distance   

 Note: the function should return a new list, not modify the existing list.
Hint: use a while loop to repeat while the list of remaining points is not empty

 

Here is an exmaple of the input and output of the function:

points = [(5, 8), (5.5,3), (3.5,1.5), (2.5,3.5), (7.5,9), (1,3), (7,9.5), (9,2), (1,0), (6,8), (3,7.5), (8,2.5)]

path = solution_path(points)

print(path)

# the first point in the input list is (5, 8), so that appears first in our output list,
# the closest point to our start point (5, 8) is (6, 8), so (6, 8) appears second in our list,
# the closest remaining point to (6, 8) is (7.5, 9), so (7.5, 9) appears third in our list,
# and so on. So the best path should be
# [(5, 8), (6, 8), (7.5, 9), (7, 9.5), (3, 7.5), (2.5, 3.5), (1, 3), (3.5, 1.5), (5.5, 3), (8, 2.5), (9, 2), (1, 0)]

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY