% This program solvs the 8-queen problem using genetic algorithms % The population is stored in a 3D 8x8 matrix. clear clc D=8; % Dimension of the table is DxD N=6; % Number of individuals in the population A = zeros(D,D,N); Population = PlaceQueens(A,N); % one queen in each column of each population member while 1 for x=1:num_pop % prikaz inicijalne populacije subplot(3,4,x), imshow((1-A(:,:,x))) end NumberOfAttacks=FindAttacks(Population,N); % The quality of each individual is measured by % the pairs of non-attacking queens. % The solution is found when the number % of pairs ofnon-attacking queens equals 28. % The non-attackingg pairs of queens are % stored in variable NoAttack. % The solution is found when NoAttack reaches 28. NoAttack=28-NumberOfAttacks; SelectedInds=selection(Population,NoAttack,N); end