继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

分布估计算法求解0-1背包问题二

慕虎7371278
关注TA
已关注
手记 1307
粉丝 202
获赞 877

一些其他函数

重量计算函数:

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);endend
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));endend



作者:mwangjs
链接:https://www.jianshu.com/p/69f1ab2a96d8


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP