Getting rid of IntCon in GA
I have code for a genetic algorithm as follows (which I got from a matlab example):
[x,fval] = ga(@objfun,4,A,b,Aeq,beq,lb,ub,@nonlcon, [1,2])
the [1,2] parameter corresponds to IntCon (see https://www.mathworks.com/help/gads/ga.html#d122e40769), and it is restricting x(1) and x(2) to integer values (which I don’t want). I want to get rid of this but when I delete it and run:
[x,fval] = ga(@objfun,4,A,b,Aeq,beq,lb,ub,@nonlcon)
I get this error:
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 364)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, …
Error in Model_Building_2 (line 101)
[x,fval] = ga(@objfun,4,A,b,Aeq,beq,lb,ub,@nonlcon)
can anyone think of any reason why this happens? the code runs well with any variable in IntCon (ie it can be [3], [4], [2,3] or any other combination) as long as there is at least one. using empty brackets [] returns the same error as above.
thanks in advance!I have code for a genetic algorithm as follows (which I got from a matlab example):
[x,fval] = ga(@objfun,4,A,b,Aeq,beq,lb,ub,@nonlcon, [1,2])
the [1,2] parameter corresponds to IntCon (see https://www.mathworks.com/help/gads/ga.html#d122e40769), and it is restricting x(1) and x(2) to integer values (which I don’t want). I want to get rid of this but when I delete it and run:
[x,fval] = ga(@objfun,4,A,b,Aeq,beq,lb,ub,@nonlcon)
I get this error:
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 364)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, …
Error in Model_Building_2 (line 101)
[x,fval] = ga(@objfun,4,A,b,Aeq,beq,lb,ub,@nonlcon)
can anyone think of any reason why this happens? the code runs well with any variable in IntCon (ie it can be [3], [4], [2,3] or any other combination) as long as there is at least one. using empty brackets [] returns the same error as above.
thanks in advance! I have code for a genetic algorithm as follows (which I got from a matlab example):
[x,fval] = ga(@objfun,4,A,b,Aeq,beq,lb,ub,@nonlcon, [1,2])
the [1,2] parameter corresponds to IntCon (see https://www.mathworks.com/help/gads/ga.html#d122e40769), and it is restricting x(1) and x(2) to integer values (which I don’t want). I want to get rid of this but when I delete it and run:
[x,fval] = ga(@objfun,4,A,b,Aeq,beq,lb,ub,@nonlcon)
I get this error:
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 364)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, …
Error in Model_Building_2 (line 101)
[x,fval] = ga(@objfun,4,A,b,Aeq,beq,lb,ub,@nonlcon)
can anyone think of any reason why this happens? the code runs well with any variable in IntCon (ie it can be [3], [4], [2,3] or any other combination) as long as there is at least one. using empty brackets [] returns the same error as above.
thanks in advance! genetic algorithm, ga, optimization, global optimization, optimisation, intcon MATLAB Answers — New Questions