Microgrid Operation Optimization Using Hybrid System Modeling and Switched Model Predictive Control

: Optimization of economic aspects of microgrid operation in both grid-connected and islanded mode leads to contradictive deﬁnitions of optimality for both modes. There is no general agreement on how to cope with this duality. To address this issue, as well as modern energy market requirements and a better renewable energy utilization necessity in the case of large facilities, a comprehensive control solution utilizing the appropriate model is needed. In response, the authors propose a hybrid microgrid model covering fundamental features and designed to work in conjunction with two switched receding horizon control laws. A relevant controller is chosen according to the current microgrid operation mode and its cost function tailored to speciﬁc demands of the islanded or grid-connected operation. Performed research led to a new switched hybrid model predictive control approach focused on microgrid economic optimization. This approach utilizes an appropriate hybrid microgrid model also contributed by the authors. The introduced solution turned out to be effective in overall energy cost reduction in the case of large commercial facilities, regardless of grid-connection and renewable generation scenarios. Furthermore, it also provides satisfactory renewable energy and storage capabilities utilization in changing grid connection conditions.


Introduction
Recent policy for climate and energy leans towards reducing greenhouse gas emissions and reaching energy systems without a significant carbon footprint. Electricity generation and consumption are at the forefront of this change. Therefore, currently used distribution and transmission grids will have to inevitably meet the above-mentioned requirements and a key solution in achieving carbon-neutral smart grids seem to be wide usage of microgrid solutions [1]. To reach that neutrality, a vast amount of renewable energy sources is vital and transition to such means of energy production is already taking place. Unfortunately, as pinpointed in [2], the adoption of renewable energy sources pose various challenges arising from user demands and fluctuate profiles of renewable energy generation far different from traditional means of energy generation. The structural solution to those new challenges is splitting the electrical network into smaller units based on distributed resources. Every smaller segment, the so-called microgrid, manages the local loads, generation and is equipped with storage capabilities. Moreover, it possesses means of connecting to and disconnecting from other segments, as well as can exchange energy with them. This approach significantly improves possibilities of remedying the instability of renewable sources and allows for fuller utilization of available renewable energy. In addition, small independent networks capable of island-mode operation tend to be incomparably more reliable in terms of continuity of supply and, with appropriate control strategies, offer economical benefits not only in remote regions.
According to [3], when considering complex microgrid control solutions, hierarchical control is mainly selected. Such systems consist of three distinguishable levels. Primary control stabilizes system frequency and voltage in response to rapid load changes, thus operating on the smallest timescale. Secondary control focuses on nullifying grid parameters deviations in steady-state and synchronizing with the public grid after the transition to grid-connected operation. Lastly, tertiary control is responsible for power flow control between microgrid elements or between microgrid clusters and upstream, public grid. Additionally, it introduces further functionalities in form of large-scale planning or economic optimization. As reported in [4], microgrid management is often associated with optimal control or optimization. Such optimization may concern economic, environmental, or technical objectives and optimal operation can be achieved using various techniques. Frequently used approaches include meta-heuristic or heuristic methods, stochastic and robust methods, Model Predictive Control in various forms, linear, dynamic, and nonlinear programming, as well as artificial intelligence.
Single and multi-objective optimization methods based on heuristic algorithms such as particle swarm or firefly optimization are a widespread choice. Some of the usage cases include cost and sizing optimization with fossil fuel share reduction in energy generation [5], microgrid load dispatch optimization [6] and for optimization of energy production cost in a microgrid [7]. Meta-heuristics are also used in combination with other techniques such as mixed-integer linear programming [8] or artificial neural networks [9]. On the other hand, artificial neural networks can adapt to uncertainties and are applicable when the exact model of a system is not available [10]. Exemplary applications include optimal energy scheduling [11] and storage system management [12]. It is worth noting that, according to [10], artificial neural networks are more commonly used in primary and secondary control than on the tertiary level. An exemplary solution utilizing a fuzzy-logic decision system in a multi-objective optimization problem can be found in [13]. Due to uncertainties, such as energy demand and generation, robust and stochastic optimization and control algorithms are also applicable in microgrid management cases. Robust optimization focused on both economy and robustness is presented in [14]. An exemplary optimal stochastic energy management system can be found in [15] and a robust economic energy and reserve management system is derived in [16]. Lastly, different mathematical programming methods are widely used, including dynamic, mixed-integer, and nonlinear programming. Some of the usage cases include energy generation cost optimization [17] and demand-generation mismatch optimization [18]. Importantly, the latter two are often equated with hybrid and nonlinear Model Predictive Control. Given the focus of this paper, usage of Model Predictive Control and mixed-integer linear programming, especially in hybrid form, will be discussed in detail below.
The applicability of Model Predictive Control (MPC in short) on all microgrid control levels is one of its most significant advantages. As reported in [19,20], the popularity of MPC stems from the fact that the resulting control strategy, due to the direct use of the process model, respects all system interactions and constraints which are not that easy to capture using other control methods. Moreover, it provides constraints satisfaction, stability guarantee and is adequate in application to multi-variable processes. Going back to the microgrid world, it is clear that any microgrid consists of a substantial amount of interacting elements, sometimes in an unintuitive manner, and controllers must operate in a significantly constrained environment. Interestingly, various phenomenons occurring in microgrid exhibit hybrid behavior, therefore building microgrid hybrid models is not overly complicated, especially in the economical scope. Additionally, receding horizon control is highly compatible with hybrid systems and such a combination is widely used. In [21], a hybrid model is used for economical optimization to include as much detail as possible and conventional MPC is used in form of a single mixed-integer linear programming (MILP) problem among other methods. The scope of research is focused on grid-connected mode and islanded operation is not considered. A Single Hybrid MPC (HMPC) solution using Mixed Logical Dynamical (MLD in short) framework in conjunction with a highly efficient MILP solver is presented in [22]. The scope of modeling focuses on economic and dynamic modeling of microgrid components including varying energy costs taken into account during optimization but no demand-side management. The exact solution is dedicated to the Brazilian energy market. In turn, the authors of [23] aim to design a management system dedicated to smart house systems. A hybrid model of its electrical and thermal system is derived, HMPC for on-grid operation proposed and solved using MILP solver. Importantly, a time-varying energy price is also introduced and no demand-side management is considered. As can be seen, the usage of mixed-integer linear programming is very wide, mainly because of highly accessible and efficient solvers, as well as simulation environments equipped with toolboxes connecting solvers and hybrid modeling tools. The synergy between microgrid modeled using discrete hybrid automata described in HYSDEL language and resulting MILP solved using CPLEX solver is precisely described in [24] where authors propose a hybrid optimization model for management of microgrid featuring automatic grid connection. A similar approach is presented in [25]. The study presents a hybrid model predictive control solution to optimal economic energy management of microgrid with hydrogen-based storage. Applied control scheme employs single Lyapunov-based HMPC using microgrid model in discrete hybrid automata form converted to MLD representation. Demand-side management is not considered and emphasis is put on grid-connected operation. The solution includes optimal dispatch and load sharing controllers. Naturally, there are other usable optimization approaches, without the introduction of receding control strategies in form of MPC. The authors of [26] use particle swarm optimization with the aim of minimizing the operation cost of a microgrid and improving photoelectric consumption by means of energy demand management. The algorithm is also solving a single MILP problem. Varying energy price is used but the microgrid remains connected to the public grid.
Considering the wide range of MILP applications and available tools authors of this paper choose to develop a novel HMPC-based control solution covering separate optimization of both on-grid and off-grid operation. To clarify, when dealing with microgrid switching between on-grid and off-grid operation mode, the control system must achieve an optimal solution regardless of the current mode. However, optimal control for each of those modes should be reached using different criteria resulting in slightly different optimization problems but still using the same microgrid model. That said, derivation of compatible microgrid hybrid model was also needed. Moreover, such a model should also cover demand-side management and the presence of energy-tariff with changing energy price.
A novel control concept utilizing switched hybrid MPC applied to economically optimize microgrid operation is the main contribution of this paper. Additionally, a compatible hybrid microgrid model in MLD form featuring demand-side management, varying energy price, and operation in both grid-connected and islanded mode is also contributed.

Economically Oriented Microgrid Hybrid Model
To date, various methods have been applied to model different aspects of microgrid operation. The general use of hybrid modeling is a well-established approach to capturing phenomenons occurring in a microgrid, understood as a dynamical system. Those phenomenons tend to be nonlinear or highly complicated and, what follows, problematic to directly model. This also entails high computational cost which is vital for model predictive control-oriented applications. Segmenting complex relationships into relatively simple pieces and switching them depending on certain conditions proves very useful, especially in the case of microgrids. Multiple distinguishable microgrid components are naturally operating in a hybrid manner, for example, energy storage is either discharged or charged, depending on energy demand and supply balance. The authors decided on employing a hybrid microgrid model in the mixed logical dynamical form given reduced computational burden and high compatibility with phenomenons occurring in a microgrid, as well as with model predictive control. This section introduces a hybrid model built to work in conjunction with the proposed switched MPC control approach.

Energy Storage Description
The derived energy storage model is based on the simple principle of energy balance sourced from [21] and expanded. Variable E st (k + 1) represents energy aggregated in energy storage at time k + 1, which depends on current storage level E st (k), constant selfdischarge E sd , energy discharged from storage 1 η d E − and amount of energy charging the storage η c E + . Charging and discharging efficiency is taken into account and labelled as η c and η d , respectively. Equation (1) describes the aforementioned relationship: Energy charging the storage unit is described as previous energy balance in microgrid E b (k − 1) multiplied by boolean δ b which indicates positive or negative E b (k − 1) as follows: where z ex (k) denotes auxiliary variable defined as a product of the real variable E b (k − 1) and the logical condition δ b . It is equivalent to the expression z ex (k) = δ b (k)E b (k − 1). A similar notation will be used throughout the whole model description. Charging delay is added to take into account that storage charging or discharging is not instant. Furthermore, energy discharged is expressed as previous energy balance E b (k − 1) minus already explained E + (k): Substitution of E + (k) and E − (k) to Equation (1) reveals that δ b is used to nullify or include certain expressions depending on energy balance. This means that, given negative E b (k), auxiliary binary variable δ b (k) becomes zero and storage is discharged with efficiency η d . On the other hand, in the case of non-negative energy balance, hence δ b (k) equal one, storage is charged with the efficiency η c . Finally, self-discharge constant E sd consists of energy spent to cool storage units labeled as E ac and energy lost due to natural self-discharge E nd : Appropriate E ac and E nd values are adopted based on informations from [27].

Transactions with a Public Energy Network
Other essential components of a microgrid model are energy transactions with a public energy network. Considering an economically oriented approach, those can be understood as costs and gains associated with buying and selling energy, respectively. At this point, it should be emphasized that authors assume energy purchase prices change over time according to the energy tariff given in [28], which is currently available in Poland. Figure 1 shows the resulting energy price chart. As can be seen from Figure 1, three pricing periods can be distinguished: standard price f f lat , morning peak price f mp and evening peak price f ep . Introduction of a simple timer t tim is necessary for the model to correctly switch between aforementioned prices. Time aggregated in t tim is increased at every time step k by sampling time T s and reset, by subtracting 24, if boolean δ tim (k) indicates that t tim (k) is equal or greater than 24. This relationship is specified by: That simple timer made switching between energy prices according to the current time possible. However, actual energy price switching is based on inequalities and binary auxiliary variables δ t1 (k), δ t2 (k), δ t3 (k) and δ t4 (k) becoming true when certain time has been exceeded. Variables t mps and t mpe indicate starting and ending time of morning peak, respectively. Similarly, t eps and t epe correspond with the evening peak as follows: In addition, the amount of energy exchanged with the public grid is denoted by E ex and related auxiliary variable δ ex , describing its sign, defined in the following way: Then, using timing taken from Equation (9) through Equation (11) and pricing according to Figure 1, variability of base energy cost c c (k) can be expressed as: At last, the total energy purchase cost is defined as an aggregate of various fees, multiplied by the amount of energy exchanged with the public grid E ex (k). Besides, according to [28], total energy cost c b (k) consists of switched base energy cost c c (k), cogeneration fee f cg , renewable energy fee f res , quality fee f q and switched power cost c p (k) further associated with the power fee f p , hence: with c p (k) defined as: Note that binary variable δ cp is associated with the grid connection status. Consequently, when in on-grid mode, δ cp equals one and in off-grid mode, its value changes to zero.
On the contrary, profit from selling excessive energy c s (k) is described by significantly simpler Equation (16). Given negative E ex (k) indicated by δ ex (k) equal to zero and active connection with public grid due to δ cp (k) = 1, energy is sold at price f sell . If at least one of those conditions is not met, the microgrid is not connected to public grid or is buying the energy, therefore c s (k) is set to zero.
As a result, profit c s (k) equals the amount of sold energy multiplied by the constant energy selling price. Appropriate energy selling price is taken from [29] and converted to euros.

Critical and Non-Critical Energy Demand
The aforementioned microgrid energy balance takes into account two main load sources. Both critical E c (k) and non-critical E n (k) loads are given as sum of various lesser loads: Due to the fact that non-critical loads are also controllable, it is necessary to introduce a demand reduction coefficient β(k). This also poses a problem because β(k) is considered as an input and disturbance E n (k) is treated as a state variable. By definition, every equation forming part of a mixed logical dynamical model must be affine and hence multiplication and division of inputs, outputs, and state variables are not permitted. In other words, it has become necessary to approximate the product of controllable loads summary demand E n (k) and demand reduction coefficient β(k). The main idea is to restrict the range of values of β(k) to predefined, fixed values of β apx by checking in what range β lies at time k, store the results of performed checks in binary variables δ b1 (k). . . δ b6 (k) defined as follows: and round original β(k) down to predefined values of β apx1 . . . β apx6 in accordance with the following rules: The resulting expressions are affine and further applicable to the energy balance equation. Figure 2 illustrates the methodology set out above through a simple example.

Power Generator and Energy Balance in Microgrid
It was decided that there would be a deadband on power generator power to mitigate inconsiderable power values resulting in unnecessary generator activation. Therefore, generator power P g (k) is checked if lower than the deadband P db and the result is stored in δ db (k). In case of the power demanded from the generator at time k being less than or equal to P db , boolean δ db (k) is set to zero as set out below: Moreover, the usage of a power generator bears some costs which cannot be omitted. Overall generator operation cost c mg is composed of fuel cost approximated by means of expression z f a1 (k) − z f a2 (k) and constant maintenance cost c mnt . The generator state is described using boolean δ g (k), with zero indicating that it is not providing any power. As a result, c mg (k) is described as: It is worth noting that when generator power output lies under specified threshold P tr , checked through the following inequality: fuel cost is independent to P g and set using f const . Otherwise, linear approximation using coefficients f a , f b and fuel price f f d gets chosen. However, the partial fuel cost z f a2 (k) is solely used to nullify the influence of f const on the fuel cost when above the threshold value. The aforementioned functionality is introduced using Equations (29) and (30).
Generator startup and shutdown is also to be penalized using already mentioned boolean generator status δ g (k), with cs SD and cs SU being two cost coefficients, respectively, for shutdown and startup. Therefore, the resulting cost c st (k) is defined as: Finally, energy balance in microgrid E b at the time k is circumscribed as the sum of various demands and supplies resulting in Equation (32). The variable E RES expresses energy provided by renewable sources, E ex2 describes transactions with the public grid and excessive energy utilization in off-grid mode, z g represents energy provided by power generator including the deadband and delay to account for power generator reaction time, E c stands for summary critical energy demand and E napx expresses the energy demand of controllable loads with respect to demand-side management, hence: Note that z g , related to the generator, is delayed one step to account for its response time. In the interests of clarity and simplicity powers provided by generator P g and renewable sources P RES are redefined to corresponding energies as follows: Furthermore, E ex2 is in fact just redefined E ex with the difference that E ex2 allows for excessive energy utilization in the off-grid mode which is irrelevant in terms of costoriented Equation (14). As shown in Equation (35), E ex2 is not zeroed either in the on-grid mode to allow energy selling or when E ex is negative, to allow excessive energy utilization in the off-grid mode. This can be then summed up using the following expression:

State-Space Model in MLD Form
All equations introduced in previous subsections are converted to single HYSDEL script in accordance with [30] and compiled, resulting in a hybrid microgrid model in general mixed logical dynamical form with x(k) being system state vector, y(k) expressing output vector and u(k) corresponding to input vector: with vectors of auxiliary variables δ(k) and z(k) defined as follows: z = [z ex z mp z ep z f lat z s z p z ex2 z apx1 z apx2 z apx3 z apx4 z apx5 z apx6 z tim z f a1 z f a2 z mnt z g ] and output, input, as well as state vectors given in the form of: Furthermore, two newly introduced output variables SOC(k) and β inv (k) account for energy storage percentage state of charge and percentage controllable load demand reduction, respectively, and are defined as: with E max indicating storage capacity. Importantly, the MLD state-space matrices are omitted due to large sizes but nonetheless, the method used in receiving them is well known and precisely described in [30,31].

Microgrid Control System Oriented towards Economic Optimization
To optimize the microgrid economical performance, adequate control strategy is needed. According to various studies including [1,2], model predictive control is one of the few methods capable of handling complex requirements in terms of control quality in a microgrid environment and at the same time is characterized by a high compatibility with complicated hybrid systems used to model microgrids. By using a novel, switched hybrid model predictive control approach authors are able to incorporate network connection tolerance in controller design.

Control System Concept with Switched Hybrid MPC
To accommodate different control objectives and slightly different perceiving of optimality in the on-grid and off-grid modes it is decided that the best approach to achieve optimal performance in terms of costs, but also relatively consistent storage energy level, is to use dual MPC switched according to connection status to the public power grid. This is done by having suboptimal control law u * (k) switch between u * o f f (k) and u * on (k) under dictation of the connection status δ cp (k). This can be then expressed as: In addition, various delays are introduced into the control system structure to take into account the time needed for performing state and output measurements and also the amount of time required to calculate control signals. For this reason, at time k, both control laws are evaluated using measurements from timestep k − 1. Thanks to that approach, an online optimization solution is applicable due to the fact, that the optimization could take up to T s . Figure 3 illustrates the implemented control system structure.

Optimization Problem Formulation
The major element of the model predictive control algorithm is the cost function that is being minimized. As already mentioned, the authors opted for switched MPC, therefore two cost functions are introduced. Based on those functions, two optimization problems are formulated, the first being used when a microgrid is connected to the public grid and the second exclusively for the off-grid operation. The generalized cost function value depends on the weighted sum of input, output, and state vector elements using vector norms. The weight matrices are denoted as R for input vector u and Q for outputs y. Moreover, J also features reference values for output variables indicated by y r . Apart from cost function, the optimization problem involves various constraints, concerning energy storage unit, power generator and demand reduction. Storage energy level, rate of charge, rate of discharge, as well as generator power, are limited in values and rates of change marked with ∆. The energy exchanged with the public grid is constrained only in terms of values. As a result, optimization problem based on the aforementioned cost function J and solved in constrained solution space is defined as follows: subject to with weight matrices and output reference values switched according to operation mode and defined as: It is also important to emphasize that Equation (36) through Equation (38) hold for each k and that x k denotes the prediction step instead of the time step. Initial prediction values x 0 , u 0 and y 0 equal state, input, and output values measured at time k for which optimization is performed.
According to Equation (46), one problem is solved at every time step k resulting in a series of N suboptimal control vectors u k , . . . , u k+N from which only the first one is used and becomes u(k + 1). Optimization problems described above are synonymous with model predictive control. Therefore, three model predictive control laws are implemented in MATLAB using Multi-Parametric Toolbox 3.0 according to the guidelines from [32]. Two of them are included in the switched MPC and one is used for comparison purposes during testing in form of the non-switched MPC. To speed up control calculation, an efficient MILP solver from Gurobi Optimizer [33] is used.

Parameters and Testing Scenario
It is important to outline model and controllers parameters used during testing and to emphasize the chosen approach in terms of energy generation and demand scenarios. The aim was to use as much real-world data as possible, in order to prove the adequacy of the developed hybrid model and control solution.

Parameters and Constraints
Various parameters are introduced in expressions composing the hybrid model as well as in the process of optimization problem formulation. They are then collected in Table 1 and their values were chosen according to distinct sources. Values of β apx1 through β apx6 are selected assuming 50% maximal controllable load reduction and, by setting adequate β constraints β max and β min , a range of values between 100 and 50 percent with 10 percent maximal rate of change ∆β max is achieved. It is assumed that the maintenance cost c mnt equals EUR 1 per hour, the shutdown cost cs SD is the same as the price of one unit of fuel and startup cost cs SD is half the shutdown cost. The natural discharge E nd , the energy needed for storage cooling E ac , the efficiencies η c and η d as well as the maximal amount of energy charged ∆E st max and discharged ∆E st min over T s are sourced from [27] as well as the storage capacity E st max . The minimal allowed level of energy in storage E st min is selected keeping in mind that deep discharge is unacceptable. Parameters f a , f b and f const , related to fuel cost are calculated based on [34]. Generator maximum power P g max comes from the same source. Although T s may prove sufficient for the chosen generator to ramp up to full power, a much smaller additional ramp up constraint ∆P g max is selected to allow for smoother operation. The energy pricing, including various fees, is borrowed from [28] and converted to euros. The generator deadband P db , fuel threshold P tr , required connection power E ex max , identical to the maximal amount of energy exchanged with public grid, sampling time T s and prediction horizon N were fine-tuned during preliminary testing.
On the other hand, matrices of weighting coefficients mentioned in Equation (47), as well as weighting matrices R s and Q s associated with single hybrid MPC used during simulation as a reference, have the following values: All outputs except for c s and SOC are to be minimized in the on-grid scenario, hence their reference values are set to zeros, which nullifies the reference value. On the other hand, c s denotes income from energy selling, therefore it is to be maximized by means of setting very high desired income and therefore turning a resulting problem into income maximization. When it comes to SOC, the reference value is introduced to encourage storage unit charging with renewable energy but, at the same time, to leave a sufficient margin. There is no energy sales opportunity in off-grid mode therefore, reference vector y ro f f , aside from storage state of charge reference, differs only in c s reference value being changed to zero. Significantly lower target stored energy level allows to not overuse diesel generator. Values of y rs are similar to y ron with one exception being the lower state of charge reference required to achieve acceptable storage utilization in both on-grid and off-grid mode.

Simulated Microgrid Configuration
The authors choose to analyse the performance of the proposed solution when applied to a large commercial facility with its own photovoltaic installation, power generator and energy storage. This is why the aggregated, total critical energy demand profile consists of various load profiles sourced from small and medium businesses as well as residential buildings, to imitate shops, workshops, public buildings, and lodging facilities connected to the considered microgrid. Figure 4 features the structure of the analysed microgrid.
What is more, basic controllable loads are also present in form of air conditioning, water heating, and decorative elements. The microgrid is connected to the public grid via the point of common coupling and energy can be exchanged in both directions. Fundamental information flow concerning the energy management system is also shown in Figure 4. Aside from energy supply and demand, information on the connection status, as well as, the storage state is delivered to the management algorithm, while the amount of energy exchanged with the public grid, generator power set-point, and degree of energy supply reduction is returned. The main optimization goal is to minimize operation cost, but it simultaneously takes into account some technical aspects such as generator and storage usage or continuity of energy supply. Still, the system is also intended to improve the use of renewable energy. Another point is that, in off-grid mode, microgrid is unable to exchange energy with the public grid but is able to utilize excessive energy. Nevertheless, such a surplus of energy is to be avoided. On the other hand, in on-grid mode, the microgrid can freely exchange energy with the public grid. It is also worth adding that switching from on-grid to off-grid mode can be also equated with a power outage in the public grid.

Energy Generation and Demand Scenarios
It is decided that the developed system will be tested using two solar power generation patterns, the first being a sunny day with nearly peak power and the second being a cloudy day with very changeable power output. By choosing such scenarios, the solution could be checked for economical benefits, storage level consistency, and solar energy utilisation in radically different renewable energy supply conditions. Both one-day scenarios are prepared using averaged data acquired from a solar plant located in Stargard in Poland. On the other hand, critical and non-critical demand profiles, already mentioned in the previous subsection, are prepared using end-user data sourced from [35]. Scenarios chosen for later use in the simulation are shown in Figure 5. What is more, the total energy demand of controllable loads is fairly constant. However, critical demand is notably higher between the hours of 9:00 and 22:00.

Performed Tests and Their Methodology
Having all the necessary data, the authors opted for three-stage testing. Firstly, a basic comparison of switched HMPC performance during the sunny and the cloudy day is made. Naturally, to activate the control law switch, microgrid grid-connection mode changes during the simulation period. Such a simple method is chosen to assess how different generation scenarios affect performance in combined on-grid and off-grid operations.
Secondly, it was considered appropriate to compare the performance of the proposed approach against a standard, single, non-switched HMPC solution. Such conduct allows for a confrontation of switched MPC approach with non-switched one without additional factors and under the same conditions. As a result, the main part of the testing process is focused on evaluating the advantages and disadvantages of switched control applied to the specific case. It is mainly through the lens of economical performance but other factors, including technical aspects, are also analysed. Consequently, two types of tests have been performed at this stage: • comparison of both control strategies over 48-h long simulation period consisting of the sunny day followed by the cloudy day and with two connection mode switches • comparison of total operation cost for both approaches using aforementioned renewable energy supply scenario but with varying initial storage state of charge SOC(0) and time of connection mode switch from on-grid to off-grid t o f f .
The first routine allows for closer inspection of how individual variables change over time and how high are output values associated with economical performance. The second one is solely dedicated to total operation cost exploration in respect to a varying initial state of charge and mode-switch time. Notably, this routine consists of combined data collected from 49 individual, 48-h long, test runs. Therefore, each time, two parallel simulations were performed. Figure 6 illustrates how the tests concerning switched and non-switched HMPC were performed in MATLAB. as well as their Cartesian product: The set X contains percentage SOC(0) values, and the set S contains connection mode switch times t o f f . The set X S contains all ordered pairs from sets X and S.
As a result, for each of the 49 pairs test runs are performed using every combination of initial states of charge SOC(0) and mode change times t o f f contained in the table X S. It is also worth adding that in this case, only one operation mode switch happens during the simulation and the microgrid always starts in on-grid mode.

Results
Having hybrid microgrid model, control laws, and all the parameters, as well as data, prepared, simulations are carried over. In order to properly analyse the results, measures of performance are introduced. Summary startup and shutdown, maintenance, and energy costs, as well as income from selling energy, are used to better understand simulation results. Moreover, average SOC and β are also analysed. All those values are presented in appropriate tables. Furthermore, corresponding figures containing storage state of charge, energy balance, and all system inputs are also provided. The comments concerning the first two testing routines are made based on information derived from relevant figure-table pairs. The last routine is discussed on the basis of the appropriate figure, as well as some additional numerical data.

Comparison of Microgrid Performance in Different Renewable Energy Generation Scenarios
The numerical results obtained from sunny and cloudy renewable energy generation scenarios analysis are summarised in Table 2, while Figure 7 compares storage state of charge, energy balance, and system inputs over the simulation horizon. It is apparent from the aforementioned table that the cloudy day turned out to be significantly more costly. For instance, C st , C mg , and C b have, respectively, about 2.5, 2.5, and 2.2 times higher values for the case of the cloudy day in comparison to the case of the sunny day. Consequently, this leads to a 146% higher total operation cost. As Figure 7 shows, such a huge difference stems from the necessity of compensating for lacking energy supply in off-grid mode, mainly after 18:00, by means of the power generator. In contrast, higher SOC in the evening of the sunny day translates into a longer period without the need for energy generated from diesel fuel. From the chart, it can be also seen that SOC in on-grid mode is kept relatively low in wait for renewable energy supply but when a significant amount of energy becomes available operation mode is changed. In both scenarios, storage is charged visibly over the level specified by the reference value, but in the case of the cloudy day, this process is much less significant. That explains why the average SOC during the cloudy day is 18% lower. Given the limited time in on-grid mode, there is no energy being sold regardless of the scenario, hence C s equals zero. Additionally, in Figure 7 there is a clear trend of reducing controllable load energy supply only when diesel generator is needed. It can be also seen from the aforementioned figure, that more fluctuations of energy balance (E b ) occur in off-grid mode. Furthermore, around 14:00 during the sunny day, a significant amount of excess energy appears. It is important to emphasize that the purpose of this test is to initially verify if chosen modeling and control approach is appropriate and combined lead to satisfactory results in one of the simpler scenarios. Summarizing, performed test exhibited that chosen switched control approach is capable of handling basic energy generation and grid-connection scenarios. It proves able to use the capacity of the storage to its advantage and to not overuse power generator although some excess energy occurred, which is not ideal.

Comparison of Microgrid Performance Using Switched and Non-Switched HMPC Control
Turning now to the second test, the developed switched HMPC approach is compared with standard, single hybrid MPC. The analysis is based on a 48-h long simulation including both the sunny and cloudy days, as well as two grid-connection mode transitions. The numerical data produced as a result are gathered in Table 3 and matching charts are presented in Figure 8. Firstly, as Table 3 shows, C mg and C b are higher for the case of single hybrid MPC by about 12% and 34%, respectively. This denotes that, although P g charts for both cases seem similar, single HMPC tend to use the generator to a slightly greater extent. What is more, switched HMPC tend to buy significantly less energy in the on-grid mode based on data contained in Figure 8. Besides, there is no excess energy at all in off-grid mode, regardless of the control approach and both control laws make the grid sell a substantial amount of energy. Interestingly enough, as presented in Table 3, a single HMPC manages to achieve 67% greater income from energy sales compared to the competitive solution but its summary operation cost is higher by about 12%. This leads to the conclusion that overall energy exchange with the public grid is more efficient in the case of switched HMPC, especially considering identical C st values and similar P g values over the whole simulation period. Another point is that switched solution also provides 8% higher average state of charge (calculated as percent relative difference). Figure 8 illustrates that both solutions exhibit similar trends in respect of SOC, although, considering E b and SOC, switched approach seem to provide a slightly more consistent storage energy level than the single MPC solution. This can prove important when considering the storage life cycle. Nevertheless, the single MPC provides 5% higher average β value even though it features a greater extent of load shedding penalization. Still, the share of the controllable load in overall energy demand is relatively small and it does not translate into significant gains in economical terms. Admittedly, the performed test shows that switched HMPC approach has a slight advantage over single HMPC control not just in terms of economical benefits.

Comparison of Switched and Non-Switched HMPC Control Performance in Various Connection Scenarios and with Varying Initial Storage State of Charge
The previous test shows the advantage of switched hybrid MPC on the example of a single scenario but it falls short in proving its superiority in a wider variety of circumstances. Therefore, to somehow address obvious concerns about the adequacy of the proposed solution third testing routine is introduced. Through preliminary testing, the initial state of charge SOC(0) and the time of the transition between on-grid and off-grid operation t o f f are selected as key factors with possibly the biggest impact on simulation results. Finally, as mentioned in the previous section, 49 simulations covering various combinations of SOC(0) and t o f f are conducted, and gathered data is used to create surfaces shown in Figure 9. Although the third testing procedure is the most complicated one, conclusions based on the relation of both surfaces are rather simple. As it turns out, the quantity of time in different operation modes has the biggest impact on total microgrid operation cost, while the impact of the initial state of charge is rather marginal. The single most striking observation to emerge from overall cost comparison is the fact, that the cost-surfaces do not intersect and the surface related to switched hybrid MPC is located below the surface tied to the single HMPC, which in turn, proves that in all 49 cases, overall operation cost is lower when utilizing the novel solution proposed by the authors. The greater the share of off-grid operation, the more significant the gains become, which may seem obvious considering two oriented on specific mode cost functions as opposed to only one. Averaged total operation cost reduction amounts to 6.26% when using switched MPC with a maximal cost reduction of 11.23% and a minimal reduction of 3.12%, which proves the adequacy of the proposed method based on simulation data available to the authors.

Conclusions
Research presented in this paper led to the development of a microgrid economical optimization strategy based on switched hybrid model predictive control as well as a compatible microgrid hybrid model on the basis of which the receding horizon control algorithm operates. The performance of the proposed control scheme was analyzed through three-stage simulation testing using real solar generation data and real energy demand profiles. The study was intended to compare and contrast the level of performance gains offered by switched model predictive control compared to non-switched one. The introduced solution proved to be effective in changing grid connection conditions and renewable energy generation regardless of the grid-connection scenario. Its usage led to a 6% averaged total operation cost reduction in comparison with the single HMPC strategy. Another important point is that the greater the share of off-grid operation, the more significant the gains become. Besides, this profit is made mainly due to better renewable energy utilisation management. An obvious drawback is the lack of means of energy demand and production forecasting, which means optimization is performed assuming constant demand and production over the prediction horizon. This is not ideal but, given the fact that the system presented in this paper manages to work well without forecasting certain data, this approach can be deemed useful for simple systems. Nonetheless, implementing such functionalities could noticeably improve performance.
Despite needing minor amendments, the proposed solution can be used in microgrid management systems intended to cope with common energy supply interruptions or highly autonomous microgrids in remote regions. Due to generalized microgrid model formulation and commonly available and exchangeable tools, the proposed model and control scheme does not depend on specific equipment or software and should be applicable to any standard microgrid. Given the conceptual character of this study, the authors intend to supplement more functionalities through further research and address shortcomings found during testing. Future work suggests the implementation of advanced energy demand and supply forecasting capabilities, as well as more sophisticated demand-side management functionalities.