% GSA code v1.1.
% Generated by Esmat Rashedi, 2010.
% "	E. Rashedi, H. Nezamabadi-pour and S. Saryazdi,
%“GSA: A Gravitational Search Algorithm? Information sciences, vol. 179,
%no. 13, pp. 2232-2248, 2009."
%
%This function calculates the mass of each agent. eq.14-20
function [M]=massCalculation(fit,min_flag)
%%%%here, make your own function of 'mass calculation'

Fmax=max(fit);
Fmin=min(fit); %Fmean=mean(fit);
[~, N]=size(fit);
if Fmax==Fmin
    M=ones(N,1);
else
    if min_flag==1 %for minimization
        best=Fmin;worst=Fmax; %eq.17-18.
    else %for maximization
        best=Fmax;worst=Fmin; %eq.19-20.
    end
    M=(fit-worst)./(best-worst); %eq.15,
end
M=M./sum(M); %eq. 16.