From 015d4e2a8914c32c09d2c62b96a66de327cd1531 Mon Sep 17 00:00:00 2001 From: "dmy@lab" Date: Mon, 2 Feb 2015 15:37:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E8=99=91=E4=BA=86-100=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dmy@lab --- evolute.m | 11 +++++++++-- initGA.m | 2 +- main.m | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/evolute.m b/evolute.m index 286aefc..40c9851 100644 --- a/evolute.m +++ b/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 diff --git a/initGA.m b/initGA.m index b412366..4ec26be 100644 --- a/initGA.m +++ b/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 diff --git a/main.m b/main.m index 763cb63..39f04a0 100644 --- a/main.m +++ b/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 );