How to fix this problem Genetic Algorithm
3 次查看(过去 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!