Genatic Algorithm input and output in vector form
1 次查看(过去 30 天)
显示 更早的评论
Hi, I am facing a problem while using Builtin Genatic Algorithm *ga*.
Usually when we run *ga* over fitness function @(x), the variable in fitness function Let say *a* take the value as a=x(1), and other variable b=x(2). So, we have two variables, output of *ga* is 1*2 (array with two elements).
But for my case, istead of using *a=x(1)* i want variable *a* as a vector of 10 rows : a=x(:,1) and similarly the second variable also of 10 rows: *b=x(:,2)*. So, the output of *ga* should be 10*2. Is there any way we can force ga to work with vectors (input and output).
0 个评论
采纳的回答
Walter Roberson
2023-1-4
(There is an exception to that if you turn on the Vectorized option)
So, No, there is no way to arrange to have the function pass in a 2D array of values that you can then access rows or columns of.
You can, however, reshape() the vector you receive as the first thing you do.
Remember that constraints and bounds will be in terms of vectors of values. So if you wanted to create a lowerbound specification in terms of columns, the first column intended to correspond to a and so on, then you can go ahead and create the constraints in that form -- just remember to reshape() the constraint array to pass it in.
You may wish to consider using Problem Based Optimization, which allows you to build constraints and objectives in terms of operations on vectors and arrays, and internally it builds the appropriate functions and vectors necessary.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!