parent
d758ad5005
commit
015d4e2a89
11
evolute.m
11
evolute.m
|
|
@ -1,9 +1,16 @@
|
|||
function [ selectedIndex ] = evolute( selectedIndex,randSNCount )
|
||||
function [ selectedIndex ] = evolute( selectedIndex,randSNCount,snSolar )
|
||||
%修改领域
|
||||
changeN=1;%选择多少时段进行修改。
|
||||
changedIndex=1:96;
|
||||
changedIndex=changedIndex( round(1+(96-1)*rand(changeN,1)) );
|
||||
selectedIndex(:,changedIndex)=round(1+(16-1)*rand(randSNCount,changeN));%这是改变后的值
|
||||
for c=1:length(changedIndex)
|
||||
% selectedIndex(:,changedIndex)=round(1+(16-1)*rand(randSNCount,changeN));%这是改变后的值
|
||||
if abs(snSolar(16,c)-(-100))<1e-5
|
||||
selectedIndex(:,c)=round(1+(4-1)*rand(randSNCount,1));%这是改变后的值
|
||||
else
|
||||
selectedIndex(:,c)=round(1+(16-1)*rand(randSNCount,1));%这是改变后的值
|
||||
end
|
||||
end
|
||||
% [ selectedWind,selectedSolar,candidateP ] = generateCandidate( snWind,snSolar,snP,randSNCount,selectedIndex );
|
||||
end
|
||||
|
||||
|
|
|
|||
2
initGA.m
2
initGA.m
|
|
@ -1,6 +1,6 @@
|
|||
function [ selectedIndex] = initGA( randSNCount )
|
||||
% 随机生成一下初始场景序列
|
||||
selectedIndex=round(1+(16-1)*rand(randSNCount,96));
|
||||
selectedIndex=round( [1+(4-1)*rand(randSNCount,5),1+(16-1)*rand(randSNCount,14),1+(4-1)*rand(randSNCount,9),1+(16-1)*rand(randSNCount,16),1+(4-1)*rand(randSNCount,9),1+(16-1)*rand(randSNCount,14),1+(4-1)*rand(randSNCount,11),1+(16-1)*rand(randSNCount,12),1+(4-1)*rand(randSNCount,6)] );
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
4
main.m
4
main.m
|
|
@ -22,7 +22,7 @@ end
|
|||
|
||||
bestFitness=0;
|
||||
bestIndex=0;
|
||||
for LOOP=1:100
|
||||
for LOOP=1:500
|
||||
fprintf('第%d次迭代\n',LOOP);
|
||||
fprintf('最好适度函数%f\n',bestFitness);
|
||||
for I=1:gaCount
|
||||
|
|
@ -34,7 +34,7 @@ for LOOP=1:100
|
|||
end
|
||||
|
||||
for I=1:gaCount
|
||||
[ selectedIndex] = evolute(selectedIndex,randSNCount );
|
||||
[ selectedIndex] = evolute(selectedIndex,randSNCount,snSolar );
|
||||
ga(I).selectedIndex=selectedIndex;
|
||||
[ selectedWind,selectedSolar,candidateP ] = generateCandidate( snWind,snSolar,snP,randSNCount,ga(I).selectedIndex );
|
||||
[ fitness ] = fitnessFun( selectedWind,selectedSolar,candidateP,randSNCount );
|
||||
|
|
|
|||
Loading…
Reference in New Issue