Optimization of water quality and energy use in large water distribution systems