www.gusucode.com > GAVPai_Book_MathworksCntrlFileEx_May2019 > GAVPai_Book_MathworksCntrlFileEx_May2019/ConstrViolnFun_130_30.m

    
function  [psi, G]  = ConstrViolnFun_130_30( weight_mat, betas_assets, C_param, alpha_param, beta_param, gencount)

    [row_mat, ~]= size(weight_mat);
    epsilon = 0.001;
    for i=1:row_mat  
        
        x_chromo=weight_mat(i,:);
   
        % compute penalty function G
        portfolio_beta_term = sum(betas_assets.* x_chromo); 
        g1_term = abs((portfolio_beta_term) - 1)-epsilon;
   
        if (g1_term <=0 )
        G(i)=0;
        else
        G(i)=1;
        end

        % compute constraint violation function
        penalty_term= power(C_param*gencount, alpha_param); 
        psi(i) = penalty_term *( G(i)*power(g1_term, beta_param));  
    
    end
end