本程序利用遗传算法来求解背包问题.采用二进制字符串编码,1表示选择物体,0则不选择. 背包问题描述:在M件物品取出若干件放在空间为W的背包里,每件物品的重量为W1,W·2……Wn,与之相对应的价值为P1,P2……Pn。求出获得最大价值的方案。注意:在本题中,所有的重量值均为整数。 以下是本程序的主要函数说明: 1.GetRandChromosomes(szChromosome() As String, iChromosomeCount As Integer):随机初始化染色体 2.GetRan
部分代码: function Population1=GA_tubian(Population,pe_tubian) %遗传算法突变算子 %pe为突变概率 Population1=Population; n=length(Population(:,1)); m=length(Population(1,:)); for i=1:n for j=1:m test=rand; if test<pe_tubian Population1(i,j)=1-Popula