What is the state structure for mixed integer ga optimization?

24 Ansichten (letzte 30 Tage)
Robbe Deproost
Robbe Deproost am 12 Dez. 2024 um 19:12
Bearbeitet: Matt J am 12 Dez. 2024 um 19:53
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!

Antworten (2)

Matt J
Matt J am 12 Dez. 2024 um 19:15
memoize might be a more direct way to achieve what you are pursuing.

Catalytic
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
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);
Current CustomField value: 1 Current CustomField value: 2 Current CustomField value: 3 Current CustomField value: 4 Current CustomField value: 5 Current CustomField value: 6 Current CustomField value: 7 Current CustomField value: 8 Current CustomField value: 9 Current CustomField value: 10 Current CustomField value: 11 Current CustomField value: 12 Current CustomField value: 13 Current CustomField value: 14 Current CustomField value: 15 Current CustomField value: 16 Current CustomField value: 17 Current CustomField value: 18 Current CustomField value: 19 Current CustomField value: 20 Current CustomField value: 21 Current CustomField value: 22 Current CustomField value: 23 Current CustomField value: 24 Current CustomField value: 25 Current CustomField value: 26 Current CustomField value: 27 Current CustomField value: 28 Current CustomField value: 29 Current CustomField value: 30 Current CustomField value: 31 Current CustomField value: 32 Current CustomField value: 33 Current CustomField value: 34 Current CustomField value: 35 Current CustomField value: 36 Current CustomField value: 37 Current CustomField value: 38 Current CustomField value: 39 Current CustomField value: 40 Current CustomField value: 41 Current CustomField value: 42 Current CustomField value: 43 Current CustomField value: 44 Current CustomField value: 45 Current CustomField value: 46 Current CustomField value: 47 Current CustomField value: 48 Current CustomField value: 49 Current CustomField value: 50 Current CustomField value: 51 Current CustomField value: 52 Current CustomField value: 53 Current CustomField value: 54 Current CustomField value: 55 Current CustomField value: 56 Current CustomField value: 57 Current CustomField value: 58 Current CustomField value: 59 Current CustomField value: 60 Current CustomField value: 61 Current CustomField value: 62 Current CustomField value: 63 Current CustomField value: 64 Current CustomField value: 65 Current CustomField value: 66 Current CustomField value: 67 Current CustomField value: 68 Current CustomField value: 69 Current CustomField value: 70 Current CustomField value: 71 Current CustomField value: 72 Current CustomField value: 73 Current CustomField value: 74 Current CustomField value: 75 Current CustomField value: 76 Current CustomField value: 77 Current CustomField value: 78 Current CustomField value: 79 Current CustomField value: 80 Current CustomField value: 81 Current CustomField value: 82 Current CustomField value: 83 Current CustomField value: 84 Current CustomField value: 85 Current CustomField value: 86 Current CustomField value: 87 Current CustomField value: 88 Current CustomField value: 89 Current CustomField value: 90 Current CustomField value: 91 Current CustomField value: 92 Current CustomField value: 93 Current CustomField value: 94 Current CustomField value: 95 Current CustomField value: 96 Current CustomField value: 97 Current CustomField value: 98 Current CustomField value: 99 Current CustomField value: 100 Current CustomField value: 101 Current CustomField value: 102 Current CustomField value: 103 Current CustomField value: 104 Current CustomField value: 105 ga stopped because the average change in the fitness value is less than options.FunctionTolerance. FINAL VALUE: 105
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Performance and Memory finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by