Constraints not satisfied with 'ga' solver and integer variables
古いコメントを表示
Hi all,
I've been struggling to understand what is the problem with my code. I wrote this long time ago, and now I'm using it with another dataset (large one) and is not working. I'm using 'ga' optimisation with integer variables, but I'm getting the legend of " Optimization terminated: average change in the penalty fitness value less than options.FunctionTolerance but constraints are not satisfied."
Basically what I want to do with my constraints is to avoid repetitions of the integer values in the vector of variables "x" (which has 42 values), and to make sure that the integer value selected for each "x" exists in the respective column of a matrix (124 rows, 42 columns). My LB and UB are between 1 to 124.
The results that I'm getting for the vector "v" are either very close to LB or UB, so 1 to 4 and 122 to 124. So I'm thinking that maybe is completely ignoring all the integer numbers and that's why it cannot find a solution. Here are the line where I call the ga:
x = [55 96 33 73 4 51 37 39 50 78 20 88 1 47 17 44 40 66 56 113 74 31 105 34 108 65 49 8 75 22 99 42 91 46 93 71 82 121 94 114 48 70];
LB=ones(1,42);
UB=zeros(1,42); UB(:)=124;
IntCon=[1:1:42];
hj=72;
options=optimset('Display', 'iter', 'FunValCheck', 'on');
[ x, fval, exitflag] = ga(@(x) ObjFun(x,TwoVal,distances, indices00,OrderedVal,hj,dimension00),42,[],[],[],[],LB,UB,@(x) constGa(x,OrderedVal),IntCon, options);
And the constraint function:
function [c,ceq] = constGa(x,OrderedVal)
ceq=[];
c1=length(unique(x)) == length(x);
c1=double(c1);
c1=(c1-1).^2;
ee=length(x);
for xe=1:ee
c2(xe)= ~ismember(x(xe),OrderedVal(:,xe));
end
c2=double(c2);
c2=sum(c2);
c=[c1;c2];
If you have an idea what I might be doing wrong, I appreciate your suggestions. When I run this in a smaller dataset of 5 "x" variables instead of 42, and LB and UB between 1 to 18 instead of 1 to 124, I get a solution with satisfied constraints and minimum objective function.
Thank you, Martha
回答 (1 件)
It looks like a difficult feasible set, depending on what OrderedVal contains. It might help to formulate c,ceq in a form that is a bit less quantized,
function [c,ceq] = constGa(x,OrderedVal)
c1=length(x)-length(unique(x));
c2=min(abs(bsxfun(@minus, Ordererval,x(:).')));
ceq=[c1,c2];
c=[];
7 件のコメント
Martha
2018 年 2 月 18 日
Matt J
2018 年 2 月 18 日
Perhaps there is no feasible solution. We would have to see OrderedVal to analyze that better.
Martha
2018 年 2 月 21 日
OrderedVal is very large to post here
You can attach .mat files. In any case, the feasible region consists of highly non-contiguous pieces. This makes it very difficult for the solver to find and optimize over. Are you sure it's non-repetitions in x(i) that you need, rather than OrderedVal(x(i),i)?
Martha
2018 年 2 月 21 日
Matt J
2018 年 2 月 21 日
I think we need to see the full problem description, including the objective function.
Martha
2018 年 2 月 22 日
カテゴリ
ヘルプ センター および File Exchange で Solver Outputs and Iterative Display についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!