Filter löschen
Filter löschen

automatic change in variable's value during optimisation

3 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 20 Apr. 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 Kommentare
Torsten
Torsten am 21 Apr. 2024
Bearbeitet: Torsten am 21 Apr. 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 am 21 Apr. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by