## 4 Network Implementation and Learning Algorithm
### Default LoRa Network  
The oil pipeline leak detection and localization monitoring system will be deployed in OMNeT++, based on the Inet and FLoRa frameworks, to cover the network part of a pipeline with a length of 200 km. An oil pipeline monitoring system is proposed to calculate a leak's volume and detect the specific location of a leak in a pipeline. Generally, it consists of two parts; the first is the endpoint-sensing part, which divides the pipeline into 100 segments. Each segment has a group of sensors deployed in the inlet and outlet parts of a pipeline segment, e.g., a pressure sensor, temperature sensor, and flow meter. Each specific sensor is used to read a certain value of the oil state, and each group of sensors is connected with LoRa nodes, which are used to collect the sensed data and transmit them to the central server. The second part of the proposed monitoring system is the real-time transient model (RTTM) technique, which is located on the LoRa server side, and it is responsible for mathematical calculations to achieve real-time monitoring and the detection of leak points. The network design of the proposed system is described as follows:  
1. The LoRa network consists of 100 LoRa nodes to cover the whole oil pipeline network. 2. Each pair of sequential nodes in the pipeline network is separated by two kilometers. This distance refers to a single pipeline segment supplied with two sensors for the inlet and outlet. 3. The network comprises ten LoRa gateways, separated over the oil pipeline network, and each one boasts a wireless coverage radius of twenty kilometers. 4. Every ten nodes attach wirelessly to a single LoRa gateway. These nodes work as sensors used to transmit the instant parameters of the oil for each pipeline segment, such as the pressure (Pt), instant time, flow rate (M), and temperature (Temp) (for both the inlet and outlet), as well as the node identifier. 5. LoRa gateways act as bridges between endpoints and the LoRaWAN server, connecting via the cloud. They are responsible for managing connections, establishing and coordinating the connected nodes, and ultimately, forwarding the sensed data to the LoRa server for further processing. 6. The function of the LoRa server is to continuously monitor the pipeline status within the simulation. On the server side, a real-time transient model is deployed to calculate the leak locations and quantities in the pipeline. To achieve this, it calculates the discrepancies, which are represented by X, which is, depending on the calculation, the difference between the values of the inlet simulated and measured (sensor) flow rate and the calculated values of the inlet flow rate, and Y refers to the same parameters but for outlet flow rates in the pipeline segment via a specific mathematical equation. \[X=M\;In\;(cal)-M\;In(mes) \tag{1}\] \[Y=M\;Out\;(cal)-M\;Out\;(mes) \tag{2}\]  
where  
* \(\rm{MIn(cal)}=\) calculated flow rate for the inlet;
* \(\rm{MIn(mes)}=\) simulated and measured flow rate for the inlet;
* \(\rm{MOut(cal)}=\) calculated flow rate for the outlet;
* \(\rm{MOut(mes)}=\) simulated and measured flow rate for the outlet. 7. The leak flow rate value M (Leak) is calculated by using the following equation:  
\[M\;(Leak)=X-Y \tag{3}\]
8. The leak position value in meters (m) X (Leak) is calculated by using the following equation:  
\[X(Leak)=(-Y/\;M)\;*\;Le+Nu\;*\;Le\]where the parameter Le is the pipeline segment length, and Nu refers to the number of LoRa nodes. The RTTM continuously utilizes the outcomes of various sensor measurements, such as the pressure, temperature, and flow rate; these are applied in a series of equations on the LoRa server to provide the necessary values for the leak calculations. This scenario validates a successful deployment of real-time LoRa technology selected for the proposed system due to its efficiency in terms of low power consumption and long-range communication and its presentation of distinct benefits over competing technologies [54].