📄 modoutputtextreport.bas
字号:
Attribute VB_Name = "ModOutputTextReport"
'输出
Sub OutputTextReport()
Dim i As Integer, j As Integer
Dim sum As Double, averge As Double
Dim x1 As Double, x2 As Double
'计算平均适应度
sum = 0#
For i = 0 To PopSize - 1
sum = sum + Population(i).fitness
Next i
averge = sum / PopSize
'输出结果
If Generation = 1 Then
Open App.Path + "/result.txt" For Output As #1
Print #1, "gen Avg best"
Print #1, Format(Generation, "00"), Format(averge, "00.00"), Format(CurrentBest.fitness, "00.00")
Close #1
Else
Open App.Path + "/result.txt" For Append As #2
Print #2, Format(Generation, "00"), Format(averge, "00.00"), Format(CurrentBest.fitness, "00.00")
Close #2
End If
'输出中间结果
If Generation = 0 Then
Open App.Path + "/betweenness.txt" For Output As #3
For i = 0 To PopSize - 1
x1 = DecodeChromosome(Population(i).chrom, 0, 10, -2.048, 2.048)
x2 = DecodeChromosome(Population(i).chrom, 10, 10, -2.048, 2.048)
Print #3, i, Format(x1, "0.000"), Format(x2, "0.000")
Next i
Print #3,
Close #3
ElseIf Generation = 5 Or Generation = 10 Or Generation = 100 Then
Open App.Path + "/betweenness.txt" For Append As #4
For i = 0 To PopSize - 1
x1 = DecodeChromosome(Population(i).chrom, 0, 10, -2.048, 2.048)
x2 = DecodeChromosome(Population(i).chrom, 10, 10, -2.048, 2.048)
Print #4, i, Format(x1, "0.000"), Format(x2, "0.000")
Next i
Print #4,
Close #4
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -