How to fix this problem Genetic Algorithm

3 views (last 30 days)
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.

Answers (1)

Walter Roberson
Walter Roberson on 27 Nov 2021
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]);
??

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!