- First make sure that the constraints in the 'constraint' function are all inequalities because equality constraints are not allowed while using the integer 'ga' solver.
- You need to check the 'exitflag' and make sure that the solver is able to find a feasible solution. One possibility as to why you are getting non-integer values is that the solver is not able to find a feasible solution. You can check the list of exit flags in the following link: http://www.mathworks.com/help/gads/ga.html#zmw57dd0e32305
- Regarding imposing binary constraints, you can simply add them as lower and upper bounds. 'ga' solves integer problems best when you provide lower and upper bounds for every 'x' component. You can also refer to the following link for more information on Integer optimization. http://www.mathworks.com/help/gads/mixed-integer-optimization.html
Binary/Integer variables in genetic algorithm
3 次查看(过去 30 天)
显示 更早的评论
I want to define some variables as integer and constraint them to be binary. Even though I set the IntCon matrix the variables that I want to be integer, the ga doesn't recognize them as integers.
function [x,fval,exitflag,output,population,score] = model()
nvars=64;
IntCon=[33:64];
TolFun_Data=10^-2;
TolCon_Data=10^-2;
options = gaoptimset;
options = gaoptimset(options,'TolFun', TolFun_Data);
options = gaoptimset(options,'TolCon', TolCon_Data);
[x,fval,exitflag,output,population,score] = ga(@objective,nvars,[],[],[],[],[],[],@constraint,IntCon,options);
The solution for the integer variables is always a non-integer value. (such as 0.0221, -0.0153).
Also, should I constraint the integer variables to binary [0,1] using linear constraint lb,ub?
0 个评论
回答(1 个)
Ghada Saleh
2015-7-15
编辑:Ghada Saleh
2015-7-15
Hi Stefanos,
I understand that the output of the generic optimization is not integer for the variables specified in 'IntCon' as integers. I would check the following:
I hope the above information helps.
Ghada
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!