📄 init_qga.m
字号:
function [pop]=init_qga(flag_eq_prob,num_of_singles,num_of_chrom,num_of_genes)
qubits_per_single=num_of_chrom*num_of_genes;
total_qubits=num_of_singles*num_of_chrom*num_of_genes;
alpha=1/sqrt(2);beta=1/sqrt(2);
gene=[alpha;beta];
chrom=zeros(2,num_of_genes);
for j=1:num_of_genes
chrom(:,j)=gene;
end
single=zeros(2,qubits_per_single);
for j=1:num_of_chrom
single(:,(j-1)*num_of_genes+1:j*num_of_genes)=chrom;
end
pop=zeros(2,total_qubits);
for j=1:num_of_singles
pop(:,(j-1)*qubits_per_single+1:j*qubits_per_single)=single;
end
if flag_eq_prob
return
end
t=[1:total_qubits];
theta=10*exp(-t/50);
for i=1:total_qubits
gate=[cos(theta(i)) -sin(theta(i));sin(theta(i)) cos(theta(i))];
pop(:,i)=gate*pop(:,i);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -