背包问题的遗传算法解法
本程序利用遗传算法来求解背包问题.采用二进制字符串编码,1表示选择物体,0则不选择. 背包问题描述:在M件物品取出若干件放在空间为W的背包里,每件物品的重量为W1,W·2……Wn,与之相对应的价值为P1,P2……Pn。求出获得最大价值的方案。注意:在本题中,所有的重量值均为整数。 以下是本程序的主要函数说明: 1.GetRandChromosomes(szChromosome() As String, iChromosomeCount As Integer):随机初始化染色体 2.GetRandValueAndContent(iValue() As Integer, iContent() As Integer, iObjectCount As Integer):随机初始化物体容量和物体价值 3.GetRandAllContentByContent(iContent() As Integer, iObjectCount As Integer):根据物体体积随机初始背包容量,使得物体的总体积大于背包的容量 4.CopyChromosomes(iProbability() As Single, szChromosome() As String, iChromosomeCount As Integer):染色体复制 5.SelChromosomeBySelProba(iProbability() As Single, iChromosomeCount As Integer) As Integer:根据选择概率选择染色体 6.IsLiveGene(szChromosome As String, iContent() As Integer, iKitContent As Integer) As Boolean:判断染色体是否为活的染色体,即是否满足条件 7.Cross(szChromosome1 As String, szChromosome2 As String, iObjectCount As Integer):染色体之间进行杂交 8.Aberrance(szChromosome As String, iObjectCount As Integer):染色体变异 9.GetAdaptablity(szChromosome As String, iValue() As Integer, iContent() As Integer, iChromosomeCount As Integer) As Integer:得到染色体的适应度 10.GetSelectProbability(iAdaptablity() As Integer, iChromosomeNum As Integer, iChromosomeCount As Integer) As Single:得到选择概率 As String, iChromosomeCount As Integer):染色体复制 5.SelChromosomeBySelProba(iProbability() As Single, iChromosomeCount As Integer) As Integer:根据选择概率选择染色体 6.IsLiveGene(szChromosome As String, iContent() As Integer, iKitContent As Integer) As Boolean:判断染色体是否为活的染色体,即是否满足条件 7.Cross(szChromosome1 As String, szChromosome2 As String, iObjectCount As Integer):染色体之间进行杂交 8.Aberrance(szChromosome As String, iObjectCount As Integer):染色体变异 9.GetAdaptablity(szChromosome As String, iValue() As Integer, iContent() As Integer, iChromosomeCount As Integer) As Integer:得到染色体的适应度 10.GetSelectProbability(iAdaptablity() As Integer, iChromosomeNum As Integer, iChromosomeCount As Integer) As Single:得到选择概率
用户评论
很好用,是玩算法人的需求
这个比较好用哦。
稍微改了改,挺好用的
还没运行成功,应该挺好的
程序不错,,下完发现不是我想要的
写得很好,也很全面,是我愚钝了。
遗传算法挺齐全的资料
看不懂 也是因为环境部对
现在正研究遗传算法,这个资料挺有意思的,值得研究一下。。。
没具体看,因为环境对不上~但是感觉代码应该写的不错!