遗传算法初始种群

Initial Population of Genetic Algorithm

如何生成像这样x=[1 0;0 1;1 0;1 0] or [1 0;1 0;0 1;1 0]的染色体

我只需要在 "x=1 when ith machine is in cell l, otherwise 0 when i= no of machine and l= no of cell."

的帮助下生成染色体

矩阵会变成这样[1 0;0 1;1 0;0 1] when i=4 & l=2.

表示1号机和3号机在单元格1中,2号机和4号机在单元格2中。

为什么不使用编码 x[1,2,1,2] 而不是 x[1,0;0,1;1,0;0,1]?然后使用 randi([1,2],[4,1]) 进行初始化。 你的编码有点多余,还是我问错了?

或者你可以这样做:

r = randi([1,2],[4,1]);

x = zeros(4,2);
for idx = 1:size(r,1);
    if r(idx) == 1
        x(idx,1) = 1;
    else
        x(idx,2) = 1;
    end
end