Abstract
This study introduces a new approach for automatic water pipe distribution network analysis by four integrated algorithms using graph theory, which are algorithms of minimal loop extraction, automatic initialization, automatic updating of initial discharges, and automatic pressure calculation at nodes. Object-oriented concepts have been used to design the algorithms for efficient data handling. The present integrated approach reduces the dependency of different processes involved in the analysis. The nested breadth first search traversal is used in the first algorithm to extract the loops without subdividing the graphical network. The initialization of pipes in loops is performed by satisfying the continuity equation at nodes in the second algorithm. The initialization, in the loop, is done in such a way that the adjacent loop will carry the residual discharge. Friction in the pipes is calculated iteratively for all flow types. Updating of discharge in pipes is according to the simultaneous loop flow adjustment method in the third algorithm. Initial discharges in the pipes of the loop in network are updated by corrective discharge in the loop according to the direction. The algorithm of nodal pressure calculation is done in the fourth algorithm, which is based on the energy equation in terms of pressure on the reference node. The results obtained by the proposed work are matched with EPANET software, in which the graphical display of the network is more user friendly and has the desired accuracy.
Keywords
1. Introduction
In the proposed research, an attempt is made to integrate four different algorithms for automatic water pipe network analysis. It reduces the dependency of the different processes involved in water pipe network analysis. Object-oriented concepts have been used in designing the algorithms for efficient data handling. Water pipe distribution network systems are vital infrastructure for domestic fresh water, power plants, and agricultural areas. For the improvement of reliability of a pipe distribution system, pipe networks are designed with loops. The problem of design and analysis of the pipe distribution system is to get the pipe diameter, reservoir head, and pumps such that the water demands are satisfied with suitable pressure and discharge at nodes. The basic prevailing equations of the pipe hydraulic system are obtained from the mass conservation at the junction of the network, energy conservation within the loop, and the head loss equation in pipes. In a looped pipe network, governing equations are nonlinear, in which unknowns may be discharge in pipes (Q), flow adjustment in loops (ΔQ), and nodal heads (H) in the network. For a given configuration and known water demands, roughness, length, diameters, and elevation at nodes, a solution of the aforesaid equations results in unique responses for the pipe flows and pressure at junctions.
For the given set of known, equations are solved for ΔQ, Q, and H using the numerical systems, such as the Hardy cross, 1 linear theory, 2 the Newton–Raphson Method,3–6 and the gradient algorithms method. 7 Todini7,8 developed several Newton–Raphson-based algorithms that are obtained through the simple linear transformation of the global algorithm. 9 Todini and Rossman 10 extended the work of Todini7,8 by developing three new linear theory-based algorithms. Giustolisi 11 modified the global gradient algorithms (GGAs) by the effective introduction of lumped nodal demand without the energy balance equation of pipes. Gudiño-Mendoza et al. 12 carried out modeling and simulation of water distribution systems using hybrid Petri nets. Equations are derived from using the concept of conservation of mass and energy. Transient and steady-state analysis have been carried out for hydraulic networks using MATLAB software. Comparison of the results has been performed with EPANET software.
Arsene et al. 13 developed a simulation model for real-time monitoring of a water distribution network by improving the numerical properties of the algorithms. To find the basic information about the network, that is, the spanning tree, the loop, and the topological matrix, they used the depth first search (DFS). A distributed scalable algorithm for fair cycle detection has been developed by Cerna and Pelanek, 14 which provides usually shorter cycles than that of the DFS. The set-based technique has been adopted by them in which the breadth first search (BFS) graph traversal is used. Courcoubetis et al. 15 used the traversal-based memory efficient technique for verification of temporal properties, which is sequential in nature and hence cannot be used for parallel and distributed processing. A parallel on-the-fly algorithm was developed by Barnat et al. 16 for model-checking in which the signature (back-level) edges for the cycle were detected by synchronizing the BFS traversal. For each back-level edge, the nested DFS is employed to extract the cycle from the graph network. Only theoretical discussions for loop extraction are presented by Barnat et al. 16 and Courcoubetis et al. 15 through the BFS. Unlike the DFS, the BFS works on the fly and can repeat vertices to extract the cycles from the graph network. Creaco and Franchini 17 developed a technique to identify the minimum loops in a water distribution network, which is used in the case of growing complexity. The computational efficiency of two algorithms, namely the Newton–Raphson global (NR-GA) and the Newton–Raphson loop flow (NR-LF), are compared in this work, which shows that the NR-LF takes less computational time.
Ivetic et al. 18 identified the minimal basis loops by BFS propagation. They first found the initial spanning tree and the initial set of loops and transformed the spanning tree to get the set of loops with the smallest number of pipes. Doing this is not guaranteed to obtain the topological minimal basis loops. Rahal 19 used the graph theory and matrix partitioning to reduce the original governing equations into a smaller set, expressed regarding the co-tree chord flows. Rahimi and Haghighi 20 analyzed the pipe network by dividing the network into two sub-graphs, the so-called base and remainders graphs. The base graph is a spanning tree of the network and the remainders graph includes pipes hypothetically removed from the network to open the loops. It increases the complexity of the pipe network and memory allocation in the computer. Shimada 21 gives a method for analyzing slow transience in complicated and large-scale pipelines using the incidence matrix on a graph theoretical framework, which is superior to the loop method for analyzing the same. Deuerlein 22 developed topological clustering tools for water supply network analysis using the graph network connectivity property. It provides deeper insight into the structure of a water pipe network. Manipulation of transforming data to sub-graphs may lose some information, which is not the case in the proposed cycle extraction formulation.
In the present work, water pipe network analysis is done by using four integrated algorithms. In the algorithm of automatic minimal loop extraction of the proposed work, unlike dividing the pipe network into sub-graphs19,20 at the initial stage, real and pseudo loops both are extracted from the graph network using the nested breadth first search (NBFS). In the current work, nesting of the BFS is done for successful extraction of the cycle in the graph network. After the extraction of loops, initialization of pipes in the loop is performed. An automatic initialization algorithm is used for initialization of the network in both the forward and reverse directions of the loops. Automatic updating of the discharge is done using the simultaneous loop flow adjustment method. In this technique, the initial solution obtained by the previous algorithm is updated. The Jacobian matrix is calculated and the incremental values of discharges in the loops are finally obtained in solving a number of equations by the Gauss elimination technique. The discharges in the pipes are updated according to the direction of flow. The pressure calculation is done taking atmospheric pressure as a reference at the supply nodes. The pressure at all other nodes is calculated concerning the reference node and flow parameters. It is a technique in which the traversal is done from the reference node and energy is balanced at all nodes through connecting pipes.
Use of the object-oriented concept makes the system memory efficient, and integrated algorithms reduce the dependency of different processes in automatic analysis of the water network. Different classes are defined, such as the pipe, node, loop, and pipe network, whose objects interact with each other. The graphical user interface (GUI) is prepared using the OpenGL Library for the graphical representation of the test results. It shows the proportional discharge in pipes and proportional pressure at nodes automatically. Manual construction is not required in the present work. The display adopted in the present work is more user-friendly than the EPANET and has the capability of the desired accuracy, which is missing in EPANET. A number of networks can be analyzed at one time.
2. Methodology
The analysis of the pipe distribution system in the present work is conducted using four algorithms. The NBFS traversal obtains all the cycles in the first algorithm, called the automatic loop extraction algorithm. Pipes are initialized using another algorithm, called the automatic initialization algorithm. Updating of the initial discharges is done in the following algorithm using the Newton–Raphson technique. 3 The last algorithm calculates pressure on the nodes. The object-oriented concept is employed in the implementation of the above algorithms.
2.1 Algorithm of automatic minimal loop extraction
Conceptually, a looped water pipe distribution network is a directed graph in which junctions and pipes are nodes and edges of the graph, respectively. The pipe and node data structure are constructed from the two input files dealing with pipe and node information. Herein, all cycles (loops) are extracted first, whether it is the real loop or the pseudo loop. The extraction of the loop in this work is done by the NBFS traversal. The BFS traversal is applied to the graph network, as shown in Figure 1. The BFS starts to traverse through vertices A, B, C, D, E, and F and, when it comes to vertex C, it finds that vertex F is already traveled. This F vertex gives the signature edge of the loop in the graph network, which will be extracted by the second BFS traversal from vertex C to vertex F. The traversal through edge CF is restricted initially. Loop C, A, B, F, C is obtained finally by repeating vertex C. Extracted cycles in the proposed work are minimal. The adjacency list is used to represent the graphical network. Pseudo loops are extracted in the present formulation in a for-loop for all supply nodes. A list of supply nodes is obtained from the node data file. Any two adjacent supply nodes form a pseudo loop by the shortest path traversal. The total number of pseudo loops extracted in the present formulation will be one less than the total number of supply nodes. Loops are ordered in the clockwise direction by checking the cross-product values of the edges of the loops.

Illustration for graph traversal.
Two loops, namely the dependent and independent loops, are shown in Figure 2. Loop_Num_1 is a dependent loop having vertices V7, V6, V4, and V3, and Loop_num_2 is an independent loop, having vertices V1, V5, V4, V6, V7, and V2. If Loop_num_1 is initialized before Loop_num_2, then the conservation of mass can be applied successfully at all nodes; otherwise, the continuity equation will not be satisfied at V3. The dependent loop nodes do not have the uninitialized adjacent pipe so cannot be initialized after the independent loop.

Dependent and independent loops.
The loop extraction procedure is called in for-loop for all nodes. It may be possible that all nodes may not give all the possible loops; in such a case, the procedure will give the message that the network needs to be divided, which is never encountered in the testing of the networks. The ordered cycles are kept in the network for further use in the initialization and updating of discharges. Pseudo loops are kept last in the cycle. The loop extraction algorithm of Jha 23 is modified in the present work to give loops in the clockwise direction.
Algorithm of automatic minimal loop extraction:
Loop Extraction ()
{
For every node j of pipe network
{
If (BFSCycleDetectionClockWise(s) == 0) Continue
else
}
Message (Graph network is to be subdivided and reuse for loop extraction)
}
BFSCycleDetectionClockWise (int node)
{
Put node j in a queue
Put node j in queue-Travelled
While (Queue is not empty)
{
Get front node from queue
Get adjacent edges of the front node
For (each edge)
{
If (edge is travelled already) Continue
Else tag the edge
Get the vertex
If (vertex is already in queue-Travelled)
{
If (BFSCycleExtractionClockWise (node, vertex) ==0)
Return 0
}
Put the vertex in queue
Put vertex in queue-Travelled
}
Remove front node from queue
}
Return 1}
BFSCycleExtraction(int node1, int node2)
{
Put node1 in queue1
successful_loop_tag=0
While (queue1 is not empty)
{
Get the front node from queue1
Get adjacent edges from front node
For (each edge)
{
If (edge is not travelled by first BFS traversal) Continue
If (edge tagged by second traversal) Continue
else tag the edge
If (Cycled-Edge-Tag value ==1 && edge is boundary)
Continue
Get next-Vertex
If (next-Vertex == node2)
{
If (order_of _cycle () ==0 ) Reverse_theorder_of_vertices() /// 0 is anticlockwise and 1 is clockwise
Make Cycles ()
Cycled-Edge-Tag++ ///for all cycled edges
successful_loop_tag ++
}
Put next-Vertex in queue1
}
Remove front node from queue1
}
If (successful_loop_tag ==0) return 0
else return 1;
}
2.2 Algorithm of automatic initialization
An automatic initialization algorithm is developed to apply the continuity equation at all nodes of the loops. It can start at any node of the loops where the demand or at least initial discharge of a pipe is given. Initialization will be done with the help of the total number of incoming pipes and outgoing pipes. If demand is not known at any node of the start loop, then the initial discharge in a pipe is assumed to be a fixed value. The summation of all known discharges in the incoming pipes and outgoing pipes are calculated separately at the node to apply the continuity equation to get the value of discharges in uninitialized incoming and outgoing pipes. Initialization in the loop will be done in the forward and backward directions. Initialization starts with an arbitrary node, called the beginning-node, and continues in the clockwise direction of the loop until it does not have an uninitialized adjacent pipe. The node that has the uninitialized adjacent edge is called branching-node. Once the branching-node is reached, then the initialization will be started in the reverse direction from the beginning-node and be continued until the branching-node. Initialization of the branching-node is done finally in the loop to give the total resultant residue discharge in the adjacent loop. A similar technique is adopted to initialize all other loops. The supply pipe compensates total residue discharge. The total number of pseudo loops will be one less than the number of supply nodes, which are automatically initialized finally to give the unbalanced discharges. Initialization of the pipe is not possible without the branching-node in the forward direction of the loop. If such a condition arises, then this loop is referred to as a degenerate case, which will be handled first. The initialization algorithms given by Jha 23 are modified to work for ordered loops. The algorithm of initialization is essential for the approximation techniques adopted1,3,23 to give the updated discharges, which is not reported in the literature mentioned above.
Algorithm of automatic initialization:
Initialize loops ()
{
Get_extracted_loops ()
AAAA:
for each loop
{
Take a node from the loop
If at this node demand is not given or at least one pipe coming out of it have not initialized
{
initialized an edge with an arbitrary value
}
assume this node as beginning-node
find number of incoming pipe at node
find number of outgoing pipes at node
Starting with this beginning-node go on initializing the pipes in loop in the forward direction (clockwise) using the continuity equation until a node (Branching-node) is found with an uninitialized adjacent edge
If (there is no such Branching-Node)
{
Uninitialized all initialized nodes and pipes
Initialized_node_where_there_is_unbalance Discharge (node)
Go to AAAA
}
Go on initializing nodes in the backward direction until the branching-node is reached
} // this is done for completion of initialization in loop
Initialized all remaining nodes which are present outside the loops in network
For all pipes
{
Double Re_No = get_Reynold_number()
Double Roughness = get_Pipe_Roughness()
Double Dia = get_pipeDia()
Calculate friction factor (Re_No, Roughness, Dia)
}
Return 1
}
2.3 Algorithm of updating of discharges
The present water distribution network analysis is done by using the simultaneous loop flow adjustment method, 3 which needs an initial estimation for discharges in the pipes of the network. Automatic loop initialization is used to provide the initial estimation for automatic water pipe network analysis. In general, many pipe networks have one or more loops in which some pipes are common. Correction in the common pipes of the loop causes energy losses around it. To improve this problem, an algorithm for updating the discharges has been developed in which loop equations were simultaneously solved by using a correction factor. 7 A large number of nonlinear equations, which is equal to the number of loops, are solved using the Newton–Raphson technique. The network needs to initialize first, which is done using the previous algorithm to obtain the updated discharge. The friction factor is calculated in each pipe iteratively for every updated discharge in the loops.
The procedure for analysis of the looped pipe network is done by using a simultaneous loop adjustment method as in the following steps.
Get the initialized loops from the previous algorithms.
The head loss equation of loops in the pipe network is as follows:
where kn is the total number of pipes in the kth loop and Kn. Fk gives the total number of nonlinear equations, which is solved by the Newton–Raphson technique.
Calculation of the friction factors fi in each pipe for every update in the discharge is given by Swamee’s 24 formula below for the turbulent case:
where R is the Reynolds number and è is the roughness factor. Details of the implementation are given in the algorithm of initialization.
where lp(n) shows the one or more loops in the network that contain pipe n. Δ is the loop correction factor.
Expansion of Equation (3) up to the first order by Taylor’s series approximation is as follows:
where cl(k) is the number of loops that have a common pipe with loop k.
All loops simultaneously given in (4) can be written in vector form as follows:
Jl is the Jacobian matrix of the first-order derivatives of the loop equation, which is solved for Δ by using the Gauss elimination method.
The discharges in the pipes are modified using Δ and the procedure is repeated until the values of Δ are more than a user given input.
Loop discharges ΔQ are shortened in decreasing order, and the first value is compared with the given allowable error (0.0000001 m3/s). Iteration will be continued until this value is more than the given allowable error; otherwise, the update value from the Equation (6) will be assumed as the final updated discharges in the pipes. The allowable error will be the user input for the program.
2.4 Algorithm of automating pressure calculation at the nodes
The nodal pressure in the network is obtained by Equation (7). The graph traversal algorithm is written for the calculation of pressure. The pressure at any node is calculated in terms of the reference node. The pressure at all other nodes in between the travel node is calculated using Equation (7). In the present formulation, the supply node is taken as the reference node. The pressure at all the supply nodes is checked, which are found to be at atmospheric pressure. This will ensure the correctness of the proposed algorithm of automatic pressure calculation at the nodes. The equation for pressure calculation is given as follows:
where Pr is the pressure at junction r, ∑HL(Q) represents the total losses in pipes between nodes, r and r–1, and Zr and Zr–1 are the elevation at nodes (r, r–1).
Different classes have been constructed in the present formulation, whose objects are interacting with each other for efficient handling of data. A GUI is prepared that can display a number of networks at a time, which seems to be difficult in EPANET software. Figure 3 shows a logical flow chart for the overall methodology of the current work. It gives a more precise view of the process flow.

Logical flow chart of the overall methodology. BFS: breadth first search.
3. Results and discussion
A numbers of networks are examined for the present work. Results are displayed graphically by using OpenGL Library. C++ programming is used for the development of different modules of the present work. All test results are implemented in a Windows XP environment, using a 2.40 GHz Intel Core i3 possessor, in a sequential mode (one tread). A simple pipe network (graph) is shown in Figure 4 with pipes and nodes. It has three closed loops that have effectively extracted in the clockwise direction by the proposed automatic minimal loop extraction technique, as shown in Figure 5. Figure 6 shows an ordered pseudo loop extracted obtained from Test Result 1 (TR-1). The loops obtained by Jha 23 are not ordered as in the proposed work. The beginning of the extraction of the loop is done in such way that the loop has the supply node extracted first and initialization is done last. Orders of loops initialization are in reverse order to that of loop extraction. Initial discharges in each pipe of the network are shown in Figure 7, which are obtained by applying the continuity equation at all the nodes of the network. The arrow and thickness of the pipe in Figure 7 shows the direction and proportional initial discharge. The supply nodes and supply pipes are also shown in Figure 7.

Pipe network of Test Result 1.

Loop extraction of Test Result 1.

Pseudo loop of Test Result 1.

Initial discharges of Test Result 1.
Discharges after flow adjustment (balanced discharges) in the pipe for TR-1 are shown in Figure 8. The arrow and thickness of the pipe demonstrate the direction of flow and proportional balance discharge in the pipes. The green rectangular blocks indicate the proportional demand at the node. Comparisons of the updated discharge (balanced discharge) by the current work and EPANET are given in Table 1. Node data and pipe data are given in the Appendix. The pressures at each node are shown in Figure 9. The green rectangular blocks indicate the proportional pressure at the node. Pressure at the nodes is obtained by giving the atmospheric pressure at any one supply (reference) node of the network. It is verified by the proposed automatic pressure calculation algorithm that the atmospheric pressure is the same at each supply node. Pressure calculated at the nodes by the proposed work is compared with EPANET software and is given in Table 2. TR-1 takes approximately 16 ms to converse in eight iterations.

Balanced discharge for Test Result 1. (Color online only.)
Comparison of balanced discharges.

Pressure at nodes for Test Result 1. (Color online only.)
Comparison of nodal pressure.
Another pipe network (TR-2) is shown in Figure 10 along with the pipe and node numbers. The loop extracted for TR-2 is shown in Figure 11. Figure 12 shows the pseudo loop obtained by the proposed technique. Figures 13 and 14 show the initial and balanced discharges for TR-2. The thickness of the pipe in the figures is according to the discharge in the pipes. The calculated pressure is shown in Figure 15, which indicates that pressure at the supply nodes is at atmospheric pressure. Pressure calculated by the proposed method is compared with the EPANET software in Table 2. Node data and pipe data are given in the Appendix. Some cases were identified in which a particular starting node has difficulty in giving entire possible loops effectively. This algorithm used the other node of the “for” loop to give all possible extracted loops. TR-2 takes approximately 16 ms to converse in eight iterations.

Pipe network of Test Result 2.

Loop extracted for Test Result 2.

Pseudo loop of Test Result 2.

Initial discharge of Test Result 2.

Balanced discharge for Test Result 2.

Pressure at the nodes for Test Result 2.
Figure 16 shows another complex test result (TR-3). Thirty-one extracted loops for TR-3 are shown in Figure 17. Figure 18 shows the three extracted pseudo loops. Initial and updated discharges in the pipe for the same result are shown in Figures 19 and 20, respectively. The pressure at all the nodes for this network is shown in Figure 21. The pressure at the supply nodes in Figure 20 is at atmospheric pressure, which indicates the correctness of the pressure calculation. TR-3 takes approximately 485 ms to converse in 11 iterations.

Pipe network of the complex problem.

Loops extracted for the complex network.

Pseudo loops of the complex network.

Initial discharges of the complex network.

Balance discharge for the complex network.

Pressure at nodes for the complex network.
Table 1 shows the balanced discharges in the pipes obtained by the proposed technique and EPANET software for TR-1 and TR-2 for comparison, which shows almost the same result. Comparison of the nodal pressure with EPANET for the same test results is shown in Table 2, which shows comparable results.
The present work can be used for online monitoring and design analysis. It can also be used for leak detection. The scales of the figures are not uniform. The graphical display of the proposed work is more user-friendly.
4. Conclusions
Integrated algorithms have been developed for automatic analysis of water pipe networks. Integration reduces the dependency of the different processes involved in water pipe network analysis. The object-oriented concept is used for efficient data handling. The NBFS traversal is used for minimum loop extraction from the pipe network, which will be used for parallel processing. These algorithms are based on ordered loop extraction of the pipe network in which all cycles are extracted simultaneously, for the simultaneous solution of the closed loop network. The basic features of this study are as follows: (1) it simplifies the hydraulic design and analysis; (2) the extracted loops obtained from the graph network are minimum in this case; (3) it gives an improved insight into the network connectivity and hydraulic analysis.
Pipes are successfully initialized and balanced discharges in pipes are obtained through the simultaneous loop flow adjustment method. The pressure obtained at all the supply nodes is at atmospheric pressure, which shows the correctness of the formulation. The pressure and discharge obtained may be used for design analysis. The pipe network shows the proportional pipe discharge and proportional pressure at the node. EPANET software is used to verify the test results, which proved the validation of the proposed work. In the proposed method, the display of the network is more user-friendly and has more control of the accuracy of the analysis. The different objects of classes interact with each other for efficient handling of data. A number of networks can be opened at one time in the present formulation. CPU time has been calculated for all test results. The current methodology can be used for extended period simulation (EPS) for variable demand patterns with time.
Footnotes
Appendix
Pipe data of Test Result 2.
| Pipe number | Connecting nodes | Length (m) | Diameter (mm) | Pipe type | |
|---|---|---|---|---|---|
| 1 | 1 | 2 | 90 | 225 | 1 |
| 2 | 2 | 8 | 88.5297 | 100 | 1 |
| 3 | 3 | 9 | 88.9522 | 100 | 1 |
| 4 | 4 | 5 | 125 | 255 | 1 |
| 5 | 4 | 10 | 125.1 | 100 | 1 |
| 6 | 3 | 6 | 90 | 255 | 1 |
| 7 | 7 | 5 | 95 | 255 | 1 |
| 8 | 8 | 10 | 88.9522 | 100 | 0 |
| 9 | 9 | 10 | 88.5297 | 100 | 0 |
| 10 | 8 | 9 | 125.1 | 100 | 0 |
| 11 | 8 | 3 | 88.529 | 100 | 1 |
| 12 | 9 | 4 | 88.9522 | 100 | 1 |
| 13 | 10 | 2 | 125.1 | 100 | 1 |
Funding
This research received no specific grant from any funding agency in the public, commercial, or not-for-profit sectors.
Author biographies
