Genetic Algorithm - Your fitness function must return a scalar value solution?
3 ビュー (過去 30 日間)
I have been working on my GA code for some time. Have been getting some weird results with my code so I tried to implement it with example from documentation (https://www.mathworks.com/help/gads/constrained-minimization-using-ga.html). It seems that my fitness function is badly coded and is not returning scalar value. Therefore, the algorithm is unable to compare solutions and the code stops. I have pinpointed the problem - loading data inside function. Data are, among other, drive cycle (speed and acceleration - both 1x661 matrix). So my fitness function returns 1x661 matrix.
So my GA is not for optimizing a function of two variables, but optimizing a function of two variables at every instant of drive cycle (661 instances).
How can I load my drive cycle data (podaci_matlab.mat) in "one-by-one" manner so I can get a scalar value?
I have attached all necessary files.
Thanks in advance !
Alan Weiss 2022 年 6 月 12 日
I am not sure what you are trying to do. Your objective function has 661 components. Are you trying to solve for 661 different values of x(1) and x(2)? If so, you should write a loop and solve 661 different problems.
Or are you trying to use the same x(1) and x(2) for all 661 objectives? In that case, your problem is not well-defined. Undoubtedly, some values of x will optimize the first objective, but different values will optimize other objectives.
I did not talk about your constraints, but if you can answer the first question, then I would imagine that you can figure out if you have 661 different problems and you have potentially different constraints for each problem, or if you have a huge multiobjective problem.
You should definitely NOT call load within the loop, if as I suspect you have 661 different problems. Load the data once and then pass it into the loop.
And one more thing. It seems that your x(2) variable takes just five values. You should not use interpolation for this. Instead, you should declare x(2) to be integer-valued with lower bound 1 and upper bound 5, and then use roundTargets(round(x(2)) as the value. (I threw the round function in case x(2) is not exactly an integer. It might be superfluous.)
MATLAB mathematical toolbox documentation