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

📄 optimumpath.frm

📁 本程序是一个用prim算法寻找最小生成树的小程序。
💻 FRM
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "Mscomctl.ocx"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   8100
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   11880
   LinkTopic       =   "Form1"
   ScaleHeight     =   8100
   ScaleWidth      =   11880
   Begin VB.PictureBox Picture1 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      DrawWidth       =   3
      ForeColor       =   &H80000008&
      Height          =   3615
      Left            =   0
      ScaleHeight     =   63.235
      ScaleMode       =   6  'Millimeter
      ScaleWidth      =   126.736
      TabIndex        =   2
      Top             =   720
      Width           =   7215
      Begin VB.Label picture2 
         Caption         =   "Label2"
         Height          =   375
         Left            =   1200
         TabIndex        =   5
         Top             =   3000
         Width           =   5175
      End
      Begin VB.Line Line1 
         BorderColor     =   &H00404000&
         Index           =   0
         Visible         =   0   'False
         X1              =   76.2
         X2              =   84.667
         Y1              =   16.933
         Y2              =   27.517
      End
      Begin VB.Label text1 
         BackStyle       =   0  'Transparent
         Caption         =   "Label2"
         ForeColor       =   &H00FF00FF&
         Height          =   255
         Index           =   0
         Left            =   2520
         TabIndex        =   4
         Top             =   600
         Width           =   255
      End
      Begin VB.Shape Shape1 
         BorderColor     =   &H00C000C0&
         Height          =   375
         Index           =   0
         Left            =   3480
         Shape           =   3  'Circle
         Top             =   840
         Visible         =   0   'False
         Width           =   375
      End
      Begin VB.Label Label1 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         BackStyle       =   0  'Transparent
         Caption         =   "Label1"
         ForeColor       =   &H00C00000&
         Height          =   255
         Index           =   0
         Left            =   2640
         TabIndex        =   3
         Top             =   960
         Visible         =   0   'False
         Width           =   255
      End
   End
   Begin MSComctlLib.StatusBar StatusBar1 
      Align           =   2  'Align Bottom
      Height          =   375
      Left            =   0
      TabIndex        =   1
      Top             =   7725
      Width           =   11880
      _ExtentX        =   20955
      _ExtentY        =   661
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   2
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   5080
            MinWidth        =   5080
         EndProperty
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.ImageList ImageList1 
      Left            =   3600
      Top             =   1440
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   32
      ImageHeight     =   32
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   5
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "optimumpath.frx":0000
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "optimumpath.frx":7126
            Key             =   ""
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "optimumpath.frx":AB70
            Key             =   ""
         EndProperty
         BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "optimumpath.frx":B11A
            Key             =   ""
         EndProperty
         BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "optimumpath.frx":CC7E
            Key             =   ""
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.Toolbar Toolbar1 
      Align           =   1  'Align Top
      Height          =   630
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   11880
      _ExtentX        =   20955
      _ExtentY        =   1111
      ButtonWidth     =   1773
      ButtonHeight    =   953
      Appearance      =   1
      _Version        =   393216
      BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
         NumButtons      =   6
         BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "增加顶点"
            Key             =   "newv"
            Description     =   "增加新节点"
         EndProperty
         BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "删除顶点"
            Key             =   "delv"
            Description     =   "删除接点"
         EndProperty
         BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "连接顶点"
            Key             =   "linkv"
            Description     =   "连接接点"
         EndProperty
         BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "最小生成树"
            Key             =   "opt"
            Description     =   "最小生成树"
         EndProperty
         BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "刷新"
         EndProperty
         BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Caption         =   "最短路径"
         EndProperty
      EndProperty
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim p As dijstra
Private Sub drf()
Picture1.Left = Toolbar1.Left
Picture1.Top = Toolbar1.Height
Picture1.Height = StatusBar1.Top - Toolbar1.Height
Picture1.Width = Toolbar1.Width
picture2.Height = 6.615
picture2.Width = Picture1.Width
picture2.Left = 0
picture2.Top = 0 'Picture1.Height - picture2.Height
End Sub
Private Sub Form_Load()
Dim i As Integer
On Error GoTo epr
cn.ConnectionTimeout = 50
cn.Provider = "sqloledb"
cn.Properties("data source").value = Getsname
cn.Properties("initial catalog").value = "test3"
cn.Properties("integrated security").value = "sspi"
cn.Open
drf
tindex = 0: aindex = 0
text1(tindex).Visible = False
Toolbar1.Buttons(2).Enabled = False
Picture1.Cls
Exit Sub
epr:
i = MsgBox(Err.Description, vbOKCancel, "error")
Err.Clear
End Sub
Private Sub Form_Resize()
drf
pref
End Sub

Private Sub Picture1_DblClick()
Form2.Show
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
StatusBar1.Panels(1).Text = "X=" & Str(X) & ":Y=" & Str(Y)
StatusBar1.Panels(2).Text = "图形显示区"
End Sub
Sub drawv()
Dim i As Integer
For i = 1 To tindex
 Unload text1(i)
 Unload Shape1(i)
Next i
tindex = loadv(ver(), "vertex")
For i = 1 To nv
Load Shape1(i)
With Shape1(i)
.Left = ver(i).px - 3
.Top = ver(i).py - 3
.Visible = True
End With
Load text1(i)
With text1(i)
.Left = Val(ver(i).px) - 3
.Top = Val(ver(i).py) - 3
.Visible = True
.Caption = Str(ver(i).id)
.ForeColor = vbRed
End With
Next i
End Sub
Sub drawa()
Dim i As Integer
For i = 1 To aindex
Unload Label1(i)
Unload Line1(i)
Next i
aindex = loada(arc(), "arc")
na = nac
Toolbar1.Buttons(2).Enabled = True
For i = 1 To aindex
 Load Line1(i)
 With Line1(i)
 .X1 = ver(arc(i).sid).px
 .Y1 = ver(arc(i).sid).py
 .X2 = ver(arc(i).eid).px
 .Y2 = ver(arc(i).eid).py
 .Visible = True
 End With
 Load Label1(i)
 With Label1(i)
 .Left = (ver(arc(i).sid).px + ver(arc(i).eid).px) / 2
 .Top = (ver(arc(i).sid).py + ver(arc(i).eid).py) / 2
 .Caption = arc(i).ilink
 .Visible = True
 End With
Next i
End Sub

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
If Button.Index = 1 Then Form2.Show: Exit Sub
If Button.Index = 3 Then Form3.Show: Exit Sub
If Button.Index = 2 Then deleteve: Exit Sub
If Button.Index = 4 Then Form4.Show: Exit Sub
If Button.Index = 5 Then pref
If Button.Index = 6 Then pref: spath
End Sub
 Sub pref()
 Picture1.Cls
 drawv
 drawa
 End Sub
Sub deleteve()
Dim i As Integer
On Error GoTo epr
i = InputBox("输入要删除的接点好", "提示")
Unload text1(i)
cn.Execute "delete from vertex where id='" & Str(i) & "'"
cn.Execute "delete from arc where sid='" & Str(i) & "'or eid='" & Str(i) & "'"
pref
Exit Sub
epr:
MsgBox Err.Description, vbOKOnly, "error"
End Sub
Sub spath()
Dim i, j As Integer
Set p = New dijstra
p.initd nv
p.loadmat nv, na
n = InputBox("起始顶点号", "提示", 1)
If IsNumeric(n) = False Or n < 1 Then Exit Sub
p.rpath n
p.huishuo
For i = 1 To nv
  For j = 1 To path(i, 1)
  Line1(path(i, j + 1)).BorderColor = vbYellow
  Next j
Next i
picture2.Caption = ""
For i = 1 To nv
picture2.Caption = picture2.Caption & " ::" & Str(pa(i).fid) & "到" & Str(pa(i).sid) & "为:" & Str(pa(i).value)
Next i
End Sub

⌨️ 快捷键说明

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