%|------------------------------------------|
%| Eisagwgi stin Texniti Noimosini (MPD306) |
%|      xeimerino eksamhno 2020-2021        |
%|------------------------------------------|
%|                 LAB 04                   |
%|  Genetikoi Algorithmoi - Paradeigma 2    |
%|                                          |
%|            8 Queens Problem              |
%|------------------------------------------|

clear all; close all; clc;

%% run optimtools with Genetic Algorithms Solver & these parameters:
%
% Fitness Function    : FitnessFunction8queens.m
% Integer variables   : yes
% Bounds
%    Lower            : 1
%    Upper            : 8
% Creation of initial
%          population : random
% Crossover fraction  : 80%
% Stall generations   : default, then 100
% Plot                : best/mean fitness in each generation
%
%% after running optimtools and exporting results in 'optimresults' variable

TELIKH_KATASTASH=repmat(' ',11,11); TELIKH_KATASTASH([2,end],2:end)='-'; TELIKH_KATASTASH(2:end,[2,end])=('|');
for i=3:10
    TELIKH_KATASTASH(1,i)=num2str(i-2);
    TELIKH_KATASTASH(i,1)=num2str(i-2);
end
row=11-optimresults.x;
for col=3:10
    TELIKH_KATASTASH(row(col-2),col) = 'Q';
end

disp(TELIKH_KATASTASH)


N=8;
fig=figure('Name','8-Queens Solution');
plot(-1. -1)
axis([1 N+1 1 N+1])
set(gca,'xTick',1:N)
set(gca,'yTick',1:N)
set(gca,'xTickLabel',{'               1','               2','               3','               4','               5','               6','               7','               8'})
set(gca,'yTickLabel',repmat('',8,1))
grid on
% shg
hold on;
for col=1:8
    scatter(col+0.5,optimresults.x(col)+0.5,300,'filled','o','MarkerEdgeColor','k','MarkerFaceColor','k');
end
hold off;


