Question: Write a function shortest _ path ( spatial _ network, source, target, max _ bound ) that takes a spatial network, initial ( source )
Write a function shortestpathspatialnetwork, source, target, maxbound that takes a spatial network, initial source location, target location and the maximum distance that a trader located in the initial location can travel as its input and returns a tuple with a shortest path and its total distance.
Input:
spatialnetwork: a list of tuples, where each tuple is of the form location neighbours and neighbours is of the form neighbour distanceneighbour distance This corresponds with the output of the function you wrote for Qa
source: the location label string of the initial location.
target: the location label string of the target location.
maxbound: an integer or None that specifies the maximum total distance that your trader can travel. If maxbound is None then always return the path with minimum distance.
Your function should return a tuple path totaldistance where path is a string of each location label in the path separated by a hyphen character, and totaldistance is the total of the distances along the path.
If there's two paths with the same minimum total distance, choose the path with more locations on it If there's two paths with the same minimum total distance and they have the same number of locations on the path then choose alphanumerically smaller path string.
If there is no path with a total distance within the maxbound then your function should return None None
You may assume:
Inputs are correctly formatted data structures and types.
Distances are nonnegative integer values.
The network is connected, so a path always exists, although it may not have a total distance within the maximum bound.
shortestpathspatialnetwork,
shortestpathspatialnetwork, L
None None
shortestpathspatialnetwork, LL
None None
shortestpathspatialnetwork, LL None
LLL
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
