Email: helpdesk@telkomuniversity.ac.id

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • Visual Paradigm
  • IBM
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Windows
      • Office
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • Visual Paradigm
  • IBM
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Windows
      • Office
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/Matlab/Optimization of water distribution network, objective is to get optimal cost

Optimization of water distribution network, objective is to get optimal cost

PuTI / 2025-02-06
Optimization of water distribution network, objective is to get optimal cost
Matlab News

I want to ask how I should use any optimization algorithm with EPANET to obtained optimal diameter and optimal cost?
After using the code attached, I am unable to get the optimal cost; it is always coming ‘inf’ even if I am using a minimum pressure requirement of 30 m for nodes, minimum velocity 0, and maximum velocity ‘inf’ for links. I am using the Hanoi network, which has 34 links, for hydraulic simulation, I am using EPANET I am also attaching the Matlab code that I am using. It would be very nice of you if anyone could help me with this.
% GENETIC ALGORITHM (GA) SETUP

clear; close(‘all’); clc;
start_toolkit;

%d = epanet(‘C:UsersAdminDesktopPipeNetworkPN_codeHanoi.inp’);

% Define GA options for optimization
options = optimoptions(‘ga’, ‘Display’, ‘iter’, ‘PopulationSize’, 16, …
‘MaxGenerations’, 6, ‘UseParallel’, false);

% Define number of pipes in the network
nvars = 34; % Number of pipes

diameterOptions = [304.8, 406.4, 508, 609.6, 762, 1016]; % Available diameters in mm
costPerDiameter = [45.73, 70.4, 98.38, 129.333, 180.8, 278.3]; % Cost per unit length for each diameter

% Define lower and upper bounds for pipe diameters
lb = repmat(min(diameterOptions), 1, nvars); % Minimum diameter constraint
ub = repmat(max(diameterOptions), 1, nvars); % Maximum diameter constraint

% Run Genetic Algorithm (GA) for optimal pipe diameter selection
[optimalDiameters, optimalCost] = ga(@pipeNetworkObjective, nvars, [], [], [], [], lb, ub, [], options);

% Display optimization results
fprintf(‘Optimal Pipe Diameters:n’);
disp(optimalDiameters);
fprintf(‘Optimal Cost:n’);
disp(optimalCost);

function cost = pipeNetworkObjective(diameters)
% Load EPANET-MATLAB Toolkit
start_toolkit;
d = epanet(‘Optimal_Configuration_eta_2.00.inp’);

% Set pipe diameters based on GA input
for i = 1:length(diameters)
d.setLinkDiameter(i, diameters(i));
end

% Run hydraulic simulation
d.solveCompleteHydraulics;

% Check constraints
pressures = d.getNodePressure;
velocities = d.getLinkVelocity;

if any(pressures < 0) || any(velocities < 0) || any(velocities > inf)
cost = inf; % Penalize infeasible solutions
else
% Calculate cost based on diameters
cost = calculateCost(diameters);
end

% Close EPANET
d.unload;
end

function totalCost = calculateCost(diameters)
% Define cost per diameter (example values)
diameterOptions = [304.8, 406.4, 508, 609.6, 762, 1016]; % Available diameters in mm
costPerDiameter = [45.73, 70.4, 98.38, 129.333, 180.8, 278.3]; % Cost per unit length for each diameter

% Calculate total cost
totalCost = 0;
for i = 1:length(diameters)
idx = find(diameterOptions == diameters(i));
totalCost = totalCost + costPerDiameter(idx);
end
endI want to ask how I should use any optimization algorithm with EPANET to obtained optimal diameter and optimal cost?
After using the code attached, I am unable to get the optimal cost; it is always coming ‘inf’ even if I am using a minimum pressure requirement of 30 m for nodes, minimum velocity 0, and maximum velocity ‘inf’ for links. I am using the Hanoi network, which has 34 links, for hydraulic simulation, I am using EPANET I am also attaching the Matlab code that I am using. It would be very nice of you if anyone could help me with this.
% GENETIC ALGORITHM (GA) SETUP

clear; close(‘all’); clc;
start_toolkit;

%d = epanet(‘C:UsersAdminDesktopPipeNetworkPN_codeHanoi.inp’);

% Define GA options for optimization
options = optimoptions(‘ga’, ‘Display’, ‘iter’, ‘PopulationSize’, 16, …
‘MaxGenerations’, 6, ‘UseParallel’, false);

% Define number of pipes in the network
nvars = 34; % Number of pipes

diameterOptions = [304.8, 406.4, 508, 609.6, 762, 1016]; % Available diameters in mm
costPerDiameter = [45.73, 70.4, 98.38, 129.333, 180.8, 278.3]; % Cost per unit length for each diameter

% Define lower and upper bounds for pipe diameters
lb = repmat(min(diameterOptions), 1, nvars); % Minimum diameter constraint
ub = repmat(max(diameterOptions), 1, nvars); % Maximum diameter constraint

% Run Genetic Algorithm (GA) for optimal pipe diameter selection
[optimalDiameters, optimalCost] = ga(@pipeNetworkObjective, nvars, [], [], [], [], lb, ub, [], options);

% Display optimization results
fprintf(‘Optimal Pipe Diameters:n’);
disp(optimalDiameters);
fprintf(‘Optimal Cost:n’);
disp(optimalCost);

function cost = pipeNetworkObjective(diameters)
% Load EPANET-MATLAB Toolkit
start_toolkit;
d = epanet(‘Optimal_Configuration_eta_2.00.inp’);

% Set pipe diameters based on GA input
for i = 1:length(diameters)
d.setLinkDiameter(i, diameters(i));
end

% Run hydraulic simulation
d.solveCompleteHydraulics;

% Check constraints
pressures = d.getNodePressure;
velocities = d.getLinkVelocity;

if any(pressures < 0) || any(velocities < 0) || any(velocities > inf)
cost = inf; % Penalize infeasible solutions
else
% Calculate cost based on diameters
cost = calculateCost(diameters);
end

% Close EPANET
d.unload;
end

function totalCost = calculateCost(diameters)
% Define cost per diameter (example values)
diameterOptions = [304.8, 406.4, 508, 609.6, 762, 1016]; % Available diameters in mm
costPerDiameter = [45.73, 70.4, 98.38, 129.333, 180.8, 278.3]; % Cost per unit length for each diameter

% Calculate total cost
totalCost = 0;
for i = 1:length(diameters)
idx = find(diameterOptions == diameters(i));
totalCost = totalCost + costPerDiameter(idx);
end
end I want to ask how I should use any optimization algorithm with EPANET to obtained optimal diameter and optimal cost?
After using the code attached, I am unable to get the optimal cost; it is always coming ‘inf’ even if I am using a minimum pressure requirement of 30 m for nodes, minimum velocity 0, and maximum velocity ‘inf’ for links. I am using the Hanoi network, which has 34 links, for hydraulic simulation, I am using EPANET I am also attaching the Matlab code that I am using. It would be very nice of you if anyone could help me with this.
% GENETIC ALGORITHM (GA) SETUP

clear; close(‘all’); clc;
start_toolkit;

%d = epanet(‘C:UsersAdminDesktopPipeNetworkPN_codeHanoi.inp’);

% Define GA options for optimization
options = optimoptions(‘ga’, ‘Display’, ‘iter’, ‘PopulationSize’, 16, …
‘MaxGenerations’, 6, ‘UseParallel’, false);

% Define number of pipes in the network
nvars = 34; % Number of pipes

diameterOptions = [304.8, 406.4, 508, 609.6, 762, 1016]; % Available diameters in mm
costPerDiameter = [45.73, 70.4, 98.38, 129.333, 180.8, 278.3]; % Cost per unit length for each diameter

% Define lower and upper bounds for pipe diameters
lb = repmat(min(diameterOptions), 1, nvars); % Minimum diameter constraint
ub = repmat(max(diameterOptions), 1, nvars); % Maximum diameter constraint

% Run Genetic Algorithm (GA) for optimal pipe diameter selection
[optimalDiameters, optimalCost] = ga(@pipeNetworkObjective, nvars, [], [], [], [], lb, ub, [], options);

% Display optimization results
fprintf(‘Optimal Pipe Diameters:n’);
disp(optimalDiameters);
fprintf(‘Optimal Cost:n’);
disp(optimalCost);

function cost = pipeNetworkObjective(diameters)
% Load EPANET-MATLAB Toolkit
start_toolkit;
d = epanet(‘Optimal_Configuration_eta_2.00.inp’);

% Set pipe diameters based on GA input
for i = 1:length(diameters)
d.setLinkDiameter(i, diameters(i));
end

% Run hydraulic simulation
d.solveCompleteHydraulics;

% Check constraints
pressures = d.getNodePressure;
velocities = d.getLinkVelocity;

if any(pressures < 0) || any(velocities < 0) || any(velocities > inf)
cost = inf; % Penalize infeasible solutions
else
% Calculate cost based on diameters
cost = calculateCost(diameters);
end

% Close EPANET
d.unload;
end

function totalCost = calculateCost(diameters)
% Define cost per diameter (example values)
diameterOptions = [304.8, 406.4, 508, 609.6, 762, 1016]; % Available diameters in mm
costPerDiameter = [45.73, 70.4, 98.38, 129.333, 180.8, 278.3]; % Cost per unit length for each diameter

% Calculate total cost
totalCost = 0;
for i = 1:length(diameters)
idx = find(diameterOptions == diameters(i));
totalCost = totalCost + costPerDiameter(idx);
end
end optimization of epanet network using ga toolkit MATLAB Answers — New Questions

​

Tags: matlab

Share this!

Related posts

Is it possible to make this tiny loop faster?
2025-05-19

Is it possible to make this tiny loop faster?

Solar Wind Battery Hybrid Integration
2025-05-19

Solar Wind Battery Hybrid Integration

Why does it say “invalid email or password” when i reinstall r2023b Product
2025-05-19

Why does it say “invalid email or password” when i reinstall r2023b Product

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: helpdesk@telkomuniversity.ac.id
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss