注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Mister.Hu(巷里人家)

Go abroad!

 
 
 

日志

 
 
关于我

A campus photograph palyer,an enthusiastic reader,a solitary writer,a future traffic engineer.

网易考拉推荐

排队系统仿真系统(BY VB)  

2016-03-05 11:56:10|  分类: Senior |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
Private Sub Command1_Click()
Dim Arri As Variant
Dim Left As Variant
Dim Num As Integer
Dim SS As Variant
Dim WNUM As Integer
Dim ACNUM As Integer
Dim SNUM As Integer
Dim WTIME As Integer
Dim WLen As Variant
Dim STime As Variant
Dim SPN() As Integer
Dim PM() As Integer
Dim WT() As Integer
Dim WL() As Integer
Dim STPM() As Integer
Dim STSPN() As Integer
Dim STWT() As Integer
Dim STWL() As Integer

Arri = Text1.Text
Left = Text2.Text
Num = Text7.Text
STime = 500
SS = Arri / Left

MSFlexGrid1.ColAlignment(0) = 4
MSFlexGrid1.ColAlignment(1) = 4
MSFlexGrid2.ColAlignment(0) = 4
MSFlexGrid2.ColAlignment(1) = 4
MSFlexGrid3.ColAlignment(0) = 4
MSFlexGrid3.ColAlignment(1) = 4
MSFlexGrid4.ColAlignment(0) = 4
MSFlexGrid4.ColAlignment(1) = 4
MSFlexGrid5.ColAlignment(0) = 4
MSFlexGrid5.ColAlignment(1) = 4
MSFlexGrid6.ColAlignment(0) = 4
MSFlexGrid6.ColAlignment(1) = 4
MSFlexGrid1.ColWidth(0) = 1200
MSFlexGrid1.ColWidth(1) = 1200
MSFlexGrid2.ColWidth(0) = 1100
MSFlexGrid2.ColWidth(1) = 1100
MSFlexGrid3.ColWidth(0) = 1100
MSFlexGrid3.ColWidth(1) = 1100


ReDim STSPN(Int(Left), STime)
ReDim STWT(0 To Arri + 50, 0 To STime - 1)
ReDim STWL(Int(Left), STime)


For st = 0 To STime - 1
ReDim SPN(Int(Left))
For k = 1 To Int(Left)
  SPN(k - 1) = RPOISSON(Arri / Left)
  STSPN(k - 1, st) = SPN(k - 1)
  MSFlexGrid1.Cols = STime + 1
  MSFlexGrid1.Rows = Int(Left) + 1
  MSFlexGrid1.WordWrap = True
  MSFlexGrid1.TextMatrix(0, 0) = "仿真秒"
  MSFlexGrid1.TextMatrix(0, 1) = "到达车辆"
  MSFlexGrid1.TextMatrix(k, st + 1) = SPN(k - 1)
  MSFlexGrid1.TextMatrix(k, 0) = k
Next k

ACNUM = 0
For k = 1 To Int(Left)
ACNUM = ACNUM + SPN(k - 1) '每次仿真产生的实际车流量
Next k

ReDim WT(ACNUM)
ReDim PM(ACNUM)
ReDim WL(Int(Left))
ReDim STPM(0 To ACNUM - 1, 0 To Int(Left) - 1)
For k = 0 To Int(Left) - 1
    WNUM = 0
    SNUM = 0
  For r = 0 To ACNUM - 1
    If PM(r) = 2 Then
      WNUM = WNUM + 1
    End If
  Next r
  For r = 0 To ACNUM - 1
    If PM(r) = 1 Then
      SNUM = SNUM + 1
    End If
  Next r
  If Num >= SPN(k) + WNUM Then
    For s = 0 To SPN(k) + WNUM - 1
      PM(SNUM + s) = 1
    Next s
  Else
    For T = 0 To Num - 1
      PM(SNUM + T) = 1
    Next T
    For TT = 0 To SPN(k) + WNUM - Num - 1
      PM(SNUM + Num + TT) = 2
    Next TT
  End If
  For SS = 0 To ACNUM - 1
  STPM(SS, k) = PM(SS)
  Next SS
Next k


For ii = 0 To ACNUM - 1
WTIME = 0
For jj = 0 To Int(Left) - 1
If STPM(ii, jj) = 2 Then
WTIME = WTIME + 1
End If
Next jj
WT(ii) = WTIME
STWT(ii, st) = WT(ii)
Next ii

For k = ACNUM To Arri + 50
STWT(k, st) = 99
Next k



For jj = 0 To Int(Left) - 1
WLen = 0
For ii = 0 To ACNUM - 1
If STPM(ii, jj) = 2 Then
WLen = WLen + 1
End If
Next ii
WL(jj) = WLen
STWL(jj, st) = WLen
Next jj

For ii = 0 To Arri + 48
  MSFlexGrid2.Cols = STime + 1
  MSFlexGrid2.Rows = Arri + 51
  MSFlexGrid2.TextMatrix(0, 0) = "车辆ID"
  MSFlexGrid2.TextMatrix(0, 1) = "排队时间"
  MSFlexGrid2.TextMatrix(ii + 1, 0) = ii + 1
  MSFlexGrid2.TextMatrix(ii + 1, st + 1) = STWT(ii, st)
Next ii

For ii = 0 To Int(Left) - 1
  MSFlexGrid3.Cols = STime + 1
  MSFlexGrid3.Rows = Int(Left) + 1
  MSFlexGrid3.TextMatrix(0, 0) = "仿真时间"
  MSFlexGrid3.TextMatrix(0, 1) = "排队长度"
  MSFlexGrid3.TextMatrix(ii + 1, 0) = ii + 1
  MSFlexGrid3.TextMatrix(ii + 1, st + 1) = WL(ii)
Next ii
Next st


Dim maxnum1 As Integer
maxnum1 = 0 
For i = 0 To Int(Left) - 1
For j = 0 To STime - 1
If STSPN(i, j) >= maxnum1 Then
  maxnum1 = STSPN(i, j)
End If
Next j
Next i

Dim SPNUM() As Integer
ReDim SPNUM(maxnum1 + 1)
For i = 0 To Int(Left) - 1
For j = 0 To STime - 1
For k = 0 To maxnum1
If STSPN(i, j) = k Then
  SPNUM(k) = SPNUM(k) + 1
End If
Next k
Next j
Next i

Dim SUMSPNUM As Variant
'SUMSPNUM = 0
For i = 0 To maxnum1
SUMSPNUM = SUMSPNUM + SPNUM(i)
Next i

Dim PSPNUM() As Variant
ReDim PSPNUM(maxnum1 + 1)
For r = 0 To maxnum1
  PSPNUM(r) = SPNUM(r) / SUMSPNUM
  
Next r

For ii = 0 To maxnum1
  MSFlexGrid4.Cols = 3
  MSFlexGrid4.Rows = maxnum1 + 2
  MSFlexGrid4.TextMatrix(0, 0) = "到达车辆"
  MSFlexGrid4.TextMatrix(0, 1) = "发生次数"
  MSFlexGrid4.TextMatrix(0, 2) = "频率"
  MSFlexGrid4.TextMatrix(ii + 1, 0) = ii
  MSFlexGrid4.TextMatrix(ii + 1, 1) = SPNUM(ii)
  MSFlexGrid4.TextMatrix(ii + 1, 2) = Format(PSPNUM(ii), "0.00000")
Next ii


Dim maxnum2 As Integer
maxnum2 = 0 
For i = 0 To ACNUM - 1
For j = 0 To STime - 1
If STWT(i, j) >= maxnum2 Then
  maxnum2 = STWT(i, j)
End If
Next j
Next i



Dim WTNUM() As Integer
ReDim WTNUM(maxnum2)
For k = 0 To maxnum2 - 1
For i = 0 To Arri + 50
For j = 0 To STime - 1
If STWT(i, j) = k Then
  WTNUM(k) = WTNUM(k) + 1
End If
Next j
Next i
Next k

Dim SUMWTNUM As Variant
'SUMSPNUM = 0
For i = 0 To maxnum2
SUMWTNUM = SUMWTNUM + WTNUM(i)
Next i

Dim JQWT As Variant
Dim PWTNUM() As Variant
ReDim PWTNUM(maxnum2 + 2)
For r = 0 To maxnum2
  PWTNUM(r) = WTNUM(r) / SUMWTNUM
   JQWT = PWTNUM(r) * r + JQWT
Next r

For ii = 0 To maxnum2
  MSFlexGrid5.Cols = 3
  MSFlexGrid5.Rows = maxnum2 + 2
  MSFlexGrid5.TextMatrix(0, 0) = "排队时间"
  MSFlexGrid5.TextMatrix(0, 1) = "发生次数"
  MSFlexGrid5.TextMatrix(0, 2) = "频率"
  MSFlexGrid5.TextMatrix(ii + 1, 0) = ii
  MSFlexGrid5.TextMatrix(ii + 1, 1) = WTNUM(ii)
  MSFlexGrid5.TextMatrix(ii + 1, 2) = Format(PWTNUM(ii), "0.00000")
Next ii

Dim maxnum3 As Integer
maxnum3 = 0 
For i = 0 To Int(Left) - 1
For j = 0 To STime - 1
If STWL(i, j) >= maxnum3 Then
  maxnum3 = STWL(i, j)
End If
Next j
Next i

Dim WLNUM() As Integer
ReDim WLNUM(maxnum3 + 1)
For i = 0 To Int(Left) - 1
For j = 0 To STime - 1
For k = 0 To maxnum3
If STWL(i, j) = k Then
  WLNUM(k) = WLNUM(k) + 1
End If
Next k
Next j
Next i

Dim SUMWLNUM As Variant
'SUMSPNUM = 0
For i = 0 To maxnum3
SUMWLNUM = SUMWLNUM + WLNUM(i)
Next i

Dim JQWL As Variant
Dim PWLNUM() As Variant
ReDim PWLNUM(maxnum3 + 1)
For r = 0 To maxnum3
  PWLNUM(r) = WLNUM(r) / SUMWLNUM
  JQWL = PWLNUM(r) * r + JQWL
Next r

For ii = 0 To maxnum3
  MSFlexGrid6.Cols = 3
  MSFlexGrid6.Rows = maxnum3 + 2
  MSFlexGrid6.TextMatrix(0, 0) = "排队长度"
  MSFlexGrid6.TextMatrix(0, 1) = "发生次数"
  MSFlexGrid6.TextMatrix(0, 2) = "频率"
  MSFlexGrid6.TextMatrix(ii + 1, 0) = ii
  MSFlexGrid6.TextMatrix(ii + 1, 1) = WLNUM(ii)
  MSFlexGrid6.TextMatrix(ii + 1, 2) = Format(PWLNUM(ii), "0.00000")
Next ii

For ii = 0 To ACNUM - 1
For jj = 0 To Int(Left) - 1
Picture1.Print STPM(ii, jj);
Next
Picture1.Print
Next



Text4.Text = Format(JQWL, "0.000")
Text5.Text = Format(JQWT * (60 / Left), "0.000")

End Sub

Function cjhs(a As Variant) As Variant
cjhs = 1
For i = 1 To a
cjhs = cjhs * i
Next
End Function

Public Function RPOISSON(lamuda As Single) As Integer
    Dim exp As Single
    exp = 0
    RPOISSON = 0
    While exp < 1
        exp = exp + REXP(lamuda)
        RPOISSON = RPOISSON + 1
    Wend
    RPOISSON = RPOISSON - 1
End Function

Public Function REXP(lamuda As Single) As Single
    Dim u As Single
    u = Rnd()
    REXP = -1 / lamuda * Log(u)
End Function



Private Sub Command2_Click()
ExportFlexDataToExcel MSFlexGrid1, CommonDialog1
End Sub

Private Sub Command3_Click()
ExportFlexDataToExcel MSFlexGrid2, CommonDialog1
End Sub

Private Sub Command4_Click()
ExportFlexDataToExcel MSFlexGrid3, CommonDialog1
End Sub




Private Sub Command5_Click()
ExportFlexDataToExcel MSFlexGrid4, CommonDialog1
End Sub

Private Sub Command6_Click()
ExportFlexDataToExcel MSFlexGrid5, CommonDialog1
End Sub

Private Sub Command7_Click()
ExportFlexDataToExcel MSFlexGrid6, CommonDialog1
End Sub

  评论这张
 
阅读(10)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016