Download the runnable example here
Step 1: Calculate the un-directional minimum distances
Definition: the un-directional minimum distance between any two reference sites is the minimum distance consists of a number of links connecting these two reference sites, regardless of their directions.
Notation: umdrsi-rsj - un-directional minimum distance between reference site rsi and reference site rsj
Method: Dijkstra minimum distance algorithm.
Step 2: Determine a given reference site's relative position
Given a link of interests [F-T], the table below shows all possible positions that a random reference site rsi can be relative to link [F-T]:
Relative Position |
Explanation |
Conditions |
Upstream |
--(rsi)-------------------------
----------(F)=====>(T)---------- |
umdrsi-F < umdrsi-T AND length(F-T) < umdrsi-T |
Overlap F |
----------(F/rsi)---------------
----------(F/rsi)===>(T)-------- |
umdrsi-F = 0 |
In Between |
--------------(rsi)-------------
----------(F)=====>(T)---------- |
umdrsi-F + umdrsi-T <= length(F-T) |
Overlap T |
-----------------(T/rsi)--------
----------(F)===>(T/rsi)-------- |
umdrsi-T = 0 |
Downstream |
------------------------(rsi)---
----------(F)=====>(T)---------- |
umdrsi-F > umdrsi-T AND length(F-T) < umdrsi-F |
Step 3: Determine a given link's relative position
Given another link [Fi-Ti], its position can be of the following 25 cases relative to link [F-T]:
Step 4: Determine the direction and the distance between two crashes
When calculating the distance from a current primary crash crashcur (occurred on link [F-T]) to a potential secondary crash crashi (occurred on link [Fi-Ti]), the following equation is used:
d = sign1*(sign2*umdFi-F - offsetcrashcur) + offsetcrashi.
where,
umdFi-F, offsetcrashi, and offsetcrashcur are all non-negative distances. When d > 0, crashi is downstream of crashcur in either direction; when d < 0, crashi is upstream of crashcur in either direction. When link [Fi-Ti], is in the same direction to link [F-T], sign1 = 1, otherwise sign1 = -1. When Fi is upstream of link [F-T], sign2 = -1; when Fi overlaps with F, sign2 = 0; otherwise, sign2 = 1. Below is a summary matrix:
|
Fi's relative position to link [F-T] |
|
Upstream |
Overlap F |
In Between |
Overlap T |
Downstream |
Ti's relative position to link [F-T]
|
Upstream |
Case1
if umdFi-F > umdTi-F, sign1 = 1,
if umdFi-F < umdTi-F, sign1 = -1;
sign2 = -1
|
Case2
sign1 = -1; sign2 = 0; |
Case3
sign1 = -1; sign2 = 1; |
Case4
sign1 = -1; sign2 = 1; |
Case5
sign1 = -1; sign2 = 1; |
Overlap F |
Case6
sign1 = 1; sign2 = -1; |
Case7 not exist |
Case8
sign1 = -1; sign2 = 1; |
Case9
sign1 = -1; sign2 = 1; |
Case10
sign1 = -1; sign2 = 1; |
In Between |
Case11
sign1 = 1; sign2 = -1; |
Case12
sign1 = 1; sign2 = 0; |
Case13
if umdFi-F < umdTi-F, sign1 = 1,
if umdFi-F > umdTi-F, sign1 = -1;
sign2 = 1
|
Case14
sign1 = -1; sign2 = 1; |
Case15
sign1 = -1; sign2 = 1; |
Overlap T |
Case16
sign1 = 1; sign2 = -1; |
Case17
sign1 = 1; sign2 = 0; |
Case18
sign1 = 1; sign2 = 1; |
Case19 not exist |
Case20
sign1 = -1; sign2 = 1; |
Downstream |
Case21
sign1 = 1; sign2 = -1; |
Case22
sign1 = 1; sign2 = 0; |
Case23
sign1 = 1; sign2 = 1; |
Case24
sign1 = 1; sign2 = 1; |
Case25
if umdFi-F < umdTi-F, sign1 = 1,
if umdFi-F > umdTi-F, sign1 = -1;
sign2 = 1
|
Appendix A: Enumeration of All Cases
Subcases
--->(Fi)=>(Ti)------->(F)=>(T)--->:
This case is true when umdFi-F > umdTi-F. In this case, link [Fi-Ti] is upstream of link [F-T] and in the same direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = -umdFi-F + offsetcrashcur - offsetcrashcur.
<---(Ti)<=(Fi)<--------------------
--------------------->(F)=>(T)--->:
This case is true when umdFi-F < umdTi-F. In this case, link [Fi-Ti] is upstream of link [F-T] and in the opposite direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = (-1)*(-umdFi-F - offsetcrashi - offsetcrashcur).
<---(Ti)<===(F/Fi)<----------------
----------->(F/Fi)=>(T)----------->:
In this case, link [Fi-Ti] is upstream of link [F-T] and in the opposite direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = (-1)*(-offsetcrashi - offsetcrashcur).
<--(Ti)<==========(Fi)<------------
------------>(F)======>(T)------->:
In this case, link [Fi-Ti] is overlapped with link [F-T] and in the opposite direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = (-1)*(umdFi-F - offsetcrashi - offsetcrashcur).
<---(Ti)<===============(T/Fi)<---
---------------->(F)===>(T/Fi)--->:
In this case, link [Fi-Ti] is containing link [F-T] and in the opposite direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = (-1)*(umdFi-F - offsetcrashi - offsetcrashcur).
<---(Ti)<=================(Fi)<---
----------->(F)===>(T)----------->:
In this case, link [Fi-Ti] is containing link [F-T] and in the opposite direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = (-1)*(umdFi-F - offsetcrashi - offsetcrashcur).
------------->(Fi)=>(F/Ti)=>(T)--->:
In this case, link [Fi-Ti] is upstream of link [F-T] and in the same direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = -umdFi-F + offsetcrashi - offsetcrashcur.
Such case doen't exist since Fi and Ti overlap.
<---(F/Ti)<====(Fi)<---------------
--->(F/Ti)==============>(T)------>:
In this case, link [Fi-Ti] is contained by link [F-T] and in the opposite direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = (-1)*(umdFi-F - offsetcrashi - offsetcrashcur).
<---(F/Ti)<========(T/Fi)<---------
--->(F/Ti)========>(T/Fi)--------->:
In this case, link [Fi-Ti] is paired link of link [F-T] and in the opposite direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = (-1)*(umdFi-F - offsetcrashi - offsetcrashcur).
<---(F/Ti)<=========(Fi)<----------
--->(F/Ti)=====>(T)--------------->:
In this case, link [Fi-Ti] is containing link [F-T] and in the opposite direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = (-1)*(umdFi-F - offsetcrashi - offsetcrashcur).
--->(Fi)==========>(Ti)----------->
-------------->(F)=======>(T)----->:
In this case, link [Fi-Ti] is overlapped with link [F-T] and in the same direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = -umdFi-F + offsetcrashi - offsetcrashcur.
--->(F/Fi)====>(Ti)--------------->
--->(F/Fi)=========>(T)----------->:
In this case, link [Fi-Ti] is contained by link [F-T] and in the same direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = offsetcrashi - offsetcrashcur.
Subcases
----------->(Fi)==>(Ti)----------->
--->(F)=================>(T)------>:
This case is true when umdFi-F < umdTi-F. In this case, link [Fi-Ti] is contained by link [F-T] and in the same direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = umdFi-F + offsetcrashi - offsetcrashcur.
<-----------(Ti)<==(Fi)<-----------
--->(F)=================>(T)------>:
This case is true when umdFi-F > umdTi-F. In this case, link [Fi-Ti] is contained by link [F-T] and in the opposite direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = (-1)*(umdFi-F - offsetcrashi - offsetcrashcur).
<-------(Ti)<=====(T/Fi)<----------
--->(F)==========>(T/Fi)---------->:
In this case, link [Fi-Ti] is contained by link [F-T] and in the opposite direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = (-1)*(umdFi-F - offsetcrashi - offsetcrashcur).
<-------(Ti)<=======(Fi)<----------
--->(F)======>(T)----------------->:
In this case, link [Fi-Ti] is overlapped with link [F-T] and in the opposite direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = (-1)*(umdFi-F - offsetcrashi - offsetcrashcur).
--->(Fi)================>(T/Ti)--->
---------------->(F)====>(T/Ti)--->:
In this case, link [Fi-Ti] is containing link [F-T] and in the same direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = -umdFi-F + offsetcrashi - offsetcrashcur.
--->(F/Fi)========>(T/Ti)--------->
--->(F/Fi)========>(T/Ti)--------->:
In this case, link [Fi-Ti] is matching link [F-T] and in the same direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = offsetcrashi - offsetcrashcur.
------------>(Fi)====>(T/Ti)------>
--->(F)==============>(T/Ti)------>:
In this case, link [Fi-Ti] is contained by link [F-T] and in the same direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = umdFi-F + offsetcrashi - offsetcrashcur.
Such case doen't exist since Fi and Ti overlap.
<-------------(T/Ti)<===(Fi)<------
--->(F)======>(T/Ti)-------------->:
In this case, link [Fi-Ti] is downstream of link [F-T] and in the opposite direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = (-1)*(umdFi-F - offsetcrashi - offsetcrashcur).
--->(Fi)==============>(Ti)------->
---------->(F)===>(T)------------->:
In this case, link [Fi-Ti] is containing link [F-T] and in the same direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = -umdFi-F + offsetcrashi - offsetcrashcur.
--->(F/Fi)============>(Ti)------->
--->(F/Fi)======>(T)-------------->:
In this case, link [Fi-Ti] is containing link [F-T] and in the same direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = offsetcrashi - offsetcrashcur.
--------->(Fi)======>(Ti)--------->
--->(F)=======>(T)---------------->:
In this case, link [Fi-Ti] is overlapped with link [F-T] and in the same direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = umdFi-F + offsetcrashi - offsetcrashcur.
------------->(T/Fi)==>(Ti)------->
--->(F)======>(T/Fi)-------------->:
In this case, link [Fi-Ti] is downstream of link [F-T] and in the same direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = umdFi-F + offsetcrashi - offsetcrashcur.
Subcases
-------------------->(Fi)=>(Ti)--->
--->(F)=>(T)---------------------->:
This case is true when umdFi-F < umdTi-F. In this case, link [Fi-Ti] is downstream of link [F-T] and in the same direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = umdFi-F + offsetcrashi - offsetcrashcur.
<----------------(Ti)<=(Fi)<-------
--->(F)=>(T)---------------------->:
This case is true when umdFi-F > umdTi-F. In this case, link [Fi-Ti] is downstream of link [F-T] and in the opposite direction.
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = (-1)*(umdFi-F - offsetcrashi - offsetcrashcur).
<