⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 genet1.frm

📁 用VB实现优化计算的智能算法
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   7770
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7080
   LinkTopic       =   "Form1"
   ScaleHeight     =   7770
   ScaleWidth      =   7080
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command3 
      Caption         =   "退出"
      Height          =   495
      Left            =   5520
      TabIndex        =   9
      Top             =   3000
      Width           =   975
   End
   Begin VB.TextBox Text3 
      Height          =   375
      Left            =   1200
      TabIndex        =   7
      Top             =   600
      Width           =   975
   End
   Begin VB.TextBox Text2 
      Height          =   495
      Left            =   3480
      TabIndex        =   4
      Top             =   0
      Width           =   1095
   End
   Begin VB.CommandButton Command2 
      Caption         =   "输入"
      Height          =   495
      Left            =   5520
      TabIndex        =   3
      Top             =   1200
      Width           =   1095
   End
   Begin VB.CommandButton Command1 
      Caption         =   "确定"
      Height          =   495
      Left            =   5520
      TabIndex        =   1
      Top             =   2040
      Width           =   1095
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   1200
      TabIndex        =   0
      Top             =   0
      Width           =   975
   End
   Begin VB.Label Label4 
      Height          =   5055
      Left            =   240
      TabIndex        =   8
      Top             =   1200
      Width           =   3735
   End
   Begin VB.Label Label3 
      Caption         =   "交叉概率"
      Height          =   375
      Left            =   0
      TabIndex        =   6
      Top             =   600
      Width           =   855
   End
   Begin VB.Label Label2 
      Caption         =   "交叉次数"
      Height          =   255
      Left            =   2520
      TabIndex        =   5
      Top             =   120
      Width           =   855
   End
   Begin VB.Label Label1 
      Caption         =   "随机数种子"
      Height          =   375
      Left            =   120
      TabIndex        =   2
      Top             =   120
      Width           =   855
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim oldrand(0 To 54) As Double
 Dim jrand%

Private Sub Command1_Click()
Dim num%, sum%, num1%

sum = 0
randomize
For num = 1 To 100

num1 = flip(Val(Text3.Text))
If (num1 = 1) Then
sum = sum + 1
End If
Next num
Text2.Text = sum
For j = 0 To 54
If (j = 0 Or j Mod 2! = 0) Then
Label4.Caption = Label4.Caption + Str(oldrand(j)) + Chr(0) + Chr(0)
Else
Label4.Caption = Label4.Caption + Str(oldrand(j)) + Chr(13) + Chr(10)
End If
Next j
End Sub

Private Sub Command2_Click()
Dim str1$, str2$
str1 = InputBox("输入随机数种子(0-1)")
str2 = InputBox("输入交叉概率(0-1)")
Text1.Text = Val(str1)
Text3.Text = Val(str2)
End Sub

Public Sub advance_random()
Dim j1%, newrand#
For j1 = 0 To 23
newrand = oldrand(j1) - oldrand(j1 + 31)
If (newrand < 0) Then
newrand = newrand + 1
End If
oldrand(j1) = newrand
Next j1
For j1 = 24 To 54
newrand = oldrand(j1) - oldrand(j1 - 24)
If (newrand < 0) Then
newrand = newrand + 1
End If
oldrand(j1) = newrand
Next j1
End Sub

Public Function randomperc() As Double
jrand = jrand + 1
If (jrand >= 55) Then
jrand = 1
advance_random
End If
randomperc = oldrand(jrand)


End Function

Public Sub randomize()
Dim randomseed!, j1%
For j1 = 0 To 54
oldrand(j1) = 0
Next j1
jrand = 0
randomseed = Val(Text1.Text)
Call warmup_random(randomseed)

End Sub

Public Sub warmup_random(random_seed As Single)
Dim j1%, ii%, new_random#, pre_random#
oldrand(54) = random_seed
new_random = 0.000000001
pre_random = random_seed
For j1 = 1 To 54
ii = (21 * j1) Mod 54
oldrand(ii) = new_random
new_random = pre_random - new_random
If (new_random < 0) Then
new_random = new_random + 1
End If
pre_random = oldrand(ii)
Next j1
advance_random
advance_random
advance_random
jrand = 0
End Sub

Public Function flip(prob As Double) As Integer
Dim tt#
tt = randomperc()
'prob = Val(Text3.Text)
If (tt <= prob) Then
flip = 1
Else
flip = 0
End If

End Function

Private Sub Command3_Click()
End
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -