I want to ask something about VB.NET code. I'm suffering from this problem a lot. Please answer me if you know the solution of my question or give me some comments.
'Declare a structure "Gene"
Public Structure Gene
Dim Seq() As Integer
End Structure
'Here is a procedure, it changes original value.
Public Sub Mutation(ByVal OriginalGene As Gene, ByRef TargetGene As Gene)
Dim P1 As Integer
Dim P2 As Integer
Dim Temp As Integer
P1 = Int((N_Jobs - 1 + 1) * Rnd(RndNum) + 0)
P2 = Int((N_Jobs - 1 + 1) * Rnd(RndNum + 1) + 0)
TargetGene.Seq = OriginalGene.Seq
Temp = TargetGene.Seq(P1)
TargetGene.Seq(P1) = TargetGene.Seq(P2)
TargetGene.Seq(P2) = Temp
End Sub
It's not actually changing the structure. All the structure contains is a pointer to an array. The reference to the array is always the same even though you can have an unlimited number of copies of the structure.
Example of immutable Gene class: