fmincon - penalty function

36 Ansichten (letzte 30 Tage)
Matthias K
Matthias K am 17 Mär. 2022
Kommentiert: Matthias K am 31 Mär. 2022
I have the following problem:
I have a data set with half-hourly data for gas production and electricity demand. These are now to be brought together via a CHP (with a certain capacity). The produced gas is to be converted into electricity to cover the electricity demand as well as possible. So I am looking for a power P at each point in time.
To do this, I have calculated the deviation between demand and power in an objective function e and then summed it up.
q = fmincon(@(x) obj_func(x,P,demand,z,P_max,V_level,V_initial,V_size,V_proz,production,BHKW_mode,d),x0,[],[],[],[],lb,ub);
function e = obj_func(x,P,demand,z,P_max,V_level,V_initial,V_size,V_proz,production,BHKW_mode,d)
e = (demand - P).^2;
e = sum(e) + sum(d);
This objective function is then to be minimized with fmincon. This is done and at any time I get : P = demand (why should it not be so).
But now my constraint comes into play.
The gas comes first into a storage and if gas is converted into electricity, the storage content becomes smaller by this quantity.
V_level(1) = V_initial + production(1) - P(1);
for i = 2:z
V_level(i) = V_level(i-1) + production(i) - P(i);
V_proz = 100*V_level/V_size;
And this storage may never be fuller than 100 % and never emptier than 0 %. I tried to realize this with a penalty function, which is added to e.
for i = 1:z
if V_proz(i) > 100
d(i) = 100000;
elseif V_proz(i) < 0
d(i) = 100000;
d(i) = 0;
But no matter how big I choose the penalty for non-compliance with this condition: Nothing changes in the result, it is not considered by the optimizer at all....
Does anyone have any idea where my error lies or how I can solve it differently?
Thank you for your help, Matthias

Akzeptierte Antwort

Torsten am 17 Mär. 2022
Bearbeitet: Torsten am 17 Mär. 2022
As far as I can see, you could formulate your problem as
min: sum_i (abs(demand(i)-P(i)))
Pmin <= P(i) <= Pmax
0 <= V_level(i) <= V_size
V_level(i) = V_level(i-1) + production(i) - P(i)
If the difference to your former objective
min: sum_i (demand(i)-P(i))^2
is acceptable, this can be formulated as a linear optimization problem in the unknown P and V_level.
Use linprog to solve.
  9 Kommentare
Torsten am 31 Mär. 2022
Bearbeitet: Torsten am 31 Mär. 2022
And which of the inputs to patternsearch did you fill ?
A, b, Aeq, beq, lb, ub, nonlcon ?
From the description, patternsearch should turn out to be quite safe, but extremely slow.
Matthias K
Matthias K am 31 Mär. 2022
Just lb and ub.
I went back to just determine the values for P. so: x=(P(1),...,P(n))
Patternsearch didn't get along well with my many linear equality constraints, because then it doesn't find an initial point for its search which complies with the l.e. constraints.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Matt J
Matt J am 17 Mär. 2022
(1) The objective function code you've shown appears to depend on everything except the unknown variables x
(2) Assuming V_proz was supposed to be one of the unknowns, your penalty d is a discontinuous function of it.
  10 Kommentare
Matthias K
Matthias K am 18 Mär. 2022
yes, x(idx) shoudl be 0;
If x(idx) = P_min, I would have jump discontinuities near x(i)=0, wouldn't I?
But thanks a lot, for your answers, I've realized a lot of mistakes I made. I'll try to formulate my problem a little different
Matt J
Matt J am 18 Mär. 2022
Bearbeitet: Matt J am 18 Mär. 2022
If x(idx) = P_min, I would have jump discontinuities near x(i)=0, wouldn't I?
No, assuming P_min>0, it would be flat at x(i)=0, which you should see if you plot your obejctive as a function of any particular x(i).

Melden Sie sich an, um zu kommentieren.




Community Treasure Hunt

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

Start Hunting!

Translated by