How to execute code for another inp file?


Hi all,

I already asked this question And @demetrios introduced me ### KIOS-Research/CCWI2016
I have a network " mynet.inp" and I want to make the same scenarios with it.I put the inp file in the corresponding folder
C:\Users\ken\Downloads\CCWI2016-master\benchmarks\asce-tf-wdst\Battle of the Water Sensor Networks

But when I run the program I got an error. What can I do to fix the error?

Error using epanet (line 457)
File "mynet.inp" is not a valid.

Error in contamination_simulation(line 4)
G = epanet('mynet.inp');

How does this code run for another network?



@ ken, You should some changes in your code based on your network. Please attach your code and network to consider it exactly.


Hi @alireza2032 , I used the following code :

%%  Case Study for CCWI2016

close all; clear; rng(1)

%% Load EPANET Network and MSX
G = epanet('Battle of the Calibration Networks System.inp'); % Load EPANET Input file
G.loadMSXFile('Arsenite.msx'); % Load MSX file

% Sensor locations
sensor_id = {'J7', 'J23', 'J42', 'J83', 'J425'};
sensor_index = G.getNodeIndex(sensor_id);

%% Simulation Setup
t_d = 5; % days
G.setTimeSimulationDuration(t_d*24*60*60); % Set simulation duration of 5 days

%% Get Network data
demand_pattern = G.getPattern;
roughness_coeff = G.getLinkRoughnessCoeff;
node_id = G.getNodeNameID;

%% Scenarios
Ns = 100; % 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 

%% Run epochs
for i = 1:Ns
    disp(['Iteration ', int2str(i)])
    % Randomize hydraulics
    r_p = -u_p + 2*u_p.*rand(size(demand_pattern,1),size(demand_pattern,2));
    new_demand_pattern = demand_pattern + demand_pattern.*r_p;
    G.setPatternMatrix(new_demand_pattern); % Set new patterns
    r_r = -u_r + 2*u_r.*rand(size(roughness_coeff,1),size(roughness_coeff,2));
    new_roughness_coeff = roughness_coeff + roughness_coeff.*r_r;
    G.setLinkRoughnessCoeff(new_roughness_coeff); % Set new roughness coefficients
    % Randomize injection
    G.setMSXSources(node_id(inj_sc(i,1)), 'AsIII', 'Setpoint', inj_sc(i,2), 'AS3PAT'); % Specify Arsenite injection source
    as3_pat = zeros(1, t_d*48);
    as3_pat(inj_sc(i,3):(inj_sc(i,3)+inj_sc(i,4))) = 1; % 
    G.setMSXPattern('AS3PAT',as3_pat); % Set pattern for injection
    Q{i} = G.getMSXComputedQualityNode(sensor_index); % Solve hydraulics and MSX quality dynamics
    G.setMSXSources(node_id(inj_sc(i,1)), 'AsIII', 'Setpoint', 0, 'AS3PAT'); % Reset injection source

%% Plot results
for i = 1:Ns
    for j = 1:length(sensor_index)
       plot(Q{i}.Time/24/60/60, Q{i}.Quality{j}(:,1),'-','Color',[0,0.7,0.9]); hold on; grid on
for i = 1:length(sensor_index)
   ylabel('Cl_2 (mg/L)')
   xlabel('Time (days)')

These are the files that I have

Battle of the Calibration Networks System.inp (98.3 KB)
I do not know why I can not upload the MSX file, I put it in png format

I got the same error for this network

Error using epanet (line 457)
File "Battle of the Calibration Networks System.inp" is not a valid.

Error in code (line 6)
G = epanet('Battle of the Calibration Networks System.inp'); % Load
EPANET Input file

Thanks & Best,



I’ve tried to use the algorithm you are using. It is running ok on my computer.

You could try the following:

  1. Please download the latest version of the toolkit and let us know if this work by openning the file
  2. If it does, you can replace the toolkit files from the CCWI code with the new one.
  3. Please describe your exact system configuration (Matlab version 32/64bits, Compiler (run “mex -setup”) and any other info which might help,


Hi @demetrios Thanks for your help, I’ll try once with the latest version of the toolkit.

Thanks again


@ken, I also tested your code with EMT 2.1.7. It was OK.