一些其他函数
重量计算函数:
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
點擊查看更多內容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦