-
Notifications
You must be signed in to change notification settings - Fork 1
/
psoDiscRandomFact.m
46 lines (31 loc) · 1.07 KB
/
psoDiscRandomFact.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
function pRand = psoDiscRandomFact( particlePos, distances, iterSteps, type )
switch(type)
case 'edgeExch'
pRand = edgeExchRandomFact( particlePos, iterSteps );
case '2opt'
pRand = twoOptRandomFact( particlePos, distances );
otherwise
pRand = particlePos;
end
end
function pRand = edgeExchRandomFact( particlePos, iterSteps )
if iterSteps <= 0 || isempty(iterSteps)
iterSteps = 2;
end
pRand = particlePos;
edgeExch = [];
for randIter=1:1:iterSteps
while true
startR = max(round((size(pRand,2)-1)*rand(1) + 1),1);
endR = startR + max(round((size(pRand,2)-1)*rand(1) + 1),1);
if r(startR, pRand) ~= r(endR, pRand)
edgeExch = [edgeExch; r(startR, pRand) r(endR, pRand)];
break
end
end
end
pRand = applyEdgeExchange( edgeExch, pRand );
end
function pRand = twoOptRandomFact( particlePos, distances )
[pRand, ~] = opt2(particlePos, distances);
end