genetic algorithm tool (Bit string)
조회 수: 1 (최근 30일)
이전 댓글 표시
%first way%
function g =myfitnesstest(X)
s=0;
if (X(1)==1)
s=s+1;
end
if (X(2)==1)
s=s+2;
end
if (X(3)==1)
s=s+4;
end
if (X(4)==1)
s=s+8;
end
if (X(5)==1)
s=s+16;
end
LAMDA=s;
TYPE=1;
ITER=1000;
R1=Routing3a3(TYPE,LAMDA,ITER);
g=-R1;
end
---------
%second way%
function g =myfitness2(X)
LAMDA=X(1)+X(2)*2+X(3)*4+X(4)*8
TYPE=1;
ITER=1000;
R1=Routing3a(TYPE,LAMDA,ITER);
g=-R1;
end
------ when i use this (first way) the matlab run it very very slowly. when i use (second way) the matlab run with out stopping with many solution with repeating. i want way to represent the value of X with bit string type to find the optimal solution (by using Matlab gatool )
댓글 수: 0
답변 (1개)
Jonathan Epperl
2012년 12월 30일
I can't try right now, but I am fairly certain that your first few if statements could be substituted by
s = 2.^(0:4) *X(:);
only this would be muuuuch faster, that should explain why your way 1 is so slow.
Of course we don't know what Routing3a does, so hard to help you if there's an error in there.
And lastly, it appears to me that
g=(R1);
while(g>=99)
g
break
end
is nothing but
if R1>=99
R1
end
so what is that line supposed to be doing?
댓글 수: 7
참고 항목
카테고리
Help Center 및 File Exchange에서 Genetic Algorithm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!