一些其他函数
重量计算函数:
function wgtsum = weightsum(pop, weights)
% 计算种群的重量
% pop input 种群
% weights input 重量向量
% wgtsum output 种群重量
popsize = size(pop, 1);
wgtsum = zeros(popsize, 1);
for i = 1:popsize
wgtsum(i, 1) = weightsumv(pop(i, :), weights);
end
end
function wgtsum = weightsumv(stuffs, weights)
% 计算一个个体的重量
% stuffs input 物品序列
% weights input 重量向量
% wgtsum output 个体重量
wgtsum = sum(weights(stuffs ~= 0));
end
收益计算函数:
function pftsum = profitssum(pop, profits)
% 计算种群收益
% pop input 种群
% profits input 收益向量
% pftsum output 种群收益
popsize = size(pop, 1);
pftsum = zeros(popsize, 1);
for i = 1:popsize
pftsum(i, 1) = sum(profits(pop(i, :) ~= 0));
end
end