2 部分代码
clear all
clc
close all
%% 参数
parameter.nvar = 2;
parameter.xmin = -1;
parameter.xmax = 1;
parameter.m = 50;
parameter.k = 15;%控制适配值之间差异的常数
parameter.num_part =10;
itermax = 2000;
crossover_probability = 0.5;
mutation_probability = 0.001;
num_part = parameter.num_part;
nvar = parameter.nvar;
xmin = parameter.xmin;
xmax = parameter.xmax;
m = parameter.m;
%% 初始化
generation = repmat([], num_part, 1);
for i = 1:num_part
generation(i).x_bi = randi([0,1],1,parameter.nvar*parameter.m);%随机初始
generation(i).cost = my_obj(generation(i).x_bi,parameter);
end