-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakingSTWv_Adj.m
87 lines (75 loc) · 2.45 KB
/
makingSTWv_Adj.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
% makingSTWv_Adj
% this function will create all s, t, weights, and v_Adj based off of the disntace and not have an
% edge to every battery level
% INPUTS
% area = is one dimension of the total area where the points are made (row
% x col = total area, it is row)
% x = the original points
% y = the original points that correspond to x
% numPoints = the amount of original points
% numLevels = the amount of levels
% v_Adj = this is the adjacency matrix that gives the costs
% OUTPUTS
function [sNew, tNew, weights, v_AdjNew, allDistances] = makingSTWv_Adj(area, x, y, numPoints, numLevels, v_Cluster)
maxDistance = sqrt((area(1)-area(2))^2+(area(3)-area(4))^2);
maxDistancePerLevel = maxDistance/numLevels;
tempLevelArray = [];
for i = 1:numLevels
tempLevelArray(end+1) = i;
end
allDistances = [];
for i = 1:numPoints
for j = 1:numPoints
comparingPoints = [x(i), y(i); x(j), y(j)];
allDistances(i, j) = pdist(comparingPoints, 'euclidean');
end
end
allDistancesRounded = ceil(allDistances./maxDistancePerLevel);
% outputv_Adj = v_Adj;
totalPoints = numPoints * numLevels;
tempv_AdjFinal = Inf(totalPoints);
tempv_Adj(1:totalPoints, 1:numPoints) = 0;
for i = 1:numPoints
fillArray = allDistancesRounded(i, :);
for j = 1:numLevels
tempv_Adj((i-1)*numLevels+j, 1:numPoints) = fillArray;
end
end
for i = 1:numPoints
fillArray = tempv_Adj(:, i);
for j = 1:numLevels
tempv_AdjFinal(1:totalPoints, (i-1)*numLevels+j) = fillArray;
end
end
pointA = [];
pointB = [];
sNew = [];
tNew = [];
weights = [];
matv_Cluster = cell2mat(v_Cluster);
for i = 1:numPoints
pointA = find(matv_Cluster == i);
for j = 1:numPoints
node = find(matv_Cluster == i, 1);
numOfIterations = allDistancesRounded(i, j);
% pointB = find(v_Cluster == j);
weightIJ = allDistances(i, j);
for k = 1:(numLevels-numOfIterations+1)
if numOfIterations == 0 || i == j % you don't need both conditions because they do the same thing, but it helps me remember how things work
break;
end
pointB = find(matv_Cluster == j);
sNew(end+1) = node;
pointB = circshift(pointB, -(numOfIterations+k-1));
tNew(end+1) = pointB(1);
node = node+1;
weights(end+1) = weightIJ;
end
end
end
numOfEdges = numel(sNew);
v_AdjNew = zeros(totalPoints);
for i = 1:numOfEdges
v_AdjNew(sNew(i), tNew(i)) = weights(i);
end
end