Future power systems with a large penetration of fluctuating renewable e= nergy production from wind and solar power generation call for demand flexi= bility. In Denmark, for instance, on average 44\% of the power load in 2017= was covered by wind power production, and during several hours the wind pr= oduction was well above 100% of the electricity load, which was possible pa= rtly because of the flexibility of the widely used district heating systems= .

Heating and cooling represent a huge part = of the total energy consumption. According to 2014 Eurostat figures, in the= EU around 30\% of the primary energy is used to produce heat, and 40\% is = used for electricity, including electricity for heat production [1]. The dy= namics and inertia of thermal systems and the low-cost storage capabilities= for hot water, implies that district heating (DH) system are capable of pl= aying an important role in the future intelligent and integrated energy sys= tem. As mentioned above, in Denmark DH systems already play a very importan= t role in the integration of the fluctuating renewable energy production an= d for providing energy balancing services to the power grid.

Historically DH systems are often consider= ed as single systems, but this is rather due to the historic emphasis on en= ergy supply as subsystems of different supply sources (e.g., gas, coal, and= electricity). However, today they act as a key element for integrating the= different energy systems, and they provide some of the needed flexibility = to the power system [2]. DH systems also provide an eminent possibility of = using excess heat from e.g. industrial production and cooling in super mark= ets.

This section briefly describes the operati= onal optimization problems involved in various parts of DH systems, and som= e methodologies and tools for solving these problems will be indicated. For= operational convenience we will split the discussion into a number of subs= ystems, which can provide flexibility to the overall DH system. Each subsys= tem leads to an optimization problem and calls for adequate related methodo= logies for providing the optimal operation. The optimal operation of the fo= llowing subsystems are considered:

- DH plant, including production and storage facilities.
- DH network with the pipes and pumps.
- DH users, which might also consist of secondary distribution networks.<= /li>
- DH connected heat pumps and boilers.

In general, DH systems often consist of a spectrum of different possibil= ities for heat production. For example, thermal solar plants are becoming i= ncreasingly popular nowadays. However, the solar energy production is often= hard to predict, and hence this calls for methods like probabilistic forec= asting and optimization under uncertainty [3]. Here methods like stochastic= programming and stochastic control theory are obvious for solving the oper= ation problem in near real time. Therefore, the operation of the total DH s= ystem can be considered as a set of nested stochastic programming and contr= ol problems, which are presented in more detail in the remainder of this se= ction. In the following description only district heating will be considere= d, but almost the same principles can be used for district cooling.

The portfolio of production units in a DH = system, comprising of combined heat and power (CHP) plants and heat-only un= its, can be used to react to current state of the energy system and thus in= crease efficiency and reduce imbalances. In periods with high generation of= intermittent renewable power resources, the generation can be shifted to h= eat-only units, which maybe even consume power (e.g. heat pumps) to lower t= he imbalance in the grid, while fulfilling the heat demand. In periods with= less power production from wind and photovoltaic, CHP plants can provide p= ower to the market while producing heat. Thus, the coupling of the operatio= n of the district heating system to the electricity markets is important [4= ]. The key to reducing costs in the operational production is by considerin= g all production units as a portfolio to make use of the flexibility. By op= timizing the entire portfolio, the interplay between the units can be used = to further reduce costs and increase income from the market. During the opt= imization several restrictions have to be considered, such as the capacitie= s of the producing units and connected thermal storages as well as technica= l characteristics of the units (e.g. start up/shut down times and costs).

In recent years, the production of heat fr= om the installed small CHP plants has slightly decreased in favor of heat-o= nly units such as boilers and heat pumps, due to the reduction of the elect= ricity prices. The design of today's electricity market forces CHP producer= s to present power production offers one day before the actual energy deliv= ery. Consequently, forecast uncertainties in prices and heat demand must be= considered for an optimal planning of DH systems. Furthermore, the above m= entioned increase in solar thermal production introduces an additional sour= ce of uncertainty from the heat production side.

To efficiently operate this mixture of hea= t production units while reducing the operational costs, several optimizati= on techniques such as mixed integer linear programming, Lagrangian relaxati= on, heuristics, or fuzzy linear programming have been proposed. However, th= e use of mixed integer linear programming prevails over the other methods d= ue to the easy implementation of these programs in available commercial sol= vers. In addition, the formulation of two-stage stochastic and robust mixed= integer linear programming problems allows the integration of uncertainty = in the optimization problem yielding in better operation plans for CHP plan= ts [5,6]. The use of two-stage stochastic programs to optimize the heat pro= duction of different heat-only, storage and CHP units translates into more = flexibility in the real-time operation [7]. Finally, stochastic programming= has been proven to be an effective tool to make use of DH networks to inte= grate the uncertain production from renewable energy sources [8].

The problem of determining the optimal operation of DH network relates t= o finding the optimal combination of flow and temperature profiles that pro= vide the minimal operational cost. Pumping costs are, however, often an ord= er of magnitude smaller than the costs related to the heat loss induced by = having a too high supply temperature profile in the network [9]. Consequent= ly, a reasonable control strategy for DH networks is to keep the supply tem= perature from the district heating plant as low as possible. This is in par= ticular the case, if the heat production takes place at a CHP plant [10,11]= .

The control is subject to some constraints= . For instance, the total heat requirement for all consumers must be suppli= ed at any time and location, such that each individual consumer is guarante= ed some minimum supply temperature. A lower supply temperature leads typica= lly to large savings, since this implies lower heat losses from the transmi= ssion and distribution networks as well as lower production costs.

As described in [11], the optimal operatio= nal problem can be formulated as a stochastic problem which can be solved u= sing dynamic programming. Furthermore, given probabilistic forecasts for th= e heat load, cf. [12], and stochastic models for the dynamics in the networ= k, the problem can be described as a problem which can be solved using stoc= hastic control theory.

A DH system is an example of a non-station= ary system, implying that model parameters have to be time varying, e.g., t= he time-delay from the plants to the end-users is unknown and time-varying.= Therefore, the methods used in conventional predictive control theory have= to be modified [13]. The modified controllers have been incorporated in a = software package, PRESS (HeatTO), developed at the Technical University of = Denmark. PRESS (HeatTO) has been applied and tested, e.g. at Vestkraft in E= sbjerg, Denmark, and significant savings have been documented [10].

The end-users in DH system can provide fle= xibility by storing energy in the thermal mass of the buildings or in a loc= al water tank. In [14] it is shown how nested stochastic control probl= ems can be defined such that the thermal mass of buildings can provide serv= ices to the future smart grid. This is further explained in [15].

Furthermore, in order to avoid, e.g., cost= ly upgrades of the existing network in large cities, it will be more and mo= re important to control the maximum energy used within a certain interval. = This can be obtained by a control that directs the maximum flow towards spe= cific end-users or districts.

Dynamic tariffs provide another option for= enabling flexibility in DH networks. For instance, to reduce the peak cons= umption in the morning, an extra price or penalty can be utilized during pe= ak hours.

It is suggested in e.g. [15] that dyn= amic electricity prices can be used to control the electricity consumption = and hence to enable the needed flexibility for integrating large shares of = fluctuating and intermittent renewable power generation.

Time-varying price signals are an example = of a penalty signal that can be linked to the optimization and control prob= lem in order to arrive at a cost optimal solution by demand response. Anoth= er example are real-time marginal CO2 signals that can be used as a penalty= signal linked to the optimization problem. Then the optimal solution will = minimize the CO2 emission associated with the optimal control or operation.=

Different penalty signals will lead to dif= ferent optimal solutions for the problem and the choice depends on the cont= ext or societal ambition. Three of the most obvious penalty signals are the= following:

**Real time CO2**. If the real time (marginal) CO2 emissio= ns related to the actual electricity production is used as penalty, then th= e optimal control will minimize the total carbon emission related to the po= wer consumption. Hence, the heat production provided by the heat pump or bo= iler will be*emission efficient*.**Real time price**. If a real time price is used as penal= ty, the objective is obviously to minimize the total cost. Hence, the optim= al operation is*cost efficient*.**Constant**. If a constant penalty is used, then the cont= rollers would simply minimize the total energy consumption. The optimal con= trol will the provide a systems which is*energy efficient*.

It is clear that a DH system with controll= ers defined by an objective of minimizing the total emission would in gener= al lead to an increased use of energy. However, this may happen during peri= ods with, e.g., a large amount of wind power production and where the alter= native would be to stop some wind turbines.

**References**

[1] J. Kiviluoma, S. Heinen, H. Qazi, H. Madsen, G. Strbac, C. Kang, N. = Zhang, D. Patteeuw, T. Naegler, Harnessing flexibility from hot and cold: h= eat storage and hybrid systems can play a major role, IEEE Power and Energy= Magazine 15 (1) (2017) 25-33.

[2] P. Meibom, K. B. Hilger, H. Madsen, D. Vinther, Energy comes togethe= r in Denmark: The key to a future fossil-free danish power system, IEEE Pow= er and Energy Magazine 11 (5) (2013) 46-55.

[3] J. M. Morales, A. J. Conejo, H. Madsen, P. Pinson, M. Zugno, Integra= ting renewables in electricity markets: operational problems, Vol. 205, Spr= inger Science & Business Media, 2013.

[4] H. Lund, S. Werner, R. Wiltshire, S. Svendsen, J. E. Thorsen, F. Hve=
lplund, B. V. Mathiesen, 4^{th }generation district heating (4GDH):=
Integrating smart thermal grids into future sustainable energy systems, En=
ergy 68 (2014) 1 - 11.

[5] I. Dimoulkas, M. Amelin, Probabilistic day-ahead CHP operation sched= uling, in: 2015 IEEE Power & Energy Society General Meeting, 2015, pp. = 1-5.

[6] M. Zugno, J. M. Morales, H. Madsen, Commitment and dispatch of heat = and power units via affinely adjustable robust optimization, Computers &= ; Operations Research 75 (2016) 191-201.

[7] M. G. Nielsen, J. M. Morales, M. Zugno, T. E. Pedersen, H. Madsen, E= conomic valuation of heat pumps and electric boilers in the danish energy s= ystem, Applied Energy 167 (2016) 189-200.

[8] A. Hellmers, M. Zugno, A. Skajaa, J. M. Morales, Operational strateg= ies for a portfolio of wind farms and CHP plants in a two-price balancing m= arket, IEEE Transactions on Power Systems 31 (3) (2016) 2182-2191.

[9] G. Sandou, S. Font, S. Tebbani, A. Hiret, C. Mondon, Predictive cont= rol of a complex district heating network, in: IEEE Conference on Decision = and Control, Vol. 44, 2005, p. 7372.

[10] H. Madsen, H. Tangen, K. Sejling, O. P. Palsson, Models and Methods= for Optimization of District Heating Systems: Part I: Models and Identific= ation Methods, Institut for Matematisk Statistik og Operationsanalyse, Tech= nical University of Denmark, 1990.

[11] H. Madsen, K. Sejling, H. T. S=C3=B8gaard, O. P. Palsson, On ow and= supply temperature control in district heating systems, Heat Recovery Syst= ems and CHP 14 (6) (1994) 613-620.

[12] H. A. Nielsen, H. Madsen, Modelling the heat consumption in distric= t heating systems using a grey-box approach, Energy and Buildings 38 (1) (2= 006) 63-71.

[13] V. Peterka, Predictor-based self-tuning control, Automatica 20 (1) = (1984) 39-50.

[14] R. Halvgaard, N. K. Poulsen, H. Madsen, J. B. J=C3=B8rgensen, Econo= mic model predictive control for building climate control in a smart grid, = in: 2012 IEEE PES Innovative Smart Grid Technologies (ISGT), 2012, pp. 1-6.=

[15] H. Madsen, J. Parvizi, R. Halvgaard, L. E. Sokoler, J. B. J=C3=B8rg= ensen, L. H. Hansen, K. B. Hilger, Control of electricity loads in future e= lectric energy systems, in: Handbook of Clean Energy Systems, Wiley Online = Library, 2014.

**Contributors**

Prof. Henrik Madsen, Technical University of Denmark

Dr. Ignacio Blanco, Technical University of Denmark

Dr. Daniela Guericke, Technical University of Denmark