What is the state structure for mixed integer ga optimization?
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everyone
Currently I'm working on a mixed integer ga optimization. In my nonlcon constraint function, I have to perform 5 finite element calculations for every individual, which is very time consuming. I want to implement a cache that stores all the previous individuals and their penalty value, so if in a future generation this individual has already been computed, the penalty value can just be taken from the cache en doesn't have to be computed again. For now I use the state structure to store each population, but for the penalty value I don't seem to find a field which is appropriate. I want to use .Score, but now I only get non-feasible individuals anymore. Does anyone how this may come and how I can resolve this? I think I also need a field to know wether a solution is feasible or not, but the .how field doesn't work for the mixed integer ga optimization.
Thanks in advance!
0 Kommentare
Antworten (2)
Matt J
am 12 Dez. 2024 um 19:15
memoize might be a more direct way to achieve what you are pursuing.
0 Kommentare
Catalytic
am 12 Dez. 2024 um 19:28
I assume the "state structure" you're talking about is for an OutputFcn. If so, the state structure is not something that can be used to cache data from previous iterations or generations. Anything you put in the state structure is discarded after the OutputFcn finishes executing. To record data from previous iterations, you should store use externally scoped variables like in this example.
1 Kommentar
Matt J
am 12 Dez. 2024 um 19:53
Bearbeitet: Matt J
am 12 Dez. 2024 um 19:53
No, in ga, the state structure propagates to future generations. You can also add custom fields to the state structure to record the previous population members and penalty values (see example below). I just think memoize() might be easier.
% Now call the GA function with this OutputFcn
options = optimoptions('ga', 'OutputFcn', @myOutputFcn);
% Define a simple objective function for the GA
objFun = @(x) sum(x.^2); % Objective: Minimize the sum of squares of the variables
% Set GA parameters (e.g., number of variables and population size)
nvars = 5; % Number of decision variables
populationSize = 50;
% Run the GA
[x, fval] = ga(objFun, nvars, [], [], [], [], -5*ones(1, nvars), 5*ones(1, nvars), [], options);
function [state, options, stop] = myOutputFcn(options, state, flag)
switch flag
case 'init'
% Initialize a custom field at the start
state.CustomField = 0; % Add a new field to the state structure
case 'iter'
% Modify the custom field in each iteration
state.CustomField = state.CustomField + 1; % Increment it for each iteration
disp(['Current CustomField value: ', num2str(state.CustomField)]);
case 'done'
% Do something when optimization is done
disp(['FINAL VALUE: ', num2str(state.CustomField)]);
end
stop = false; % Prevent premature stopping
end
Siehe auch
Kategorien
Mehr zu Performance and Memory finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!