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.  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)] ------ best_path(points) == [(2.8, 9.8), (4.4, 8.8), (5.0, 8.2), (6.8, 7.4), (3.4, 6.9), (0.7, 7.9), (0.3, 8.3), (4.8, 3.2), (4.1, 0.3), (4.5, 0.0), (7.6, 1.1), (7.7, 1.8)] # Should return True

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. 

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)]

------

best_path(points) == [(2.8, 9.8), (4.4, 8.8), (5.0, 8.2), (6.8, 7.4), (3.4, 6.9), (0.7, 7.9), (0.3, 8.3), (4.8, 3.2), (4.1, 0.3), (4.5, 0.0), (7.6, 1.1), (7.7, 1.8)]
# Should return True

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