\(\(\(
\)\( (*Definicia\ stylov\ popisov\ a\ fontov*) \)\(\($TextStyle = {FontFamily -> "Helvetica", FontSize -> 12, 
          FontWeight -> "Bold"};\)



    \(<< Statistics`ContinuousDistributions`;\)

    \)\)\)

n = 2;
\(\(f[
          x_] := \((\((x[\([1]\)] - 1)\)^2\ \  + 
              2\ 25 \((1 + \ Sin[x[\([1]\)]])\))\)*\ \((\((x[\([2]\)] - 
                    1)\)^2\ \  + 
              3\ 25 \((1 + \ 
                    Sin[x[\([2]\)]])\))\);\)

\)
Plot3D[f[{x1, x2}],  {x1, -10, 23},  {x2, -20, 23},  
        PlotPoints -> 200, 
Mesh -> 
          False, 
ImageSize -> 
          6*72];

    
DensityPlot[
        f[{x1, x2}],  {x1, -10, 23},  {x2, -20, 
          23}, 
PlotPoints -> 
          200, 
ColorFunction -> Hue,  
        Mesh -> False, 
ImageSize -> 
          6*72];
grafcontour = 
        ContourPlot[
          f[{x1, x2}],  {x1, -10, 23},  {x2, -20, 
            23}, 
PlotPoints -> 
            200, 
Contours -> 
            Table[k^3, {k, 0, 50, 
                1.5}], 
ColorFunction -> 
            Hue, 
ImageSize -> 6*72];

(* 
      Funkcia usporiadania pola podla fit funkcie f  *) 

UsporiadajPodlaFitFunkcie[
          pole_] := Module[{}, 
rozmer = 
            Length[pole]; 
rozsirenepole = 
            Table[ {f[pole[[i]] ],  pole[[i]]}, {i, 1, 
                rozmer}]; 
usporiadanerozsirenepole = 
            Sort[rozsirenepole]; 
usporiadanepole = 
            Table[ usporiadanerozsirenepole[[i]][[2]], {i, 1, 
                rozmer}]; 
usporiadanepole
];


 (* 
      Funkcia mutacie pola *) 


    MutaciaPola[pole_,  sigma_] := 
        Module[{}, 
dist = 
            NormalDistribution[0, sigma]; 
rozmer = 
            Length[pole]; 
novepole = 
            Table[ pole[[i]]  +  Table[Random[dist], {j, 1, n}], {i, 
                1, rozmer}]; 
novepole
];


 (* 
      Funkcia vyberu pola dlzky c z pola pole *) 


    VyberPole[pole_,  c_] := 
        Module[{}, 
novepole = 
            Table[ pole[[i]], {i, 1, 
                Min[c, Length[
                    pole]]}]; 
novepole
];

(* 
      Startovaci generacia rodicov *) 

 (* 
      rozmer rodicovskej generacie *) 
p = 
        1000;

 (* 
      rozmer generacie potomkov *) 

    c = 500;

 (* 
      nahodne generovana generacia rodicov *) 

    rodicia = 
        Table[ Table[21 + 0.  Random[], { j, 1, n}],  {i, 1, 
            p}];

tau0 = 1. ;

xlist = {};
\(\(For[generacia = 1, \ generacia ≤ 40, \ 
        1, 
{
dist = 
            NormalDistribution[0, tau0]; 
sigma = 
            Exp[Random[dist]]; 

deti = 
            VyberPole[\ 
              MutaciaPola[rodicia, \ 
                sigma], \ \ c]; 
novirodicia = 
            VyberPole[UsporiadajPodlaFitFunkcie[Join[rodicia, deti]], \ 
              p]; 

x = 
            novirodicia[\([1]\)]; 
xlist = 
            Join[xlist, \ {x}]; 


Print["Minimalna hodnota Fitness funkcie v generacii:"]; 
Print[" generacia = ", \ 
            generacia, " je f = ", 
            f[novirodicia[\([1]\)]], \ " x = ", \ 
            x]; 

rodicia = 
            novirodicia; 
\(generacia++\);}];\)\)

\(\(\(
\)\(\(grafmin = 
        Graphics[{{PointSize[ .02], RGBColor[1, 1, 1], 
              Text["minimum", {x[\([1]\)], x[\([2]\)] - 2}, 
                TextStyle -> {FontFamily -> "Helvetica", 
                    FontWeight -> "Bold", 
                    FontSize -> 
                      16}]}, 
{PointSize[ .02], 
              RGBColor[1, 1, 1], Point[x]}}];\)


    \(grafdraha = 
        ListPlot[xlist, PlotJoined -> True, 
          PlotStyle -> RGBColor[1, 1, 1], 
          DisplayFunction -> Identity];\)


    \(Show[grafcontour, grafmin];\)

    \(Show[grafcontour, grafmin, grafdraha];\)\)\)\)