📄 form2.vb
字号:
'GroupBox4
'
Me.GroupBox4.Controls.Add(Me.min4)
Me.GroupBox4.Controls.Add(Me.max4)
Me.GroupBox4.Location = New System.Drawing.Point(584, 8)
Me.GroupBox4.Name = "GroupBox4"
Me.GroupBox4.Size = New System.Drawing.Size(88, 88)
Me.GroupBox4.TabIndex = 46
Me.GroupBox4.TabStop = False
Me.GroupBox4.Text = "车道4"
'
'GroupBox5
'
Me.GroupBox5.Controls.Add(Me.min5)
Me.GroupBox5.Controls.Add(Me.max5)
Me.GroupBox5.Location = New System.Drawing.Point(200, 104)
Me.GroupBox5.Name = "GroupBox5"
Me.GroupBox5.Size = New System.Drawing.Size(88, 88)
Me.GroupBox5.TabIndex = 47
Me.GroupBox5.TabStop = False
Me.GroupBox5.Text = "车道5"
'
'GroupBox6
'
Me.GroupBox6.Controls.Add(Me.min6)
Me.GroupBox6.Controls.Add(Me.max6)
Me.GroupBox6.Location = New System.Drawing.Point(328, 104)
Me.GroupBox6.Name = "GroupBox6"
Me.GroupBox6.Size = New System.Drawing.Size(88, 88)
Me.GroupBox6.TabIndex = 48
Me.GroupBox6.TabStop = False
Me.GroupBox6.Text = "车道6"
'
'GroupBox7
'
Me.GroupBox7.Controls.Add(Me.min7)
Me.GroupBox7.Controls.Add(Me.max7)
Me.GroupBox7.Location = New System.Drawing.Point(456, 104)
Me.GroupBox7.Name = "GroupBox7"
Me.GroupBox7.Size = New System.Drawing.Size(88, 88)
Me.GroupBox7.TabIndex = 49
Me.GroupBox7.TabStop = False
Me.GroupBox7.Text = "车道7"
'
'GroupBox8
'
Me.GroupBox8.Controls.Add(Me.min8)
Me.GroupBox8.Controls.Add(Me.max8)
Me.GroupBox8.Location = New System.Drawing.Point(584, 104)
Me.GroupBox8.Name = "GroupBox8"
Me.GroupBox8.Size = New System.Drawing.Size(88, 88)
Me.GroupBox8.TabIndex = 50
Me.GroupBox8.TabStop = False
Me.GroupBox8.Text = "车道8"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(200, 296)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(104, 21)
Me.TextBox2.TabIndex = 52
Me.TextBox2.Text = ""
'
'PictureBox1
'
Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
Me.PictureBox1.Location = New System.Drawing.Point(320, 200)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(360, 128)
Me.PictureBox1.TabIndex = 53
Me.PictureBox1.TabStop = False
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(24, 296)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(160, 24)
Me.Label6.TabIndex = 54
Me.Label6.Text = "汽车的平均等待时间(秒)"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(200, 352)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(128, 48)
Me.Button2.TabIndex = 55
Me.Button2.Text = "退出程序&E"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(376, 352)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(128, 48)
Me.Button3.TabIndex = 56
Me.Button3.Text = "关于我们&A"
'
'PictureBox2
'
Me.PictureBox2.Image = CType(resources.GetObject("PictureBox2.Image"), System.Drawing.Image)
Me.PictureBox2.Location = New System.Drawing.Point(568, 336)
Me.PictureBox2.Name = "PictureBox2"
Me.PictureBox2.Size = New System.Drawing.Size(104, 104)
Me.PictureBox2.TabIndex = 57
Me.PictureBox2.TabStop = False
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(728, 470)
Me.Controls.Add(Me.PictureBox2)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.PictureBox1)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.GroupBox8)
Me.Controls.Add(Me.GroupBox7)
Me.Controls.Add(Me.GroupBox6)
Me.Controls.Add(Me.GroupBox5)
Me.Controls.Add(Me.GroupBox4)
Me.Controls.Add(Me.GroupBox3)
Me.Controls.Add(Me.GroupBox2)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.Label22)
Me.Controls.Add(Me.Label23)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.TextBox5)
Me.Controls.Add(Me.TextBox4)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Form2"
Me.Text = "value"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
Me.GroupBox3.ResumeLayout(False)
Me.GroupBox4.ResumeLayout(False)
Me.GroupBox5.ResumeLayout(False)
Me.GroupBox6.ResumeLayout(False)
Me.GroupBox7.ResumeLayout(False)
Me.GroupBox8.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myTW As New XmlTextWriter(Application.StartupPath & "\carInfor.xml", Nothing)
Dim myTW2 As New XmlTextWriter(Application.StartupPath & "\lightInfor.xml", Nothing)
Dim myTW3 As New XmlTextWriter(Application.StartupPath & "\lightInfor2.xml", Nothing)
Dim myTW4 As New XmlTextWriter(Application.StartupPath & "\lightInfor3.xml", Nothing)
Dim myTW5 As New XmlTextWriter(Application.StartupPath & "\lightInfor4.xml", Nothing)
Dim carNumber As Long
Dim totalTime As Long
Dim i, j As Integer
Dim u As Double
Dim typeCar As String
Dim typeNum As Integer
Dim OnWhichRoad As Integer
Dim speed(8) As Integer
Dim maxspeed(8) As Integer
Dim minspeed(8) As Integer
Dim arrival(6) As Long
Dim time(10000) As Integer
Dim beta As Integer
Dim flag As Integer
Dim L As Integer
Dim interval As Integer
Dim num As Integer
Dim state As String
Dim a, b, c, a1, b1 As Integer
Dim count As Integer
Dim turn As Integer 'when=1 count
Dim turn2 As Integer 'when =1 count waiting time
Dim waittime As Integer
'----初始化时间和计算所考察时间内出现的车辆数
totalTime = TextBox1.Text
beta = TextBox4.Text
'----车辆到达时间按指数分布呈现
For i = 0 To 5
Do
u = CDbl(1.0 * Rnd() + 0.0)
arrival(i) = -beta * Log(u)
Loop Until arrival(i) <> 0
Next
'----车辆数
For i = 0 To 5
carNumber = (carNumber + totalTime \ arrival(i))
Next
Debug.WriteLine(carNumber)
'---创建XML信息表,方便操作及升级软件功能
myTW.WriteStartDocument()
myTW.Formatting = Formatting.Indented
myTW.WriteStartElement("group")
'---车速上限初始化
maxspeed(0) = max1.Text
maxspeed(1) = max2.Text
maxspeed(2) = max3.Text
maxspeed(3) = max4.Text
maxspeed(4) = max5.Text
maxspeed(5) = max6.Text
maxspeed(6) = max7.Text
maxspeed(7) = max8.Text
'---车速下限初始化
minspeed(0) = min1.Text
minspeed(1) = min2.Text
minspeed(2) = min3.Text
minspeed(3) = min4.Text
minspeed(4) = min5.Text
minspeed(5) = min6.Text
minspeed(6) = min7.Text
minspeed(7) = min8.Text
'---速度初始化
For j = 0 To 7
speed(j) = CDbl((maxspeed(j) * Rnd()) + minspeed(j))
Debug.WriteLine(speed(j))
Next
'---Car type
'---初始化计数器以及车辆信息
count = 1
For i = 0 To 5
For j = 1 To totalTime / arrival(i)
typeNum = CInt(Int(4 * Rnd()) + 1)
Select Case typeNum
Case 1
typeCar = "Truck"
Case 2
typeCar = "Car"
Case 3
typeCar = "SUV"
Case 4
typeCar = "Jeep"
End Select
turn = CInt(Int(2 * Rnd()) + 1)
Select Case (i + 1)
Case 1
turn2 = 0
Case 2
If turn = 2 Then
turn2 = CInt(Int(2 * Rnd()) + 1)
Else
turn2 = 2
End If
Case 3
turn2 = 0
Case 4
If turn = 2 Then
turn2 = CInt(Int(2 * Rnd()) + 1)
Else
turn2 = 2
End If
Case 5
If turn = 1 Then
turn2 = CInt(Int(2 * Rnd()) + 1)
Else
turn2 = 2
End If
Case 6
If turn = 1 Then
turn2 = CInt(Int(2 * Rnd()) + 1)
Else
turn2 = 2
End If
End Select
myTW.WriteStartElement("CarNo." & count)
time(j) = time(j - 1) + arrival(i)
If time(j) >= totalTime Then
time(j) = totalTime - 1
End If
myTW.WriteElementString("type", typeCar)
myTW.WriteElementString("road", i + 1)
myTW.WriteElementString("arrival", time(j))
myTW.WriteElementString("turn", turn)
myTW.WriteElementString("turn2", turn2)
count = count + 1
myTW.WriteEndElement()
Next j
Next i
myTW.WriteEndElement()
myTW.WriteEndDocument()
myTW.Close()
L = TextBox5.Text
'-----在主干道上车辆到达下一路口所需参考时间
interval = (L / speed(6) + L / speed(7)) / 2
While interval > 30
interval = interval / 2
End While
Debug.WriteLine(interval)
'-------红绿灯组 f1,f2
myTW2.WriteStartDocument()
myTW2.Formatting = Formatting.Indented
myTW2.WriteStartElement("group")
b1 = totalTime \ interval
a1 = totalTime Mod interval
count = 0
flag = 1
For i = 1 To b1
For j = 1 To interval / 3 * 2
If flag = 1 Then
state = "green"
Else
state = "red"
End If
myTW2.WriteElementString("no" & count, state)
count = count + 1
Next j
For j = interval / 3 * 2 To interval
If flag = 1 Then
state = "yellow"
Else
state = "red"
End If
myTW2.WriteElementString("no" & count, state)
count = count + 1
Next j
flag = -1 * flag
Next i
If a1 > interval Then
For i = 1 To interval / 3 * 2
myTW2.WriteElementString("no" & count, "green")
count = count + 1
Next
For i = interval / 3 * 2 To interval
myTW2.WriteElementString("no" & count, "yellow")
count = count + 1
Next
For i = 1 To a1 - interval
myTW2.WriteElementString("no" & count, "red")
count = count + 1
Next
Else
For i = 1 To a1 / 3 * 2
myTW2.WriteElementString("no" & count, "green")
count = count + 1
Next i
For i = a1 / 3 * 2 To a1
myTW2.WriteElementString("no" & count, "yellow")
count = count + 1
Next i
End If
myTW2.WriteEndElement()
myTW2.WriteEndDocument()
myTW2.Close()
'----红绿灯组f6,f7
myTW3.WriteStartDocument()
myTW3.Formatting = Formatting.Indented
myTW3.WriteStartElement("group")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -