www.gusucode.com > GAVPai_Book_MathworksCntrlFileEx_May2019 > GAVPai_Book_MathworksCntrlFileEx_May2019/weight_std_130_30_boundsconstr.m
%STANDARDIZATION OF WEIGHTS EXTRACTED FROM THE CHROMOSOMES TO SATISFY %BOUNDING and SHORT SALES CONSTRAINTS %------------------------------------------------------------------------ % function std_weight_mat = weight_std_130_30_boundsconstr(weight_mat, low_up_bounds) [row_mat, col_mat]=size(weight_mat); [~, up_bound] = size(low_up_bounds); % Steps 1 and 2 of Weight Repair Strategy Phase 1 % standardize weights to satisfy their lower bounds while summing up to 1 for i=1: row_mat %R: those weights which are less than their respective lower bounds R=[]; c_R=0; for j=1:col_mat if (weight_mat(i,j)< low_up_bounds(1,j)) weight_mat(i,j)= low_up_bounds(1,j); c_R = c_R+1; R(c_R) = j; end end %Q: those weights which satisfy their lower bounds Q = setdiff([1:col_mat], R); F = 1 - sum(low_up_bounds(1,R))- sum(low_up_bounds(1,Q)); L = sum(abs(weight_mat(i,Q))); if (L==0) term = F / length(Q); weight_mat(i,Q)= low_up_bounds(1,Q)+ term; else term = F / L; weight_mat(i,Q) = low_up_bounds(1,Q)+ abs(weight_mat(i,Q))* term; end end % Steps 3-6 of Weight Repair Strategy Phase 1 % standardize upper bounds so that weights ultimately satisfy both upper % and lower bounds and sum up to 1 for i = 1: row_mat kr = 1; r = []; ex_flag = true; q = setdiff([1:col_mat], r); while (ex_flag == true) ex_flag = false; for j = 1: length(q) if ( weight_mat(i, q(j)) <= low_up_bounds(2, q(j)) ) continue; else ex_flag = true; r(kr) = q(j); kr = kr+1; end end q = setdiff([1:col_mat], r); if (ex_flag == true) L = sum(abs(weight_mat(i,q))); F = 1 - ( sum(low_up_bounds(1,q))+ sum( low_up_bounds(2,r)) ); if (L==0) term = F; weight_mat(i,q(1))= term; else term = F/L; weight_mat(i,q) = low_up_bounds(1,q) + (abs(weight_mat(i,q))* term); end weight_mat(i,r)=low_up_bounds(2,r); end end std_weight_mat = weight_mat; end end