Hi friends, I have a problem with optimization algorithm like GA, fmincon and patternsearch. When I try to add constrain to my problem error below appear:
Error using Constrain
Too many output arguments.
Error in poptimfcnchk (line 58)
[cineq,ceq] = feval(nonlcon,reshapeinput(Xin,X),conFcnArg{:});
Error in patternsearch (line 343)
[Iterate,OUTPUT.funccount] = poptimfcnchk(FUN,nonlcon,initialX,Iterate, ...
Error in Main (line 30)
[x,Fval,exitFlag,output]=patternsearch(@(x)
Objective(x),X0,[],[],[],[],LB,UB,@Constrain,options)
Caused by:
Failure in initial user-supplied nonlinear constraint function evaluation.
PATTERNSEARCH cannot continue.
However, when I omit the constrain from optimization it works very well. After adding adding constrain to my problem this error occur. Could anyone help???
Thanks.

댓글 수: 2

Torsten
Torsten 2015년 11월 24일
You will have to show us your function with name "Constrain".
Best wishes
Torsten.
The Constrain function is not like what other simple functions. Because of sizing component which runs with ADVISOR is implemented, it may sounds weird to you. Anyway, I bring me code down there:
function Con=Constrain(x)
input.accel.param = {'spds','max_speed_bool'} ;
input.accel.value = {[0 37.28]};%;37.28 55.9234]} ;
[error, resp] = adv_no_gui('accel_test',input) ;
accel_1 = resp.accel.times(1) ;
MaxSpeed = resp.accel.max_speed*1.60934 ;
if ~error
Con=[accel_1/10-1;1-MaxSpeed/100];
end

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

 채택된 답변

Alan Weiss
Alan Weiss 2015년 11월 24일

0 개 추천

To quote the documentation on nonlinear constraints, "Nonlinear constraint functions must return both c and ceq, the inequality and equality constraint functions, even if they do not both exist. Return empty [] for a nonexistent constraint."
In other words, you need to rewrite your constraint function as follows, assuming your existing constraints are inequality rather than equality constraints:
function [Con,coneq] = Constrain(x)
Con = [];
coneq = [];
input.accel.param = {'spds','max_speed_bool'} ;
input.accel.value = {[0 37.28]};%;37.28 55.9234]} ;
[error, resp] = adv_no_gui('accel_test',input) ;
accel_1 = resp.accel.times(1) ;
MaxSpeed = resp.accel.max_speed*1.60934 ;
if ~error
Con=[accel_1/10-1;1-MaxSpeed/100];
end
Alan Weiss
MATLAB mathematical toolbox documentation

댓글 수: 1

Ali T
Ali T 2015년 11월 24일
편집: Ali T 2015년 11월 24일
Marvelous, that worked... amazing, thank you. Unfortunately I am not convinced why do I have to use con=[] and coneq=[] ??? When I ran my code, something new error pops up... Could you please help me solving this error too???
Error in adv_no_gui case {accel_test}:
Index exceeds matrix dimensions.
Attempt to reference field of non-structure array.
Error in Constrain (line 11)
accel_1 = resp.accel.times(1) ;
Error in poptimfcnchk (line 58)
[cineq,ceq] = feval(nonlcon,reshapeinput(Xin,X),conFcnArg{:});
Error in patternsearch (line 343)
[Iterate,OUTPUT.funccount] = poptimfcnchk(FUN,nonlcon,initialX,Iterate, ...
Error in Main (line 30)
[x,Fval,exitFlag,output]=patternsearch(@Objective,X0,[],[],[],[],LB,UB,@Constrain,options)
Caused by:
Failure in initial user-supplied nonlinear constraint function evaluation.
PATTERNSEARCH cannot continue.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

질문:

2015년 11월 24일

편집:

2015년 11월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by