VERSION 5.00 Begin VB.Form FrmBBAnalysis Caption = "Brownian Bridge Probabilities Along a Road" ClientHeight = 7335 ClientLeft = 45 ClientTop = 525 ClientWidth = 8010 LinkTopic = "Form1" ScaleHeight = 7335 ScaleWidth = 8010 StartUpPosition = 3 'Windows Default Begin VB.CommandButton CmdLoadLocFile Caption = "Load Location File (with header row)" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 1920 TabIndex = 16 Top = 120 Width = 5175 End Begin VB.TextBox TxtTelemError Height = 375 Left = 2040 TabIndex = 14 Text = "28.85" Top = 2160 Width = 1215 End Begin VB.CommandButton CmdBBGrid Caption = "Calculate Brownian Bridge Probabilities Over a Grid" Height = 612 Left = 4440 TabIndex = 13 Top = 3360 Width = 2892 End Begin VB.Frame Frame1 Caption = "Analysis Options" Height = 1935 Left = 600 TabIndex = 10 Top = 2640 Width = 3612 Begin VB.TextBox TxtTotalTimeTooLong Height = 285 Left = 240 TabIndex = 17 Text = "2000" Top = 1320 Width = 495 End Begin VB.OptionButton OptCrossLocs Caption = "Use only paired locations that are on opposite sides of road" Height = 372 Left = 360 TabIndex = 12 Top = 840 Value = -1 'True Width = 2412 End Begin VB.OptionButton OptAllLocs Caption = "Use all locations" Height = 252 Left = 360 TabIndex = 11 Top = 360 Width = 3012 End Begin VB.Label Label6 Caption = "Enter total time limit between locations for calculating BB" Height = 495 Left = 840 TabIndex = 18 Top = 1320 Width = 2535 End End Begin VB.CommandButton CmdBBRoad Caption = "Calculate Brownian Bridge Probabilities Along the Road" Height = 612 Left = 2760 TabIndex = 9 Top = 6360 Width = 2892 End Begin VB.CommandButton CmdLoadRoadFile Caption = "Load Road File (with header row)" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 1800 TabIndex = 5 Top = 4680 Width = 5175 End Begin VB.TextBox TxtRoadFile Height = 615 Left = 1560 MultiLine = -1 'True TabIndex = 4 Top = 5640 Width = 5535 End Begin VB.TextBox TxtBBVar Height = 372 Left = 6360 TabIndex = 3 Text = "642.44" Top = 2160 Width = 1575 End Begin VB.CommandButton CmdEstimateVar Caption = "Estimate Brownian Bridge Variance" Height = 372 Left = 3360 TabIndex = 2 Top = 2160 Width = 2892 End Begin VB.TextBox TxtLocationFile Height = 615 Left = 1680 MultiLine = -1 'True TabIndex = 0 Top = 1080 Width = 5535 End Begin VB.Label Label5 Caption = "Enter standard deviation for normal telemetry error" Height = 495 Left = 0 TabIndex = 15 Top = 2160 Width = 2415 End Begin VB.Label Label4 Caption = "Note: Input file should be a tab delimited text file with road vertecies in 2 columns: x-coordinate, y-coordinate" Height = 495 Left = 1800 TabIndex = 8 Top = 5160 Width = 4455 End Begin VB.Label Label3 Caption = "Note: Input file should be a tab delimited text file with 3 columns in this order: x-coordinate, y-coordinate, time" Height = 492 Left = 2160 TabIndex = 7 Top = 600 Width = 4452 End Begin VB.Label Label2 Caption = """Road"" File:" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 240 TabIndex = 6 Top = 5640 Width = 1335 End Begin VB.Label Label1 Caption = "Location File:" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 252 Left = 360 TabIndex = 1 Top = 1080 Width = 1332 End End Attribute VB_Name = "FrmBBAnalysis" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub CmdEstimateVar_Click() 'Sort the location data by time ascending Dim I As Long Dim TimeI As Single Dim TotalTimeI As Single Dim BBMeanXi As Single Dim BBMeanYi As Single Dim DistanceSqByN As Single Dim BBDistanceSqByN As Single Dim SumDistanceSqByN As Single I = 1 Dim count As Integer count = (NumOfLocs - 1) / 2 Do Until I > NumOfLocs - 2 TimeI = SortedXYArray(I, 2) - SortedXYArray(I - 1, 2) TotalTimeI = SortedXYArray(I + 1, 2) - SortedXYArray(I - 1, 2) BBMeanXi = (TimeI / TotalTimeI) * (SortedXYArray(I + 1, 0) - SortedXYArray(I - 1, 0)) + SortedXYArray(I - 1, 0) BBMeanYi = (TimeI / TotalTimeI) * (SortedXYArray(I + 1, 1) - SortedXYArray(I - 1, 1)) + SortedXYArray(I - 1, 1) DistanceSqByN = ((SortedXYArray(I, 0) - BBMeanXi) ^ 2 + (SortedXYArray(I, 1) - BBMeanYi) ^ 2) / (2 * (count - 1)) BBDistanceSqByN = DistanceSqByN * (TotalTimeI / (TimeI * (TotalTimeI - TimeI))) SumDistanceSqByN = SumDistanceSqByN + BBDistanceSqByN I = I + 2 Loop BBVariance = SumDistanceSqByN 'BBVariance = BBVariance Dim VarBegin As Single Dim VarMiddle As Single Dim VarEnd As Single VarBegin = BBVariance - (0.7 * BBVariance) VarEnd = BBVariance - (0.5 * BBVariance) TelemErrorStdDev = TxtTelemError.Text Call MNBRAKCV(VarBegin, VarEnd, NumOfLocs) VarBegin = A VarMiddle = B VarEnd = C Tolerance = 0.0001 Call goldenCV(VarBegin, VarMiddle, VarEnd, Tolerance, NumOfLocs) BBVariance = Xmin TxtBBVar.Text = BBVariance End Sub Private Sub CmdLoadLocFile_Click() ShowHRFrame = True OpenFileCaption = "Open Location File..." FileType = "location" FrmOpenFileBB.Show End Sub Private Sub CmdLoadRoadFile_Click() ShowHRFrame = True OpenFileCaption = "Open Road File..." FileType = "Road" FrmOpenFileBB.Show End Sub Private Sub CmdBBRoad_Click() If OptAllLocs.Value = True Then UseAllLocs = True Else UseAllLocs = False End If 'If UseAllLocs = False Then 'MsgBox "Warning!! You selected to use paired locations that cross the road. Therefore, you must load a different location file that contains only the locations that cross the road." 'Exit Sub 'End If TelemErrorStdDev = TxtTelemError.Text BBVariance = TxtBBVar.Text TotalTimeTooLong = TxtTotalTimeTooLong.Text Dim StartX As Single Dim StartY As Single Dim EndX As Single Dim EndY As Single Dim StartTime As Single Dim EndTime As Single 'Dim BBVar As Single Dim EntireTime As Single Dim TotalTime As Single Dim TimeT As Single Dim TimeStep As Single Dim MeanXTimeT As Single Dim MeanYTimeT As Single Dim Alpha As Single Dim VarTimeT As Single Dim ProbAtTimeT As Double Dim SqDistance As Single Dim SumProbAcrossTime As Double Dim BBProbDensityAtVertex As Double Dim SumBBProbDensityAtVertex As Double ReDim ProbDensityAtVertexArray(NumOfRoadVerts, 3) Dim VertNum As Long Dim LocNum As Long 'EntireTime = SortedXYArray(NumOfLocs - 1, 2) - SortedXYArray(0, 2) If TelemErrorStdDev = 0 Then TelemErrorStdDev = 0.0001 End If Dim DistBetweenRdPts As Double DistBetweenRdPts = Sqr((RoadArray(0, 0) - RoadArray(1, 0)) ^ 2 + (RoadArray(0, 1) - RoadArray(1, 1)) ^ 2) For VertNum = 0 To NumOfRoadVerts - 1 CurrentX = RoadArray(VertNum, 0) CurrentY = RoadArray(VertNum, 1) SumBBProbDensityAtVertex = 0 'Calculate Brownian Bridge Probability at roadvertex For LocNum = 0 To NumOfLocs - 2 StartX = SortedXYArray(LocNum, 0) StartY = SortedXYArray(LocNum, 1) StartTime = SortedXYArray(LocNum, 2) EndX = SortedXYArray(LocNum + 1, 0) EndY = SortedXYArray(LocNum + 1, 1) EndTime = SortedXYArray(LocNum + 1, 2) TotalTime = EndTime - StartTime TimeStep = TotalTime / 100 TimeT = 0 SumProbAcrossTime = 0 Do Until TimeT > TotalTime If TotalTime > TotalTimeTooLong Then Else Alpha = TimeT / TotalTime MeanXTimeT = StartX + ((Alpha) * (EndX - StartX)) MeanYTimeT = StartY + ((Alpha) * (EndY - StartY)) VarTimeT = TotalTime * Alpha * (1 - Alpha) * BBVariance + (Alpha ^ 2 + (1 - Alpha) ^ 2) * TelemErrorStdDev ^ 2 SqDistance = (CurrentX - MeanXTimeT) ^ 2 + (CurrentY - MeanYTimeT) ^ 2 ProbAtTimeT = (1 / (2 * Pi * VarTimeT)) * Exp(-0.5 * (SqDistance / VarTimeT)) * TimeStep SumProbAcrossTime = SumProbAcrossTime + ProbAtTimeT TimeT = TimeT + TimeStep End If Loop EntireTime = EntireTime + TotalTime BBProbDensityAtVertex = (SumProbAcrossTime) SumBBProbDensityAtVertex = SumBBProbDensityAtVertex + BBProbDensityAtVertex If UseAllLocs = False Then LocNum = LocNum + 1 End If Next LocNum ProbDensityAtVertexArray(VertNum, 0) = CurrentX ProbDensityAtVertexArray(VertNum, 1) = CurrentY ProbDensityAtVertexArray(VertNum, 2) = SumBBProbDensityAtVertex / (EntireTime) ProbDensityAtVertexArray(VertNum, 2) = ProbDensityAtVertexArray(VertNum, 2) * DistBetweenRdPts * DistBetweenRdPts Next VertNum SaveFileType = "RoadBB" FrmSaveAsBrownBridge.Show End Sub Private Sub CmdBBGrid_Click() If OptAllLocs.Value = True Then UseAllLocs = True Else UseAllLocs = False End If 'If UseAllLocs = False Then 'MsgBox "Warning!! You selected to use paired locations that cross the road. Therefore, you must load a different location file that contains only the locations that cross the road." 'Exit Sub 'End If TelemErrorStdDev = TxtTelemError.Text BBVariance = TxtBBVar.Text TotalTimeTooLong = TxtTotalTimeTooLong.Text Call Unload(FrmBBAnalysis) FrmGridExtent.Show End Sub Private Sub Form_Load() Pi = 4 * Atn(1) TxtLocationFile.Text = LocationFileFullName TxtRoadFile.Text = RoadFileFullName TxtBBVar.Text = BBVariance End Sub