## 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]:

 Fi's relative position to link [F-T] Upstream Overlap F In Between Overlap T Downstream Ti'srelativepositiontolink[F-T] Upstream Case1 Case2 Case3 Case4 Case5 Overlap F Case6 Case7 Case8 Case9 Case10 In Between Case11 Case12 Case13 Case14 Case15 Overlap T Case16 Case17 Case18 Case19 Case20 Downstream Case21 Case22 Case23 Case24 Case25

## 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'srelativepositiontolink[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; Case7not 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; Case19not 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

### Case1(table)

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).

### Case2(table)

• ```<---(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).

### Case3(table)

• ```<--(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).

### Case4(table)

• ```<---(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).

### Case5(table)

• ```<---(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).

### Case6(table)

• `------------->(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.

### Case7(table)

Such case doen't exist since Fi and Ti overlap.

### Case8(table)

• ```<---(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).

### Case9(table)

• ```<---(F/Ti)<========(T/Fi)<--------- --->(F/Ti)========>(T/Fi)--------->:```
The distance from crashcur on [F-T] to crashi on [Fi-Ti] can be calculated as d = (-1)*(umdFi-F - offsetcrashi - offsetcrashcur).

### Case10(table)

• ```<---(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).

### Case11(table)

• ```--->(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.

### Case12(table)

• ```--->(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.

### Case13(table)

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).

### Case14(table)

• ```<-------(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).

### Case15(table)

• ```<-------(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).

### Case16(table)

• ```--->(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.

### Case17(table)

• ```--->(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.

### Case18(table)

• ```------------>(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.

### Case19(table)

Such case doen't exist since Fi and Ti overlap.

### Case20(table)

• ```<-------------(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).

### Case21(table)

• ```--->(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.

### Case22(table)

• ```--->(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.

### Case23(table)

• ```--------->(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.

### Case24(table)

• ```------------->(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.

### Case25(table)

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).
<