Hi everybody!

I’m going to make a matrix namely " Volume “, each matrix element in the form V (i, j,t).

" V(i,j,t) : the volume of polluted water that is consumed prior to the arrival of the pollution from node i to node, j , in time t”

that’s mean,Each column in the matrix represents a contamination event and each row, a network node. Each value of the matrix represents an assessment of the consumption of the contaminated

water assuming that a sensor in the related node is the first to detect the event, in time ‘t’.

I want to do these things to make this matrix,

First I Sort all reachable nodes from node i, on the network, according to the shortest path length, in an increasing order ,at time ‘t’ .

2) I simulate a pollution event in node i , at time ‘t’.

3) I Start from the first sorted node, and then I Calculate the volume of polluted water that is consumed prior to the arrival of the pollution from node i to the current sorted node, j , in time ‘t’.

4) I assign the amount of obtained polluted water at row i and column j of the “Volume” matrix and repeat for the next sorted node , in time pattern ‘t’.

I’m having difficulty step 2 and 3 and I do not know exactly what to do.I used these commands for step 1 :

ّFirst, I got the length of the pipes by “getLinkLength”, and then I got the speed of water in each pipe by “getLinkVelocity”. Then, by dividing the length over the speed, I got the time and sorted them according to the shortest path length, in an increasing order. (I calculated the shortest paths with the Floyd-Warshall algorithm , already).

in the second step %%simulate an event

step 2 :

```
%% Load EPANET Network and MSX
G = epanet('BWSN_Network_1.inp'); % Load EPANET Input file
G.loadMSXFile('Arsenite.msx'); % Load MSX file
% Sensor locations = first sorted node j (suppose first sorted node j is JUNCTION-17' )
sensor_id = {'JUNCTION-17'};
sensor_index = G.getNodeIndex(sensor_id);
%% Simulation Setup
t_d = 4; % days
G.setTimeSimulationDuration(t_d*24*60*60); % Set simulation duration of 4 days
%% Get Network data
demand_pattern = G.getPattern;
roughness_coeff = G.getLinkRoughnessCoeff;
node_id = G.getNodeNameID;
%% Scenarios
Ns = 8; % Number of scenarios to simulate
u_p = 0.20; % pattern uncertainty
u_r = 0.20; % roughness coefficient uncertainty
max_inj_conc = 2.0;
inj_start_time = 2*48; % after day 2 (Dt = 30min)
inj_duration = 24; % maximum duration of 12 hours
inj_sc=[randi(G.NodeCount,Ns,1), max_inj_conc*rand(Ns,1), randi(48,Ns,1)+inj_start_time,
randi(inj_duration,Ns,1)]; % Injection location, magnitude, start time, duration
```

…

I don’t know what to do in the second step exactly. How to simulate the pollution event for the different time period in one MATLAB code?

And is there an automatic method when I want to calculate the amount of polluted water for the next node ( next sorted node)? Because I change sensor_id every time and run the program for the new sensor_id again. Is that what I’m doing right?

is there a better way that I don’t know about for calculating the volume of consumed of contaminated water?

Thanks in advence!

Atosa