当我尝试为 GA 生成人口时,我遇到了错误。我使用二维数组来帮助生成人口。首先,用户将在用户表单中输入种群大小,然后是染色体长度。
我的变量:
Dim Generation As Integer
Dim Chromolength As Integer
Dim varchromolength As Integer
Dim Poparr() As Integer
然后我从用户窗体中获取值:
PopSize = PopulationSize.value
aVariables = AOV.value 'assign userform value entered to this variable
varchromolength = Chromolengthentered.value 'assign userform value entered to this variable
Chromolength = varchromolength * aVariables 'Chromosome length equals the length of each varaible chromosome combined
然后是发生错误的编码:
For i = 1 To PopSize
For j = 1 To Chromolength
If Rnd < 0.5 Then
Poparr(i, j) = 0 'assign o to gene
Else
Poparr(i, j) = 1 'assign 1 to gene
End If
Next j
Next i
抱歉,我对 VBA 还很陌生。任何有关此错误的帮助将不胜感激。