## 4 Collision Avoidance Algorithm  
The collision avoidance algorithm consists of ship detection, risk calculation, COLREG judgment, and avoidance action decision modules. The ship detection module detects nearby ships and recognizes the situation. In general, ship detection modules applied to actual ships use multi-sensor fusion technology to overcome the characteristics and noise of various sensors. However, the ship detection module described in this paper is specifically used to avoid collisions between the generated virtual ship and the own ship or other ships that have already been identified. It is configured with a simple logic that measures distance to determine whether a ship is potentially dangerous. The risk calculation module calculates the risks from the detected ships and determines avoidance and priorities. The COLREG judgment module induces avoidance against the ships for which avoidance and priorities are determined according to COLREG [34]. The avoidance action decision module determines the position of the helm that must be used to move to the predetermined avoidance position. Figure 5 shows the configuration of the collision avoidance algorithm [35]. The ship detection module determines the collision risk as well as the time and distance at which action must be initiated. Based on a case in which DCPA was analyzed to be more than one mile when the other ship was first detected at a distance of more than eight miles on the sea and less than one mile when it was first detected at a distance of less than eight miles [36], the target of this algorithm was set to less than eight miles. Algorithm 3 shows the pseudocode of the ship detection module. In this module, the distance of a ship is calculated using Equations (1)-(5):  
\[R=\sqrt{\lambda^{2}+\varphi^{2}} \tag{1}\]  
\[\varphi=Lat2-Lat1=\frac{u}{me} \tag{2}\]  
\[\lambda=Long2-Long1=\frac{v}{ne\times cos(Lat1)} \tag{3}\]  
\[me=\frac{REA(1-E^{2})}{\left(1-E^{2}sin^{2}(Lat1)\right)^{3/2}} \tag{4}\]  
\[ne=\frac{REA}{\sqrt{1-E^{2}sin^{2}(Lat1)}} \tag{5}\]  
where \(R\) denotes the distance, \(Lat1\), \(Long1\) denotes the position of own ship, \(Lat2\), \(Long2\) denotes the position of the other ship, \(u\) denotes the longitudinal velocity, \(v\) denotes the lateral velocity, \(me\) denotes the prime vertical radius of curvature, \(ne\) denotes the meridian radius of curvature, \(REA=6,378,137\) m is the semi major axis, \(REB=REA(1-f)\) is the semi minor axis, \(f=1/298.257223563\) is the flattening factor (Reference ellipsoid name: WGS-84), and \(E=\frac{\sqrt{REA^{2}-REB^{2}}}{REA}\) denotes the first eccentricity. Figure 5: Configuration of the collision avoidance algorithm. The risk calculation module calculates the risk from the detected ships. Many theories of risk have been proposed. In this algorithm, the maritime traffic risk [37; 38] is calculated based on the parameters determined by characteristics of coastal areas in Korea and the perceptions of ship operators. This model has the advantage that it reflects the risk perceived by actual navigators. However, some of the factors required for risk measurement cannot be easily obtained; hence, risk calculation is difficult. Algorithms A1-A4 in Appendix A present the pseudocodes of the risk calculation module, while Figure 6 shows the flowchart of the risk calculation module. The COLREG judgment module distinguishes between give-way and stand-on vessels depending on the encounter situation and induces avoidance based on the pre-determined rules; thus, collision avoidance operation can be performed in a way similar to that used by ship operators. According to the rules, the stand-on vessel must maintain its course and speed, and can take avoidance actions under the judgment that the give-way vessel does not take appropriate measures. The judgment module functions accordingly. Algorithms A5-A7 in Appendix A show the pseudocodes of the COLREG judgment module [39].