## Appendix A \begin{tabular}{r l} \hline \hline
**Algorithm A1.** Internal risk calculation module \\ \hline
1 & **Procedure:** PSEUDOCODE FOR CA_2 Cal_INT Risk level() \\
2 & Type_factor = (\(-\)0.0782, \(-\)0.33532, \(-\)0.03167, \(-\)0.08258, 0.315854, \(-\)1.59798, \(-\)0.11654, 0) \\
3 & Length_factor = ((\(-\)1.06559, \(-\)2.48791, \(-\)0.53392, \(-\)0.142, \(-\)0.09125, 0.754828, \(-\)0.49936, 4) \\
4 & \(-\)0.92794, 0.56287, 0.046498, 0.709714, \(-\)0.24955), (0, 70, 90, 108, 123, 140, \\
5 & 160, 185, 223, 243, 259, 277)) \\
6 & Width_factor = ((0.500588, \(-\)0.02551, 0.210588, \(-\)0.2892, 0.360838, 0.099504, 0.343936, \\
7 & 0.046159, \(-\)0.28957), (0, 10, 15, 20, 25, 30, 35, 40, 45)) \\
8 & Tonnage_factor = ((0.634656, \(-\)0.22998, 2.180813, \(-\)0.09324, \(-\)0.3456, \(-\)0.76563, \(-\)0.12622, \\  & \(-\)0.13153, \\
9 & 0.217815, \(-\)0.14535, \(-\)0.65614, 0.06369, \(-\)0.38126, 0.313252, 0), (0, 500, 1000, \\
3000, & 5000, 7000, 10,000, 15,000, 20,000, 25,000, 30,000, 50,000, 60,000, 75,000, \\
100,000)) \\
11 & Career_factor = (\(-\)0.10483, \(-\)0.33236, \(-\)0.06423, \(-\)0.13673) \\
12 & License_factor = (0.177682, 0.109177, 0.245199) \\
13 & Position_factor = (0.184283, 0.176755, 0.296052, \(-\)0.07518) \\
14 & Type_SelectIndex = Fishing Vessel: 1, Container Ship: 2, Pure Car Carrier: 3, \\
15 & Tanker: 4, LNG/LPG Carrier: 5, Passenger Ship: 6, Towing \\
16 & Vessel: 7, Other Cargo ship: 8 \\
17 & Career_SelectIndex = less than 1 year: 1, 1-3 years: 2, 3-5 years: 3, more than 5 years: 4 \\
18 & License_SelectIndex = merchant 1 class: 1, merchant 2 class: 2, merchant 3 class: 3 \\
19 & Position_SelectIndex = Captain: 1, Chief officer: 2, 2 nd officer: 3, 3 rd officer: 4 \\
20 & Int 1= Type_factor(Type_SelectIndex) \\
21 & **For** i = 0 To 11, k = 0 to 8, j = 0 to 14 \\
22 & **If** LOA > Length_factor(1, i) **Then** \\
23 & Int 2= Length_factor(0, i) \\
24 & **End** **If** \\
25 & **If** width > Width_factor(1, k) **Then** \\
26 & Int 3= Width_factor(0, k) \\
27 & **End** \\
28 & **If** Tonnage > Tonnage_factor(1, j) **Then** \\
29 & Int 4= Tonnage_factor(0, j) \\
30 & **End** **If** \\
31 & **Next** \\
32 & Int 5= Career_factor(Career.SelectIndex) \\
33 & Int 6= License_factor(License.SelectIndex) \\
34 & Int 7= Position_factor(Position.SelectIndex) \\
35 & **End procedure** \\ \hline \hline \end{tabular}   
```
1  Procedure: PSEUDOCODE FOR CA_3 Cal_EXT Risk level()
2  Crossing_factor = (0.468465, 0.500211, 0.660194, 0.626923)
3  Side_factor = (-0.0566, 0)
4  In_out_factor = (0.062305, 0)
5  Speed_factor = (0.120578, -0.05652, 0)
6  Harbor_SelectIndex = Inner: 1, Outer: 2
7  If (174 <= | own_hdg-other_hdg1 And | own_hdg-other_hdg1 <= 186) And (354 <= 8  Rela_bearing Or Rela_bearing <= 6) Then
9  Ext 1 = Crossing_factor(4)
10  ElseIf ((0 <= Rela_bearing And Rela_bearing <= 45) Or (315 <= Rela_bearing And Rela_bearing <= 360)) Then
11  Ext 1= Crossing_factor(1)
12  ElseIf ((45 < Rela_bearing And Rela_bearing <= 90) Or (270 <= Rela_bearing And Rela_bearing < 315)) Then
15  Ext 1 = Crossing_factor(2)
16  Elseif 90 < Rela_bearing And Rela_bearing < 270 Then
17  Ext 1 = Crossing_factor(3)
18  End If
19  If Rela_bearing < 180 Then
20  Ext 2 = Side_factor(1)
21  Else
22  Ext 2 = Side_factor(2)
23  End If
24  Ext 3 = In_out_factor(Harbor_SelectedIndex)
25  If own_speed = other_speed Then
26  Ext 4 = speed_factor(1)
27  ElseIf own_speed < other_speed Then
28  Ext 4 = speed_factor(2)
29  ElseIf own_speed > other_speed Then
30  Ext 4 = speed_factor(3)
31  End If
32  End procedure
```  
**Algorithm A2** External risk calculation module  
```
1  Procedure: PSEUDOCODE FOR CA_5 Final Risk level()
2  Input: List of Detect Ship
3  List_LOA = (0, 50, 100, 200)
4  Matrix_Risk = ((7, 6, 5, 4), (6, 6, 5, 4), (5, 5, 5, 4), (4, 4, 4, 4))
5  List_r,cpa = (3, 5, 10, 15)
6  Matrix_r,cpa = ((0.03, 0.05, 0.11, 0.16), (0.1, 0.2, 0.3, 0.5), (0.2, 0.3, 0.6, 1), (0.3, 0.5, 1.1, 1.6))
8  For each Ship **do**
```
**Algorithm A4**Cont.