필터 지우기
필터 지우기

fmincon - penalty function

조회 수: 9 (최근 30일)
Matthias K
Matthias K 2022년 3월 17일
댓글: Matthias K 2022년 3월 31일
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

채택된 답변

Torsten
Torsten 2022년 3월 17일
편집: Torsten 2022년 3월 17일
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
Torsten
Torsten 2022년 3월 31일
편집: Torsten 2022년 3월 31일
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 2022년 3월 31일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2022년 3월 17일
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
Matthias K
Matthias K 2022년 3월 18일
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 2022년 3월 18일
편집: Matt J 2022년 3월 18일
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).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Linear Least Squares에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by