## 3 Traffic Model and Knowledge Discovery
```
0:\(messages\) // AIS messages containing static and dynamic info, e.g., \(MMSI\), COG, SOG, \(x\), \(y\), \(timestamp\)
0:\(\tau\) // time needed before labeling the vessel as being 'lost'
0:\(Vs,ENs,POs,EXs,Rs\) // list of vessel, waypoint and route objects
0:\(N_{ENs},N_{POs},N_{EXs},Eps_{ENs},Eps_{POs},Eps_{EXs}\) // clustering parameters (see Algorithm 2)
1:for all\(message\in messages\)do
2:if\(not(Vs\{MMSI\})\)then
3: // the vessel object identified by \(MMSI\) does not exist: it is added to the \(Vs\) list, its status initialized as'sailing', an entry event generated to be analyzed for \(ENs\) objects clustering and the routes list \(Rs\) updated
4:\(Vs\gets add(Vs\{MMSI\})\)
5:\(Vs\{MMSI\}.status\leftarrow\) ('sailing')
6:\(Vs\{MMSI\}.track\leftarrow(x,y,COG,SOG,timestamp,\dots)\)
7:\([Rs,ENs,Vs\{MMSI\}]\leftarrow\mathit{Online\_WPs}.Clustering(ENs,Vs\{MMSI\},Eps_{ENs},N_{ENs})\) // see Algorithm 2
8:\([Rs,Vs\{MMSI\}]\leftarrow\mathit{Rout\_Objects\_Manager}(Rs,Vs\{MMSI\})\) // (see Algorithm 3)
9:else
10: // the vessel exists: its parameters are updated and tested
11:\(Vs\{MMSI\}.track(end+1)\leftarrow(x,y,COG,SOG,timestamp,\dots)\)
12:\(Vs\{MMSI\}.avg\_speed=\Delta_{pos}/\Delta_{t}\) // observed average speed shown by the vessel
13:if\(Vs\{MMSI\}.avg\_speed<min\_speed\)and\(Vs\{MMSI\}.status=\)'sailing'then
14: // the vessel has stopped and a stationary event generated that is considered for POs (ports and offshore platforms) object clustering
15:\(Vs\{MMSI\}.status\leftarrow\) ('stationary')
16:\([Rs,POs,Vs\{MMSI\}]\leftarrow\mathit{Online\_WPs}.Clustering(POs,Vs\{MMSI\},Eps_{POs},N_{POs})\)
17:\([Rs,Vs\{MMSI\}]\leftarrow\mathit{Rout\_Objects\_Manager}(Rs,Vs\{MMSI\})\)
18:endif
19:if\(Vs\{MMSI\}.status=\)'lost'then
20: // the vessel is observed again after having been lost (e.g., exited the bounding box area)
21:\(Vs\{MMSI\}.status\leftarrow\) ('sailing')
22:\([Rs,ENs,Vs\{MMSI\}]\leftarrow\mathit{Online\_WPs}.Clustering(ENs,Vs\{MMSI\},Eps_{ENs},N_{ENs})\)
23:\([Rs,Vs\{MMSI\}]\leftarrow\mathit{Rout\_Objects\_Manager}(Rs,Vs\{MMSI\})\)
24:endif
25:endif
26: // every \(\Delta_{days}\), look for vessels not having been updated in the last \(\tau\) time interval and update the \(EXs\) list
27:if\(\text{mod}(timestamp,\Delta_{days})=0\)then
28:for all\(v\in Vs\)do
29:if\(v.last\_update>\tau\)and\(v.status\
eq\) ('lost') then
30: // the last recorded position of the vessel is used to modify the \(EXs\) list, to update the list of vessel waypoints and to create/update the routes, \(Rs\)
31:\(v.status\leftarrow\) ('lost')
32:\([Rs,EXs,v]\leftarrow\mathit{Online\_WPs}.Clustering(EXs,v,Eps_{EXs},N_{EXs}))\)
33:\([Rs,v]\leftarrow\mathit{Rout\_Objects\_Manager}(Rs,v)\)
34:endif
35:endfor
36:endif
37:endfor
38:return\(Vs,EXs,ENs,POs,Rs\)
```  
**Algorithm 1**\(Unsupervised\ Route\ Extraction\)  
From the AIS data stream, the status of vessel objects is derived and updated. Changes of the status of vessel objects are events of interest, such as \"lost\" when not observed for a time \(\tau\), which is a multiple of the maximum AIS message refresh rate in the area of interest. Additional vessel statuses are \"stationary\"/\"sailing\", and their transitions identify other events of interest, such as when the vessel stopsor starts sailing again from a stoppage. Such events create or update waypoint objects, \(WPs\), as shown in Annex A, Algorithm 1--Unsupervised Route Extraction--and Algorithm 2--On-Line WPs Clustering. ```
1:\(Vs,v\) // list of all vessels, \(Vs\), and vessel, \(v\), that generated the event of interest to be clustered
2:\(WPs,Rs\) // list of waypoints to be clustered,, either \(ENs\), \(EXs\) or \(POs\), and routes to be modified
3:\(Eps,N\) // minimum number of points, \(N\), in the \(Eps\) neighborhood of the event located in \(v.track(end)\) that is required to generate a cluster \(wp_{n}\in WPs\)
4:\([WPs,op]\gets Incremental\_DBSCAN(WPs,v.track(end),N,Eps)\) // see Incremental DBSCAN in [37].