MATLAB: How to solve linear constraint in genetic algorithm with population type of Bit string .

binaryconstraintgenetic algorithmlinear constraintMATLAB

I am trying to solve binary optimisation problem in matlab R2016a , where i am giving popultion type as 'Bitstring' Problem is when i am giving linear constraint (sum(x)=20), it is ignoring it. How to fix this ?
}
if
{opts = gaoptimset('PopulationSize',300,'InitialPopulation',mypop,..
'PopulationType', 'bitstring','SelectionFcn',{@selectiontournament,tournamentSize},...
'MutationFcn',{@mutationuniform, 0.1},'CrossoverFcn', {@crossoverarithmetic,0.8},...
'EliteCount',2,'StallGenLimit',50,'PlotFcns',{@gaplotbestf},'Display', 'iter');
num=100;
Aeq=[ones(1,num);-ones(1,num)];Beq=[20;-20];
[X_opt,feval,exitflag,output]=ga(@(z)myfunc4_full_2(z,phi_100),num,Aineq,Bineq,[],[],[],[],[],[],opts);
end

Best Answer

1. Please format your question using the {} Code button as appropriate so that we can read your code.
2. You probably don't want to use a bit string population type. As documented, bit string population ignores all constraints. Instead, I suggest that you use the mixed integer optimization formulation, which allows for most constraint types, but no equality constraints.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation