frmCar.frm
资源名称:lx.rar [点击查看]
上传用户:sdxhx123
上传日期:2022-08-06
资源大小:3453k
文件大小:16k
源码类别:
数值算法/人工智能
开发平台:
Visual Basic
- VERSION 5.00
- Begin VB.Form frmCar
- BorderStyle = 1 'Fixed Single
- Caption = "背包问题简单应用"
- ClientHeight = 8865
- ClientLeft = 45
- ClientTop = 405
- ClientWidth = 9315
- BeginProperty Font
- Name = "宋体"
- Size = 10.5
- Charset = 134
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Icon = "frmCar.frx":0000
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- Picture = "frmCar.frx":030A
- ScaleHeight = 8865
- ScaleWidth = 9315
- StartUpPosition = 3 '窗口缺省
- Begin VB.ListBox List1
- BeginProperty Font
- Name = "隶书"
- Size = 15.75
- Charset = 134
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 1950
- Left = 1800
- TabIndex = 21
- Top = 6360
- Width = 5535
- End
- Begin VB.TextBox Text9
- BeginProperty Font
- Name = "Times New Roman"
- Size = 14.25
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 400
- Left = 4440
- TabIndex = 9
- Top = 4200
- Width = 1800
- End
- Begin VB.CommandButton Command2
- Caption = "清空数据"
- Height = 400
- Left = 5880
- TabIndex = 11
- Top = 5000
- Width = 1500
- End
- Begin VB.CommandButton Command1
- Caption = "确定/决策"
- Height = 400
- Left = 2160
- TabIndex = 10
- Top = 5000
- Width = 1500
- End
- Begin VB.TextBox Text8
- BeginProperty Font
- Name = "Times New Roman"
- Size = 14.25
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 400
- Left = 6000
- TabIndex = 8
- Top = 3500
- Width = 1440
- End
- Begin VB.TextBox Text7
- BeginProperty Font
- Name = "Times New Roman"
- Size = 14.25
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 400
- Left = 6000
- TabIndex = 7
- Top = 2900
- Width = 1440
- End
- Begin VB.TextBox Text6
- BeginProperty Font
- Name = "Times New Roman"
- Size = 14.25
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 400
- Left = 6000
- TabIndex = 6
- Top = 2300
- Width = 1440
- End
- Begin VB.TextBox Text5
- BeginProperty Font
- Name = "Times New Roman"
- Size = 14.25
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 400
- Left = 6000
- TabIndex = 5
- Top = 1680
- Width = 1440
- End
- Begin VB.TextBox Text4
- BeginProperty Font
- Name = "Times New Roman"
- Size = 14.25
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 400
- Left = 3360
- TabIndex = 4
- Top = 3500
- Width = 1440
- End
- Begin VB.TextBox Text3
- BeginProperty Font
- Name = "Times New Roman"
- Size = 14.25
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 400
- Left = 3360
- TabIndex = 3
- Top = 2900
- Width = 1440
- End
- Begin VB.TextBox Text2
- BeginProperty Font
- Name = "Times New Roman"
- Size = 14.25
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 400
- Left = 3360
- TabIndex = 2
- Top = 2300
- Width = 1440
- End
- Begin VB.TextBox Text1
- BeginProperty Font
- Name = "Times New Roman"
- Size = 14.25
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 400
- Left = 3360
- TabIndex = 1
- Top = 1700
- Width = 1440
- End
- Begin VB.Line Line2
- X1 = 5400
- X2 = 5400
- Y1 = 1560
- Y2 = 3960
- End
- Begin VB.Line Line1
- X1 = 600
- X2 = 8520
- Y1 = 5640
- Y2 = 5640
- End
- Begin VB.Label Label11
- BackStyle = 0 'Transparent
- Caption = "可用资金/万元:"
- BeginProperty Font
- Name = "楷体_GB2312"
- Size = 15.75
- Charset = 134
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 315
- Left = 1800
- TabIndex = 20
- Top = 4320
- Width = 2715
- End
- Begin VB.Label Label9
- BackStyle = 0 'Transparent
- Caption = "最佳投资决策是:"
- BeginProperty Font
- Name = "楷体_GB2312"
- Size = 15.75
- Charset = 134
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 375
- Left = 720
- TabIndex = 19
- Top = 5880
- Width = 2775
- End
- Begin VB.Label Label8
- Appearance = 0 'Flat
- BackColor = &H80000005&
- BackStyle = 0 'Transparent
- Caption = "项目四:"
- BeginProperty Font
- Name = "隶书"
- Size = 15
- Charset = 134
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 405
- Left = 1800
- TabIndex = 18
- Top = 3480
- Width = 1245
- End
- Begin VB.Label Label7
- Appearance = 0 'Flat
- BackColor = &H80000005&
- BackStyle = 0 'Transparent
- Caption = "项目三:"
- BeginProperty Font
- Name = "隶书"
- Size = 15
- Charset = 134
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 405
- Left = 1800
- TabIndex = 17
- Top = 2895
- Width = 1245
- End
- Begin VB.Label Label6
- Appearance = 0 'Flat
- BackColor = &H80000005&
- BackStyle = 0 'Transparent
- Caption = "项目二:"
- BeginProperty Font
- Name = "隶书"
- Size = 15
- Charset = 134
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 405
- Left = 1800
- TabIndex = 16
- Top = 2280
- Width = 1245
- End
- Begin VB.Label Label5
- Appearance = 0 'Flat
- BackColor = &H80000005&
- BackStyle = 0 'Transparent
- Caption = "项目一:"
- BeginProperty Font
- Name = "隶书"
- Size = 15
- Charset = 134
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 330
- Left = 1800
- TabIndex = 15
- Top = 1680
- Width = 1245
- End
- Begin VB.Label Label4
- Appearance = 0 'Flat
- BackColor = &H80000005&
- BackStyle = 0 'Transparent
- Caption = "净回报额/万元"
- BeginProperty Font
- Name = "楷体_GB2312"
- Size = 15.75
- Charset = 134
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 405
- Left = 5760
- TabIndex = 14
- Top = 1080
- Width = 2325
- End
- Begin VB.Label Label3
- Appearance = 0 'Flat
- BackColor = &H80000005&
- BackStyle = 0 'Transparent
- Caption = "投资额/万元"
- BeginProperty Font
- Name = "楷体_GB2312"
- Size = 15.75
- Charset = 134
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 405
- Left = 3240
- TabIndex = 13
- Top = 1080
- Width = 1965
- End
- Begin VB.Label Label2
- Appearance = 0 'Flat
- BackColor = &H80000005&
- BackStyle = 0 'Transparent
- Caption = "项目编号"
- BeginProperty Font
- Name = "楷体_GB2312"
- Size = 15.75
- Charset = 134
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 405
- Left = 1560
- TabIndex = 12
- Top = 1095
- Width = 1485
- End
- Begin VB.Label Label1
- BackStyle = 0 'Transparent
- Caption = "投资回报决策优化"
- BeginProperty Font
- Name = "楷体_GB2312"
- Size = 21.75
- Charset = 134
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 420
- Left = 2760
- TabIndex = 0
- Top = 240
- Width = 3825
- End
- End
- Attribute VB_Name = "frmCar"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- '====================================
- '回溯法求解背包问题(2008.5.10)
- '南京邮电大学毕业设计
- 'www.njupt.edu.cn
- '模块名称:应用
- '====================================
- Option Explicit
- Dim o(1 To 4), c(1 To 4) As Integer
- Dim limitiw, maxv, W(1 To 4), v(1 To 4) As Single
- Public Function np(i As Integer, tw As Single, tv As Single)
- Dim k As Integer
- If tw + W(i) <= limitiw Then
- c(i) = 1
- If i < 4 Then
- Call np(i + 1, tw + W(i), tv)
- Else
- For k = 1 To 4
- o(k) = c(k)
- Next
- maxv = tv
- End If
- c(i) = 0
- End If
- If tv - v(i) > maxv Then
- If i < 4 Then
- Call np(i + 1, tw, tv - v(i))
- Else
- For k = 1 To 4
- o(k) = c(k)
- Next
- maxv = tv - v(i)
- End If
- End If
- End Function
- Private Sub Command1_Click()
- Dim i As Integer
- Dim a, b, c, d, e, F, g, h As Integer
- a = Val(Text1.Text)
- b = Val(Text2.Text)
- c = Val(Text3.Text)
- d = Val(Text4.Text)
- e = Val(Text5.Text)
- F = Val(Text6.Text)
- g = Val(Text7.Text)
- h = Val(Text8.Text)
- limitiw = Val(Text9.Text)
- For i = 1 To 4
- W(1) = a
- v(1) = e
- W(2) = b
- v(2) = F
- W(3) = c
- v(3) = g
- W(4) = d
- v(4) = h
- Next
- Dim totv As Single
- totv = 0
- For i = 1 To 4
- totv = totv + v(i)
- Next
- maxv = 0
- Call np(1, 0#, totv)
- List1.AddItem "被选中投资项目的编号为:"
- For i = 1 To 4
- If o(i) = 1 Then
- List1.AddItem Str(i)
- End If
- Next
- List1.AddItem "最大回报额是:"
- List1.AddItem maxv
- If a = 0 And c = 0 And e = 0 And g = 0 Then
- List1.Clear
- List1.AddItem "请输入项目的投资成本和回报金额!"
- End If
- If a > limitiw And c > limitiw And e > limitiw And g > limitiw Then
- List1.Clear
- List1.AddItem "目前,您需要更多的可用资金来完成投资!"
- End If
- If limitiw = 0 Then
- List1.AddItem "请输入您的可用资金!"
- End If
- End Sub
- Private Sub Command2_Click()
- Text1.Text = ""
- Text2.Text = ""
- Text3.Text = ""
- Text4.Text = ""
- Text5.Text = ""
- Text6.Text = ""
- Text7.Text = ""
- Text8.Text = ""
- Text9.Text = ""
- List1.Clear
- End Sub