 ## Author: M. Turhan ÇOBAN
## Created: 2021-11-07
## Genetic optimisation using binary genes 0010011100101000111..
## genetic_opt

function [BestX BestY] =int_genetic_opt(iPOPSIZE,iMAXGENS,iPXOVER,iPMUTATION,x,y)
# Maximizing a function
POPSIZE=iPOPSIZE;      ## population size
MAXGENS=iMAXGENS;      ## maximum number of generations;
PXOVER=iPXOVER;        ## probability of crossover;
PMUTATION=iPMUTATION;  ## proportion of mutated variables
Best=1;                ## The best genotype in the population
nBest=2;               ## next to  best genotype in the population
##============= INITIAL ==================
## set initial population
# x=[80.90169944	58.77852523	30.90169944	6.12E-15	-30.90169944	-58.77852523	-80.90169944	-95.10565163	-100	-95.10565163	-80.90169944	-58.77852523	-30.90169944	-1.84E-14	30.90169944	58.77852523	80.90169944	95.10565163];
# y=[58.77852523	80.90169944	95.10565163	100	95.10565163	80.90169944	58.77852523	30.90169944	1.22E-14	-30.90169944	-58.77852523	-80.90169944	-95.10565163	-100	-95.10565163	-80.90169944	-58.77852523	-30.90169944];
[population,min,nmin]=set_random_population(x,y,POPSIZE);
## generate new generations
for j=1:MAXGENS
  ## create new population
  [population,min,nmin]=generate_new_population(population,PXOVER,PMUTATION);
  j
  BestX=population(nmin).id
  BestY=population(nmin).z
endfor
endfunction 