How to fix this problem Genetic Algorithm

3 Ansichten (letzte 30 Tage)
Ana Gabriela Fuentes
Ana Gabriela Fuentes am 27 Nov. 2021
Beantwortet: Walter Roberson am 27 Nov. 2021
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.

Antworten (1)

Walter Roberson
Walter Roberson am 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]);
??

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by