MATLAB GA error help!

12 ビュー (過去 30 日間)
joichiro nishi
joichiro nishi 2018 年 12 月 5 日
コメント済み: Walter Roberson 2018 年 12 月 6 日
Note: Updated the files and error message
Like the Subject says, I need help in sorting out the errors. Basically I'm trying to find the optimal bidding coefficients bd with the purpose of enhancing the profit F for the 2nd player (the 2 in Custom_Fitness_Fcn). Now the problem is that whenever I try to run main I get these errors:
>> main
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in Custom_Constraint_Fcn (line 10)
P(n) = (R-ac(n))/bd(n);
Error in main>@(bd)Custom_Constraint_Fcn(ac,bd,limit,i,l,Q0,K)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in constrValidate (line 21)
[tmpCineq,tmpCeq] = nonlcon([Iterate.x Iterate.x]');
Error in gacommon (line 125)
[LinearConstr, Iterate,nineqcstr,neqcstr,ncstr] = constrValidate(NonconFcn, ...
Error in ga (line 336)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, ...
Error in main (line 9)
[bd,F] = ga(FitnessFcn,nvars,[],[],[],[],[],[],ConstraintFcn,options);
Caused by:
Failure in initial user-supplied nonlinear constraint function evaluation.
>>
I've been trying to debug this thing for days, and I really need it in less than 2. Somebody please help!
  14 件のコメント
joichiro nishi
joichiro nishi 2018 年 12 月 6 日
>The first two matrices being vertcat are i(end) by max(i) with all rows having the same value.
The third and fourth are l(end)-i(end) by max(l) with all rows having the same value.
You will not be able to horzcat or vertcat this collection together.
Ok. But before that I think my main issue is that for some reason the bd that gets passed to the constraint consists of this weird size and value that I have no idea where it came from [see images]. I'm weary of maybe my fitness function handle messing up the bd and from there it goes on to be passed to the constraint instead (If I haven't misunderstood, the function handle call "locks in" the variables it calls, is that right?).
Anyway, now that I've used a generated initial population instead of a custom creation function, is my code for the constraint correct? Or do I need to vectorialize some lines like R = ...?
[The wrong one is the first pic, and the correct bd value is the second pic]
NmhcVxh.png
D466bF2.png
Walter Roberson
Walter Roberson 2018 年 12 月 6 日
your posted attached custom constraint function passes ac bd . your debugging snapshot shows aa custom constraint that expects bd ac.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by