Dynamic modeling and optimal operation of district heating systems