7.1 Stochastic MPC Concept and Mathematical Formulation

The feedback mechanism of MPC provides some robustness to the control of systems with uncertainties, but when they are significant, other alternatives have to be considered, although some MPC schemes guarantee feasibility and stability when disturbances are considered [3]. With this objective, robust MPC algorithms have received significant interest in last years. In robust MPC, uncertainties are considered deterministic and bounded.

The design of robust deterministic MPC approaches has many solutions [2, 13, 22]; however, in these algorithms feasibility and stability are usually oriented to a worst-case analysis. Consequently, their solutions are conservative or even unfeasible in the case of unbounded uncertainties and they may require the solution of min-max optimization problems that are computationally very demanding. Also, these approaches do not take into account any knowledge of the statistical properties of the disturbances, as probability distribution functions, which can be estimated in many problems, i.e., wind and irradiance forecast in renewable-energy-related problems.

This section presents the formulation of the stochastic MPC problem. Two main elements are first considered: the used model and the stochastic characterization of constraints. Next, the complete optimization problem will be formulated for several different approaches.

7.1.1 Models and Constraints

Most of the algorithms in MPC literature are based on linear models, and stochastic MPC is not an exception. The optimization problem is more complex than in deterministic MPC, and that explains the use of simpler models. Nevertheless, a few works on nonlinear stochastic MPC approaches can be found, as [28, 41].

Let us consider a state-space discrete-time linear model. Models must include the effect of uncertainty in the dynamic process. Basically, two approaches are used: additive, where the uncertainty is added to the deterministic part of the dynamics and multiplicative, where the uncertainty multiplies state or inputs variables. In the case of additive uncertainty:

$$\begin{aligned} \begin{aligned} x(t+1)=Ax(t)+Bu(t)+B_d d(t) \end{aligned} \end{aligned}$$
(7.1)

with \(x \in \mathbb {R}^{n_x}, u \in \mathbb {R}^{n_u}\), and \(d \in \mathbb {R}^{n_d}\). For linear systems with multiplicative uncertainties, the state-space matrices are time-varying with known probability distribution:

$$\begin{aligned} \begin{aligned} x(t+1)=Ax(t)+Bu(t)+ \sum _{j=1}^{q} ( \bar{A}_j x(t) + \bar{B}_j u(t) ) d_{t,j} \end{aligned} \end{aligned}$$
(7.2)

where \(\{d_{t,j}\}_{j=1}^q\) is a sequence of q zero mean independent and identically distributed (i.i.d.) random variables with known variance [28]. Multiplicative uncertainty in MPC framework increases the complexity of the problem, because of the product of future state or inputs and the uncertain variable, all of them random variables.

In this chapter, only discrete linear systems with additive uncertainty will be considered. As it will be seen in examples, an additive term models adequately the uncertainty typically found in microgrid systems.

Regarding constraints, taking into account that uncertainties of the state and input disturbances are characterized as stochastic processes, they should be reformulated in a probabilistic way. Notice that a deterministic constraint \(Gx \le g\), taking into account uncertainty, can lead to infeasibility, for example, when using unbounded Gaussian distributions, and obviously it is impossible to ensure deterministic constraints on the state variable.

The most common stochastic constraints are [12] as follows:

  • Expectation constraints: \(\mathbb {E}[Gx] \le 0\),

  • Chance constraints: \(\mathbb {P}[Gx \le 0] > 1-\delta _x\),

where operator \(\mathbb {E}\) is the expected value and \(\mathbb {P}\) denotes probability. Notice that in both cases, constraints can be violated, but they are satisfied on averages (expectation constraints) or with a given probability (chance constraints).

7.1.2 Stochastic MPC Formulation

As mentioned above, in a stochastic framework, not only the MPC optimization problem has to be reconsidered but also how the uncertainty is modeled, generated, and managed. In this respect, mainly two alternatives can be considered as given below:

  • Scenario-based approaches: The stochastic system dynamics can be characterized by a finite set of random realization of uncertainties, utilized to solve the MPC optimization problem. The number of scenarios is a key issue, because a high number of them increases the computational burden of the MPC optimization problem. Scenario reduction techniques and more efficient scenarios implementation (i.e., tree-based structures) acquire great importance in these approaches. Many of the solutions in literature are based on stochastic programming techniques.

  • Analytic approaches: These methods are based on the knowledge of mathematical models of uncertainty (i.e., probabilistic functions). Cost function and chance constraints are reformulated in a deterministic way by the use of statistical elements: mean, variance, cumulative distribution functions, etc.).

The MPC cost function in a stochastic framework is a random variable since the states are also random processes, so it must be treated from a statistical point of view. Some of the alternatives are as follows:

  • Cost Function Expectation:

    $$\begin{aligned} \begin{aligned} \Phi = \mathbb {E}\left[ \sum _{i=1}^{N_p} J(\hat{x}(t+i \mid t),u(t+i \mid t)\right] \end{aligned} \end{aligned}$$
    (7.3)
  • If \(N_s\) scenarios are considered, then an approximate cost function expectation can be computed as follows:

    $$\begin{aligned} \begin{aligned} \Phi = \frac{1}{N_s}\sum _{j=1}^{N_s} \left[ \sum _{i=1}^{N_p} J(\hat{x}_j(t+i\mid t),u(t+i\mid t) \right] \end{aligned} \end{aligned}$$
    (7.4)
  • Worst-case selection in scenario-based approach:

    $$\begin{aligned} \begin{aligned} \Phi = \max _{j=1,...N_s} \left[ \sum _{i=1}^{N_p} J(\hat{x}_j(t+i \mid t),u(t+i \mid t) \right] \end{aligned} \end{aligned}$$
    (7.5)

Next section describes different stochastic MPC approaches. First, the stochastic programming method as a key concept in SMPC is described. Next, two scenario-based MPC approaches will be studied: the first one is a simple Multiple-Scenario Algorithm (MS-MPC) also called multiple MPC in [42], and the second one is a scenario approach organized in a tree-based structure MPC (TB-MPC). Finally, an MPC based on an analytical approach using chance constraints (CC-MPC) will be considered. These last three approaches will be tested, validated, and compared on a real plant, specifically the laboratory-scale microgrid described in previous chapters.

7.2 Stochastic MPC Approaches

This section presents three SMPC methods that will be applied to a laboratory-scale microgrid in next sections. The described methods are not an exhaustive list of SMPC algorithms that can be found in literature, but some of them with relevance in microgrid applications. The section begins with a brief description of stochastic programming, a general method for optimization of stochastic problems used by some of the SMPC techniques. A more complete list of SMPC methods can be found in [27, 37].

7.2.1 Stochastic Programming

A widespread method to solving stochastic MPC is the application of stochastic programming techniques. The classic two-stage stochastic program with recourse assumes that some problem data are uncertain and a probabilistic description of the random variable is available. The are two types of decision variables [5]:

  • First-stage decisions (x variables): The decision is taken before the realization of the random events d. The period where these decisions are taken is called first stage.

  • Second-stage decisions (y(d)) variables: The decision has to be taken after the realization of the random event and the first state decision, that is, y(d) where d is the disturbance, describes the consequences of x decision.

In order to clarify these concepts, let us consider the following example of a microgrid [23]. The optimal management of a microgrid needs to consider uncertainties in generation (wind and solar) and load consumption. If the microgrid participates in the electricity market, the first decision consists of the cost of the electricity sold or purchased in advance. Obviously, real values of random variables (realization of random events) are unknown at this moment, so only probabilistic values of random variables can be used in this stage.

The inevitable unbalance between generation and load due to random variables will be solved using storage units (or spinning reserves) with operational costs. The cost of using storage units or the use of spinning reserves are the second-stage variables, whose values depend on the electricity purchase in the first stage and on the realization of random variables. The two-stage stochastic program can be formulated as the following optimization problem [37]:

$$\begin{aligned} \begin{aligned} \min J=f_1(x)+\mathbb {E}[f_2(y(d),d)] \end{aligned} \end{aligned}$$
(7.6)

subject to

$$\begin{aligned} g_m(x) \le 0 \end{aligned}$$
(7.7a)
$$\begin{aligned} h_n(x,y(d)) \le 0 \end{aligned}$$
(7.7b)

where x and y(d) are the set of first-stage and second-stage decision variables, respectively. \(g_m(x) \le 0\) is the set of first-stage constraints (i.e., limits of electricity purchase in the previous example). On the other side, constraints  \(h_n(x,y(d)) \le 0\) link first- and second-stage variables (i.e., balance equation in the example).

The previous problem is quite complex to solve, in particular, the computation of the expected value of the second stage. In practical applications, the problem can be simplified by choosing a set of samples of the random variables and forming scenarios. Then, the problem is decomposed in a set of deterministic optimization problems.

7.2.2 Scenario-Based MPC Approaches

The main idea of the scenario-based techniques is to draw samples of the uncertainty or to use historical data to formulate the MPC control problem. In this way, the stochastic optimization is transformed into a deterministic one with a larger number of deterministic constraints  corresponding to the original constraints  evaluated for every scenario.

A suitable modeling of scenarios is necessary to manage the stochastic optimization problem properly. The selected scenarios must correspond to real situations and can be associated to an occurrence probability. Otherwise, the number of scenarios is a critical issue, because statistically, a high number of scenarios are needed to reduce uncertainty but, on the other hand, it creates a more complex optimization problem. Scenario reduction techniques and the use of more efficient methods to manage a high number of scenarios, as fan- or tree-based approaches, are active fields of research.

In this section, two scenario-based approaches are described. The first one is a simple solution where a collection of different scenarios produces a single control sequence. The second one uses a tree-based approach to handle disturbances throughout the prediction horizon, with also the control actions structured in the tree.

Multi-scenario MPC

Multi-Scenario MPC (MS-MPC) approach is an intuitive and simple to formulate technique that generates a unique control sequence considering simultaneously all the selected scenarios, as a result of a deterministic convex optimization, even when the original problem is not convex [39]. This technique does not need to know statistical information of the random variables in advance (although such knowledge can be exploited). This approach has been applied in [42] for water systems. In this work, three scenarios have been considered. Two of them are maximum and minimum scenarios, both with small probabilities of occurrence, while the third one is the most likely average scenario. A unique set of control actions is generated for all the scenarios. An application on microgrid system can be found in [30], where a finite set of scenarios is used to solve the first stage of a two-stage stochastic-programming-based MPC.

In this approach, a finite set of scenarios is considered, and the same dynamical system is used for different disturbance realizations, resulting in the following optimization problem:

$$\begin{aligned} \begin{aligned} \min \sum _{j=1}^{N_s} \left( \sum _{i=1}^{N_p} J(\hat{x}_j(t+i \mid t),u(t+i \mid t) \right) \end{aligned} \end{aligned}$$
(7.8)

subject to

$$\begin{aligned}&x_j(t+1)=Ax_j(t)+Bu(t)+B_w d_j(t)\end{aligned}$$
(7.9a)
$$\begin{aligned}&x_j(t+1) \in \mathcal {X} \end{aligned}$$
(7.9b)
$$\begin{aligned}&u(t) \in \mathcal {U} \end{aligned}$$
(7.9c)

where \(N_s\) is the finite number of scenarios, \(d_j(t)\) is the random disturbance forecast for scenario \({j=1...N_s}\), and \(\mathcal {X}\), \(\mathcal {U}\) are the sets of state and input constraints, that is [14],

$$\begin{aligned} \mathcal {X} \equiv \{ x(t) \, |\, Gx(t) \le g \} \quad \forall t\end{aligned}$$
(7.10a)
$$\begin{aligned} \mathcal {U} \equiv \{ u(t) \, |\, Fu(t) \le f \} \quad \forall t \end{aligned}$$
(7.10b)

being \(c_x\) and \(c_u\) the number of state and input constraints, respectively. \(N_s\) different state trajectories over the prediction horizon are implicit in the solution, each for a different scenario but all of them obtained with the same input sequence. The cost function measures an average over all scenarios. As mentioned above, each scenario can be associated to an occurrence probability.

Unlike the simple scenario generation of [42], a more systematic scenario generation, with a careful selection of the number of scenarios \(N_s\), can be used to find limits of the probability of violation of the constraints as a function of this number [6]. Nevertheless, due to its nature, this method cannot guarantee feasibility.

The scenario-based approach converts a stochastic control problem into multiple deterministic problems by substituting each scenario by a set of constraints and considering a new cost function as an average of the cost functions of individual scenarios. Nevertheless, as mentioned in [39], the solution can produce a randomization of the control law, and occasionally an erratic behavior could be shown.

A formal selection of \(N_s\) is based on the early works on sampled convex programs in [6, 7] and later works in [39]. Notice that a higher value of \(N_s\) makes the solution more robust but the computational complexity increases. The aim of these works is to find a lower bound of \(N_s\) which fulfills a set of statistical conditions about the satisfaction of state constraints, with assumptions about the distribution function of the uncertainties. The demonstration of these results is out of the scope of this book, but an interested reader will find it in previous references.

In order to determine a lower bound of \(N_s\), let us consider \(\delta _x \in [0,1]\) as the acceptable risk level of violation of the constraints for the system states in the next sampling time:

$$\begin{aligned} \begin{aligned} \mathbb {P}[x_j(t+1) \in \mathcal {X}] > 1-\delta _x \end{aligned} \end{aligned}$$
(7.11)

and let us define a quite small confidence level \(\beta \in [0,1]\). According to [7], the lower bound on \(N_s\) depends on the number of optimization variables (z), \(\delta _x\) and \(\beta \), and has to satisfy the following:

$$\begin{aligned} \begin{aligned} \sum _{i=0}^{z-1} \begin{pmatrix} N_s \\ i \end{pmatrix} {\delta _x}^i (1-{\delta _x})^{N_s-i} \le \beta \end{aligned} \end{aligned}$$
(7.12)

based on a binomial distribution function. The limit value of \(N_s\) can be obtained from this expression as indicated in [12]

$$\begin{aligned} N_s \ge \frac{z+1+\ln (1/\beta ) + \sqrt{2(z+1) \ln (1/\beta ) }}{\delta _x} \end{aligned}$$
(7.13)

As mentioned above, this approach will result in a single control action that satisfies all the constraints of the different scenarios with a specified probability.

Tree-Based MPC

A more efficient way to manage the uncertainty of stochastic systems is the use of trees to model uncertainty and control actions. The inherent concept of this technique is that uncertainty increases with time, that is, an accurate prediction of energy demand and energy generation by a renewable source is easier to obtain in a short-term horizon. In this approach, the different feasible evolutions of the disturbances are represented by a tree, where a branching point is established when possible disturbances lead to more than one different trajectories. Therefore, distinct control actions can be decided in each branch, and the result is a tree of control actions. This method has been applied to a semi-batch reactor in [24] to open water systems in [25], and finally to an energy management system of a microgrid with hydrogen storage in [35].

Therefore, this approach consists of confining the different considered evolutions of the disturbances in a tree, whose root is in the current sampling time. Using the terminology of [29], let us consider d(t) as a stochastic disturbance with values restricted to a finite set \(\{\bar{d}_1, \bar{d}_2,...\bar{d}_s\} \) and a known p(t) probability mass function of d, where

$$\begin{aligned} \begin{aligned} \forall t, \, p_j(t)=\mathbb {P}[d(t)=\bar{d}_j],\quad p_j(t) \ge 0,\quad \sum _{j=1}^{s}p_j(t)=1 \end{aligned} \end{aligned}$$
(7.14)

in such a way that it can be predicted in the future using only the information at time t.

At time t, in MPC problems with prediction horizon \(N_p\), a tree of s alternatives in each bifurcation point and a depth of \(N_p\) steps produces \(s^N_p\) scenarios, each of one being a sequence of \(N_p\) consecutive disturbance values. This approach is impractical for the large number of scenarios, because all possible disturbance sequences are being considered. Consequently, scenario reduction techniques are needed, in such a way that only the more likely sequences are considered through pruning of the tree.

In the method proposed in [4, 29], a path from the root to a leaf node defines a scenario and consists of a sequence of disturbance realizations. In a first step, from the root node, all the s possible values of the disturbances are considered and added to the tree. After this step, only the leaf node with the highest probability of reaching that node from the root is expanded. The result is a tree expanded in the most promising direction, where the paths from the root to leaf nodes have different lengths, and consequently different prediction horizons. Typically, the algorithm ends when the tree reaches a predetermined value of maximum number of nodes. The algorithm is repeated at every sampled time (See Fig. 7.1). Other techniques for the reduction of the number of scenarios can be found in [39].

Nevertheless, as in the previous multi-scenario approach, the selected number of scenarios plays an important role in the robustness of the method and in the probability of constraint violations.

Fig. 7.1
figure 1

Scenario tree over the prediction horizon

Unlike the MS-MPC approach, a different control sequence in the prediction horizon is computed for each scenario in the tree, and consequently, more decision variables are needed. Due to causality, if two scenarios share the same path in the tree from the root to level m, both scenarios necessarily will have the same input sequence until that level m, and as mentioned previously, the solution is also a tree of control inputs. Obviously, this MPC only applies the first input of this tree, the root element, common for all the scenarios. Let us consider \(N_s\) as the number of different scenarios in the disturbances tree. The tree-based MPC (TB-MPC) problem can be formulated as follows:

$$\begin{aligned} \begin{aligned} \min \sum _{j=1}^{N_s} \left( \sum _{i=1}^{N_p} J(\hat{x}_j(t+i \mid t),u_j(t+i \mid t) \right) \end{aligned} \end{aligned}$$
(7.15)

subject to

$$\begin{aligned} x_j(t+1)=Ax_j(t)+Bu(t)+B_d d_j(t)\end{aligned}$$
(7.16a)
$$\begin{aligned} x_j(t+1) \in \mathcal {X} \end{aligned}$$
(7.16b)
$$\begin{aligned} u_j(t) \in \mathcal {U} \end{aligned}$$
(7.16c)

Another important issue in this approach is the need for the introduction of non-anticipative constraints to guarantee that the controller computes its input actions considering only the observed disturbances before the branching points [36]. These non-anticipative constraints can be represented by

$$\begin{aligned} u_i(t+k) = u_j(t+k) \quad if \quad {d}_i(t+k) = {d}_j(t+k); \quad \forall k=0,..,m \quad \forall i \ne j \end{aligned}$$
(7.17)

Equation (7.17) can be introduced in the optimization problem using equality constraints.

7.2.3 Analytical-Based SMPC

Analytical approaches are based on the explicit use of mathematical probabilistic models of the disturbances. This strategy implies the reformulation of the MPC elements, mainly cost functions and constraints, in a deterministic mode using statistical concepts, i.e., cumulative distribution or probability density functions.

Different applications of these techniques can be found in literature. The work in [15] uses an analytical-based SMPC to a drinking water network. In addition, [14] shows a comparison between analytical- and tree-based approaches applied to those systems. In the context of the control of microgrids, these techniques are having a remarkable interest among researchers, for example, the works presented in [19, 21, 26, 48]. Also, this approach has been used in [46] to a unit commitment problem with uncertainty in the wind power, with a solution based on two-stage stochastic programming. The work in [31] presents a prediction based on an ARMA model for load and generation uncertainties.

In this section, an analytical method named chance-constraint MPC (CC-MPC) is presented. Let us consider the linear dynamics with stochastic disturbances.

$$\begin{aligned} \begin{aligned} x(t+1)=Ax(t)+Bu(t)+B_d d(t)\\ \end{aligned} \end{aligned}$$
(7.18)

Considering the set of state constraints \(\mathcal {X}\) in (7.10), an individual constraint i, that is, the ith row of \(\mathcal {X}\), can be notated as follows:

$$\begin{aligned} G_{(i)} x\le g_{(i)} \end{aligned}$$
(7.19)

Due to the stochastic nature of the problem, in CC-MPC, state constraints are relaxed with a predefined probability as follows:

$$\begin{aligned} \mathbb {P}[x(t) \in \mathcal {X}] \ge 1- \delta _x \end{aligned}$$
(7.20)

This probability of constraint violation has a considerable effect on the solution of the SMPC. A low value will have as a consequence a more conservative solution, with a reduced number of unsatisfied constraints, only in very unlikely situations, but normally with an increment in the value of the cost function. A selection of this probability is an important issue in SMPC and a compromise solution must be adopted. If the probability distribution is known, chance constraints can be transformed in deterministic constraints as follows:

$$\begin{aligned} F_{G_{(i)}x}^{-1}(1-\delta _x) \le g_{(i)} \end{aligned}$$
(7.21)

where \( F_{Gx}^{-1}(\cdot )\) is its inverse cumulative distribution. Probabilistic constraints can be defined in two different ways [15]:

  • Individual chance constraints: Each row of the constraint set has to be validated with its respective probabilities

    $$\begin{aligned} \mathbb {P}[ G_{(i)}x(t) < g_{(i)}] > 1- \delta _{x,i}, \quad \forall i = 1...c_x \end{aligned}$$
    (7.22)

    where \(G_{(i)}\) and \(g_{(i)}\) are the ith row of G and g, respectively.

  • Joint chance constraints: There is an unique probability of constraint violation \(\delta _x\) that has to be fulfilled jointly by all constraints:

    $$\begin{aligned} \mathbb {P}[ G_{(i)}x < g_{(i)}, \forall i = 1...c_x ] > 1- \delta _x \end{aligned}$$
    (7.23)

Let us consider a known quasi-concave probability distribution and consequently a known cumulative distribution function [15, 43, 44]. Equation (7.23) can be transformed to a deterministic equivalent constraint when applied to the prediction horizon in the controller in the following way:

$$\begin{aligned} \begin{aligned} \mathbb {P}[ G_{(i)}x(t+1)< g_{(i)}]> 1- \delta _x \\ \Leftrightarrow F_{G_{(i)}B_d d(t)} (g_{(i)}-G_{(i)}(Ax(t)+Bu(t))) > 1- \delta _x \\ \Leftrightarrow G_{(i)}(Ax(t)+Bu(t)) < g_{(i)} - F_{G_{(i)}B_d d(t)}^{-1} (1- \delta _x) \end{aligned} \end{aligned}$$
(7.24)

Here, \(F_{G_{(i)}B_d d(t)}(\cdot )\) is the cumulative distribution function of the random variable \(G_{(i)}B_d d(t)\), and \(F_{G_{(i)} B_d d(t)}^{-1}(\cdot )\) is its inverse cumulative distribution function.

Then, CC-MPC must solve an optimization problem defined as follows:

$$\begin{aligned} \begin{aligned} \min \sum _{j=1}^{N_p} \mathbb {E}[J(x_(t+j|t),u_j(t+j |t)] \end{aligned} \end{aligned}$$
(7.25)

subject to

$$\begin{aligned} x(t+1)=Ax(t)+Bu(t)+B_d d(t)\end{aligned}$$
(7.26a)
$$\begin{aligned} G_{(i)}(Ax(t)+Bu(t)) < g_{(i)} - F_{G_{(i)}B_d d(t)}^{-1} (1- \delta _x)\end{aligned}$$
(7.26b)
$$\begin{aligned} u_j(t) \in \mathcal {U} \end{aligned}$$
(7.26c)

7.3 Stochastic MPC Applied to Microgrids

This section describes different stochastic MPC approaches applied to energy management systems with renewable energy sources, and specifically to microgrids.

A previous problem when using multi-scenarios, tree-based MPC or approaches based on stochastic dynamic programming is the selection of scenarios. MPC with a large number of scenarios requires an unacceptable calculation effort in most practical applications, so scenario reduction without loss of critical information of the stochastic process is needed. Two interesting general papers about scenario creation and reduction are [10, 18]. Scenario reduction and scenario construction approaches with application to power management systems are presented in [16]. A set of scenarios for electric load and wind power generation is computed in [1].

In [20] an islanded microgrid composed of wind farm, a fuel cell, a battery storage system, and the customer load are controlled. The uncertainty in the wind profile is modeled using a Gaussian distribution and the disturbance term in the load is assumed to have a normal distribution. The authors present a method to solve an MPC problem using an approximate expected value of a quadratic cost function and dynamic programming.

A scenario-based stochastic MPC algorithm to solve in real time, the optimal power dispatch of a problem considering the market is presented in [33]. Loads, power generation, and energy prices are defined as stochastic processes without a priori assumption on its distribution. A grid-connected system consisting of conventional and renewable generators and energy storage units is used.

Another scenario-based stochastic MPC approach is shown in [49] for the economic dispatch problem. The authors decomposed the SMPC problem into subproblems which can be solved in parallel using the optimality condition decomposition [9]. The scenario enumeration approach of [3] is applied in [38] to a similar energy management problem: hybrid electric vehicle power management.

In [17], a tree-based approach for isolated microgrids is proposed. Fans of forecast scenarios are created, and then a scenario tree is produced to reduce the number of scenarios to keep the computing effort of the SMPC problem manageable, using the forward selection algorithm of [18].

The work in [30] proposes a two-stage algorithm for an EMS of isolated microgrids. First stage computes a unit commitment using a stochastic approach. It is formulated as a fixed-recourse, two-stage stochastic problem, resulting in a mixed-integer linear programming problem, considering different scenarios for the renewable energy generation. Second stage performs an optimal power flow using a nonlinear shrinking horizon control algorithm.

The paper [32] tackles an optimal operation management of a microgrid under generation and load uncertainties with economic and environmental objectives, considering thermal and electricity demand. The approach is based on MPC with mixed-integer linear programming and stochasticity managed with a two-stage stochastic programming approach. A chance-constrained MPC approach is proposed in [31], incorporating ARMA prediction models, and considering the correlation between wind generation and demand to obtain a probability distribution of forecast based on current and past observations. The obtained probability distribution is used to evaluate the probability of constraint violations. A similar approach is applied to a hybrid wind–solar–thermal plant in [47].

Also, a chance-constraint MPC is used in [8] focused on a microgrid composed of gas microturbine, a battery, a PV generator, customer load, and grid connection. The authors propose a two-layer control system, where the high-level controller works with the nominal operating conditions of the components, optimizing an economic performance index. Uncertainties are taken into account in the low-level controller, whose objective is to compensate disturbances on load and renewable generation and to guarantee operational constraints. A CC-MPC approach with uncertainties modeled with Gaussian distribution functions is proposed.

7.4 Case Study

7.4.1 Plant Description

The microgrid used in this section is HyLab, the laboratory-scale plant described in Chap. 4. [40, 45]. The system (see Fig. 7.2) consists of renewable generation (solar or wind), emulated by a programmable power source. Consumption profiles can also be emulated by an electronic load. The system includes two types of storage: batteries and hydrogen to manage the excess or deficit of energy between generation and demand. The hydrogen storage system includes a fuel cell to supplement the lack of generation and an electrolyzer to store hydrogen when generation is higher than load. Hydrogen is stored in a metal hydride tank. Additionally, the microgrid allows sale or purchase energy from the main grid. The technical characteristics of the equipment are summarized in Chap. 4, Table 4.1.

Fig. 7.2
figure 2

Hylab scheme

7.4.2 MPC Problem Statement

As described in previous chapters, MPC controllers require a control-oriented model to predict the evolution of the system throughout the prediction horizon. This model must be simple because it will be included in a mathematical optimization problem at each sampling time. A linear model will be used as control-oriented model in these experiments:

$$\begin{aligned} \begin{aligned} x(t+1)=x(t)+Bu(t)B_d d(t) \end{aligned} \end{aligned}$$
(7.27)

In the proposed model, the state vector is \(x(t)=[SOC(t) \, LOH(t)]^T\), where SOC is the state of charge of the battery and LOH is the level of hydrogen in the hydride tanks. A fixed value of the efficiency of the battery is used to avoid the use of binary variables.

$$\begin{aligned} SOC(t+1)= & {} SOC(t) - \frac{\eta _{bat} T_s}{C_{\max }} P_{bat} (t) \end{aligned}$$
(7.28)
$$\begin{aligned} LOH(t+1)= & {} LOH(t) + \frac{\eta _{elz} T_s}{V_{\max }} P_{elz} (t) - \frac{T_s}{\eta _{fc} V_{\max }} P_{fc} (t) \end{aligned}$$
(7.29)

\(P_{bat}\) is the power supplied by the battery and \(V_{\max }\) is the capacity of \(H_2\) (in normal cubic meters) in the metal hydride tanks. As described in Chap. 4, and additional simplification is performed: power of fuel cell and electrolyzer is condensed in an unique variable \(P_{H_2}=P_{fc}-P_{elz}\).

The manipulated variables are the power that can be exchanged with the hydrogen system (\(P_{H_2}\)) and the grid (\(P_{grid}\)). The disturbances are defined as \(d(t)=P_{net}(t)= P_{gen}(t)-P_{load}(t)\). Finally, the battery is directly connected to the DC bus and absorbs the unbalance, so \(P_{bat}\) can be obtained from the balance equation:

$$\begin{aligned} P_{bat}(t)= -P_{H_2}(t)- P_{grid}(t) -P_{net}(t) \end{aligned}$$
(7.30)

In this case study, the control objective is similar but simpler than the one used in Chap. 4:

$$\begin{aligned} \begin{aligned} J(x(t),u(t)) = \sum \limits _{k=1}^{N_c} \alpha _1 P_{H_2}^2 (t+k) + \alpha _2 P_{grid}^2(t+k) + \\ + \sum \limits _{k=1}^{N_p} \gamma _1 (SOC(t+k)-SOC_{ref})^2 + \gamma _2 (LOH(t+k)-LOH_{ref})^2 \end{aligned} \end{aligned}$$
(7.31)

that is, a multi-objective weighted cost function looking for an efficient use of the power of the microgrid components and tracking the hydrogen and battery reference levels.

Upper and lower values of levels of energy storage systems and power variables are the physical constraints in this application example. Also, constraints on power increments will be taken into account. The hydrogen-related powers (electrolyzer and fuel cell) are limited to 0.9 kW. This value is lower than their nominal operational points, with the objective of the protection of hydrogen equipment, looking for an increase in their lifespan. On the other hand, the minimum production of electrolyzer and fuel cell powers has been fixed to 0.1 kW. The power limits of the electronic units determine the constraints for \(P_{grid}(t)\). Also, constraints on their incremental signals \(\Delta P_{H_2}(t)\) and \(\Delta P_{grid}(t)\) have been included.

$$\begin{aligned}&-0.9 \ kW \le P_{H_2}(t) \le 0.9 \ kW\end{aligned}$$
(7.32a)
$$\begin{aligned}&-2.5 \ kW \le P_{grid}(t) \le 2 \ kW \end{aligned}$$
(7.32b)
$$\begin{aligned}&-20 \ Ws^{-1} \le \Delta P_{H_2}(t) \le 20 \ Ws^{-1}\end{aligned}$$
(7.32c)
$$\begin{aligned}&-2.5 \ kWs^{-1} \le \Delta P_{grid}(t) \le 2 \ Ws^{-1} \end{aligned}$$
(7.32d)

With respect to state constraints, operational limits have been considered to battery and metal hydride levels. Batteries are responsible for maintaining the bus voltage level, and consequently undercharge must be avoided. Also, the metal hydride tank must maintain a minimum pressure, corresponding to a minimum value of LOH. Upper bound is imposed by safety reasons. The state constraints x(t) in these experiments are given below:

$$\begin{aligned} 40 \% \le SOC(t) \le 90 \%\end{aligned}$$
(7.33a)
$$\begin{aligned} 10 \% \le LOH(t) \le 90 \% \end{aligned}$$
(7.33b)

7.4.3 Stochastic MPC Algorithms Setup

Setting the values of the parameters of the controller according to the control objectives is a key issue in MPC. The main objective is an equilibrate use of the devices, and consequently the weight associated to power exchange with the grid and the weight corresponding to hydrogen power are similar. The tracking of reference levels has been considered as a secondary objective, and consequently the weights corresponding to the power of hydrogen equipment and main grid are much higher than those of the storage levels. The specific values \(\gamma _i\) and \(\alpha _i\) of the cost function  have been tuned using the studies and results of [11, 34, 40].

A prediction horizon of \(N_p=5\) and a sampling time of 30 s has been considered. Constant references have been selected for battery SOC and metal hydride level, \(SOC_{ref} = 65\%\) and \(LOH_{ref} = 40\%\).

A probability of violation of constraint \( \delta _x \le 10\%\) has been selected for the tests in all the approaches. \( \delta _x\) is a direct parameter in CC-MPC, but it is the result of the number of scenarios in the other two approaches. According to Eq. (7.13), the number of scenarios has been set at 316 for both scenario-based approaches. These scenarios have been determined using the electricity demand and the solar generation obtained from historical data, published by the TSO of the Spanish electricity system Red Eléctrica de España (REE), including sunny and cloudy days. Historical generation and demand from the same source have also been used to obtain the cumulative distribution function needed for the chance-constraint method. Next sections present experimental results on the plant carried out in [43, 44].

7.4.4 Experimental Results

Each experiment was carried out in the microgrid real plant during a period of 20 hours. The controllers were tested with solar generation profile corresponding to a sunny day, with high irradiance during the central hours of the day. Load profile used in the experiments are scaled data (adapted to microgrid power values) of the real demand on May 23, 2014, registered by the REE.Footnote 1 Generation and demand are shown in Fig. 7.3.

Fig. 7.3
figure 3

Generation corresponding to a sunny day and demand considered in experiments

The initial values of the state variables were \(SOC(0)= 70\%\) and \(LOH(0)=50\%\) for all the experiments. Figures 7.4, 7.5, and 7.6 show the behavior of the microgrid using MS-MPC, TB-MPC, and CC-MPC, respectively. Power evolution of the different components is presented on the left and the storage level evolution on the right.

Fig. 7.4
figure 4

Power flows and storage using MS-MPC controller

Fig. 7.5
figure 5

Power flows and storage using TB-MPC controller

Fig. 7.6
figure 6

Power flows and storage using CC-MPC controller

The qualitative behavior of all controllers is similar. They have to manage the excess of energy during the central part of the day and the deficit during the first and last parts of the day. The deficit of energy during the first hours is supplied by the batteries, fuel cell, and to a lesser extent, the main grid. The energy surplus in the following hours is used mainly to charge the batteries, but when the SOC is reaching its upper value, a portion of the energy is used to produce hydrogen with the electrolyzer and part of the energy is sold to the main grid. The deficit during the last hours of the day is supplied by the battery, fuel cell, and main grid in different ways depending on the controller. The evolution of the SOC and LOH is almost free between their operational limits since the weights utilized in the cost function for reference tracking are small.

As can be noticed, each approach shows particular quantitative differences. CC-MPC controller carries out a more intensive use of battery and electrolyzer during the central hours of the day with an important energy excess (see Fig. 7.7), with the consequence of an approach to the upper operational limit of the SOC. Nevertheless, the state variable constraints are never violated in any of the controllers. On the other side, TB-MPC shows a smoother use of the battery and electrolyzer. Finally, MS-MPC technique has a behavior between the two other methods.

As a consequence of the limited use of the self-consumption components (battery and hydrogen system), TB-MPC carries out a more intensive energy exchange with the grid (see Fig. 7.8-left). The positive face of this type of action is the smoothing of the use of the microgrid equipment, and consequently a possible limitation of the degradation effects.

Figure 7.8 (right) shows a comparison in the SOC evolution for the three approaches. A deeper cycle of batteries is performed in MS-MPC and specially in CC-MPC. In both of them, a value near the upper limit is reached at the end of the energy excess period at central hours of the day.

Fig. 7.7
figure 7

Battery (left) and hydrogen system (right) evolutions when the stochastic MPC approaches are used

Fig. 7.8
figure 8

Main grid energy (left) and SOC (right) evolutions when the stochastic MPC approaches are applied

Table 7.1 summarizes the cumulative value of the cost function for the complete experiment period and the computation time for the three tested SMPC algorithms.

Regarding the cumulative cost of the objective function, the highest value corresponds to MS-MPC approach. This is due to the nature of the procedure, where a conservative optimal solution is obtained as a consequence of the fact that the computed sequence of control actions is valid for all considered scenarios, that is, those close to the present disturbance conditions but also to less favorable ones.

The constraint of the considered scenarios in a tree structure permits a more effective implementation of disturbance occurrence probabilities, resulting in a lesser value of the cost function in the TB-MPC approach. But as a drawback of the method, an increment in the number of control variables involved in the optimization problem, also in a tree structure, has effect on the computational time, the biggest among evaluated SMPC techniques in this experiment. Finally, CC-MPC has the lowest cumulative cost, with the advantage that the number of control variables has not been increased in relation to the MS-MPC approach.

Anyway, even when there are important differences among the computational time of the SMPC controllers, it is important to remark that all of them solve the optimization problems faster than the sampling period.

Table 7.1 Performance indicators obtained with the three SMPC methods

As a summary of the behavior of the controlled microgrid, the energy supplied by the fuel cells, the provided energy to electrolyzers, and the net exchange with the main grid and batteries throughout the 20 h of the experiments are shown in Table 7.2. According to the sign criteria in this book, a positive value in energy of batteries implies that the energy discharged is greater than that charged (see SOC evolution in Figs. 7.4, 7.5, and 7.6). Concerning the main grid, a positive value entails a purchase of energy greater than the sale.

Table 7.2 Comparison of the energy produced by the fuel cell, consumed by the electrolyzer, and exchanged by batteries and main grid during the experiments

Another important issue in hydrogen-based systems is the startups of the fuel cell and electrolyzer. Chapter 5 of this book has considered the repercussion of the startups in the degradation and how to include it in a cost function. In this chapter, a very simple linear discrete model has been used, and the direct economical loss and reduction of the lifespan of hydrogen equipment have not been explicitly considered. Nevertheless, in this experiment, the number of startups is the same for all the controllers and is a very limited number. To be precise, the fuel cell has been connected twice and the electrolyzer only once.

Finally, Table 7.3 shows the maximum and minimum values of different variables throughout the experiments using the proposed approaches. It is important to notice that the constraints presented in (7.32) and (7.33) are always satisfied independently of the SMPC method in these tests.

Table 7.3 Interval of the values of the states and control inputs during the experiments

As a conclusion, the results of CC-MPC show a better performance, both in the value of the cost function and, as expected because of the size of the problem, in the computation time of the optimization problem. Nevertheless, regarding the cost function results and other performance indicators, these results are far to be conclusive. Notice that the number and selected scenarios in scenario-based approaches and the obtaining of the cumulative distribution function in analytical approaches (using historical data in this experiment) are key points in the controller performance.