Optimisation Framework for Operation of Battery Storage within Solar Rich Microgrids

The growing trend of distributed generation, such as solar photovoltaic (PV) systems and small scale wind turbines have promoted the development of microgrids which are highly dependent on renewable energy. Due to the intermittent nature of renewable energy, these microgrids are generally equipped with energy storage, such as batteries. Batteries are generally operated using fixed control methods, often deviating from the optimal operation. This aspect has created an opportunity to gain improved outcomes for microgrid owners and operators. This research study describes a pathway for designing an optimisation framework which can be used to optimise the charge and discharge operation of battery storage within a microgrid containing a solar PV system. Optimisation is implemented in terms of gaining maximum cost benefit for microgrid owners. The advantages of using model predictive control optimisation compared to fixed control methods for this particular problem, solvers and verification procedures are highlighted. A case study is provided with results including analysis of battery operation, energy usage, and impact on overall tariff. The study describes each step of the control and optimisation platform development ensuring readers to be able to replicate the process utilised.


Introduction
Microgrids are small electrical and/or thermal networks consisting of the distributed generation which can be connected to the grid, to import or export its energy, or disconnected from the grid to operate in an islanded mode [1]. The concept of microgrids has been present in electrical networks since the beginning of the age of light when small generations such as coal and gas generators were connected to local loads close by. Then, with the expansion of the electricity grid, large generators were connected to the grid and transmitted through longer networks increasing losses and complexity of maintaining the network. However, distribution generators such as solar photovoltaic (PV) systems, wind generators, fuel cells, etc., which have been the trend of the last decade, has brought back the concept of de-centralised generation capable of supplying electricity and/or thermal comfort to local loads [2]. More recently, microgrids which are solely powered by renewable generation, especially solar PV, have received more attention. This category includes houses with rooftop solar PV and installed battery storage.
Renewable based microgrids are impacted by the intermittency of energy sources [3] and it's not always accounted for in the optimal operation of battery storage. In most cases, battery storage is operated according to a pre-configured control method with no dependency on future variations [4]. Operating renewable based microgrids (focusing on the operation of the battery storage) in an optimal way to potentially create more financial gains and functional opportunities [2].
The progression of implementation of optimisation methods for optimal operation of battery energy storage systems in microgrids, highlighted in the literature, is discussed in Sections 2 and 3. However, none of the research papers provides a step by step pathway of developing an optimisation framework for optimal operation of a microgrid (especially a renewable microgrid).
Developing a model with all the key parameters related to a microgrid and performing analyses based on such a complex model can tarnish the effectiveness of an optimal control process as each and every parameter does not effectively reflect on the optimal operation. Therefore, a structured model formulation with identification of effective parameters in the optimal operation of a microgrid is considered as a necessity in this paper. Comprehensive sensitivity analyses to identify the importance of model parameters are also found to be minimally discussed in the literature and this paper has widely analysed the effect of the associated optimisation model parameters.
This paper comprehensively outlines a pathway of designing an optimisation framework which can be used to control renewable based microgrids containing battery energy storage systems. The paper is structured in a way that the presented modelling information can be used to develop optimisation models for different system architectures such as a PV-concentrated solar power system with thermal energy storage as detailed in [5]. The paper is outlined as follows. Section 2 puts together the need for energy storage systems in renewable-rich microgrids, introducing the battery storage technology, and the requirement for optimisation platforms. Section 3 includes the background work on the research, introducing hybrid system description language (HYSDEL), which enables the usage of model predictive control (MPC) method. The MPC method used for this work is detailed in Section 4. Section 5 describes the anatomy of the real systems with all relevant information, including the usage of multi-parametric toolbox (MPT). The details are provided in a step-by-step process, which cannot be found in the existing literature. Finally, Section 6 comprehensively discusses the results of the analyses, which have been undertaken using the developed controller.

Importance of energy storage
Renewable-rich microgrids are often vulnerable to inconsistent natural energy sources; this is especially the case for solar PV and wind [6]. Therefore, renewable-rich microgrids have to consider inconsistent generation scenarios throughout the year. The void created by the inconsistent nature of renewable generation can be filled [7] using energy storage, which is already widely used in microgrids to provide energy whenever demand arises. Microgrids designed to be marginally above demand will utilise energy storage by necessity on a daily basis, while others will use the energy storage less frequently, e.g. for emergency demand only. Among many energy storage technologies, battery storage technology has been around for long time providing much-needed support to microgrids. It is also evident that battery storage technologies are also used for renewable capacity framing, electric energy time shift, and electricity bill management [8]. This is due to both the uncertainty of renewable energy generation and the lower market rates for energy exports.

Why is optimisation important?
Battery storage plays a major role in terms of the overall operation of the renewable-rich microgrid. Most hybrid inverters, which are used to control battery storages in renewable microgrids, use realtime control where the control actions are based on the present data or pre-configured modes. If an optimisation platform is capable of utilising varying future data (i.e. for generation and loads) to come up with an optimal operation for the battery storage, the savings for the microgrid customers can be improved as the inconsistent nature of the generation is considered in the operation avoiding unnecessary low value exports to the grid.
Further, battery technologies are expensive and this has also been one of the main drivers for optimisation processes, which aims to maximise the financial performance for microgrid owners. Also, battery storage generally has a limited operating lifetime, which depends on the number of battery cycles [9]. Therefore, it is important to balance the flexibility of battery use with impact on lifecycle in the control of charging/discharging. Therefore, significant demand exists for optimisation platforms, which can be used to optimise the operation of battery storage either for profit, reliability, or other improvement metrics.

Optimisation methods
Optimisation models can be derived using a number of different techniques and solvers/software packages. Among the most popular methods are [10]: linear programing; mixed-integer linear/ non-linear programing (MILP/MINLP); particle swarm optimisation (PSO); and genetic algorithm (GA). A method can be selected depending on the structure of the problem, objective function, variables, and related constraints. Similarly, software or solvers are chosen depending on their capabilities of solving different types of problems or models. MATLAB, CPLEX, and GAMS are few of the many common software/solvers [10].
In [11], a comprehensive study can be found on the approaches and methods/algorithms used for implementing optimisation at a planning stage in case of microgrids. The main approaches have been categorised into single-objective optimisation, multi-objective optimisation, heuristic optimisation, and metaheuristic optimisation. The main focus of most of the research articles is the operational scheduling of microgrids.
In [12], a multi-objective optimisation approach has been proposed for a network of microgrids connected to a system. For a microgrid, the objective is to maximise the net gain derived from consuming the available power while the objective for the grid is to maximise the net value derived from providing excess power to the network.
In [13], a business model is proposed for optimal operation of the community-based multi-party microgrid. This has considered critical loads and generators owned by multiple owners operating with unique operating goals.
Although the greater interest is to investigate the optimal operation of single or multiple microgrids connected to a network, it is always important to identify the optimal operation of energy storage systems in microgrids. Previous work on optimising generation and energy storage systems in microgrids, especially with solar PV, are included as follows. Scheduling of generation and an energy storage system of a microgrid system has been conducted in [14] where the objective function minimises the overall cost of electricity in the microgrid while maintaining the self-sufficiency and vital constraints of the battery storage. In [15], another approach can be identified in which optimal charging and discharging patterns for the battery storage system are generated. In both cases, the optimisation is defined as a mixed-integer problem.
Another method can be found in [16] where a rolling optimisation strategy is utilised in order to determine the optimal dispatch for energy storage based on short-term forecast. In this study, the optimisation horizon and time interval are selected as 4 h and 15 min, respectively.

MPC approach for microgrid control
MPC approaches have been used in [17,18] in which the objective is to achieve optimal cost by controlling battery storage. In [18], a similar approach has been undertaken to optimise the operation of a microgrid considering the lifetime of the battery. Most of the MPC approaches have been used in developing energy management systems for microgrids.
Important works related to the MPC approach have been reviewed in [19], emphasising the contributions of each work. Main contributions include minimising the grid involvement cost while utilising the battery storage, minimising the total operational cost of the microgrid, and maintaining other important parameters such as voltage, load shedding, etc.
In [20], MPC is used to maximise the utilisation of a battery to shave peaks in solar PV generation and load profile. Load and generation forecast profiles were used as inputs to make the battery on-off decision based on the developed controller. A similar approach has been utilised in [21] to control charging and discharging of a battery in a residential solar PV system. Here, the primary objective was to minimise the total cost for the customer. A time of use (TOU) tariff scheme was used in the model; however, there is no mention of feed-in tariff during energy export.
Examples of new operational strategies and frameworks for microgrids based on MPC have been reported in [22][23][24], which attempt to minimise total energy cost, carbon emissions, or battery lifetime loss, or increase utilisation of the available renewable energy resources. Performance during grid scheduled blackouts was considered in [22]. The effect of the control horizon, the accuracy of the load forecast and battery health has also been investigated in [24].
In [17], a predictive control framework is proposed to increase the utilisation of the battery to reduce the purchasing of electricity from the grid. It also provides a more realistic model of the battery considering leakage current and a switched model with charging/ discharging functions.
An MPC approach has been used in [25] to manage the thermal and electrical energy in a combined cooling, heating, and power microgrid in terms of achieving economic operation. In this work, two different tariffs have been used for import and export.
Another MPC based approach can be seen in [26] which stores and distributes energy in an efficient manner in the microgrid. This has been obtained while minimising the charge/discharge cycles to increase the battery life. However, the work itself suggests the complexity of solving these types of problems when more constraints are considered.
In [27], the study presents an MPC scheme which is designed to optimally manage the thermal and electrical subsystems of a smart house. The objective is set to minimise the expense for buying energy from the grid while gaining thermal comfort levels. This paper discusses the importance of using a hybrid dynamical model when the binary control inputs are used together with continuous inputs.
A preliminary study on applying MPC technique to efficiently optimise the microgrid operations can be found in [28]. This is done while the important operation constraints and a time-varying request are met. The main objectives are the unit commitment, the economic dispatch of distributed generators, obtaining the time of charging/discharging the storage, and the decision on the time and amount of energy purchased from the grid. Further, this emphasises the importance of using a technique like MPC to solve the problem using commercial solvers without resorting to complex heuristics or decomposition techniques.
In [29], an optimal control strategy has been proposed using MPC to coordinate energy storage and a diesel generator in a rural A supervisory MPC method has been developed in [30] for optimal power management and control in a hydrogen-based microgrid. This is designed based on two main objectives where the first one is to calculate power reference signals to electrolyser, the fuel cell, and the grid in order to satisfy the user power demand while the second one is to maintain the optimal duty cycles, operational constraints and energy savings.
Another use of mixed logical dynamical (MLD) systems where both continuous and discrete dynamics are captured and an MPC technique to maximise the economic benefits to hydrogen-based microgrid and minimise the degradation in the hybrid energy storage system, can be found in [31].
Also, stochastic MPC (SMPC) approaches can be found in the literature, which have taken the forecasting uncertainties into account. In [32], an SMPC approach has been utilised for integrated energy management in a microgrid, wherein the forecasting uncertainties of loads, generation, and electricity prices have been considered.
In [33], an energy management system has been proposed for a domestic microgrid, which contains solar PV, battery storage and domestic hot water tank in order to ensure the least cost operation. This has been achieved using two different algorithms: one to consider future uncertainties with a deterministic forecast while the other to model the uncertainties as probability distributions. A similar approach can be found in [34] where a two-stage decision process has been proposed to address uncertainties. The first stage uses a stochastic mixed-integer linear programming, whereas the second stage is based on a nonlinear programming formulation.
In [35], a control strategy has been developed using MPC to incorporate battery aging cost. This problem is solved to find the optimal balance between the utility cost and the battery life cycle cost. The study has demonstrated the effectiveness of the proposed method using a case study with different control simulations for a commercial building. Another study can be found in [36], where a TOU-MPC-based energy management system has been proposed for a commercial building to minimise the electricity cost of the building. Also, [37] has proposed an optimal residential MPC energy management strategy with PV microgeneration. The intention of this study is to achieve best temperature comfort levels and energy costs while deciding on the best TOU electricity tariff option. This study has also provided a comprehensive comparison between the MPC method with the normal on/off control and the proportional integral derivative control for a domestic heating ventilation and air conditioning system.
The literature has not covered a comprehensive pathway of developing optimisation platforms, which can enable online analyses and controlling of the battery storage systems, taking the tariff structures and constraints of the battery storage into account, especially the cost for charging/discharging and the changes in the usage of the battery storage due to the optimal operation. In the next section this paper provides such a pathway: (i) identifying the need for HYSDEL in the optimisation process, which enables the usage of the MPC method; (ii) describing the anatomy of the HYSDEL model with all relevant information including the usage of MPT, which cannot be found in the literature; (iii) comprehensively discussing the results from the case study model, which has been carried out using the developed controller; and (iv) studying the vitality of different verification methods for optimisation solutions, which are rarely discussed in the literature. Emphasis is given to the relationship of the battery usage with the export tariff and battery charging/discharging cost.

Methodology
The goal was to formulate a charging/discharging pattern for the battery bank of a microgrid shown as in Fig. 1, for each day, while minimising total electrical energy cost. Therefore, the objective function of the system was set as follows: where Z is the total cost for electrical energy; G i is the forecasted generation for the ith hour; L i is the forecasted load for the ith hour; T i is the electricity tariff rate for the ith hour; x i is the battery charging/discharging for the ith hour. The main constraint of the optimisation was the state of charge (SOC) of the battery bank, where SOC is maintained between 0.2 and 1.0 per unit of battery capacity [38,39]. The minimum SOC value has been decided considering an energy reserve for emergency loads, if it exists [14].
In the preliminary study, the export of electrical energy to the point of common coupling was considered as a saving to the precinct and assigned the negative value of the tariff rate of the particular hour. This was valid only for the definition of the export energy as a saving. However, the intention was to define an optimisation model having separate import and export tariffs. Therefore, additional conditional constraints were required, assigning an import tariff when the microgrid imports and export tariff when it exports. This is defined as follows where the T Ex is the export tariff and T Im is the import tariff.

Why HYSDEL?
Direct applicability of MATLAB optimisation functions was not possible as this particular case contains conditional constraints, which cannot be dealt with as yet by any built-in MATLAB optimisation functions. Decomposition methods or rearrangement of the objective function may have been used; however, this would have added more complexity to the problem formulation and contributed to computational times. Therefore, the search of a solver/platform, which can handle these types of conditional constraints, directed the study towards HYSDEL, which can be used to model the logical systems in a general mathematical representation [40], which then can be used to solve using MPT [41]. Hybrid systems are models which contain continuous components as well as discrete components which are associated with logic devices. These can be switches, digital circuitry or software code, and clearly match the needs of this particular case where conditional constraints exist.

What is HYSDEL?
HYSDEL is a language which can be used to represent a hybrid model more in abstractive level which can be easily formulated similar to the handwritten mathematical formulation. Then the HYSDEL compiler is used to convert the model into a computational model, which can be used in system optimisation [42].
HYSDEL specialises in describing continuous models combined with logical conditions. HYSDEL compilers generate compact computational models which are generally more efficient compared to the models acquired from other general-purpose modelling software. Formulating a system, which contains logical behaviours, using general-purpose optimisation software tools can be tedious and complex. HYSDEL is run in MATLAB environment, which makes the coding and post-analyses effective.

MPC method
MPC method has been used in different study areas for more than three decades. The general definition of MPC is to come up with a profile of a future manipulative variable to optimise the output (objective function) [43]. The optimisation is carried out within a specific time window, which is known as a receding or control horizon.
When applied to microgrid operation, the future charging/ discharging amounts of a battery bank will be computed to optimise the total electrical energy cost incurred by the microgrid. The process shown in Fig. 2 elaborates how the MPC can be used to optimise the charging/discharging amounts by using past and future generation (G), loads (L), and the battery charging/ discharging (x) values with cost profile and constraints.

State-space model for the microgrid
The following generalised state-space model is used in HYSDEL to represent the microgrid. , where P PV is the active power generated by the solar PV system, P ESS is the active power import/ export (charging ( + ve)/discharging (−ve)) from the battery, P L is the active power load supplied by the microgrid P grid = P PV + P L + P ESS (4)

Constraints
The model should satisfy the following main constraint related to the battery storage where the SOC of the battery storage should be within the assigned limits. The SOC min and SOC max are dependent on the type and properties of the battery storage used.
The other major constraint, which is considered in this particular research, is the charging or the discharging rate of the battery storage i.e. P ESS . The charging/discharging rate of battery storage depends on many factors. It can simply be a fixed value or an output of the complex relationship of other factors such as voltage and current.

Control horizon
The control horizon of this particular model for a renewable microgrid is critical in many ways. At a given state there are four variables including the state variable and the inputs. At least two major constraints are involved in the same stage. As the control horizon increases the number of total variables and constraints considerably increase as the solving should take in all the variables and constraints included in the control horizon. Therefore, if the instantaneous power is considered with a control horizon of 24 h it will put the pressure on the solver as the number of variables and constraints are increased. Comparatively, if the control horizon is reduced, the applicability of an MPC model for a renewable microgrid will be debatable as the renewable generation especially the solar PV generation varies within a 24 h period.
However, if the electrical energy for an hour is considered, there are only 24 states for a control horizon of 24 h reducing the complexity of the model. The final HYSDEL model, which has been used contains a control horizon of 24 with electrical energy is considered for each state.

HYSDEL model for solving the proposed problem
The optimisation of the case study system discussed in Section 3 was primarily focused on charging/discharging of the battery bank, while the solar PV generation and load are assumed to be known. The tariff schemes are the main reason why the HYSDEL is used. There are separate tariff values for import and export, which depend on both microgrid condition (import/export) and charging/discharging value of the battery. This type of complex logical relationship can be represented in HYSDEL and then converted into the computational model using HYSDEL compiler.
The model discussed in Section 4 was then represented in HYSDEL. Fig. 3 indicates the process of how HYSDEL compiler was used to convert the model into a computational model, which then can be used in MPT to solve and obtain the results. Table 1  summarises the terms used in the HYSDEL code and referred to in the latter sections. The relevant code is shown in Fig. 4. Solving the developed model using MPT needs to satisfy the requirements of the controller.evaluate() function.
The solution of the function outputs u, feasible and openloop. They are the first element of the optimal control sequence (charging/discharging amount), the Boolean flag indicating whether the optimisation problem is a feasible solution (feasible = 1) and open loop predictions of states, respectively. The controller is the MPC controller generated by MPT based on the HYSDEL model and other parameters, which are discussed in the latter part of this section. Initial conditions are indicated by the x0 and the above command is capable of taking only one vector of initial conditions. This required finding ways of taking in all the inputs in the microgrid system as described in the HYSDEL model (4) while the charging/discharging amount of the battery storage needs be kept as the control input which can be obtained by solving the controller.
As per above, the representation of the model in HYSDEL and solving it using MPT is not straight forward and the following comprehensive steps elaborate the process (refer also to the complete HYSDEL model in the Fig. 4).

HYSDEL model
In the model discussed in Section 4, there is only one state variable, which is the SOC of the battery storage. This state is represented as x in the HYSDEL model. However, to overcome the issue related to the initial conditions, the inputs related to the solar PV generation and the loads are defined as the state variables in the INTERFACE section in the HYSDEL model along with the remaining input (charging/discharging amount), output, and the parameters.
The other major section of the HYSDEL model is the IMPLEMENTATION section where auxiliary variables are defined with other major components of the model. These auxiliary variables are used to connect the (5)-(9) and (10) and declared in the AUX section. Auxiliary variable delta is declared as a Boolean variable, which represents the condition of the microgrid. If the microgrid exports electricity, delta will be one and else will be zero.
Equation (5) is derived in the AD section where the analogue to digital conversion is declared. Then, depending on the state of delta, the relationship defined in (9) and (10) is derived, which is a case of converting the digital condition to an analogue relationship. This is represented in the DA section, which will derive the cost function (6) depending on which tariff scheme is to be used based on import/export of energy from the microgrid.
Then, the MUST section is used to specify constraints on the states, input and output variables. Maximum charging and discharging amount per hour is assumed to be 40 kWh, while the SOC of the battery can be between 20 and 100%. These parameter values can be any value depending on the type of battery storage that is used in the microgrid.
Finally, the CONTINUOUS and OUTPUT sections are declared where the CONTINUOUS section describes the state equation. As there are extra state variables, a special method discussed in [44] is used to keep the continuity of the extra state variables.
The rolling sequence of the extra variables is defined in the CONTINUOUS section. Then the complete HYSDEL model can be used to solve using MPT.

MPT codes
MPT provides more efficient computational methods to obtain controllers for constrained optimal control problems. MPT also works on the MATLAB environment. MPT provides the mpt_import() function to convert a system described on HYSDEL to a model, which can be used to solve by obtaining a controller.
The system structure and problem structure variables, which are used in the mpt_import() function can be created using specific functions. mpt_sys() function will generate a MLD representation of a hybrid model, defined in a HYSDEL file, which then can be used as the system structure variable (sysStruct).
probStruct or the problem structure is the section where the parameters are assigned to MPT to solve the optimisation problem. In order to define this, there are defined problem structures present as norm1, norm 2, and norm infinity [45]. Linear cost functions are referred to as 'norm1' while quadratic cost functions and min/max problems are categorised into 'norm2' and 'norm infinity', respectively. Further, 'norm1' and 'norm2' problems can be given by the following equation [46] min where u is the vector of manipulated variables; N is the prediction horizon; p is the linear norm; Q is the weighting matrix on the states; R is the weighting matrix on the manipulated variables. When solving using MPT, the user can specify the problem type using the mandatory fields under the probStruct variable which are given for the above-mentioned variables in (12). Prediction horizon, weights on the states, weights on the inputs, norm, and level of optimality fields were defined in this particular problem while two other optional fields were selected out from the ten other optional fields.
probStruct.Qy: This field is used for output regulation. The controller will regulate the output(s) to the given references (usually zero, or provided by probStruct.yref).
probStruct.yref: This field is used to assign a reference value for the output regulation.
In this particular case Q and R are the output weight matrices and are selected to be zeros. The size of the Q matrix should be equal to the number of state variables, which is 49 in this model and the size of the R is set to be one as the number of inputs is one. The level of optimality is set to be the default (zero), which the cost-optimal solution leads to a control law that minimises a given performance index. This case is a linear objective function and therefore, the performance index is selected to the 'norm1'.
Once the mpt_import() function is run, the model will be created which then can be used to generate the model predictive controller using MPCController()function which takes in the model created from the function and the control horizon defined in the problem structure.
Finally, the task is to solve the model with the inputs (extrastate variables) and the initial state of the state variable using the controller.evaluate() function, which was explained earlier in this section.

Optimisation results for the proposed case study
As a case study model for this study, a grid-connected microgrid, which consists of 166.5 kWp solar PV, electrical loads, and an energy storage system (battery bank), is considered. A 100 kWh Li-ion battery storage system is designed [47] for the microgrid and considered in the analyses.

Solver-dependent results
The effect of the optimisation solvers on the simulation results is comparatively high. This is evidently true with any generalised optimisation formulation. Therefore, it is highly essential to gauge results using different solvers. Also, the processing time varies with different solvers, e.g. for the case study system, the CPLEX solver outperforms the GLPK solver as the time required when the GLPK solver was used was comparatively higher. Therefore, the CPLEX solver was assigned to solve the model. Fig. 5. indicates the load, generation and charging/discharging pattern for the battery, which was obtained using open loop results of the MPT toolbox. Importantly, the tariff structure should be considered. Here it is assumed to be a flat rate tariff throughout the day, and consequently, the charging/discharging outcomes of the battery are not related to the time of the day. The charging/ discharging pattern illustrated in Fig. 5 has been generated in an optimal way as follows: (i) the battery is assumed to be fully charged at the beginning of the day (i.e. SOC is 100% at hour 00:00); (ii) there is a discharging of the battery from 00:00 to 07:00 when there is zero solar generation; (iii) from 08:00 to 16:00 there is excess generation and the battery both charges and discharges to reach a higher profit/minimal cost value; (iv) importantly the generated results show that the SOC level again reaches 100% at hour 18:00 when the next range with no solar generation starts (this is expected as results were generated autonomously without any control instructions); (v) then the last few hours of the day where there is no solar generation, the battery discharges to its' lowest SOC limit (this can be different if a longer control horizon is used which looks ahead another day or further); and (vi) some charging can be seen in hour 18:00 due to the objective of reaching to a minimal cost value and the flat tariff structure.

Verification of the results
For the verification process, it is critical to have a set of benchmark results, which can be compared with the obtained optimisation results. This is important for any kind of optimisation problem. With the problem model developed, the HYSDEL-MPT toolbox is able to generate results for any data set, however it is necessary to justify the results to showcase the importance of the optimisation platform. Therefore, the first step was to perform 'brute force' analyses to generate (all potential) feasible results, which can be used to justify the optimisation results. This was a complex method as it generates a large number of data patterns. Filters and assumptions were used to narrow down the amount of usable data patterns. Further constraints could be used to filter the optimal results and limit the number of occurrences for each optimal value, e.g. a cost per cycle or cycle limit could be assigned for the number of battery cycles.
However, the reliability of the 'brute force' method is dependent on the resolution of the generated data. In this case, the patterns were generated using combinations of charging/ discharging values −40, −20, 0, 20, and 40 kWh/h. If the resolution of the charging/discharging range matrix is higher it will take more time to generate the combinations. Fig. 6 shows the number of times each optimal value has occurred, illustrating how multiple instances of charging/ discharging patterns generate the same optimal cost value. Further, it indicates that the optimal value is a point closer to the zero and the number of patterns is a lower value. Therefore, this is a clear indication that the pattern obtained from the MPT generates an optimal cost value. The other process was to manually generate charging and discharging patterns for each hour in a way how a fixed control [48] battery storage (connected to a typical real-time control-based hybrid inverter) would react to. Then those patterns were used to obtain cost values for the particular day and then observed whether the values are in a close range of the values obtained by the optimisation program. In this case, also it was evident that the optimisation program generates more feasible results or rather best charging/discharging pattern in order to gain an optimal value for the cost.

More controllability using terminal constraints
One important factor of using MPT toolbox is the availability of the terminal constraints. This allows the user to assign a constraint value, which should be reached at the end of the control horizon (e.g. at the end of the day).
For the case study, SOC was used as the terminal constraint. The optimisation model was modified in a way this will generate charging/discharging patterns, which give a pre-defined SOC level at the end of the control horizon while maintaining the objective of reaching an optimal value for the electrical energy cost of the microgrid. This scenario was tested and the results are presented in Figs. 7 and 8.
According to Fig. 7, the SOC level at the end of the control horizon has reached the pre-defined value, which is 1.0 (100%). This is advantageous if the microgrid does not use a closed loop controller with comparatively longer control horizon, which is capable to adjust the charging/discharging patterns depending on the existing system state and future forecasting. In that case, these terminal constraints can help to maintain the SOC level to a predefined value, e.g. fully charged state, so that the microgrid is ready for another day of operation. Similarly, Fig. 8 shows the charging/discharging pattern when the pre-defined SOC level was assigned as 50%, which leads the electrical energy cost value to AUD$ 0.88 compared to AUD$ 6.88 in the case of SOC equals to 100%.

Closed-loop analyses
Even though the open loop results are the optimal results for a particular day, for which the generation and load profiles were forecasted at the start of the day, the real profiles change with every hour as the day continues. This will lead to a variation of the optimal results whereas the battery charging/discharging profile remains same for the whole day if the results are taken from the open loop results.
Closed loop analysis will enable the ability to foresee the future (prediction/receding horizon) and adjust the control output (charging/discharging) to obtain the optimal results on a continuous basis. For the analyses, different scenarios can be considered. In this case, two consecutive days are selected with 24 h prediction horizon.
The generation and load profiles are kept the same for two days while the charging/discharging profile is generated considering the day ahead. The only feedback used for the closed loop was the SOC of the battery. Fig. 9 shows the results for the closed loop analysis for two days containing the same generation and load profiles. It is illustrated that at the end of the day one (at the 24th hour) the SOC level has been raised to a suitable level in preparation for the next 24 h prediction without any SOC level constraint. To demonstrate the performance of the closed loop controller, another scenario was created with zero solar generation ahead (worst case scenario), for which the system generated a charging/discharging profile that brings the SOC level to a higher level compared to the previous case, as required.

Cost for charging/discharging
Li-ion batteries tend to have more life span than the other types of batteries. However, the installation of a battery storage system demands associated cost considerations. The operational costs of the battery, especially related to charging/discharging were not initially considered.
In order to examine the effect of the cost of charging/ discharging, the objective function is changed by adding a cost for charging/discharging of each 1 kWh unit and the associated results are analysed. The cost for charging/discharging is then changed in a range while all the other values and constraints discussed above in the open loop analysis remain the same. The results show the battery goes to an idle mode where it does not charge/discharge further, due to the cost of the charging/discharging. This demonstrates that battery charging/discharging cost, usage of the battery, and export tariff all need to be carefully considered to observe the feasibility of a battery storage system in a microgrid.  Table 2 shows the variation of battery usage with different battery cost per 1 kWh usage. It is evident that the usage of the battery goes down even with increments of AUD$ 0.01/kWh and gradually the battery storage system only uses the energy of the pre-charged battery, and then leads to idle operation. This analysis is based on export and import tariffs of AUD$ 0.05/kWh and AUD $ 0.12/kWh, respectively, as acquired from [49]. In Table 2 the values at which battery charge/discharge cost is approximately equal to import/export tariff are highlighted. These two costs may be used when a battery type needs to be selected for a project (most battery manufacturers provide a charging/discharging cost in terms of $/kWh).
The relationship between export tariff and battery usage was also analysed. Fig. 10 shows the variation of usage of battery storage with the export tariff for each battery cost. There is a significant difference between no allocated cost for battery usage to when battery usage cost was AUD$ 0.01/kWh. Similar behaviour of the battery usage is observed for each case around the point where export tariff equals import tariff (AUD$ 0.12/kWh). However, there was a significant change after battery cost reached AUD$ 0.07/kWh where the battery goes to idle mode (no operation). This continues until the battery comes back to operation when the cost is AUD$ 0.13/kWh. Therefore, the designed battery (100 kWh) for this particular microgrid may be infeasible if the battery cost is within the range AUD$ 0.07-0.12/kWh and the export tariff falls in the range AUD$ 0.00-0.15/kWh. Graphs similar to Fig. 11 may be useful when selecting the battery storage systems for microgrids. Fig. 11 indicates the optimal cost variation for each case and illustrates where each cost variation sits compared to the no battery storage system case. The higher the battery charging/discharging cost, the closer the optimal cost graph gets to the cost surface with no battery storage system. In regions where battery charging/discharging is higher, it can be seen that the optimal cost is higher than to the no battery cost.
Above initial analyses were mainly focused on the export tariff structures as it is a selective factor for the microgrid customer whereas the import tariff may not differ greatly from utility provider to provider.
However, the effect of import tariff along with the export tariff together on the optimal cost and the usage of the battery were analysed. For this particular analysis two different battery charging/discharging costs were used.
Figs. 12 and 13 both show how the MPC open loop controller performs better than the simple battery controller (SBC), which is discussed in [48], as the 'MPC' surface of the figure deviates from both 'No Battery' and 'SBC' surfaces. These figures also show another factor where the SBC poorly performs than the no battery values, in a low import tariff region (especially for the import tariff values lower than the battery charging/discharging values), where the 'SBC' surface emerges through the 'No Battery' surface. According to Fig. 13 the area where the SBC performs poorly compared to the no battery operation has increased with the higher charging/discharging cost.
Further insight was needed to identify how the battery usage varies with all three factors, i.e. import tariff, export tariff, and  charging/discharging cost. Fig. 14 illustrates how the battery usage has affected by the three factors. The battery usage drops with the increase of the import tariff and levels into an idle value where the battery is limited to operate only to that kWh value (166 kWh). Then, when the battery charging/discharging cost is increased to AUD$ 0.05, the battery drops its usage to the idle value at a lower value of import tariff compared to AUD$ 0.01 charging/ discharging cost. These findings further emphasise the benefit of using the MPC method, as it generates optimal results compared to SBC or no battery operation.

Conclusion
The objective of this paper was to discuss the pathway of developing an optimisation platform and the associated case study results. A descriptive section is included in regard to defining a real controller on the HYSDEL and solving the optimisation problem using MPT, as it is often one of the bottlenecks associated with conditional constraints. This is required when different import and export tariff, as practically exists, are used in the controller. The case study has highlighted a number of practical issues with implementing the optimisation platform. Terminal constraints were used to obtain preferred horizon SOC levels for the battery, thereby ensuring self-sufficiency in case of no local generation in the microgrid.
Closed loop results have proved the controller can be used when taking into account existing system state and future predictions of load and generation. The effects of using the battery cost as a constraint in the optimisation model can establish the feasibility of selecting different types of batteries with different charging/discharging costs. An extension of this work will be to assign TOU tariffs as opposed to flat-rate tariffs.