Constraints not satisfied with 'ga' solver and integer variables
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
Matt J
le 17 Fév 2018
Modifié(e) : Matt J
le 17 Fév 2018
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 commentaires
Matt J
le 21 Fév 2018
I think we need to see the full problem description, including the objective function.
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!