-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateCustomerGrid.m
41 lines (29 loc) · 1.18 KB
/
updateCustomerGrid.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function [ ] = updateCustomerGrid( )
global customerGrid n noOfStores storeLocation storePrice
for i=1:n
for j=1:n
min = distanceFormula(storePrice(1,1), [i j], storeLocation(1,:) );
distance = zeros(1, noOfStores);
sameDistance = zeros(noOfStores);
count = 2;
for k=1:noOfStores
distance(1,k) = distanceFormula(storePrice(1,k), [i j], storeLocation(k,:) );
if distance(1,k) <= min
min = distance(1,k);
sameDistance(1) = k;
end
end
for k=1:noOfStores
if distance(1,k) == min && k ~= sameDistance(1)
sameDistance(count) = k;
count = count + 1;
end
end
nearestStore = sameDistance(randi(count-1,1,1));
customerGrid(i,j) = nearestStore;
end
end
for i=1:noOfStores
customerGrid(storeLocation(i,1), storeLocation(i,2)) = i + noOfStores;
end
end