Hi Pooja,
To optimize a pipe network for minimum cost using MATLAB's Genetic Algorithm (GA) toolbox, you can follow these general steps. The process involves integrating EPANET with MATLAB, defining the optimization problem, and using GA to find the optimal pipe diameters.
1) Prepare the EPANET Model: Ensure your EPANET model (.inp file) is correctly set up with all pipes, nodes, and the reservoir.
2) Integrate EPANET with MATLAB: Use the EPANET-MATLAB Toolkit, which allows you to interact with EPANET files directly from MATLAB. You can download it from the MATLAB File Exchange : OpenWaterAnalytics/EPANET-MATLAB-Toolkit 3) Define the Optimization Problem:
- Objective Function: Minimize the total cost of the network by selecting pipe diameters.
- Decision Variables: Diameters of the 80 pipes.
- Constraints: i) Minimum pressure head at outlet nodes ≥ 1 m. ii) Velocity in pipes between 0.6 and 1.8 m/s.
4) Implement the Objective Function in MATLAB:
- Create a function that calculates the total cost based on the diameters chosen by GA.
- Use the EPANET-MATLAB Toolkit to simulate the hydraulic model and check constraints.
function cost = pipeNetworkObjective(diameters)
d = epanet('your_network.inp');
for i = 1:length(diameters)
d.setLinkDiameter(i, diameters(i));
d.solveCompleteHydraulics;
pressures = d.getNodePressure;
velocities = d.getLinkVelocity;
if any(pressures < 1) || any(velocities < 0.6) || any(velocities > 1.8)
cost = calculateCost(diameters);
function totalCost = calculateCost(diameters)
diameterOptions = [100, 150, 200];
costPerDiameter = [10, 15, 20];
for i = 1:length(diameters)
idx = find(diameterOptions == diameters(i));
totalCost = totalCost + costPerDiameter(idx);
5) Configure and Run GA in MATLAB: Set up the GA options and constraints.
options = optimoptions('ga', 'Display', 'iter', 'PopulationSize', 100, ...
'MaxGenerations', 100, 'UseParallel', true);
lb = repmat(min(diameterOptions), 1, nvars);
ub = repmat(max(diameterOptions), 1, nvars);
[optimalDiameters, optimalCost] = ga(@pipeNetworkObjective, nvars, [], [], [], [], lb, ub, [], options);
disp('Optimal Diameters:');
Hope this helps!
Best,
Umang