-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnchConflictResolution.m
94 lines (94 loc) · 5.32 KB
/
AnchConflictResolution.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
88
89
90
91
92
93
94
function [newTurbX,newTurbY,newAnchX,newAnchY,lastConflicts,conflicts] =...
AnchConflictResolution(SiteX,SiteY,Angles,TADistance,eps,...
AnchDists,minAnchDist,minTurbDist,existingTurbX,existingTurbY,existingAnchX,...
existingAnchY,lastConflicts,DesignType)
% Resolves distance conflicts between anchors that are too close to each
% other (i.e. less than minAnchDist from each other; 500 meters by
% default). If using single line anchors, the current turbine randomly
% moves to a different location in the site until no anchor conflicts
% remain. If using multiline anchors, the current turbine moves to the
% appropriate position to allow the conflicting anchors to instead share an
% anchor.
conflicts = 1;
currentConflicts = AnchDists(AnchDists < minAnchDist & AnchDists > eps);
% If an anchor is caught between two other anchors less than minAnchDist
% apart, pop it to a random other location. This prevents an infinite loop
% from occurring where the anchor switches back and forth between the two
% nearby anchors. Also do this for arrays using only single line anchors.
if any(ismember(round(currentConflicts,4),round(lastConflicts,4))) || contains(DesignType,'single')
newTurbX = SiteX*rand;
newTurbY = SiteY*rand;
newAnchX = newTurbX + TADistance*cosd(Angles);
newAnchY = newTurbY + TADistance*sind(Angles);
[TurbDists,AnchDists] = ComponentDistance(newTurbX,existingTurbX,...
newTurbY,existingTurbY,newAnchX,existingAnchX,...
newAnchY,existingAnchY);
if all(TurbDists < eps | TurbDists > minTurbDist) && all(AnchDists(:) < eps | AnchDists(:) > minAnchDist)
conflicts = 0;
end
else
[conflictedAnchRow,conflictedAnchCol] = find(AnchDists < minAnchDist & AnchDists > eps);
% If conflicting anchors are in congruent positions to their
% respective turbines (e.g. anchor 1 conflicts with a previous
% anchor 1), pop the current turbine to a different location.
% Without this, turbines could overlap on one another.
for k = 1:length(conflictedAnchCol)
if conflictedAnchRow(k) >= 1 && conflictedAnchRow(k) <= length(existingTurbX)
if conflictedAnchCol(k) == 1
newTurbX = SiteX*rand;
newTurbY = SiteY*rand;
newAnchX = newTurbX + TADistance*cosd(Angles);
newAnchY = newTurbY + TADistance*sind(Angles);
% If conflicting anchors are in complementary positions,
% move the current position to where the anchors overlap.
% This will result in the extra anchor being eliminated
% and the remaining one acting as a shared anchor later on.
else
RelocationCoordX = existingAnchX(conflictedAnchRow(k), conflictedAnchCol(k));
RelocationCoordY = existingAnchY(conflictedAnchRow(k), conflictedAnchCol(k));
newTurbX = RelocationCoordX - TADistance*cosd(Angles(1));
newTurbY = RelocationCoordY - TADistance*sind(Angles(1));
newAnchX = newTurbX + TADistance*cosd(Angles);
newAnchY = newTurbY + TADistance*sind(Angles);
end
elseif conflictedAnchRow(k) >= length(existingTurbX)+1 && conflictedAnchRow(k) <= 2*length(existingTurbX)
if conflictedAnchCol(k) == 2
newTurbX = SiteX*rand;
newTurbY = SiteY*rand;
newAnchX = newTurbX + TADistance*cosd(Angles);
newAnchY = newTurbY + TADistance*sind(Angles);
else
RelocationCoordX = existingAnchX(conflictedAnchRow(k)-length(existingTurbX), conflictedAnchCol(k));
RelocationCoordY = existingAnchY(conflictedAnchRow(k)-length(existingTurbX), conflictedAnchCol(k));
newTurbX = RelocationCoordX - TADistance*cosd(Angles(2));
newTurbY = RelocationCoordY - TADistance*sind(Angles(2));
newAnchX = newTurbX + TADistance*cosd(Angles);
newAnchY = newTurbY + TADistance*sind(Angles);
end
elseif conflictedAnchRow(k) >= 2*length(existingTurbX)+1 && conflictedAnchRow(k) <= 3*length(existingTurbX)
if conflictedAnchCol(k) == 3
newTurbX = SiteX*rand;
newTurbY = SiteY*rand;
newAnchX = newTurbX + TADistance*cosd(Angles);
newAnchY = newTurbY + TADistance*sind(Angles);
else
RelocationCoordX = existingAnchX(conflictedAnchRow(k)-2*length(existingTurbX), conflictedAnchCol(k));
RelocationCoordY = existingAnchY(conflictedAnchRow(k)-2*length(existingTurbX), conflictedAnchCol(k));
newTurbX = RelocationCoordX - TADistance*cosd(Angles(3));
newTurbY = RelocationCoordY - TADistance*sind(Angles(3));
newAnchX = newTurbX + TADistance*cosd(Angles);
newAnchY = newTurbY + TADistance*sind(Angles);
end
end
end
% Recalculate turbine and anchor distances to determine if
% all distance conflicts are resolved.
[TurbDists,AnchDists] = ComponentDistance(newTurbX,existingTurbX,...
newTurbY,existingTurbY,newAnchX,existingAnchX,...
newAnchY,existingAnchY);
if all(TurbDists < eps | TurbDists > minTurbDist) && all(AnchDists(:) < eps | AnchDists(:) > minAnchDist)
conflicts = 0;
end
lastConflicts = currentConflicts;
end
end