How to fix this problem Genetic Algorithm
조회 수: 9 (최근 30일)
이전 댓글 표시
This error appears in my code while trying to run it. I´m using this Genetic Algorithm to solve the problem of knapsack. Someone can tell me what im doing wrong?
I attach the code and the excel of the problem.
in the Excel file, first column is the article, second column the weight and third is the value. Im trying to solve for the optimal combination. 

댓글 수: 0
답변 (1개)
Walter Roberson
2021년 11월 27일
initpop = randi([0,1]);
So initpop is a single random scalar value, either 0.0 or 1.0 ?
pop= initpop(popsize,n) %初始种群initpop.m
So you are attempting to index that scalar value at (1000, something) ?
function pop=initpop(popsize,n)
but then it is also to be a function ??
Why are you doing
initpop = randi([0,1]);
??
댓글 수: 0
참고 항목
카테고리
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!