Objective: Given a list of customer coordinates (xi, yi) and the volume of mater
ID: 3739919 • Letter: O
Question
Objective: Given a list of customer coordinates (xi, yi) and the volume of material Vi to be distributed to those customers, find the location of a distribution center (a, b) that would minimize the total distribution costs Description: In a standard Euclidean plane with origin at (0,0), assume we have the following data for n customers: customer x (miles) (miles) Volume (tons/week) V? T2 T3 y2 ?? 34 3 yn The total delivery cost depends on the volume to be delivered Vi and the distance a customer from the distribution center. Assuming the distribution center is at coordinates (a, b), we will just use the Euclidean distance formula for the distance di to reach each customer. The cost ci for customer i can be approximated by diVi The distribution center will be placed somewhere at integer coordinates (a, b) with 0 S a 30 and 0 b The goal is to create a function that accepts input vectors z and y and V containing the dat columns of the table, and outputs the location values a and b representing the best location for the d 50 a in the above nter, that is, the one that minimizes the TOTAL cost for delivering to all customers Directions: Download the template function file named delivery.m and add your name and date in the ents on the indicated lines. Fill in the code to accomplish the objectives below. Inside the function file you will also see two local functions. Create the local functions first, then call them inside n function whenever needed as a way to simplify your code. Your main function file the following: 1. The name of the main function should be 'delivery' and have the form function [a,b] delivery (x,y,V) 2. It should accept three inputs, x, y, and V. The first input will be a row vector with all of the r-coordinates for the locations of each customer. The second input will be a row vector with all of the y-coordinates for the locations of each customer. The third input will be a row vector V containing the weekly volumes requested by each customer. Your function should should produce two outputs a and b, which are the best coordinates for the distribution center as described above.Explanation / Answer
Matlab Script for delivery(x,y,V):--
function [a,b]=delivery(x,y,V)
oldcost=inf;
for i=0:1:30 %for eavery position in the intervel 0<=i<=30
for j=0:1:50 %for eavery position in the intervel 0<=j<=50
newcost=totalCost(x,y,V,i,j); %cost for distribution from the point (i,j)
if newcost<oldcost %if cost if lessthan previous cost
a=i; %assign new a as i for new x position
b=j; %assign new b as j for new y position
oldcost=newcost; %assign newcost to oldcost for next compare
end
end
end
end
Matlab Script for totalCost(x,y,V,A,B):--
function [C]=totalCost(x,y,V,A,B)
length=size(x); %find length for x
for k=1:length(2) %for every point given point (x(k),y(k))
distance=dist(x(k),y(k),A,B); %calculate distance from point (A,B)
cost(k)=distance*V(k)/2; %calculate cost to point (x(k),y(k)) from distribution center at (A,B)
end
C=sum(cost); %calculate total cost from distribution center at (A,B)
end
Matlab Script for dist(X,Y,A,B):--
function [d]=dist(X,Y,A,B)
d=sqrt((A-X).^2+(B-Y).^2); %distance between points (X,Y) and (A,B)
end
Sample output:--
>> x=[1 18 3 20 15 30];
>> y=[1 20 3 45 25 30];
>> v=[100 200 150 50 60 90];
>> [a,b]=delivery(x,y,v)
a =
18
b =
20
>>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.