Effacer les filtres
Effacer les filtres

fmincon - penalty function

8 vues (au cours des 30 derniers jours)
Matthias K
Matthias K le 17 Mar 2022
Commenté : Matthias K le 31 Mar 2022
Hi,
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);
end
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;
else
d(i) = 0;
end
end
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

Réponse acceptée

Torsten
Torsten le 17 Mar 2022
Modifié(e) : Torsten le 17 Mar 2022
As far as I can see, you could formulate your problem as
min: sum_i (abs(demand(i)-P(i)))
s.c.
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 commentaires
Torsten
Torsten le 31 Mar 2022
Modifié(e) : Torsten le 31 Mar 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 le 31 Mar 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.

Connectez-vous pour commenter.

Plus de réponses (1)

Matt J
Matt J le 17 Mar 2022
Problems
(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 commentaires
Matthias K
Matthias K le 18 Mar 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 le 18 Mar 2022
Modifié(e) : Matt J le 18 Mar 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).

Connectez-vous pour commenter.

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by