nonlinear constrain error must return real value

조회 수: 17 (최근 30일)
Maria Lepouri
Maria Lepouri 2018년 12월 12일
댓글: Maria Lepouri 2018년 12월 12일
Hello! When trying to solve an optimization problem( linear and nonlinear constrains) using the ga function it returns the following error:
>> [x,fval] = ga(ObjectiveFunction,nvars,[],[],Aeq,Beq,lb,ub,ConstraintFunction)
Error using constrValidate (line 59)
Constraint function must return real value.
Error in gacommon (line 125)
[LinearConstr, Iterate,nineqcstr,neqcstr,ncstr] = constrValidate(NonconFcn, ...
Error in ga (line 363)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, ...
My non linear constrains are:
function [C,Ceq] = simple_constraint(x)
Ceq=[x(1)*70+x(8)*x(12)-x(3)*x(9);
x(2)*70+x(7)*x(11)-x(4)*x(10);
120-x(3)*(x(11)-x(9));
120-x(16)*0.2*x(13);
17.5-x(4)*(x(12)-x(10));
17.5-x(17)*0.5*x(14);
90-x(18)*0.5*x(15);
x(13)-((90-x(9))-(150-x(11)))/(log(abs((90-x(9))/(150-x(11)))));
x(14)-((264-x(10))-(264-x(12)))/(log(abs((264-x(10))/(264-x(12)))));
x(15)-((264-70)-(264-100))/(log(abs((264-70)/(264-100))))];
C=[];
end
And my function for minimizing is :
function y = simple_fitness(x)
y=5750*(x(16)^0.59+x(17)^0.59+x(18)^0.59);
end
We tried using the dbstop if error and in the c vector there was a NaN value (we think that is a problem in the 9th nonlean equality constrain, or do the c and ceq equality vectors don't connect?).
Thanks beforehand!
  댓글 수: 2
madhan ravi
madhan ravi 2018년 12월 12일
upload the full code where was simple_constraint used?
Maria Lepouri
Maria Lepouri 2018년 12월 12일
It was used here:
ObjectiveFunction = @simple_fitness;
nvars = 2; % Number of variables
LB = [0 0]; % Lower bound
UB = [1 13]; % Upper bound
ConstraintFunction = @simple_constraint;
[x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],LB,UB, ...
ConstraintFunction)

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

답변 (1개)

Star Strider
Star Strider 2018년 12월 12일
The expression beginning with ‘x(13)’ contains a log argument that could become negative if ‘x(11)’ is greater than 150, and similarly, ‘x(14)’ contains a log argument that could become negative if ‘x(12)’ is greater than 264. Logarithms of negative numbers are complex. Constraining these parameters in the ‘ub’ vector could be one solution, although since I do not know in what order the constraints are checked, might not prevent the error.
To illustrate:
log(abs((90-x(9))/(150-x(11))))
log(abs((264-x(10))/(264-x(12))))
  댓글 수: 1
Maria Lepouri
Maria Lepouri 2018년 12월 12일
I understand what you say but I've already used the abs function to prevent a negative log. I will check it thought and add an abs to both numerator and denominator.

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

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by