필터 지우기
필터 지우기

Constraints not satisfied with 'ga' solver and integer variables

조회 수: 6 (최근 30일)
Martha
Martha 2018년 2월 17일
댓글: Martha 2018년 2월 22일
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개)

Matt J
Matt J 2018년 2월 17일
편집: Matt J 2018년 2월 17일
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
Matt J
Matt J 2018년 2월 21일
I think we need to see the full problem description, including the objective function.
Martha
Martha 2018년 2월 22일
Hi Matt, Here is the objective function:
function a = ObjFunA(x,TwoParts,dim, OrgVal,OrderedVal,dimTotal)
klp=size(dim); klp=klp(1);
differences=zeros(1,klp);
for lp=1:klp
Part1=TwoParts(1,lp); Part2=TwoParts(2,lp);
Val_1=x(Part1); Val_2=x(Part2);
n=dim(lp);
Temp1=find(OrgVal(:,Part1)==lp);
Temp2=find(OrgVal(:,Part2)==lp);
id1=find(OrderedVal(:,Part1) == Val_1);
id2=find(OrderedVal(:,Part2) == Val_2);
q1=dimTotal(id1,Part1,Temp1);
q2=dimTotal(id2,Part2,Temp2);
additions=18;
Total=((q1+q2)/2)+additions;
Space(lp)=n-((q1+q2)/2);
sumDim(lp)=(Space(lp)-additions).^2;
end
a=sum(sumDim);
I hope is not confusing, the value of "x" indicates to select an specific element for many combinations of elements that I have. In this case "klp" is the number of total combinations that I need to analyse. I need to find the best combination of "x" values that give me the minimum value of "a". However, I know that most likely "a" will never be zero. I just need to find the best combination with the minimum value of "x".
Thank you, Martha

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

카테고리

Help CenterFile 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!

Translated by