Continuous changes in the demand and valve operation in each district metered area (DMA) introduce undesired behaviors in a water distribution system (WDS). In order to dynamically correct the emergence of these undesired pressure transients, an adaptive controller using foraging theory as an optimization method is developed. Specifically, an E. Coli bacterial algorithm is customized to be used in an adaptive control scheme (indirect and direct) with real time requirements.