Dim xp As Double '=x*100 Dim yp As Double '=y*100 Dim xn As Double '=xnew Dim yn As Double '=ynew Dim x As Double 'first variable Dim y As Double 'second variable Dim T0 As Double 'intial temparture Dim T As Double 'current temperate Dim alfa As Double 'decreasing rate Dim Num As Integer 'number of base Dim Ax(10) As Double 'base Dim Ay(10) As Double 'base Dim Abinary(10) As Integer 'base Dim Fxyc As Double 'current objective function Dim Fxyn As Double ' new objective function Dim random As Double 'random variable Dim Bolzman As Double Dim counter As Long Dim functionxy(200000) As Double counter = 0 xp = 0 yp = 0 x = 0 y = 0 T0 = 0 T = 0 alfa = 0 Num = 10 Fxyc = 0 Fxyn = 0 random = 0 Bolzman = 0 'step 1 initialization step T0 = 100 T = T0 alfa = 0.999 For i = 0 To 9 Ax(i) = 0 Next For i = 0 To 9 Ay(i) = 0 Next Abinary(0) = 1 For i = 1 To 9 Abinary(i) = Abinary(i - 1) * 2 Next 'step 2 constructing step For i = 0 To 9 xp = Abinary(i) * Ax(i) + xp yp = Abinary(i) * Ay(i) + yp Next x = xp / 100 y = yp / 100 Fxyc = (1.5 - x + x * y) * (1.5 - x + x * y) + (2.25 - x + x * y * y) * (2.25 - x + x * y * y) + (2.625 - x + x * y * y * y) * (2.625 - x + x * y * y * y) 'step 3 calculating neighbour While T > 0.001 counter = counter + 1 Dim randstep3 As Double Dim First As Boolean randstep3 = Math.Rnd If randstep3 < 0.5 Then First = True Else First = False End If Dim random0_9 As Double If First = True Then random0_9 = Fix(Math.Rnd * 10) Select Case random0_9 Case 0 If Ax(random0_9) = 0 Then Ax(random0_9) = 1 Else Ax(random0_9) = 0 End If Case 1 If Ax(random0_9) = 0 Then Ax(random0_9) = 1 Else Ax(random0_9) = 0 End If Case 2 If Ax(random0_9) = 0 Then Ax(random0_9) = 1 Else Ax(random0_9) = 0 End If Case 3 If Ax(random0_9) = 0 Then Ax(random0_9) = 1 Else Ax(random0_9) = 0 End If Case 4 If Ax(random0_9) = 0 Then Ax(random0_9) = 1 Else Ax(random0_9) = 0 End If Case 5 If Ax(random0_9) = 0 Then Ax(random0_9) = 1 Else Ax(random0_9) = 0 End If Case 6 If Ax(random0_9) = 0 Then Ax(random0_9) = 1 Else Ax(random0_9) = 0 End If Case 7 If Ax(random0_9) = 0 Then Ax(random0_9) = 1 Else Ax(random0_9) = 0 End If Case 8 If Ax(random0_9) = 0 Then Ax(random0_9) = 1 Else Ax(random0_9) = 0 End If Case 9 If Ax(random0_9) = 0 Then Ax(random0_9) = 1 Else Ax(random0_9) = 0 End If End Select Else 'Dim random0_9 As Double random0_9 = Fix(Math.Rnd * 10) Select Case random0_9 Case 0 If Ay(random0_9) = 0 Then Ay(random0_9) = 1 Else Ay(random0_9) = 0 End If Case 1 If Ay(random0_9) = 0 Then Ay(random0_9) = 1 Else Ay(random0_9) = 0 End If Case 2 If Ay(random0_9) = 0 Then Ay(random0_9) = 1 Else Ay(random0_9) = 0 End If Case 3 If Ay(random0_9) = 0 Then Ay(random0_9) = 1 Else Ay(random0_9) = 0 End If Case 4 If Ay(random0_9) = 0 Then Ay(random0_9) = 1 Else Ay(random0_9) = 0 End If Case 5 If Ay(random0_9) = 0 Then Ay(random0_9) = 1 Else Ay(random0_9) = 0 End If Case 6 If Ay(random0_9) = 0 Then Ay(random0_9) = 1 Else Ay(random0_9) = 0 End If Case 7 If Ay(random0_9) = 0 Then Ay(random0_9) = 1 Else Ay(random0_9) = 0 End If Case 8 If Ay(random0_9) = 0 Then Ay(random0_9) = 1 Else Ay(random0_9) = 0 End If Case 9 If Ay(random0_9) = 0 Then Ay(random0_9) = 1 Else Ay(random0_9) = 0 End If End Select End If 'step 5 xp = 0 yp = 0 For i = 0 To 9 xp = Abinary(i) * Ax(i) + xp yp = Abinary(i) * Ay(i) + yp Next xn = xp / 100 yn = yp / 100 Fxyn = (1.5 - xn + xn * yn) * (1.5 - xn + xn * yn) + (2.25 - xn + xn * yn * yn) * (2.25 - xn + xn * yn * yn) + (2.625 - xn + xn * yn * yn * yn) * (2.625 - xn + xn * yn * yn * yn) Dim deltaf As Double deltaf = Fxyn - Fxyc If deltaf < 0 Then x = xn y = yn Fxyc = Fxyn Else Bolzman = Math.Exp(-deltaf / T) Dim r As Double r = Math.Rnd If r < Bolzman Then x = xn y = yn Fxyc = Fxyn End If End If 'step 6 Dim minglobal As Double T = T * alfa functionxy(counter) = Fxyc Wend