フィルターのクリア

Ga does not find the optimal value

2 ビュー (過去 30 日間)
Erik Beste
Erik Beste 2022 年 5 月 4 日
コメント済み: Erik Beste 2022 年 5 月 5 日
Hi Matlab comunity after I tried fmincon:
I now tried ga to solve my problem with integers
x=ga(@(x)fAraucoMarkt(x,AraucoEnergy),4,[],[],[],[],LB,RB,@(x)bedMarkt(x,AraucoEnergy),[2:4]);
I guess it works but I do not get the optimal solution:
x=ga(@(x)fAraucoMarkt(x,AraucoEnergy),4,[],[],[],[],LB,RB,@(x)bedMarkt(x,AraucoEnergy),[2:4]);
Optimization terminated: average change in the penalty fitness value less than options.FunctionTolerance
but constraints are not satisfied.
Is there anyway to get a better solution (I was thinking of random starting numbers and than a list of all found solutions) but as I can not define start point I do not know how to get this.
And while I am at it I had an nonlinear eauqlity constrain which was like this
ceq(1)=Restschuld-0;
I was thinking in changing it to a inequality constrain Restschuld is smaller than 1 and bigger than -1
but I dont know how to do this any idea?
Anyone an Idea
Greetings
Erik
  2 件のコメント
Walter Roberson
Walter Roberson 2022 年 5 月 4 日
Restschuld is smaller than 1 and bigger than -1
Those would be bounds constraints, which you would store in LB and RB
Erik Beste
Erik Beste 2022 年 5 月 4 日
So my conditions are like this
function [c,ceq] = bedMarkt(x,AraucoEnergy)
%UNTITLED5 Summary of this function goes here
% Detailed explanation goes here
minSpeicher=fminSpeich(x,AraucoEnergy);
Restschuld=fRestschuld(x,AraucoEnergy);
c=0.1-minSpeicher;
ceq=Restschuld-0;
end
I tought that the bound constrains just adress the input parameters

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2022 年 5 月 4 日
You have 3 variables, each of which can only be the integers 2, 3, or 4. That is only 3^3 = 27 possibilities.
Just run all of those possibilities separately, in a loop, with those variables as constants for the duration of the run.
This would have the additional advantage that since you would no longer have integer constraints, you would be able to add your own nonlinear constraint function.
  13 件のコメント
Torsten
Torsten 2022 年 5 月 4 日
編集済み: Torsten 2022 年 5 月 4 日
xf = zeros(1,3);
LB = 0;
RB = 1;
%optval = Inf;
index = 0;
for i = 0:15
for j = 1:30
for k = 0:70
%Fremdkapitalanteil
x0 = (RBFK-LBFK).*rand(1,1) + LBFK;
xf(1) = i;
xf(2) = j;
xf(3) = k;
[x,fval]=fmincon(@(x)fAraucoMarkt(x,xf,AraucoEnergy),x0,[],[],[],[],LB,RB,@(x)bedMarkt(x,xf,AraucoEnergy));
%if fval < optval
% optval = fval;
% xopt = x;
% xopt1 = i;
% xopt2 = j;
% xopt3 = k;
%end
index = index + 1;
Return=fAraucoMarkt(x,xf,AraucoEnergy);
Results(index,1:4)=[x,xf];
Results(index,5)=Return;
Results(index,6)=fminSpeich(x,xf,AraucoEnergy);
Results(index,7)=fRestschuld(x,xf,AraucoEnergy);
end
end
end
Erik Beste
Erik Beste 2022 年 5 月 5 日
I used it and it works perfectly fine thanks a lot all of you !

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2022 年 5 月 4 日
編集済み: Matt J 2022 年 5 月 4 日
I was thinking in changing it to a inequality constrain Restschuld is smaller than 1 and bigger than -1
I'm surprised you were even able to run the code in its current form. From the ga documentation:
"When intcon is nonempty, nonlcon must return empty for ceq. For more information on integer programming, see Mixed Integer ga Optimization."
  1 件のコメント
Erik Beste
Erik Beste 2022 年 5 月 4 日
@Matt J sorry I changed it
function [c,ceq] = fbedga(x,AraucoEnergy)
%UNTITLED5 Summary of this function goes here
% Detailed explanation goes here
minSpeicher=fminSpeich(x,AraucoEnergy);
Restschuld=fRestschuld(x,AraucoEnergy);
c(1)=0.1-minSpeicher;
c(2)=(abs(Restschuld))-1;
ceq=[];
end
that was my idea of solving it.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by