Question: Can you fill out the following code : [ from pulp import * from math import sqrt def euclidean _ distance ( location _ coords,
Can you fill out the following code :from pulp import
from math import sqrt
def euclideandistancelocationcoords, i j:
assert i and i lenlocationcoords
assert j and j lenlocationcoords
if i j:
return
xi yi locationcoordsi # unpack coordinate
xj yj locationcoordsj
return sqrtxj xiyj yi
def solvewarehouselocationlocationcoords, R:
assert R 'radius must be positive'
n lenlocationcoords
prob LpProblemWarehouselocation LpMinimize
# Formulate the decision variables
# Add the constraints for each vertex and edge in the graph.
# Solve and interpret the status of the solution.
# Return the result in the required form to pass the tests below.
# your code here
raise NotImplementedError
from matplotlib import pyplot as plt
def checksolutionlocationcoords, R warehouselocs:
# for each location i calculate all locations j within distance R of location i
# use list comprehension instead of accumulating using a nested for loop.
n lenlocationcoords
assert allj and j n for j in warehouselocs f'Warehouse locations must be between and n
neighborhoods j for j in rangen if euclideandistancelocationcoords, i j R for i in rangen
W setwarehouselocs
for i nlist in enumerateneighborhoods:
assert anyj in W for j in nlist f'Location # i has no warehouse within distance R The locations within distance R are nlist
printYour solution passed test'
def visualizesolutionlocationcoords, R warehouselocs:
n lenlocationcoords
xCoords yCoords ziplocationcoords
warehousex warehousey xCoordsj for j in warehouselocsyCoordsj for j in warehouselocs
fig, ax pltsubplots
axsetaspectequal
pltscatterxCoords yCoords
for j in warehouselocs:
circ pltCirclelocationcoordsj R alpha colorglslweck
axaddpatchcirc
for i in rangen:
xy locationcoordsi
axannotatefi locationcoordsi
pltscatterwarehousex warehousey markerxcr s
locationcoords
R
locs solvewarehouselocationlocationcoords, R
printfYour code returned warehouse locatitons: locs
assert lenlocs f'Error: There is an solution involving just locations whereas your code returns lenlocs
visualizesolutionlocationcoords, R locs
checksolutionlocationcoords, R locs
such that it passes the following test:from matplotlib import pyplot as plt
def checksolutionlocationcoords, R warehouselocs:
# for each location i calculate all locations j within distance R of location i
# use list comprehension instead of accumulating using a nested for loop.
n lenlocationcoords
assert allj and j n for j in warehouselocs f'Warehouse locations must be between and n
neighborhoods j for j in rangen if euclideandistancelocationcoords, i j R for i in rangen
W setwarehouselocs
for i nlist in enumerateneighborhoods:
assert anyj in W for j in nlist f'Location # i has no warehouse within distance R The locations within distance R are nlist
printYour solution passed test'
def visualizesolutionlocationcoords, R warehouselocs:
n lenlocationcoords
xCoords yCoords ziplocationcoords
warehousex warehousey xCoordsj for j in warehouselocsyCoordsj for j in warehouselocs
fig, ax pltsubplots
axsetaspectequal
pltscatterxCoords yCoords
for j in warehouselocs:
circ pltCirclelocationcoordsj R alpha colorglslweck
axaddpatchcirc
for i in rangen:
xy locationcoordsi
axannotatefi locationcoordsi
pltscatterwarehousex warehousey markerxcr s
locationcoords
## TEST
R
printR Test:"
locs solvewarehouselocationlocationcoords, R
printfYour code returned warehouse locatitons: locs
assert lenlocs f'Error: There is an solution involving just locations whereas your code returns lenlocs
visualizesolutionlocationcoords, R locs
checksolutionlocationcoords, R locs
printTest with R has passed'
## TEST
printR Test:"
R
locs solvewarehouselocationlocationcoords, R
printfYour code returned warehouse locatitons: locs
assert lenlocs f'Error: There is an solution involving just locations whereas your code returns lenlocs
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
