📄 tushi.frm
字号:
VERSION 5.00
Begin VB.Form Run
Caption = "调度算法的演示程序"
ClientHeight = 4470
ClientLeft = 8535
ClientTop = 4350
ClientWidth = 6150
Icon = "tushi.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4470
ScaleWidth = 6150
Begin VB.PictureBox Picture1
Appearance = 0 'Flat
ForeColor = &H80000008&
Height = 1935
Left = 240
ScaleHeight = 1905
ScaleWidth = 5625
TabIndex = 11
Top = 2400
Width = 5655
End
Begin VB.Label lab
AutoSize = -1 'True
Caption = "F"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Index = 5
Left = 240
TabIndex = 10
Top = 1920
Visible = 0 'False
Width = 135
End
Begin VB.Label lab
AutoSize = -1 'True
Caption = "E"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Index = 4
Left = 240
TabIndex = 9
Top = 1560
Visible = 0 'False
Width = 135
End
Begin VB.Label lab
AutoSize = -1 'True
Caption = "D"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Index = 3
Left = 240
TabIndex = 8
Top = 1200
Visible = 0 'False
Width = 135
End
Begin VB.Label lab
AutoSize = -1 'True
Caption = "C"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Index = 2
Left = 240
TabIndex = 7
Top = 840
Visible = 0 'False
Width = 135
End
Begin VB.Label lab
AutoSize = -1 'True
Caption = "B"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Index = 1
Left = 240
TabIndex = 6
Top = 510
Visible = 0 'False
Width = 135
End
Begin VB.Label lab
AutoSize = -1 'True
Caption = "A"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Index = 0
Left = 240
TabIndex = 5
Top = 240
Visible = 0 'False
Width = 135
End
Begin VB.Label Label5
AutoSize = -1 'True
Caption = "进程"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 210
Left = 720
TabIndex = 4
Top = 2640
Width = 450
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "带权周转时间"
Height = 180
Left = 360
TabIndex = 3
Top = 3845
Width = 1080
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "周转时间"
Height = 180
Left = 600
TabIndex = 2
Top = 3480
Width = 720
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "完成时间"
Height = 180
Left = 600
TabIndex = 1
Top = 3120
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Label1"
Height = 180
Left = 120
TabIndex = 0
Top = 120
Width = 540
End
End
Attribute VB_Name = "Run"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim ftsum As Integer, rtsum As Integer
Dim work As Integer, h As Integer, l As Integer
Dim rtime(5) As Single, stime(5) As Single, ftime(5) As Single, btime(5) As Single, ttime(5) As Single, wtime(5) As Single
Dim amin, k, r, am, sm, preftime, sumt, sump As Integer, avgt, avgp As Single
Private Sub Form_Load()
Show
Cls
prftime = 0
sumt = 0
sump = 0
Dim pro(1 To 6) As ProType
Dim i As Integer, j As Integer, sum As Integer
Dim x As Integer, y As Integer
Dim xa As Integer
Dim group As Integer
work = MDIForm1.num.Text
Scale (0, 0)-(100, 100)
Label1.Top = 1
Label1.Left = 1
For i = 0 To work - 1
rtime(i) = MDIForm1.reach(i).Text
stime(i) = MDIForm1.service(i).Text
lab(i).Visible = True
Next i
For i = 0 To work - 1
pro(i + 1).rtime = MDIForm1.reach(i).Text
pro(i + 1).stime = MDIForm1.service(i).Text
lab(i).Visible = True
Next i
Line (0, 0)-(50, 0), QBColor(4)
Line (10, 48)-(90, 48), QBColor(4)
Line (10, 5)-(10, 48), QBColor(4)
Line (0, 52)-(100, 52), QBColor(0)
Line (5, 55)-(95, 55), QBColor(0)
Line (5, 95)-(95, 95), QBColor(0)
Line (5, 55)-(5, 95), QBColor(0)
Line (95, 55)-(95, 95), QBColor(0)
Run.DrawWidth = 3
For y = 7 To 48
PSet (10, y), QBColor(4)
y = y + 6
Next y
'--------FCFS算法----------------------------------------------------
If MDIForm1.title.Caption = "——FCFS方式" Then
btime(0) = rtime(0) 'btime()开始时间
ftime(0) = btime(0) + stime(0) 'ftime()完成时间
ttime(0) = ftime(0) - rtime(0) 'ttime()周转时间
wtime(0) = ttime(0) / stime(0) 'wtime()带权周转时间
For i = 1 To work - 1
If rtime(i) < ftime(i - 1) Then
btime(i) = ftime(i - 1)
ftime(i) = btime(i) + stime(i)
ttime(i) = ftime(i) - rtime(i)
wtime(i) = ttime(i) / stime(i)
Else
btime(i) = rtime(i)
ftime(i) = btime(i) + stime(i)
ttime(i) = ftime(i) - rtime(i)
wtime(i) = ttime(i) / stime(i)
End If
ftsum = ftime(i)
rtsum = rtime(i)
'group = 73 / ftsum
Next i
Label1.Caption = "进程完成需要的总时间为:" & ftsum
group = 0
sum = 0
Do While sum < 80
sum = group * ftsum
group = group + 1
Loop
group = group - 2
For x = 10 To 95
PSet (x, 48), QBColor(4)
x = x + group
Next x
Run.DrawWidth = 5
For xa = btime(0) * group + 11 To ftime(0) * group + 12
PSet (xa, 7), QBColor(1)
Next xa
For i = 1 To work - 1
For xa = btime(i) * group + 12 + i * 2 To ftime(i) * group + 12 + i * 2
PSet (xa, 7 * (i + 1)), QBColor(1 + i)
Next xa
Next i
Picture1.Cls
Picture1.Print
Picture1.Print " 进程 到达时间 服务时间 完成时间 周转时间 带权周转时间";
Picture1.Print
For i = 0 To work - 1
Picture1.Print " "; i + 1; " "; rtime(i); " "; stime(i); " "; ftime(i); " "; ttime(i); " "; wtime(i); " ";
Picture1.Print
Next i
'------SJF方式----------------------------------------------------
ElseIf MDIForm1.title.Caption = "——SPF(非抢占)方式" Then
For i = 0 To work - 1
pro(i + 1).rtime = MDIForm1.reach(i).Text
pro(i + 1).stime = MDIForm1.service(i).Text
pro(i + 1).flag = False
Next i
Call arraybyrtime
With pro(1)
.ftime = .rtime + .stime
.flag = True
.ttime = .ftime - .rtime
.wtime = .ttime / .stime
preftime = .ftime
.btime = .rtime
sumt = sumt + .ttime
sump = sump + .wtime
End With
k = 2
Do
r = 0
For i = 1 To work
If pro(i).rtime <= preftime And pro(i).flag = False Then
r = r + 1
m = pro(i).stime
amin = i
End If
Next i
j = 0
For i = 1 To work
If pro(i).rtime <= preftime And pro(i).flag = False And r <> 0 Then
If pro(i).stime < m Then
m = pro(i).stime
amin = i
End If
j = j + 1
If j > r - 1 Then
Exit For
End If
ElseIf pro(i).rtime > preftime And pro(i).flag = False And r = 0 Then
amin = i
Exit For
End If
Next i
With pro(amin)
If .rtime > preftime Then
.ftime = .rtime + .stime
.btime = .rtime
Else
.ftime = preftime + .stime
.btime = preftime
End If
preftime = .ftime
.ttime = .ftime - .rtime
.wtime = .ttime / .stime
.flag = True
sumt = sumt + .ttime
sump = sump + .wtime
End With
k = k + 1
Loop While (k <= work)
Label1.Caption = "进程完成需要的总时间为:" & preftime
group = 0
sum = 0
Do While sum < 80
sum = group * preftime
group = group + 1
Loop
group = group - 2
For x = 10 To 95
PSet (x, 48), QBColor(4)
x = x + group
Next x
For xa = pro(1).btime * group + 11 To pro(1).ftime * group + 12
PSet (xa, 7), QBColor(1)
Next xa
For i = 2 To work
For xa = pro(i).btime * group + 12 + i To pro(i).ftime * group + 12 + i
PSet (xa, 7 * i), QBColor(i)
Next xa
Next i
Picture1.Cls
Picture1.Print
Picture1.Print " 进程 到达时间 服务时间 完成时间 周转时间 带权周转时间";
Picture1.Print
For i = 1 To work
With pro(i)
Picture1.Print " "; i; " "; .rtime; " "; .stime; " "; .ftime; " "; .ttime; " "; .wtime; " ";
End With
Picture1.Print
Next i
'--------------------------------HRRN方式----------------------------------------
ElseIf MDIForm1.title.Caption = "——HRRN方式" Then
For i = 0 To work - 1
pro(i + 1).rtime = MDIForm1.reach(i).Text
pro(i + 1).stime = MDIForm1.service(i).Text
pro(i + 1).flag = False
Next i
Call arraybyrtime '以到达时间先后排序
sumt = 0
sump = 0
With pro(1)
.ftime = .rtime + .stime
.ttime = .ftime - .rtime
.wtime = .ttime / .stime
preftime = .ftime
sumt = sumt + .ttime
sump = sump + .wtime
End With
k = 2
Do
r = 0
For i = 2 To work
pro(i).respond = 1 + (preftime - pro(i).rtime) / pro(i).stime
If pro(i).rtime <= preftime And pro(i).flag = False Then
r = r + 1
End If
Next i
j = 0
m = 0
For i = 2 To work
If pro(i).rtime <= preftime And pro(i).flag = False Then
If pro(i).respond > m Then
imax = i
m = pro(imax).respond
End If
j = j + 1
If j > r - 1 Then
Exit For
End If
ElseIf pro(i).rtime > preftime And pro(i).flag = False Then
imax = i
Exit For
End If
Next i
With pro(imax)
If .rtime > preftime Then
.btime = .rtime
.ftime = .rtime + .stime
Else
.ftime = preftime + .stime
.btime = preftime
End If
preftime = .ftime
.ttime = .ftime - .rtime
.wtime = .ttime / .stime
.flag = True
sumt = sumt + .ttime
sump = sump + .wtime
End With
k = k + 1
Loop While (k <= work)
Label1.Caption = "进程完成需要的总时间为:" & preftime
group = 0
sum = 0
Do While sum < 80
sum = group * preftime
group = group + 1
Loop
group = group - 2
For x = 10 To 95
PSet (x, 48), QBColor(4)
x = x + group
Next x
For xa = pro(1).btime * group + 11 To pro(1).ftime * group + 12
PSet (xa, 7), QBColor(1)
Next xa
For i = 2 To work
For xa = pro(i).btime * group + 12 + i To pro(i).ftime * group + 12 + i
PSet (xa, 7 * i), QBColor(i)
Next xa
Next i
Picture1.Cls
Picture1.Print
Picture1.Print " 进程 到达时间 服务时间 完成时间 周转时间 带权周转时间";
Picture1.Print
For i = 1 To work
With pro(i)
Picture1.Print " "; i; " "; .rtime; " "; .stime; " "; .ftime; " "; .ttime; " "; .wtime; " ";
End With
Picture1.Print
Next i
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -