📄 随机网络.frm
字号:
VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1
Caption = "产生随机网络"
ClientHeight = 10080
ClientLeft = 60
ClientTop = 450
ClientWidth = 14445
LinkTopic = "Form1"
ScaleHeight = 10080
ScaleWidth = 14445
Begin VB.CommandButton Command3
Caption = "保存"
Height = 495
Left = 10680
TabIndex = 9
Top = 9480
Width = 855
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 11880
Top = 9480
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin RichTextLib.RichTextBox RText1
Height = 7095
Left = 12600
TabIndex = 8
Top = 2760
Width = 1575
_ExtentX = 2778
_ExtentY = 12515
_Version = 393217
ScrollBars = 2
TextRTF = $"随机网络.frx":0000
End
Begin VB.CommandButton Command2
Caption = "退出"
Height = 495
Left = 9480
TabIndex = 7
Top = 9480
Width = 975
End
Begin VB.TextBox Text4
Height = 375
Left = 12600
TabIndex = 1
Text = "0.01"
Top = 1680
Width = 1335
End
Begin VB.TextBox Text3
Height = 375
Left = 12600
TabIndex = 0
Text = "100"
Top = 720
Width = 1335
End
Begin VB.TextBox Text2
Height = 735
Left = 240
MultiLine = -1 'True
TabIndex = 3
Top = 9360
Width = 9135
End
Begin VB.CommandButton Command1
Caption = "运行"
Height = 495
Left = 12600
TabIndex = 2
Top = 2040
Width = 1335
End
Begin VB.PictureBox Pic1
AutoRedraw = -1 'True
Height = 9015
Left = 240
ScaleHeight = 597
ScaleMode = 3 'Pixel
ScaleWidth = 813
TabIndex = 5
Top = 240
Width = 12255
End
Begin VB.Label Label3
Caption = "点:"
Height = 255
Left = 12600
TabIndex = 11
Top = 2520
Width = 375
End
Begin VB.Label Label4
Caption = "度"
Height = 255
Left = 13080
TabIndex = 10
Top = 2520
Width = 375
End
Begin VB.Label Label2
Caption = "输入连接概率(默认为0.01)"
Height = 375
Left = 12600
TabIndex = 6
Top = 1200
Width = 1215
End
Begin VB.Label Label1
Caption = "输入节点个数(默认为100)"
Height = 375
Left = 12600
TabIndex = 4
Top = 360
Width = 1095
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Type POINTAPI '自定义类型,确定坐标点
X As Long
Y As Long
End Type
Dim PointCount As Integer '点数量
Public PicX As Integer '点的宽度
Public PicY As Integer '点的高度
Public pWidth As Integer '
Dim Points() As POINTAPI
Dim Counts() As Integer '统计度
Dim M() As Integer '统计度
Dim p As Single '连接概率
Dim Avedegree As Double '平均度'
Private Sub Command1_Click()
PointCount = Val(Text3.Text)
p = Val(Text4.Text)
ReDim M(1 To PointCount, 1 To PointCount) As Integer
ReDim Counts(1 To PointCount) As Integer
ReDim Points(1 To PointCount) As POINTAPI
Pic1.Cls
CreatePic
Command1.Caption = "再来一次"
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Command3_Click()
Dim Degree As String
CommonDialog1.Filter = "text file(*.txt)|*.txt"
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowSave
Degree = CommonDialog1.FileName
RText1.SaveFile Degree
End Sub
Private Sub Form_Load()
PicX = Pic1.ScaleWidth
PicY = Pic1.ScaleHeight
pWidth = 2
End Sub
Private Sub CreatePic()
Randomize
For i = 1 To PointCount
Points(i).X = PicX * Rnd()
Points(i).Y = PicY * Rnd()
Counts(i) = 0
Pic1.Line (Points(i).X - pWidth, Points(i).Y - pWidth)-(Points(i).X + pWidth, Points(i).Y + pWidth), vbRed, B
Next i '生成所设定的节点
For i = 1 To PointCount - 1
For j = i + 1 To PointCount
If Rnd(1) < p Then '根据概率P连接节点
Pic1.Line (Points(i).X, Points(i).Y)-(Points(j).X, Points(j).Y), vbBlue
Counts(i) = Counts(i) + 1
Counts(j) = Counts(j) + 1
M(i, j) = 1
M(j, i) = 1
End If
Next j
Next i
RText1.Text = ""
For i = 1 To PointCount
RText1.Text = RText1.Text + CStr(i) + " " + CStr(Counts(i)) + vbCrLf
Next i
Text2.Text = ""
Avedegree = 0
For i = 1 To PointCount
Avedegree = Avedegree + Counts(i)
Next i
Avedegree = Avedegree / PointCount
Text2.Text = Text2.Text + "该随机网络点为:" + CStr(PointCount) + vbCrLf + "连接概率p=" + CStr(p) + vbCrLf + "该随机网络平均度为:" + CStr(Avedegree) + vbCrLf
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -