Genatic Algorithm input and output in vector form

5 visualizaciones (últimos 30 días)
moaad
moaad el 4 de En. de 2023
Respondida: Walter Roberson el 4 de En. de 2023
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).

Respuesta aceptada

Walter Roberson
Walter Roberson el 4 de En. de 2023
Write the objective function to accept a row vector of length nvars and return a scalar value.
(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.

Más respuestas (0)

Categorías

Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by