Private Sub CalculateB_Click(sender As Object, e As EventArgs) Handles CalculateB.Click
'//////////Configuration/////////////////////////////////////////
Dim lb As Integer = 1
Dim ub As Integer = 3
Dim fname As String = "D:\Onechrmsm.txt"
Dim chrmsmize As Integer = 18
'///////////////////fin confoguration////////////////////////////
Dim cgen As New Chrmsm
cgen = RandomGen(chrmsmize, lb, ub)
'cgen.Genome = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
cgen = Solve({cgen}.ToList)(1)
WriteTextToFile({cgen.Bfitness, cgen.Bfitness, "solution", StringGenerator(cgen.Solution), "PMPlan", StringGenerator(cgen.Genome)}, fname, True)
MsgBox(cgen.Fitness)
End Sub
Public Function Solve(ByRef population As List(Of Chrmsm), Optional ByVal PMBt As Double = 1111) As List(Of Chrmsm)
Dim newPop As New List(Of Chrmsm)
'==============================================================
Dim nbT As Integer = 6
Dim nbM As Integer = 3
Dim nbP As Integer = 2
'Dim PMBt As Double = 1111
Dim penalty As Double = 111
Dim fname As String = "D:\results.txt"
'=============================================================
Dim PMB As Array = {PMBt, PMBt, PMBt, PMBt, PMBt, PMBt}
For i As Integer = 1 To population.Count - 1
Dim cchrmsm As New Chrmsm
cchrmsm = population(i)
If Not cchrmsm.IsSolved Then
cchrmsm = solveM(cchrmsm, nbT, nbM, nbP, PMB, penalty, fname, False)
End If
newPop.Add(cchrmsm)
Next
Return newPop
End Function
Public Structure Chrmsm
Public Property Bfitness As Double
Public Property DetailSolution As Double()
Public Property Distance As Double
Public Property Entropy As Double
Public Property Fitness As Double
Public Property Genome As Integer()
Public Property IsFeasible As Boolean
Public Property IsSolved As Boolean
Public Property Rank1 As Integer
Public Property Rank2 As Integer
Public Property Solution As Double()
End Structure
答案 0 :(得分:0)
Dim cgen As New Chrmsm
为您提供Chrmsm结构的新实例
cgen = RandomGen(chrmsmize, lb, ub)
我假设RandomGen返回一个Chrmsm实例,这意味着您浪费了New实例。只是...
Dim cgen As Chrmsm = RandomGen(chrmsmize, lb, ub)
我打破了下一行,所以我可以更好地理解它。
Dim lstChrsms1 As List(Of Chrmsm) = {cgen}.ToList
在索引为0的一个Chrmsm上创建一个列表。 关于以下代码行...
cgen = Solve({cgen}.ToList)(1)
您的Solve函数返回一个List(Of Chrmsm),因此无法分配给Chrmsm类型的变量。 所以...
Dim lstChrsms2 as List(OfChrism) = Solve(lstChrsms1)
希望这会有所帮助。