Percent "Input":
% ryk2-Day breakeven matrix, xt_num-combined system number, P-PRM left interval, m-md left interval
% P_INDEX-PRM interval type, 1:[5,6) 2: (5,6]
% m_index-md interval type, 1:[3,4) 2: (3,4]
% PM_INDEX-PRM, MD approximation direction, 1 is to meet the PRM in the case of the close range of MD approximation, 2 to meet the MD in the case of approaching the closed interval of the PRM
Percent "Output":
% syd-Population Fitness, MD or PRM
% zq_org-optimized population, which is the combined system number
% qq-suitability meets interval requirements
function [Syd,zq_org]=ss_ga_gaijin4 (Ryk,xt_num,m,pm_index)
Xt_num_all=size (ryk,2);% sequence total length "change"
Percent Step1:ga Process
%==================== "Initial population" =================
num_org=50;% "Change"
Zq_org=zeros (Num_org,xt_num);
For mrows=1:num_org
Temp1=randperm (Xt_num_all);
Zq_org (mrows,:) =temp1 (1:xt_num);
End
%==================== "Genetic Evolution" =================
daishu=10;% "Change"
For Mrows=1:daishu
% disp ([' "Population Evolutionary algebra": ', Num2str (mrows)]);
%**************** "Cross" ****************
Zq_cross=[];
Cross_m=nchoosek (1:size (zq_org,1), 2);
For K=1:size (cross_m,1)
Temp1=zq_org (Cross_m (k,1),:);
Temp2=zq_org (Cross_m (k,2),:);
[Temp3,temp4]=fun_cross (Temp1,temp2,xt_num_all);
Zq_cross=[zq_cross;temp3;temp4];
End
Zq_cross=sort (zq_cross,2);
Zq_cross=unique (Zq_cross, ' rows ');
%**************** "Mutation" ****************
Zq_variation=[];
num_variation=10;% Variation Multiplier "Change"
For K=1:size (zq_org,1)
A_temp1=zq_org (K,:);
B_temp1=setdiff ([1:XT_NUM_ALL],A_TEMP1);
For Kk=1:num_variation
A_temp2=randperm (Length (A_TEMP1));
B_temp2=randperm (Length (B_TEMP1));
A_temp3=union (B_TEMP1 (B_TEMP2 (1)), Setdiff (A_TEMP1,A_TEMP1 (A_TEMP2 (1)));
Zq_variation=[zq_variation;a_temp3];
End
End
Zq_variation=sort (zq_variation,2);
Zq_variation=unique (zq_variation, ' rows ');
%**************** "New species generation" **********
num_org1=10*num_org;% "Change"
Zq_new=zeros (Num_org1,xt_num);
For K=1:NUM_ORG1
Temp1=randperm (Xt_num_all);
Zq_new (K,:) =temp1 (1:xt_num);
End
%**************** "Evolutionary Elimination" ************
Zq_inherit=[zq_cross; Zq_variation; Zq_new; Zq_org];
Zq_inherit=sort (zq_inherit,2);
Zq_inherit=unique (Zq_inherit, ' rows ');
Syd_inherit=zeros (Size (zq_inherit,1), 1);
For Flag_k=1:size (zq_inherit,1)
M_temp1=zq_inherit (Flag_k,:);
Syd_inherit (flag_k,1) =fun_syd (m_temp1,ryk,m,pm_index);% "Change"
End
[M_temp3,m_temp2]=sort (Syd_inherit, ' descend ');% "Change"
Zq_org=zq_inherit (M_TEMP2 (1:num_org),:);
% disp ([' Evolutionary sequence ': ', Num2str (zq_org (1,:))]);
DISP ([' "Population Evolutionary algebra": ', Num2str (mrows), '-"evolutionary sequence": ', Num2str (zq_org (1,:)), '-', Num2str (M_temp3 (1,:))]);
End
Percent STEP3: specific problem output
For Flag_k=1:size (zq_org,1)
M_temp1=zq_org (Flag_k,:);
SYD (flag_k,1) =fun_syd (M_temp1,ryk,m,pm_index);
End
Percent Run Complete dialog box
% Tt=toc;
% MsgBox ([' "Run Time": ', Num2str (TT), ' seconds '], ' warm tips! ');
% disp ([' "Run Time": ', Num2str (TT), ' sec! ‘]);
% ******************************************************************************************************
Percent "sub-function" crossover operator
Function [New_xl1,new_xl2]=fun_cross (A1,B1,C)
C_temp1=[1:c];
new_xl1=a1;
New_xl2=b1;
A2=setdiff (C_TEMP1,A1);
B2=setdiff (C_TEMP1,B1);
C_temp2=intersect (A1,B2);
C_temp3=intersect (B1,A2);
If ~isempty (C_TEMP2)
if ~isempty (C_temp3)
C_temp4=randperm (Length (C_TEMP2));
X_TEMP=C_TEMP2 (C_temp4 (1));
C_temp5=randperm (Length (C_temp3));
Y_temp=c_temp3 (C_TEMP5 (1));
New_xl1=union (Y_temp,setdiff (a1,x_temp));
New_xl2=union (X_temp,setdiff (b1,y_temp));
End
End
End
Percent of "sub-function" Fitness function
function SYDM = Fun_syd (Xl,ryk,m,pm_index)
H_temp1=ryk (:, XL);
H_temp2=sum (h_temp1,2);
[Ljyk,qqgd,huitiao,huitiao_didian,huitiao_didian_time,buyinliqi,lianxuyinli,lianxukuisuan] = Fun_MD (H_TEMP2, 200000*length (XL));
Pp=sum (H_TEMP2);
Mm=abs (min (huitiao)) *100;% "Change" Consider 2 ways: current MD or This period of time min MD
If pm_index==1% means that the PRM is as large as possible in the case of the MD interval [m,m+1]
if (mm<m) | (mm>m+1)
Sydm=-inf;
Else
SYDM=PP;
End
ElseIf pm_index==2% means that the PRM is as small as possible in the case of the MD interval [m,m+1]
if (mm<m) | (mm>m+1)
Sydm=-inf;
Else
SYDM=-PP;
End
Else
MsgBox (' Pm_index set error, Value range: 1 or 2 ');
Return
End
End
End
Genetic algorithm for system combination