## 3 Traffic Model and Knowledge Discovery
5:if\(op=\)'none' then
6: // the event is not clustered and is considered as noise
7:\(v.wps(end+1)\leftarrow\) ('Unclassified Waypoint', \(v.track(end)\))
8:else
9: // the operation performed in the WPs space is either the generation of a new waypoint, the absorption into an existing one or the merge of multiple waypoints:
10:if\(op\) ='new cluster' then
11: // the event has created a new cluster, \(wp_{n}\), the vessel list of waypoints is updated together with the time, \(timestamp_{wp_{n}}\), of information, as extracted from \(v.track(end)\)
12:\(WPs\gets add\)('WP\({}_{n}\)')
13:\(v.wps(end+1)\leftarrow\) ('WP\({}_{n}\)')
14:\(v.timestamp_{wp}(end+1)\leftarrow\) (\(v.track(end)\))
15: // info regarding the \(MMSI\) of the vessel and its last position is recorded into \(wp_{n}\)
16:\([wp_{n}.List\_MMSIs(end+1),wp_{n}.tracks(end+1)]\leftarrow(v.MMSI,v.track(end))\)
17:endif
18:endif
19:if\(op=\)'cluster expanded' then
20: // the event is absorbed into the cluster, \(wp_{n}\):
21: \(v.wps(end+1)\leftarrow\) ('WP\({}_{n}\)')
22:\(v.timestamp_{wp}(end+1)\leftarrow\) (\(v.track(end)\))
23:\([wp_{n}.List\_MMSIs(end+1),wp_{n}.tracks(end+1)]\leftarrow(v.MMSI,v.track(end))\)
24:endif
25:if\(op=\)'clusters merged' then
26: // the new event causes the merging of two clusters, \(wp_{m}\) and \(wp_{n}\), into \(wp_{n}\), the event is clustered, \(wp_{n}\) updated and, finally, \(wp_{m}\) deleted. 27:\(v.wps(end+1)\leftarrow\) ('WP\({}_{n}\)')
28:\(v.timestamp(end+1)\leftarrow\) (\(v.track(end)\))
29:\(wp_{n}\leftarrow(v.MMSI,v.track(end))\)
30:\(wp_{n}\leftarrow merge(wp_{n},wp_{m})\)
31:for all\(\hat{v}\in Vs\{MMSI=wp_{m}.List\_MMSIs\}\)do
32:\(\hat{v}.wps(\hat{v}.wps=\)'WP\({}_{m}\)') ('WP\({}_{n}\)')
33:endfor
34: // merge the affected routes and update the relevant list
35:for all\(\hat{R}\in(R_{s}.wps(1)=\)'WP\({}_{m}\)'\(|R_{s}.wps(2)=\)'WP\({}_{m}\)') do
36:\(\hat{R}\leftarrow(R_{s}.wps(\hat{R}.wps=\)'WP\({}_{m}\)') ='WP\({}_{n}\)')
37:\(\hat{R}\gets merge(\hat{R},\hat{R})\)
38:\(delete(\hat{R})\)
39:endfor
40:\(delete(\)'WP\({}_{m}\)')
41:endif
42:endif
43:endif
44:return\(WPs,v,Rs\)
```  
**Algorithm 2**\(On-line\)\(WPs\)\(Clustering\)  
Stationary Objects Manager:A special class of waypoints is represented by stationary points, such as ports and offshore platforms, \(POs\). This class of objects consists of vessels having a speed lower than a given threshold. In particular, as can be seen in Annex A, Algorithm 1--Unsupervised Route Extraction--stationary events are detected by speed gating based on the last observations related to the vessel of interest: the parameters, \(\Delta_{t}\) and \(\Delta_{pos}\) (_i.e._, the last observed time interval and the resulting displacement in position), are computed to empirically derive the average vessel speed. This is implemented, since the field, \(SOG\), in the AIS messages is unreliable to be used in detecting stationary events. Port and offshore platforms are learned by clustering the stationary behavior of vessels, and their areas are progressively shaped by vessels following the same behavior. Waypoints clustering is based on DBSCAN (_i.e._, Density-Based Spatial Clustering of Applications with Noise) methodology ([38]). DBSCAN forms clusters of elements on the basis of the density of points in their neighborhood. In other words, given a specific point, \(p\), if the cardinality of the neighborhood of a given radius, _Eps_, is greater than a certain threshold of the minimum number of points, then such points are density-reachable from \(p\) and belong to the same cluster. Moreover, two points, \(p\) and \(q\), are density-connected if there is a third point, \(o\), such that \(p\) and \(q\) are density-reachable from \(o\). Points that are density-connected to each other belong to the same cluster, and points that are density-connected to any point of the cluster are also part of the cluster. In this framework, those points that are not density-connected to other points do not belong to any cluster and are considered noise.