Determine the number of links connected to each node and their IDs with EPANET-MATLAB toolkit

Hi everyone,
In a large water distribution network with 1000 nodes, how can I determine the number of links connected to each node and their IDs with EPANET-MATLAB toolkit?
Best Regards,
Fatemeh Attarzadeh

@Fatemeh, I suggest follow the below steps:
1- Make a matrix A, contain of pipeID, Node1, Node2: you can open the .inp file in excel and separate the mentioned columns above in a another file and then call in MATLAB.

  1. Make a zero matrix B, contain of [number of row=number of junction, number of column=5]. Because of for a junction, can connect maximum 4 pipe and the first column is the id junction.

  2. Search row by row the id of network junctions in matrix A, and save the number of rows which find the id junction in them in columns 2 to 5.

  3. For every row in B matrix, the non-zero column is the number of pipe connect to every junction and number of every column is the pipe index which is connect to junction. Then, you can find the id pipe from pipe index, easily.

1 Like

Hi @Fatemeh, the number of links connected to each node you can find from

connmatrix = d.getConnectivityMatrix;
sum(connmatrix)

Example:

start_toolkit;

d = epanet('Net1.inp');

connmatrix = d.getConnectivityMatrix;
nodesConnectingLinksIndex = d.getNodesConnectingLinksIndex;

nodeConnLinkIDs = {};
for i=1:size(connmatrix, 1)
   nodeIndices = find(connmatrix(: , i))';
   linksconnFrom = find(nodesConnectingLinksIndex(:, 1) == i);
   linksconnTo = find(nodesConnectingLinksIndex(:, 2) == i);
   nodeConnLinkIDs{i} = d.getLinkNameID(unique([linksconnFrom', linksconnTo']));
end

links_connected_to_each_node = sum(connmatrix)
nodeConnLinkIDs

Regards,
Marios

2 Likes

@alireza2032
Thank you very much @alireza2032 for your suggestion.

Thank you very much @Mariosmsk ,
The code was very useful.