function genetic()
clc
clear all
global start_Time

s=0;
while s==0
    try
        s=textread('d:\link.txt','%f');
    catch
        s=0;
    end
end
nvars=s(2,1);
PopulationSize=s(3,1)
Generations=s(4,1)

disp('GA is runing');
pause(1)
fitnessFunction = @GAFunc;
options = gaoptimset;
%options = gaoptimset(options,'PopInitRange' ,[0 ; 0.2]);
options = gaoptimset(options,'PopulationSize' ,PopulationSize);
options = gaoptimset(options,'Generations' ,Generations);
options = gaoptimset(options,'StallGenLimit' ,Inf);
options = gaoptimset(options,'StallTimeLimit' ,Inf);
options = gaoptimset(options,'MutationFcn' ,{ @mutationgaussian 1 1 });
options = gaoptimset(options,'Display' ,'off');
%options = gaoptimset(options,'PlotFcns' ,{ @gaplotbestf });
%options = gaoptimset(options,'PlotFcns' ,{ @gaplotscores });

start_Time=clock;
options = gaoptimset(options,'HybridFcn' ,{ @fminunc [] });
startTime=clock;
[X,FVAL,REASON,OUTPUT,POPULATION,SCORES] = ga(fitnessFunction,nvars,options);
currentTime = etime(clock,startTime)

for i=1:6
    beep;   pause(.1)
end
clc
GAFunc(X)

fidd=fopen('d:\link.txt','wt');
fprintf(fidd,'%1g\n%6.4f\n',4,X);
fclose(fidd);

%mcc -m file_name.m -o new_file_name
