1 Introduction

According to different sources, there are tens of thousands of power plants around the world (A Global Database of Power Plants 2018). Thermal plants harvest energy from coal, gas, oil, nuclear, biomass, waste, and geothermal sources, while there are also hydro, wind, and solar power plant sources. Due to the wide range of different sources (such as coal, gas, oil, etc.), electricity generation methods, applied technological processes, and the overall number of plants, there also arise questions about the effectiveness and efficiency of energy production. Operating costs, process parameters, design of the plant and its subsystems, environmental impact, and sustainability could be studied in detail, and remarkable optimization results are reachable (Jiang et al. 2019). To improve operating costs, several papers have compiled very precise models of boilers, turbines, valves, or cooling systems (Li et al. 2014). These models helped to optimize control parameters to achieve better performance and more efficient energy production by using methods such as mixed-integer nonlinear programming (MILP) (Serna-González et al. 2010) or pinch analysis (Kim and Smith 2001). Apart from the cost reduction, the environmental impact is also important; its modeling can be done by, e.g., adding energy savings and pollutant reduction into the cost function of an optimization model (Douglas and Big-Alabo 2018).

With growing emphasis on sustainability and carbon neutrality, requirements to increase renewable energy sources utilization are being placed (Li et al. 2022). However, such unreliable energy sources might contribute to the instability of the electricity grid (Rosenkranz et al. 2016). In the case of an unbalanced output, large fluctuations in the energy market might occur and, in the worst case, lead to a blackout (Godoy-González et al. 2020), such as the one that occurred recently in the Texas power crisis in 2021 (Busby et al. 2021). With a remarkable share of renewable resources in the power grid energy generation portfolio, system operators must possess advanced tools and efficient mechanisms to accommodate high variability and intermittency (Khoshjahan et al. 2021). Otherwise, degraded reliability of the grid, drastic price spikes in real-time operations (Fig. 1), and a decline in profitability of renewable source investments should be expected; this highlights the necessity to embed higher flexibility into a power grid operation (Cochran et al. 2014).

Fig. 1
figure 1

Natural Gas Price (U.S. Energy Information Administration 2022)

Currently, various utility plants are implemented in the infrastructure for regulating the electrical network and energy supply, and different plants can be connected to the network. A utility system is mainly composed of boilers and turbines, where the boiler is used to generate superheated steam from burning fuels such as coal, residual fuel oils, natural gas, and flue gas. Another more efficient, sustainable, and environmentally friendly option is biomass thermal plants or waste-to-energy plants that can recover energy from plant or animal material (Paletto et al. 2019) and municipal solid waste (Putna et al. 2018, 2022).

Generally, there are three main issues in controlling a utility's operations: its effectivity, handling uncertain parameters, and operational scheduling. The effectiveness of the utility system is directly related to its impact on the environment. With the right settings, the number of harmful by-products of energy generation can be reduced, e.g., the amount of emission produced by fuel burning into the air, water consumption, and others. Deterministic models are a powerful tool for improving system efficiency. A precise model of turbines and boilers can lead to good results. But because of the widespread uncertainty, these results are often suboptimal or infeasible. Therefore, the optimized model should consider the randomness of the processes so that the chosen modern approach can be used in real operations. And when real operations are considered, uncertainty in the values of the parameters must be accounted for, as the state of the utility system changes over time. It is, therefore, not enough to find out the optimal settings of a utility system for only one moment. To ensure the most efficient operation of the utility system, it is important to prepare an optimal settings plan for the various scenarios that the uncertainty introduces into the system.

Utilities, such as steam and electricity, consume much fuel during production. The process is energy-intensive and requires high operating costs. As this is a large-scale process consisting of many different sub-components, a wide operational field has opened up for the application of optimization research. Some case studies have been set up focusing on different parts of the energy generation process.

Before implementing the utility system, it is necessary to prepare a scheme for the whole system. It is possible to make optimal decisions in the initial plant design phase. Due to the randomness of demand, the price of generated resources (electricity and steam), and fuel prices, it is possible to prepare an optimal plant design so that the total costs consisting of the initial investment and subsequent operating costs are minimal. In (Sun et al. 2017), the authors added the environmental impact to the total costs in the amount of CO2, SO2, and NOx generated from fuel combustion.

However, most of the plants have long been designed and built. Therefore, it is no longer possible to plan a set of modules, their interconnections, and their parameters, which implies that most plants still work inefficiently. Based on the European Environment Agency (2018) study, the European average in electricity and heat production efficiency was 50% in 2016. The graph in Fig. 2 shows an 8% improvement since 1990, meaning there is still plenty of room for additional growth. However, the data shown in Fig. 2 are only estimates that are burdened with uncertainties in data and methodologies, and as such should be used cautiously. The work of Zhao and You (2019) takes into account the uncertainty of the coefficients of the extraction-exhausting steam turbine using robust optimization. They succeeded in the mentioned case study in reducing operating costs by approximately 10% in the worst-case scenario. Based on the realization of uncertainty, reductions are up to 18%.

Fig. 2
figure 2

The efficiency of thermal power production in Europe (European Environment Agency 2018)

The method described in this paper aims to minimize varying operational costs of utility systems concerning real-life limitations while handling uncertainties in demand and prices. The main contribution of this paper is developing a method that produces optimal plant settings not just for one moment, but it prepares an optimal schedule for chosen time horizon and with a chosen time step of variable length. In addition to finding the optimal plan, we also offer risk analysis. This task is divided into two parts. The first part consists of finding the optimal setting of the individual components of the studied combined heat and power station (CHP) for given values of uncertain parameters (in the studied case, the demand for different kinds of steam and the price of electricity). This is achieved using a MILP model and solving it through parametric programming. The second part solves the optimal setting of the CHP in the time axis using dynamic programming and rolling horizon control. By using this two-level approach, apart from finding the optimal control, a significant reduction in computational time is also achieved, allowing for solving the problem for long time horizons. In addition, the result of this effort is to provide a tool that allows inserting a general model of the utility system. The user can modify the parameters, fuel type (coal, gas, biomass, or waste), and the number of utility devices (boilers, engines, or turbines). It also allows modifying the required parameters of the generated energy at different levels and constraints, such as shutting down conditions of the individual equipment for maintenance purposes, etc.

The rest of the paper is structured as follows. Section 2 provides the literature review. Section 3 describes in detail both the lower-level model (the internal operations of the CHP) and the upper-level model (the time-dependence of the control of some of the components of the CHP). Section 4 introduces the methodology used for solving the models: parametric programming, dynamic programming, and rolling horizon control. Section 5 gives the details about the case study that was used to validate the proposed approach. In Sect. 6, the results of the case study are discussed, along with its limitations and possible extensions. Finally, conclusions are drawn in Sect. 7.

2 Literature review

Utility systems are used to transmit or distribute energy from the source of supply to the point of demand. Even if the sources can vary, the energy producers typically face high price and demand volatility affecting their operational costs, although for different reasons. This can be historical crude oil price volatility (Alola et al. 2022), intermediate effects on the energy markets such as the Covid-19 pandemic or the Russian invasion of Ukraine (Yagi and Managi 2023), short-time daily effects (McKenna et al. 2022), increasing amount of the renewable energy integrated into the power grid (Blackburn et al. 2019), or also source material such as waste composition and amount uncertainty (Pluskal et al. 2022). On the other hand, these volatile energy prices are strongly related to energy demand that is even more unpredictable than before. CHP provides an alternative the EU promotes due to its flexibility on demand, allowing a variation management strategy in an energy system context where a single energy source can simultaneously generate electricity and heat to meet the heating and cooling demands (Beiron et al. 2022). For real-life deployment, there are additional constraints on the operation of the components. The devices such as boilers or turbines cannot be turned on immediately and assume that they will work on the required performance, and the same goes for their shutdowns. It is necessary to respect these devices' given start-up and shutdown phases.

An increasing number of models in the literature optimize the design of heat and power systems. For example, Guo et al. (2013) introduce a two-stage optimal planning and design method for combined cooling, heating, and power microgrid systems. The system design is optimized in the first stage using a generic multi-objective optimization approach. The operational costs are minimized in the second stage for several obtained designs. Pruitt et al. (2014) present a mixed-integer nonlinear programming (MINLP) model for the optimal design and dispatch of distributed energy systems. Pruitt et al. (2013b) prescribe a global minimum cost system design and dispatch, considering off-design hardware performance characteristics for CHP and energy storage, while Pruitt et al. (2013a) establish conditions for the economic viability of the system. Krug et al. (2020) provide a nonlinear optimization model for the time-dependent control of district heating networks. Rong and Lahdelma (2007) study the CO2 emissions trading planning in a multi-period stochastic optimization model; during each trading period, the future CHP production until the end of the planning horizon is optimized based on scenarios for heat demand, power price, and allowance price. The work by Hirwa et al. (2022) presents a MILP formulation to optimize the design of a renewable energy system combined with heat and power, following previous research on renewable energy sources (Ogunmodede et al. 2021). Multi-objective optimization approaches have also been applied to solve the design (and dispatch) problem for the CHP system. For example, Hollermann et al. (2021) account for economic and environmental criteria to obtain a sustainable design.

For practical reasons, considering a certain time horizon within a control scheme for real-life operations also plays an important role. Therefore, the design of a method (or an algorithm) that can make dynamic decisions to ensure the optimal setting of the system during its entire operation is necessary. There are several approaches to solving such a problem. The problem can be formulated as a MILP problem (Iyer and Grossmann 1998). Still, the disadvantage of this approach is the linearization of the nonlinear system model and the extensive computational complexity of (mixed-) integer programming, which becomes especially burdensome for longer time horizons. The second approach is decomposing the problem into several stages, which can be solved separately under certain conditions. Kim and Han (2001) divided the task into several sub-tasks: generate feasible configurations set of the plant via heuristic and calculate the optimum for the nonlinear programming sub-problem at any given time. They found the optimal solution for a short time horizon using dynamic programming. Lozano et al. (2010) optimized the costs of combined heat, cooling, and power systems under legal constraints using a MILP approach. The same methodology was used by Ameri and Besharati (2016) for the control of a cooling, heating, and power system of a residential district. Operation scheduling of a coal-fired combined heat and power station was studied by Liu et al. (2021), where a metaheuristic (particle swarm optimization algorithm) was utilized. Mamaghani et al. (2017) also used a metaheuristic (genetic programming) to optimize a fuel cell-based micro-combined heat and power plant. However, since the performance of metaheuristics strongly depends on their initialization (Matoušek et al. 2022) and chosen parameters (Kazíková et al. 2020), they can lead to suboptimal results.

The rolling horizon approach has been applied in various applications where a MILP is solved over a smaller number of periods in successive iterations (Soni et al. 2021). See, for example, the work by (Silvente et al. 2015) that applied the rolling horizon to simultaneous energy supply and demand planning. The rolling horizon approach, a common decomposition method, can reduce the computational time needed to solve problems with many variables. Typically, the problem is solved for successive planning intervals representing a small part of the horizon rather than solving a complex problem considering its whole time horizon. This helps reduce the problem's size per interval, breaking down one large problem into easily solved sub-problems (Marquant et al. 2015).

This paper proposes a novel method for optimal control of CHP station operation for a given time horizon. The two-level approach and the combination of the solution approaches across the levels (parametric programming for the lower-level model and dynamic programming with the rolling horizon for the upper-level model) have not yet been applied and used in the literature on CHP optimization. It allows us to solve computationally challenging tasks effectively and in a reasonable time. Therefore, the main contribution of the paper is the two-level modeling approach together with the application of the computational approach application.

3 Problem definition

The studied CHP is schematically described in Fig. 3. The main purpose of this CHP is to produce steam (heat), with a secondary possibility of producing electricity. The main sources of power are two coal boilers (B1 and B2) that are used to produce steam S1. This steam can either be used to power a turbine (TG) that produces electricity or can be transformed into steam with lower parameters (S2), which is used in various industrial applications. There is also a backup boiler (B3) that burns natural gas and can produce steam S2. Steam S2 can be further transformed into steam S3 (used in industrial applications) and steam S4 (transformed into hot water for municipal heating). Four gas engines (GE1–GE4) produce both electricity and steam, S3 and S4. The demand for the different kinds of steam (S2–S4) is denoted by D1–D3 and is expressed in terms of MW.

Fig. 3
figure 3

System diagram of the combined heat and power station

3.1 Lower-level problem

The lower-level problem then consists of the optimal setting of the individual components of the CHP: which of the parts should be running, at what power level, and what should be the flow of energy between the components. The objective is to minimize the costs related to energy generation, with the demand for the different kinds of steam being met. In the studied system, boilers B1 and B2 have the same characteristics. The same can be said about the gas engines GE1–GE4. This situation helps to reduce the number of model variables by merging the flows from the two boilers (and four gas engines) into a single one. We also refrain from modeling the flows from S1 to S2, S2 to S3, etc., explicitly, and use an equivalent implicit model (that uses flows from the two boilers to S1, S2, etc.) instead. The explicit model, and its relation to the implicit one, are described in the Supplementary material. The individual parameters and variables of the model are shown in Table 1.

Table 1 Lower-level optimization model parameters and variables

The optimization model can be expressed as a MILP problem of the following form:

$${\text{minimize}} \,\,{\mathrm{c}}^{\mathrm{B}1}{\mathrm{x}}^{\mathrm{B}1,\mathrm{T}}+{\mathrm{c}}^{\mathrm{B}3}{\mathrm{x}}^{\mathrm{B}3,\mathrm{T}}+{\mathrm{c}}^{\mathrm{GE}}{\mathrm{x}}^{\mathrm{GE},\mathrm{T}}-{\mathrm{p}}^{\mathrm{E}}({\mathrm{x}}^{\mathrm{TG},\mathrm{E}}+{\mathrm{x}}^{\mathrm{GE},\mathrm{E}})$$
(1)
$${\text{Subject to } }\,\,{x}^{B1,T}={x}^{B1,S2}+{x}^{B1,S3}+{x}^{B1,S4}+{x}^{B1,TG}$$
(2)
$${x}^{B3,T}={x}^{B3,S2}+{x}^{B3,S3}+{x}^{B3,S4}$$
(3)
$${\beta }^{GE,H}{x}^{GE,T}={x}^{GE,S3}+{x}^{GE,S4}$$
(4)
$${\beta }^{GE,E}{x}^{GE,T}={x}^{GE,E}$$
(5)
$${x}^{B1,TG}={x}^{TG,S3}+{x}^{TG,S4}+{x}^{TG,E}$$
(6)
$${x}^{TG,E}=\alpha {x}^{B1,TG}$$
(7)
$${x}^{B1,S2}+{x}^{B3,S2}\ge D1$$
(8)
$${x}^{B1,S3}+{x}^{B3,S3}+{x}^{TG,S3}+{x}^{GE,S3}\ge D2$$
(9)
$${x}^{B1,S4}+{x}^{B3,S4}+{x}^{TG,S4}+{x}^{GE,S4}\ge D3$$
(10)
$${LB}^{B1}{y}^{B1}\le {x}^{B1,T}\le {UB}^{B1}{y}^{B1}$$
(11)
$${LB}^{B3}{y}^{B3}\le {x}^{B3,T}\le {UB}^{B3}{y}^{B3}$$
(12)
$${LB}^{GE}{y}^{GE}\le {x}^{GE,T}\le {UB}^{GE}{y}^{GE}$$
(13)
$${LB}^{TG}{y}^{TG}\le {x}^{B1,TG}\le {UB}^{TG}{y}^{TG}$$
(14)
$${x}^{B1,T}, {x}^{B1,S2}, {x}^{B1,S3}, {x}^{B1,S4}, {x}^{B1,TG}\ge 0$$
(15)
$${x}^{B3,T}, {x}^{B3,S2}, {x}^{B3,S3}, {x}^{B3,S4}\ge 0$$
(16)
$${x}^{GE,T}, {x}^{GE,S3}, {x}^{GE,S4}, {x}^{GE,E}\ge 0$$
(17)
$${y}^{B1}\in \left\{0, 1, 2\right\}, {y}^{B3}\in \left\{0, 1\right\}, {y}^{TG}\in \left\{0, 1\right\}, {y}^{GE}\in \left\{0, 1, 2, 3, 4\right\}$$
(18)

The objective function (1) is the difference between the operational costs for producing energy at the individual components and the sold electrical energy. It is assumed that the profit from supplying the steam streams is fixed (and, as such, is not important for the computation). Constraints (2) and (3) describe the flow of energy from B1 (and B2) and B3 to S2, S3, and S4. Constraints (4) and (5) express the electrical and heat energy generated by GE1–GE4. Constraints (6) and (7) describe the energy flow through the turbine. Constraints (8)–(10) encode the demand for different types of steam. Constraints (11)–(14) define the operational limits of the individual CHP components. Constraints (15)–(17) enforce nonnegativity on the energy flows. Constraint (18) defines how many of the CHP components are available.

3.2 Upper-level problem

The goal of the control is not to have the optimal setup for the CHP for one particular demand and electricity price but rather to find the optimal schedule of operations for varying demands and prices throughout the year. The main concern is boilers B1 and B2, which cannot be turned on and off frequently. It is assumed that the same property can be neglected for the other CHP components. This situation is modeled as a discrete dynamical system with four states:—\({s}_{k}^{B1,ON}\)for how long has boiler B1 been running at time \(k\), \({s}_{k}^{B1,OFF}\)—for how long has boiler B1 been inactive at time \(k\), \({s}_{k}^{B2,ON}\)—for how long has boiler B2 been running at time \(k\), \({s}_{k}^{B2,OFF}\)—for how long has boiler B2 has been inactive at time \(k\). The control consists of two decisions \({u}_{k}^{B1}\) and \({u}_{k}^{B2}\), which determines if the corresponding boiler should be active (value 1) or inactive (value 0) at time \(k\). The switch between the two values of \({u}_{k}^{B1}\) and \({u}_{k}^{B2}\) can only be made after it the corresponding boiler has been running (or inactive) for at least \({m}^{ON}\) (or \({m}^{OFF}\)) time units. The state space can be reduced by mapping all states that correspond to the boilers being active (or idle) for a longer time than \({m}^{ON}\) (or \({m}^{OFF}\)) onto the state with a value \({m}^{ON}\) (or \({m}^{OFF}\)). This can be done because the information that the boiler has been running (inactive) for at least \({m}^{ON}\) (or \({m}^{OFF}\)) is enough to define the possible actions (i.e., one does not need to know for how much longer that \({m}^{ON}\) has been running). The discrete dynamical system, with a fixed horizon \(N\), has \({{(m}^{ON}+{m}^{OFF})}^{2}\) possible state values and can be described by the following equations:

$${s}_{k+1}^{B1,ON}=\left\{\begin{array}{ll}{\text{m}}{\text{a}}{\text{x}} \left({s}_{k}^{B1,ON}+1,{m}^{ON}\right), &\quad {\text{if}} {u}_{k}^{B1}=1\\ 0, &\quad {\text{if}} {u}_{k}^{B1}=0\end{array}\right.\quad k=0, 1, \dots ,N-1$$
(19)
$${s}_{k+1}^{B1,OFF}=\left\{\begin{array}{ll}{\text{m}}{\text{a}}{\text{x}} \left({s}_{k}^{B1,OFF}+1,{m}^{OFF}\right), &\quad {\text{if}} {u}_{k}^{B1}=0\\ 0, &\quad {\text{if}} {u}_{k}^{B1}=1\end{array}\right. \quad k=0, 1, \dots ,N-1$$
(20)
$${s}_{k+1}^{B2,ON}=\left\{\begin{array}{ll}{\text{m}}{\text{a}}{\text{x}} \left({s}_{k}^{B2,ON}+1,{m}^{ON}\right), &\quad {\text{if}} {u}_{k}^{B2}=1\\ 0, &\quad {\text{if}} {u}_{k}^{B2}=0\end{array}\right. \quad k=0, 1, \dots ,N-1$$
(21)
$${s}_{k+1}^{B2,OFF}=\left\{\begin{array}{ll}{\text{m}}{\text{a}}{\text{x}} \left({s}_{k}^{B2,OFF}+1,{m}^{OFF}\right), &\quad {\text{if}} {u}_{k}^{B2}=0\\ 0, &\quad {\text{if}} {u}_{k}^{B2}=1\end{array}\right. \quad k=0, 1, \dots ,N-1$$
(22)
$${u}_{k}^{B1}\in {U}_{k}^{B1}\left({s}_{k}^{B1,ON}, {s}_{k}^{B1,OFF}\right)=\left\{\begin{array}{ll}1, &\quad {\text{if}} {s}_{k}^{B1,ON}<{m}^{ON}\\ 0, &\quad {\text{if}} {s}_{k}^{B1,OFF}<{m}^{OFF}\\ \left\{0, 1\right\}, &\quad {\text{otherwise}} \end{array}\right. \quad k=0, 1, \dots ,N-1$$
(23)
$${u}_{k}^{B2}\in {U}_{k}^{B2}\left({s}_{k}^{B2,ON}, {s}_{k}^{B2,OFF}\right)=\left\{\begin{array}{ll}1, &\quad {\text{if}} {s}_{k}^{B2,ON}<{m}^{ON}\\ 0, &\quad {\text{if}} {s}_{k}^{B2,OFF}<{m}^{OFF}\\ \left\{0, 1\right\}, &\quad {\text{otherwise}} \end{array}\right.\quad k=0, 1, \dots ,N-1$$
(24)

The cost associated with each state \({g}_{k}({s}_{k}, {w}_{k})\) (with \({s}_{k}=[{s}_{k}^{B1,ON}, {s}_{k}^{B1,OFF}, {s}_{k}^{B2,ON}, {s}_{k}^{B3,OFF}]\)) corresponds to the optimal value of the lower-level problem with \({y}^{B1}\) equal the number of boilers in operation, and with \({w}_{k}\) containing the demands D1, D2, and D3 and electricity price \({p}^{E}\) at time \(k\). The aim of the control is to find the optimal sequence of decisions \({\pi }^{*}=\{{u}_{0}^{*}, {u}_{1}^{*}, \dots , {u}_{N-1}^{*}\}\) (with \({u}_{k}^{*}=[{u}_{k}^{B1,*}, {u}_{k}^{B2,*}]\)) that minimize the expected accumulated costs \({J}^{*}\):

$${\pi }^{*}= \, {\text{argmin}}_{{u}_{k};k=0,\dots ,N-1 }{{\varvec{E}}}_{{w}_{k};k=0,\dots ,N} \left\{\sum_{k=0}^{N}{g}_{k}\left({s}_{k}\right)\right\}$$
(25)
$${J}^{*}= \, {\text{min}}_{{u}_{k};k=0,\dots ,N-1 }{{\varvec{E}}}_{{w}_{k};k=0,\dots ,N} \left\{\sum_{k=0}^{N}{g}_{k}\left({s}_{k},{w}_{k}\right)\right\}$$
(26)

4 Methods

In this section, we give a brief overview of the different techniques needed for the successful implementation of the two-level approach. These techniques encompass parametric programming, dynamic programming, and rolling horizon control.

4.1 Parametric programming

To compute the costs at a given dynamic system state, one would need to recompute the optimal solution to mixed integer linear problem (1)–(18) for every value of the uncertain parameters. Although the optimization problem is relatively small, it would still bring high computational costs. The first step in approaching this issue is to realize that there are only 60 possible combinations for the values of the integer-constrained variables. This means that if the resulting linear problem can be solved efficiently (with the integer-constrained variables being fixed at a particular value), a large fraction of the computational time can be saved. The chosen method for this efficient computation was parametric programming.

Parametric programming is a powerful method for investigating the effect of variability or uncertainty in mathematical programming problems (Pistikopoulos et al. 2012). It allows for a systematic analysis of the effect of varying parameters on the optimal value and solution of an optimization problem, providing more robust solutions (Avraamidou and Pistikopoulos 2020). Parametric programming has found numerous applications, mainly in distributed energy system scheduling (Liu et al. 2013) and operational scheduling of microgrids (Umeozor and Trifkovic 2016).

In general, a parametric linear programming problem can be defined as:

$$z\left(\uptheta \right)=\text{minimize }{(c+{P}_{c}\uptheta )}^{T}x$$
(27)
$$\text{subject to }Ax\le b+{P}_{b}\uptheta $$
(28)
$$\uptheta \in \Theta $$
(29)

where the matrices \({P}_{c}\) and \({P}_{b}\) have appropriate dimensions. The solution to the problem (27)–(29) has the form of a partitioning of the feasible parameter space \({\Theta }_{f}=\Theta \) into several polytopic regions, known as critical regions. Each of the critical regions is associated with the optimal solution \({x}^{*}(\uptheta )\) and objective function \({z}^{*}(\uptheta )\), that are affine functions of θ (Oberdieck et al. 2016). This means that by solving the original problem (1)–(18) as a parametric one (27)–(29) for a given range of the parameters (\(\uptheta =[D1,D2,D3,{p}^{E}]\)), the optimal solution to (1)–(18) is obtained for a particular value of the parameters by simply calling the function \({x}^{*}(\uptheta )\).

4.2 Dynamic programming

Dynamic programming is the most extensively used method for finding the optimal control for discrete dynamical systems (Bertsekas 1995), such as (19)–(26). Recently, it has been used for dynamic energy management of microgrids (Zeng et al. 2018), energy management of electric vehicles (Lee et al. 2020), optimal scheduling of electric bus fleets (Wang et al. 2020), or operation strategies for grid-connected battery systems (Zou et al. 2022).

Based on the principle of optimality in dynamic programming, the optimal control for the discrete dynamical system can be solved by recursively computing Bellman's equation backward in time as follows (Bertsekas 1995):

$${J}_{N}\left({s}_{N}\right)={g}_{N}({s}_{N})$$
(30)
$${J}_{k}\left({s}_{k}\right)=\underset{{u}_{k}\in {U}_{k}}{\mathrm{min}}{{\varvec{E}}}_{{w}_{k}}\left\{{g}_{k}\left({s}_{k}\right)+{J}_{k+1}\left({s}_{k+1}\right)\right\}, k=N-1,\dots , 0$$
(31)

For a given initial state \({s}_{0}\), the optimal expected cost \({J}^{*}\) is equal to \({J}_{0}({s}_{0})\). Furthermore, if the minimizers of the right side of (31) \({u}_{k}^{*}={u}_{k}^{*}({s}_{k})\) are collected for each \({s}_{k}\) and \(k\), the optimal policy \({\pi }^{*}=\{{u}_{0}^{*}, {u}_{1}^{*}, \dots , {u}_{N-1}^{*}\}\) can be easily retrieved.

Since the system equation is deterministic (there is only uncertainty in costs), the discrete dynamical problem can be transformed into an equivalent graph problem (Bertsekas 1995). The individual states correspond to nodes in the graph, while edges describe the possible transitions from one state to another. The optimal control then corresponds to finding the shortest path in the graph from a given starting state \({s}_{0}\) to any state \({s}_{N}\) in time \(N\). This transformation is schematically described in Fig. 4 for a problem with \({m}^{ON}=3\), \({m}^{OFF}=2\) (i.e., 25 different states), and \(N=4\). The four large numbers correspond to the state (\([{s}_{k}^{B1,ON}, {s}_{k}^{B1,OFF}, {s}_{k}^{B2,ON}, {s}_{k}^{B2,OFF}]\)), the dashed lines are the possible transitions, and the numbers in brackets show the cost of the state (the value of the optimal solution to (1)–(18) with the number of boilers in operation based on the state). The initial state was \({s}_{0}=[1, 0, 0, 2]\), In this case, there were three optimal control schedules (i.e., with the same expected costs)—they are highlighted in red in Fig. 4.

Fig. 4
figure 4

Graph equivalent to the discrete dynamical system. The states and transitions (with possible states highlighted) are shown in black, and the optimal control is in red

4.3 Rolling horizon control

If the perfect knowledge about the future values of the uncertain parameters was available to the controller, the dynamic programming method described above would give the optimal control scheme. If one does not have this knowledge, approximate forecasts for the values of the uncertain parameters have to be used, and the control must be based on those forecasts. The rolling horizon control is an approach for reducing the effect errors in the forecast of the values of the uncertain parameters (Das and Ni 2020). Other names for this approach are predictive model control in engineering and receding horizon control in operations research (Powell 2011). It has been utilized to solve problems from infrastructure planning (Kůdela et al. 2020), microgrid control (Elkazaz et al. 2020), or production planning (Ziarnetzky et al. 2018).

The rolling horizon control is a real-time (online) optimization technique that computes the solution to constrained optimization problems repeatedly, considering the current state, predictions of future costs, disturbances, and constraints over a sliding time horizon to find the optimal control for the current period. In this paper's context, the schedule will be computed for a reduced time horizon and with a different granularity of time steps. This approach is outlined in Fig. 5, where the blue line shows a random parameter's ``real'' value. In contrast, the red line shows the forecast of the rolling horizon procedure, with periods where a decision can be made being highlighted by a cross.

Fig. 5
figure 5

Outline of the rolling horizon control

5 Case study

To study the effectiveness of the proposed approach, a case study with synthetic data is analyzed. The time step of the control is set to be one hour, and the control horizon is 100 days (or 2400 h). The values of the different parameters for the lower-level model are shown in Table 2.

Table 2 Values of the parameters for the case study – lower-level model

The “true” values of the uncertain parameters (demands for different kinds of steam D1, D2, D3, and electricity price \({p}^{E}\)) are shown in Figs. 6 and 7. The chosen progression of the demand for steam is chosen in such a way that it simulates the end of the heating season (from the end of winter to late spring/early summer).

Fig. 6
figure 6

Demand for the different kinds of steam in the 100-day horizon

Fig. 7
figure 7

Price of electricity in the 100-day horizon

For the upper-level model, four possible settings for the values of \({m}^{ON}\) and \({m}^{OFF}\) were considered (with different resulting numbers of states), and four different settings for the rolling horizon periods H. These were compared with the optimal solution with access to perfect knowledge about the values of the uncertain parameters (computed using the dynamic programming algorithm). The chosen values of these settings are shown in Table 3.

Table 3 Values for the different settings for the case study—upper-level model

For example, the H1 setting for the horizon corresponds to a “greedy” control that takes into account only the forecast for the uncertain variables in the current period (0) and the upcoming one (in 1 h) and makes the decision that minimizes the costs based only on this information. In the case of multiple optimal decisions (such as the ones shown in Fig. 4), the algorithm prefers the solution that does not change the control variables (in the case of Fig. 4); it would prefer the solution on the top).

The implementation of both the lower-level and upper-level models was done in MATLAB R2021b. For the lower-level model, the toolbox “Multi-Parametric Toolbox 3.0” developed by (Herceg et al. 2013) was used to compute the partitioning of the feasible parameter space into polytopic regions. It was found that solving and pre-computing these regions using the parametric programming resulted in an approximately 20 times faster execution of the method when compared to solving (1)–(18) each time by the linear programming solver embedded in MATLAB. The computations were carried out on an ordinary computer (with 3.2 GHz i5-4460 CPU and 16 GB RAM).

6 Results and discussion

First, the computational complexities are compared of the four horizon settings H1-H4 and the optimal control scheme with perfect knowledge (labeled as OPT) on the four possible values for \({m}^{ON}\) and \({m}^{OFF}\). For this purpose, three main parts of the control are defined, and the time for their evaluation is measured: \({t}_{1}\)—construction of the state space (possible state values and transitions, construction of the associated graph), \({t}_{2}\)—evaluation of the possible states (i.e., solving (1)–(18) by utilizing the partitioning obtained by the parametric programming approach), \({t}_{3}\)—computation of the optimal control (i.e., finding the optimal path in the graph). For the OPT control scheme, the three parts are evaluated only once, while for the rolling horizon schemes H1–H4, only the first part is computed once, while the other two are computed each time the horizon shifts (i.e., 2,400 times in the studied case). The results of this comparison are reported in Table 4.

Table 4 The computational complexity of the different settings (s)

The first thing to note is that for a given control scheme the \({t}_{2}\) value does not depend on \({m}^{ON}/{m}^{OFF}\)—this should be expected, as the optimal value of (1)–(18) depends only on the number of boilers in operation, not on the particular time they were running. Another interesting observation is that the time to construct the graph (\({t}_{1}\)) is very similar for H1 and H2—this can be explained by the fact that both control schemes use the same time step for the entire horizon (one hour), even though the length of the horizon differs. Adding time steps with different lengths in the horizon increases \({t}_{1}\), as can be seen by comparing the values of H1 and H2 to H3 and H4. Also, \({t}_{1}\) increases with a higher number of possible states. The time for the finding of the optimal path in the graph (\({t}_{3}\)) depends mainly on the number of time steps on the horizon and on the number of possible states. This is the reason the control scheme H1 had the fastest evaluation (only two-time steps), while H2–H4 were relatively comparable (with 10–13 time steps).

Next, the costs of the different control settings are compared based on the values of \({\mathrm{m}}^{\mathrm{ON}}/{\mathrm{m}}^{\mathrm{OFF}}\), and the results of this comparison are summarized in Table 5. Naturally, the control with perfect knowledge (OPT) is the one with the lowest cost and can serve as a benchmark for the rolling horizon control schemes. The first thing to note is that the cost of the control schemes generally increases with increasing values of \({m}^{ON}/{m}^{OFF}\), especially between the 18/12, 24/18 and 36/24 values, while there is little to no difference between 36/24 and 48/36. This can be explained by noticing the increasing the \({m}^{ON}/{m}^{OFF}\) values result in more constrained situations, where the boilers must run (or be switched off) for longer periods of time, which limits available options for control and results in higher costs. This small difference between 36/24 and 48/36 is probably due to the particular structure of the data. As can be seen from the results, there is no one rolling control scheme that would be best in all situations. On the other hand, the "greedy" scheme H1 was (quite expectedly) the worst-performing one, especially for the higher values of \({m}^{ON}/{m}^{OFF}\), where decision have longer lasting consequences. The other three control schemes H2–H4 have all performed very well when compared with the optimal control. For \({m}^{ON}/{m}^{OFF}=18/12\) the best control scheme was H2, for \({m}^{ON}/{m}^{OFF}=24/18\) it was H4, and for \({m}^{ON}/{m}^{OFF}=36/24\) and 48/36 the best were H3 and H4 (with just a very little difference between the two). In all cases, the best-performing scheme was worse than the optimal control by no more than 0.12%. This confirms that the rolling horizon control approach is well suited for the studied problem.

Table 5 Cost for the different control settings [EUR]

The comparisons of computational complexity and resulting costs show that the presented method is appropriate for real-time control of the studied CHP. Having the optimal (or close to optimal) control enables the investigation of various relations between the uncertain parameters and results of the control. For instance, Fig. 8 depicts the dependence of the amount of produced electricity on the combined demand for steam. It shows that the optimal amount of produced electricity is generally between 1 and 4 MW and rises with increased demand for steam. Similarly, the number of coal boilers is naturally higher for the higher demand for steam. In some cases, both boilers should be switched off for a brief period, as can be seen in Fig. 9.

Fig. 8
figure 8

Demand for the steam vs. produced electricity, optimal control, \({m}^{ON}/{m}^{OFF}=36/24\)

Fig. 9
figure 9

Demand for the steam vs. number of coal boilers in operation, optimal control, \({m}^{ON}/{m}^{OFF}=36/24\)

It should be acknowledged that the presented model is not without its limitations. Firstly, the CHP model is not perfect, as it does not consider start-up times for the turbine and different efficiency levels for the boilers and the turbine, which affect the whole operation of the CHP. Also, the costs do not reflect the whole operation, such as employee pay, maintenance costs, etc. Finally, the model does not include the environmental or social aspects of operating a CHP. All of these issues are expected to be addressed in upcoming studies.

On the other hand, the presented model allows for several interesting possibilities. As the problem is solved in a graph form, it is quite straightforward to incorporate maintenance scheduling (simply by changing the values of the corresponding states). It also enables the investigation of different pricing options for the different steam streams throughout the year. Moreover, additional experiments with constructing the graph and computing the control for a model with 1 million possible states found that it could be realized—the construction of the graph took a little under two hours. This, however, is not an issue as this part can be pre-computed. Evaluating the states and finding the optimal control took just a few seconds. This could allow for expanding state space by having finer time steps and by including states that describe the operation of the turbine. Other extensions that would make the CHP model even more realistic and applicable could include the power streams from the recurring equipment.

7 Conclusion

In this paper, a method for the optimal control of CHP operations was described, and its performance was investigated through a case study. The method's main idea was decomposing the problem of controlling the operations of the CHP into two levels and solving these subproblems with appropriate methods. The evaluation of the proposed method, both from computational and cost perspectives, showed its effectiveness and utility. The findings can also guide engineers and stakeholders to optimize and evaluate the control of systems with a similar structure. There are several conclusions that can be drawn:

  • The use of parametric programming brings substantial computational savings, computing the solution to the lower-level problem roughly 20 times faster than the corresponding linear optimization solver, which leads to the faster evaluation of the possible states. This makes the analysis of the control schemes for long time horizons computationally attainable.

  • The rolling horizon control schemes displayed high utility in handling the development of the uncertain parameters—the best ones for a particular setting of the CHP operations resulted in control that was no more than 0.12% worse than the optimal control with perfect information.

  • Although there was no "one-size-fits-all" rolling horizon scheme, all the proposed schemes displayed good performance (apart from the "greedy" scheme H1). This suggests that the problem is not extremely sensitive to the choice of the rolling horizon (but finding an appropriate one for the particular CHP settings can be valuable).

  • Even though there were limitations to the presented model, the very low computational requirements for the analysis of the different schemes leave room for making more precise models of the CHP operations, the possible inclusion of competing objectives, and finer granularity of the time steps, that would still result in a computationally tractable method.