automatic change in variable's value during optimisation

1 visualización (últimos 30 días)
I am currently working on optimising the cost of charge of an electric vehicule by scheduling a charging/discharging process during 9 intervals.
During the process an uncertainty of battery degradation occures in a specific interval, the capacity is reduced from 60ah to 58.2ah.
My question is to how to update the new value while the code is running so the optimisation algorithm performs a rescheduing based on the new value ? Thank you.

Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de Abr. de 2024
You do not do that. It is a truism that during any one call to the optimization routine, that given any particular set of trial parameters, the cost function must always return the same value for those trial parameters. No scheduling is possible.
You need to instead loop running the optimization function in segments of consistent parameters.
For example,
nvars = 17; %adjust as needed
maxphases = 9;
battery_degredation = linspace(60, 58.2, maxphases);
pop = [];
scores = [];
A = []; b = [];
Aeq = []; beq = [];
lb = []; ub = [];
nonlcon = [];
for phase = 1 : maxphases
if phase == 1
opts = optimoptions('ga', 'MaxFunctionEvaluations', 1000, 'MaxIterations', 1000);
else
opts = optimoptions(opts, 'InitialPopulationMatrix', pop, 'InitialScoresMatrix', scores);
end
[X,FVAL,EXITFLAG,OUTPUT,pop,scores] = ga(@(PARAMS) do_cost_function(PARAMS, batter_degredation(phase)), nvars, A, b, Aeq, beq, lb, ub, nonlcon, opts);
if EXITFLAG < 0
warning('EXITFLAG %d on phase %d', EXITFLAG, phase);
break
end
end
  3 comentarios
Torsten
Torsten el 21 de Abr. de 2024
Editada: Torsten el 21 de Abr. de 2024
The code above assumes that the 9 phases can be optimized one after the other without coupling. Only the result of the last phase is used as initial input for the next phase.
The parameter "battery-degradation" is passed to your cost function so that it can be used there depending on the specific interval you are in:
[X,FVAL,EXITFLAG,OUTPUT,pop,scores] = ga(@(PARAMS) do_cost_function(PARAMS, battery_degredation(phase)), nvars, A, b, Aeq, beq, lb, ub, nonlcon, opts);
Walter Roberson
Walter Roberson el 21 de Abr. de 2024
I just realized that it should probably be
opts = optimoptions(opts, 'InitialPopulationMatrix', pop);
with no initial scores matrix -- the scores will change with the degraded battery.
The way this code works is to optimize a population given a particular battery degredation. Then it takes the optimal locations and uses them as starting points for the next phase, with the next battery degredation.
Because I used ga() here, mutation and cross-over will be taking place. As a result, the effect is not of tracing particles through from the beginning to the end. Each phase is effectively providing hints to the next phase, but only hints. And if you take the final population and run them through the cost calculations from the start, then you might get fairly different answers.
To be honest, I think the whole approach is not likely to match your needs.
I suspect that you instead need to model each phase as a variable (or two) that describes the charging strategy for the phase, and model the overall "score" of the charging somehow.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by