MATLAB Answers

genetic algorithm - reg

조회 수: 3(최근 30일)
I want to use genetic algorithm for inventory classification. Number of variables is 6. All the variables must lie between 0 and 1. If we add first 4 variables, the sum must be 1. Also 5 th variable must be greater than 6 th variable. My doubt is whether the Fitness function should return a single scalar value or the fitness function should return all the fitness values of the population. I think the GA can be solved using the toolbox of GA in MATLAB. I tried to run GA in optimtool toolbox. The population size is 50. The fitness function is InvGAClassifyFitnessFunc(Position, classGA1,ClassDM!) where Position is the chromosome with the above properties. I have written the inequalities as Aineq=[0,0,0,0,-1,1] Bineq=0;
Aeq as [1,1,1,1,0,0] and Beq as [1];
lb as [0,0,0,0,0,0] and ub as [1,1,1,1,1,1];
creation function as constraint-dependent. Population type is double.Scaling function as Rank. Selection function as 'Roulette'.Mutation function as 'Adaptive feasible'. Crossover function as 'Constraint dependent'. All other options as default.
When i ran this problem in MATLAB it is giving error " Not enough input arguments".
Please guide me.

  댓글 수: 0

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 11 Dec 2018
Your fitness function will be passed a single population member in the form of a vector . It should return aa scalar . ga will call it as many times as needed to pass in all the population members .
Your fitness function appears to require 3 inputs needing classGA1 and ClassDM1 as the second and third parameters . ga only passes a single parameter to the fitness function . You probably need to paramaterize the fitness function
ff = @(Position) InvGAClassifyFitnessFunc(Position, classGA1, ClassDM1 )
and then pass ff as the fitness function .

  댓글 수: 3

Kallam Haranadha Reddy
I wrote the following code to run genetic algorithm . The best fitness and mean fitness are remaining same at 1 through out the generations. Where did i made the mistake.
[ Position ] = InvClassifyGAFunc2(4,68);
[classGA1 ] = @(Position)InvClassifyGAWeightedSumFunc(Position);
for i=1:68
ff = @(Position) InvClassifyGAFitnessFunc(Position, classGA1, ClassDM1 ) ;
options= gaoptimset('PlotFcn',@gaplotbestf);
Walter Roberson
Walter Roberson 11 Dec 2018
Note: char(68,1) does not reserve a 68 x 1 array of characters. char(68,1) is the same as
[char(68); char(1)]
which takes the character that is assigned position 68, namely 'D', and put below it the character assigned position 1, namely SOH, Start Of Heading.
Walter Roberson
Walter Roberson 11 Dec 2018
It would be easier if we had your source code to work with.
for i=1:68
Okay so the first ClassDM1{i,1} assignment extracts some data from Data.ClassDM. But then the second one overwrites what was just assigned... overwrites it with itself ??
and that overwrites the cell array just built up, with a function handle to an anonymous function that extracts one cell (not the contents of the cell) from a variable that is still only initialized to cell(68,1) ?
And the function handle is being passed as a parameter to InvClassifyGAFitnessFunc ??

댓글을 달려면 로그인하십시오.

추가 답변(0개)




Community Treasure Hunt

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

Start Hunting!

Translated by