In the present work, a model is presented for the optimization of water distribution networks (WDN). The developed model can be used to verify node pressures, head losses, and fluid flow rate and velocity in each pipe. The algorithm is based on particle swarm optimization (PSO), considering real and discrete variables and avoiding premature convergence to local optima using objective function penalization. The model yields the minimum cost of the network, the node pressures and the velocities in the pipes. The pressures and velocities are calculated using the hydraulic simulator Epanet. Some benchmark problems are used to test the applicability of the developed model, considering WDN for small-, medium-, and large-scale problems. Obtained results are consistent with those found in the literature.