A Multi-Criteria Computer Package-Based Energy Management System for a Grid-Connected AC Nanogrid

The electric system scenario has been changing during the last years moving to a distributed system with a high penetration of renewables. Due to the unpredictable behavior of some renewables sources, the development of the energy management system is considered crucial to guarantee the reliability and stability of the system. At the same time, increasing the lifespan of the energy storage system is one of the most important points to take into account. In this sense, a software package implemented in the computer algebra system Maple is proposed in this work to control a grid-connected nanogrid with hybrid energy storage system (composed by batteries and supercapacitors). The energy management system considers several rules as the state of charge of the energy storage system, the photovoltaic power generation and the load profile, the nanogrid power trend and the energy prices. The improved performance of the nanogrid is proven by simulations in MATLAB/Simulink.


Introduction
The European Commission defines as main goals for 2030 a 40% reductions in greenhouse gas emissions compared to 1990 levels (although an increase up to 55% was recently established), a 32% share of green energies in the generation mix and an improvement of at least 32.5% in energy efficiency [1]). In this sense, a high penetration of renewable energies is currently being experienced.
Concurrently, microgrids (MG) are intended as the essential building blocks of smart grids, being the latter defined as "electricity network that can intelligently integrate the actions of all users connected to it (generators, consumers and those that do both) to efficiently deliver sustainable, economic and secure electricity supplies" [2]. At the same time, nanogrids (NGs) with various electric appliances were defined as kW scale smart grids that can combine different power sources with the help of information technology [3]. In the context of this paper, a NG is understood as a single-end user with embedded generation, storage and loads. Some examples of NG applications include households, buildings, businesses and campuses. This concept has been studied in several works in the last few years [4][5][6][7]. The NGs usually include emerging technologies as new power electronic converters acting as interfaces to distributed energy resources (DER), mainly based on renewable energy sources (RES) (e.g., solar and wind), which are able to operate in both grid-connected (GC) [4] and stand-alone (SA) [8,9] modes to supply the local consumers. The use of the energy storage system (ESS) is crucial in the NG operation to guarantee the continuity of supply. The optimal use of these resources allows the NG's users to obtain energy bills savings as the electricity is mainly supplied by the RES. Furthermore, profits for owners of ESS and RES also rise because they can sell the energy to the utility grid during high-price periods [4,10] or they can even locally optimize their resources by using a peer-to-peer energy sharing approach [11].
The "brain" of the NG is the energy management system (EMS), which determines the power flows between the main grid, the loads existing in the NG, and the different DERs to achieve a finite set of goals, providing several benefits for the NG´s stakeholders. Some of these goals may include: a reduction in the NG operation costs, to maximize the overall efficiency, to minimize the peak demand and to minimize emissions or the fuel usage among others [12]. Communication between the EMS and other devices and sensors installed in the NG allows an optimal energy management by the EMS, collecting and computing some parameters, e.g., state of charge (SOC) of batteries, weather forecast, energy prices and consumption profiles [10]. Both DER and ESS are equipped with power electronic interfaces that are capable of tracking the set-points given by the EMS.
Once the NG topology has been designed and the main objectives to be met by the NG have been determined, the EMS can be implemented by different manners and techniques The techniques used for the EMS implementation in NG applications found in the literature can be based on: fuzzy logic control [10,[13][14][15][16], linear programming [4,5], integer programming [17], dynamic programing [8], neural networks [10], a finite state machine [18], game theory approaches [7,19] and model predictive control [20]. The EMS for NG based on linear programming approaches defines a feasible region which is used to find the optimal solution considering a set of linear inequalities [4,5]. In order to reduce the computational time, the integer programming technique can be an alternative as expenses of relaxing the constraints, but the accuracy is sacrificed [17]. A neural network-based EMS has the advantage of being adaptive (with reinforcement learning) and being able to learn complex models. In fact, for our application field, the neural networks are commonly included in the forecast stage (e.g., solar irradiance) [10]. The implementation of a finite set of states to determine the operation mode of the NG by means of a finite state machine was studied in [18]. The main objectives were to provide ancillary services to the grid and to guarantee a coordination with the distribution system operation. From another side, some EMS for NG determines the operation mode by means of the Nash equilibrium point of the game [7,19]. This kind of method highlights because the motivation and incentives they generate among the users. Finally, model predictive control was used in a smart building EMS [20]. The basis of this technique is the analysis of the future trajectories of the plant states in a defined prediction horizon. Its main drawback is to require many plant parameters that can usually be unknown.
Fuzzy logic stands out among other control approaches for the design and implementation of EMS. Thus, this technique has been widely applied. In [13], fuzzy logic is applied to regulate the operation of the ESS of a direct current (DC) small microgrid and the energy trading. This fuzzy logic-based approach can also take into account the evolution of the energy prices, generation and demand [13]. As previously mentioned, if the MG/NG includes controllable loads (smart lighting, water pumps, etc.), the fuzzy logic control can perform some demand response strategies. Following this approach, an EMS for a residential grid-connected MG architecture based on wind and photovoltaic (PV) sources and ESS based on batteries is proposed in [14]. This study implements a 25-rules based fuzzy logic control to smooth the power exchanged with the utility, but meeting at any time the power consumption and some ESS constrains. An extension of previous works that considers the problems derived from the unpredictable nature of the energy consumption and production can be found in [15]. In that document, power demand and generation trends are included as extra inputs to the fuzzy logic controller (consisting of 50 control rules that define the operation of the EMS). The optimization of such an approach in order to reduce the system complexity is presented by the same authors in [16].
In this work, a software package in the computer algebra system Maple (Maple is a trademark of Waterloo Maple Inc.) is developed and implemented as EMS for a grid-connected alternating current (AC) NG with a hybrid ESS and a PV system. The package is based on a multi-criteria system approach, where several rules related to individual SOC, PV power, maximum charging/discharging ESS power, demanded power, NG power trend and energy prices are computed. The main goals of the proposed EMS are: i.
to smoothen the power exchanged with the utility;(be list format, and add the full bracket) ii.
to keep the SOC within secure thresholds; iii.
to apply energy curtailment to the PV power if required (when, for example, power injection into the utility network is not permitted by contract and there is a situation of high PV production, low local load and batteries fully charged); iv.
to guarantee a safety operation of the hybrid ESS in terms of power rating; and v.
to maximize the revenue coming from energy trading with the utility.
The contribution of this paper is as follows: 1. A new multi-criteria approach based on rules or knowledge is included in the EMS for controlling the operation of a NG. 2. The hybrid combination of batteries and supercapacitors at the residential level in the considered grid-connected NG is quite interesting for increasing the lifespan of such infrastructure. 3. The proposed package can be easily upgraded by including other rules or parameters in a very easy way. This fact is possible due to the powerful algebraic capabilities of Maple.
The rest of the paper is organized as follows. Section 2 describes the architecture and main variables of the NG under study as well as its modelling. Then, in Section 3; rules, constrains, thresholds and priorities are carefully described to develop the EMS. Sections 4-6 detail the step by step design of the multi-criteria computer package. Section 7 illustrates the NG performance through simulation results using MATLAB/Simulink (MATLAB and Simulink are registered trademarks of The MathWorks, Inc.) where the SOC improvements for both the battery and the supercapacitor are represented. Finally, Section 8 presents the main conclusions of this work.

Nanogrid (NG) under Study
The architecture of the residential NG under study is represented schematically in Figure 1. It is composed of a PV array with a peak power equal to 4 kW. The NG is capable to store electrical energy in the hybrid energy storage system (HESS) based on the association between a lead-acid battery pack and supercapacitors. The rated capacity of the battery pack and supercapacitors are 14.4 kWh and 15 F, respectively. Each of these equipment is connected to the DC voltage bus by means of a DC-DC power converter. A common DC-AC power converter interfaces the NG to the main grid, regulating the power flow between them. The static transfer switch (STS) connects the utility to the system at the PCC. Moreover, household loads belonging to the NG are also connected there.

NG Modelling
The PV and HESS are modelled to emulate the behavior of the DERs. The following subsections describe in detail the model implemented for the NG study by means of their mathematical expressions.

Photovoltaic (PV) Array Model
Manufacturers of PV modules provide the main parameters in their datasheet referred to reference values of irradiance (W) and temperature (T) at standard test conditions (STC), which corresponds to 1000 W/m 2 and 25 °C and a family of curves that illustrates how the panel curves are modified when those values change. An example of the named main parameters is available in Table 1, which shows the main specifications of module Shell SP150 referred to STC. Most of the models in the literature assume the PV cell to be an electrical equivalent circuit ( Figure 2). Those models require some parameters such as shunt resistance (Rsh), series resistance (Rs), the diode factor and the effective cell area. Nevertheless, they are not provided by the manufacturers in the datasheet, so this makes them complex to use. Due to the aforementioned reasons, the mathematical model proposed in [21] is used in the NG study. Firstly, the PV current and voltage (I-V) curve in the STC is fitted and  then the influence of irradiance and temperature is taken into account. The equations that describe the model are expressed as follows (1)-(5): where and are the module current and voltage respectively. Short-circuit current at any irradiance and temperature conditions ( , ) is determined as (2): In (2), , is the short-circuit current at STC, and W and are the current and the reference irradiance (1000 W/m 2 ) respectively. Open-circuit voltage at any irradiance and temperature conditions (VOC,TW) are determined in (3): with , , , and as the open-circuit voltage at STC, the reference temperature (25 ºC) and the temperature and irradiance coefficient respectively. Constants B and τ can be calculated by the expressions (4) and (5), being and , the voltage and current values at the maximum power point (MPP) respectively: To validate the accuracy of the model, these equations are implemented in MATLAB/Simulink using as input parameters those in Table 1. Figure 3a,c represents the curves provided by the manufacturer and Figure 3b,d the simulated ones, respectively.  One of the most common ESS model aims to estimate the battery open-circuit voltage ( , ) as a function of the battery current ( ). The estimated voltage can control a voltage source in series with a resistance that models the instantaneous voltage drop due to the internal ESS resistance. , is obtained from (6) [22]: where 0 is the battery voltage, K is the polarization voltage, Q is the battery capacity, ∫ represents the actual battery charge, A is the exponential zone amplitude and B the exponential zone time constant inverse.
In a similar way, it is possible to develop a generic model based on the supercapacitor parameters. Supercapacitor voltage ( ) is estimated by the Stern Equation (7) [23]: .
, and represents the number of series and parallel supercapacitors, and the number of layers of electrodes respectively.
, d, , 0 , F, R and correspond to the electric charge, molecular radius, permittivity of the material, permittivity of free space, Faraday constant, ideal gas constant and the area between electrodes and electrolyte. Finally, and stand for the total resistance and the supercapacitor current.

Residential Nanogrid Energy Management System
According to Figure 1, the power flow is considered positive in the direction of the corresponding black arrows. Red arrows represent the possibility of each element of the system to operate in unidirectional or bidirectional way. From the same figure, the main power flow relationships are derived as: where PNET represents the net power. PPV and PLOAD corresponds to the PV power and the power demanded by the household loads respectively. At the same time, PHESS, PBAT and PSC are the injected power by the HESS (total storage system, battery and supercapacitors). Finally, PNG is the power generated by the residential NG under study. Furthermore, the power demanded from the utility PGRID is positive when it injects power to the NG.

Hybrid Energy Storage System (HESS) Strategy and Constraints
Both battery and supercapacitor powers must be limited during their charging ( − and − ) and discharging ( − and − ) cycles to ensure their safety and life. In this sense, the following constrains have to be accomplished at any time ((11)-(14)): Just in case any of the previous variables overpass their maximum limits, the EMS will have to saturate the corresponding value, rearranging the energy surplus somehow. At the same time, the HESS has to operate within healthy SOC limits. Assuming that the initial SOC ( 0 ) is known, the current SOC for the battery and supercapacitors can be estimated. The selected method for estimating the current battery SOC is based on the Coulomb counting method, which integrates the battery current flow over time. This method presents a simple implementation and just one measurement is required. In our particular case, the current flowing from the battery to the DC bus is considered positive and the current battery SOC ( ) is determined by Equation (15) [24]: with iBAT (t) and QBAT as the battery current (A) and capacity (Ah), respectively. To determine the supercapacitor SOC (i.e., ), the following expression is derived (16) [25]: In (16), VSC and are the supercapacitor voltage and the supercapacitor nominal voltage. The HESS deals with several functionalities. For example, depending on the energy price, the HESS or the utility will release power when PNET > 0 if possible. The battery and the supercapacitors can also fulfill energy shifting by storing energy in some strategical times. For these kinds of purposes, the SOC is considered as a crucial issue. The ideal situation for any practical NG operation would be to keep the SOC around 50%. To further distinguish a multi-criteria based decision making, five SOC intervals are proposed. The SOC is divided by 4 user-customizable levels, k1, ..., k4, which can be different for the battery and for the supercapacitors. Figure 4 represents such different levels and the action to be taken (if possible). As an example, if k4BAT < SOCBAT < k3BAT and PNET > 0, probably (depending on other factors) the utility will provide power to guarantee the load supply and to charge the battery. Another situation could be that 0 < SOCSC < k4SC and k2BAT < SOCBAT < k1BAT, and, depending on other factors to be detailed later, the battery will inject power to the supercapacitors.
In order to distribute the amount of PHESS that will be delivered or stored by the battery or by the supercapacitor, the following reasons are considered. Batteries are usually devoted to providing the bulk of energy in the long term, presenting a slow dynamic. Meanwhile, supercapacitors are suitable for providing or absorbing the power generation or demand peaks because of its fast response. In this sense, many previous works like [25,26] aim to distinguish between the low-frequency component and the high-frequency component of the power to be delivered/absorbed by the HESS. For this purpose, a conventional low-pass filter (LPF) will be used to extract the low-frequency component, which is LPF( ). Then, the power sharing will be as follows (17) and (18):

NG Net Power Trend
A quite interesting parameter to develop operation rules in the EMS for controlling the NG is the consideration of both the generation and consumption trend within the NG. The NG net power trend ( ) can be understood as the predicted behavior of the net power. This parameter can help to improve the NG capability by storing or delivering power. In this sense, the NG can anticipate a future scenario with a more adequate HESS state. The will help to smooth the power exchanged with the main grid and to improve the SOCBAT, besides contributing to increase the revenues for the NG users. It is important to note that this parameter will have only influence in the low-frequency component of PHESS, that is, in the battery power. Calculation of is based on the derivative of PNET (19): where TS is the sample rate (in the considered case of study is one hour). A positive slope of PNET means that PPV is increased and/or PLOAD is decreased. Nevertheless, a negative slope is related to an increase in PPV generation and/or a reduction in PLOAD. At the same time, values can be classified into several ranges: positive, slightly positive, zero, slightly negative or negative. Thresholds to determine this classification can be user-defined, depending on the power rating. In the NG under study, four thresholds are considered (τ1, τ2, τ3 and τ4) to define five ranges for , as shown in Table 2. An example of a possible rule in our expert system based on the consideration of could be as follows. If τ4 < < τ3 (slightly negative) and k2BAT < SOCBAT < k1BAT (obligatory discharge), and, depending on other factors to be detailed later, the battery will supply the load power instead of the main grid.

PV Power Regulation
The main goal of a PV system is usually the extraction of the maximum possible power from the panels, i.e., operation at the MPP is required. This operation corresponds to the maximum environmental benefits and renewable resources exploitation but, in certain situation, it could be required to apply power generation curtailment, changing from MPP operation mode to reference power point (RPP) operation mode. In this work, the operation at RPP will be taken as a secondary option due to the aforementioned reasons. At the same time, RPP can help to maintain SOCBAT and SOCSC within healthy limits (for example, if PLOAD is low and SOCBAT is high) or for providing ancillary services to the main grid (voltage and frequency regulation). There are several approaches to implement a RPP algorithm in the PV DC/DC power converter. This algorithm calculates the proper duty cycle for the power electronics switches to make the PV array working at any reference working point. In this paper, an algorithm based on the perturb and observe (P&O) method with adaptive step to minimize the power fluctuation is implemented. Details of this method are available in [27]. Figure 5 represents a typical P-V curve where the maximum power point with coordinates (VMPP, PMPP) is marked. The EMS will generate a reference power for the PV system ( ) depending on a specific situation. As can be seen, there are two feasible points that correspond with (x and y). The one placed at the right of the MPP will be the desired one for a better operation as VPV is higher (leading to a reduced duty cycle). For example, if during the NG operation PLOAD is low and SOCBAT is high, and at the same time the utility is not available, the EMS will determine the appropriate .

Energy Price
The NG under study can produce renewable energy for its own usage and sell excess to the main grid. Besides the aim of obtaining a friendly bi-directional operation between the NG and the utility, maximization of revenues is interesting to incentive the NG user in this business model, establishing negotiations with the utility or any aggregator [19]. At the same time, the HESS can store the energy surplus to be delivered during high-price time periods. In the case supposed in this paper, the EMS considers the same energy price for selling the energy by the NG to the utility and vice versa. At the same time, high-price and low-price periods are distinguished.

Comtrol Rules
The proposed EMS strategy consists of a set of rules to control the energy flow between the different components of the NG. The main objectives are the stability and the economy of the system. From the stability point of view, the power generation must satisfy the load demand at any time, and the AC system voltage and frequency must remain within the allowed range. From the economic point of view, the cost must be reduced as much as possible under the premise of guaranteeing system stability. The instructions at time t + 1 are computed using multi-objective optimization rules at time t. Taking into account the consideration mentioned in the previous sub-sections, the detailed rules are summarized in Tables 3-5. The NG is working in grid-connected mode and the PV is operating at MPP. Remind that is not controllable as no demand response strategy is applied. Table 3 shows the rules regarding charging/discharging the batteries and the injecting/extracting power into/from the utility grid, related to conditions about power production and load. The following acronyms are used for the power flows: B2L: Battery to load; B2G: Battery to Grid; G2B: Grid to Battery; N2G: Surplus to Grid; N2B: Surplus to Battery; G2L: Grid to Load. The inputs are SOCBAT and . Each cell is divided into two or four x y PV sub-cells. The latter occupy the central part of the table. Within each cell, the sub-cells on the left represent the case of > 0 and those on the right < 0. On the other hand, also within each cell, the top ones correspond to the case of high energy prices and the bottom ones to low energy prices. When a sub-cell contains two lines, it indicates that two actions are executed simultaneously, both with equal power flow. For the cells outside the central box, the SOC is in the limit zone and presents a strong slope. In such a case, the priority will be to redirect the SOC to the central zone in order to assure the battery health. On the other hand, in the cells in the central box, attention will also be paid to the power purchase/sale price in order to get economic benefits. The reading of one of the cells is given below as an example (the one highlighted in yellow): If ( 3 ≥ ≥ 4 -battery discharged) and ( 1 ≥ ≥ 2 -trends is slightly positive ( ) ) and ( > 0more power is required for PLOAD)) and (price is low) then the load will be supplied by the grid (50%, as the price is low) and by the battery (50%)(as we are not in the state of the battery "strongly discharged"). Table 4 shows the rules regarding the regulation of the SOC in the supercapacitors. The following acronyms are used for the power flows: B2SC: Battery to Supercapacitor; G2SC: Grid to Supercapacitor. Inside each main cell, division in left and right corresponds to high-price and low-price time respectively. Table 5 shows the rules regarding the regulation the operation mode in the PV system: MPPT: Maximum Power Point Tracking; RPPT: Reference Power Point Tracking. Inside each main cell, the division into left and right corresponds to > 0 and < 0.

The Associated Rule-Based Expert System (RBES)
The NG described in this paper is a first step of a new development in the line of research of these authors. Therefore, the method and the representation of knowledge chosen is a frame designed to be reused in more complex (detailed) scenarios.
On the one hand, the experts summarize the electrical knowledge in tables, the conclusions of which have to be concatenated (in this first step that will take place only with Tables 3, 4 and 5, but will be increased when further details are considered in future extensions of this work). The advantages of using rules when deductions have to be concatenated are well known. Tables   Let us use Table 3 to illustrate the procedure. This table is not homogeneous, as some cells have been merged.

Analysing the Structuring of the Information in the
Four variables are considered as input: SOCBAT , P T NET, PNET, price and 5 intervals are distinguished for the first and second variables and 2 possibilities for the third and fourth variables. In the expert system they will be abbreviated for the sake of simplicity: There are 6 possible conclusions (operations modes): GRID2LOAD, GRID2BAT, NET2GRID, NET2BAT, BAT2LOAD, BAT2GRID.
In some cases (cells) there is one operation mode to be carried out, but in other cases there are two to be carried out.
In this case we would initially have a table with 5 2 × 2 2 cells = 100 cells. Nevertheless, the experts in electrical grids have grouped all cells outside the dark black rectangle in pairs (the third variable, z, is not considered for those cells), resulting in double height cells outside the dark black rectangle. One example is the upper left cell: BAT2LOAD is recommended if we have x1 and y1 and u1 (despite having z1 or z2) (these groupings are from an engineering origin: in many cases it does not matter whether we have z1 or z2: the same operation mode(s) is(are) recommended).
The table with abbreviated names of variables can be found in Table 6.

Combinatorial Manual Grouping of the Information in the Tables
For instance, the cell in the upper left corner of the table can be merged with the one below it. The same can be said about the two cells to their right.
There are many other possible groupings. Using colors can simplify viewing possible groupings (a task to be performed by a second group of experts: mathematicians or computer scientists, that have to consider which cells can be easily grouped into a single logic rule or into a few logic rules).
For instance, as exactly one yi must hold (because the intervals considered for PNET T are mutually exclusive), the information provided by all the cells containing GRID2BAT in the lower row of Table 6 (all columns but the last three ones) can be summarized as follows: IF ×5 AND (NOT(y4 AND u2) OR NOT y5) THEN GRID2BAT that is, "in the situation described by the last row (x5) and any of the possibilities for the columns yi (i{1,2,3,4,5}) except ((simultaneously y4 and u2) or y5) then GRID2BAT is operation mode is recommended". If we use the usual logic symbols: ∧ (conjunction), ∨ (disjunction), ¬ (negation) and → (implication), it can be written: Nevertheless, that would imply to include an integrity constraint describing that exactly one yi must hold. A preferable alternative equivalent way to express it (without the need to include integrity constraints) is: that is, "in the situation described by the last row (x5) and the columns (y1 or y2 or y3 or (y4 and u1)) then GRID2BAT operation mode is recommended". An advantage of the logic rule translation is that there are no problems if the groupings do not describe a partition of the set of cells but a covering, that is, if the subsets of cells are not disjointed two by two-that will only allow a conclusion (that is, the operation mode(s)) to be reached by forward firing more than one rule, which is not a problem.
For instance, an exact description of the information provided by the three cells containing GRID2BAT in the antepenultimate and penultimate rows and the first and second columns of the table is: which is equivalent to the two simpler rules: The latter rules describing two intersecting (non-disjoint) subsets of cells (these will be the rules R2 and R3 of our RBES). Note that this is a technique typically used in Karnaugh maps. Table 6. Table 3 with the notation of the rule-based expert system (RBES). NUMBE  R 6   y1  y2  y3  y4  y5   u1  u2  u1  u2  u1  u2  u1  u2  u1  u2   x1   z1 -----z2

About the Inference Engine Chosen
We have decided to use the algebraic inference engine described in detail in [28,29]. Among the many available existing approaches, we have chosen this one because of our experience with it and because of the possibility to straightforwardly move to a multivalued modal logic in future extensions, if necessary. where I = <x1 2 − x1,x2 2 − x2,…,xm 2 − xm> denotes the ideal generated by x1 2 − x1,x2 2 − x2,…,xm 2 − xm. If ∧ ∨Y, and ¬X are translated by x· y, x + y − x· y, x· y and 1−x, respectively, we have a ring isomorphism (or a Boolean algebra isomorphism, depending on the logic and algebraic operations considered).

A Brief Overview of the Algebraic Model for Logic
The advantage of moving to the algebraic model is that we have an effective method for performing computations: Grö bner bases (and the derived normal form of a polynomial modulo an ideal) [30,31].
The main result is that Q is a tautological consequence of P (P→Q) is equivalent in the algebraic model to NormalForm(1 − q,<1 − p> + I) = 0, where p and q are the translations of P and Q in the polynomial model, respectively (and let us recall that 1−p and 1−q are the translations of ¬P and ¬Q in the polynomial model, respectively).

A Brief Overview of the Algebraic Model for RBES (Boolean Case)
The facts, rules and integrity constraints are logic formulae stated as true. The rules and integrity constraints are fixed, meanwhile the set of facts stated as true change (although it must be a subset of the set of potential facts). The corresponding polynomial model presented in the previous subsection was Z2[x1,x2,…,xm]/<x1 2 − x1,x2 2 − x2,…,xm 2 − xm> = Z2[x1,x2,…,xm]/I.

As the facts, rules and integrity constraints are stated as true, if
• J is the polynomial ideal generated by the polynomial translation of the negation of the rules and integrity constraints, and • K is the polynomial ideal generated by the polynomial translation of the negation of the given facts, Then its polynomial model is the residue-class ring: (Z2[x1,x2,…,xm]/I)/(J + K)= Z2[x1,x2,…,xm]/(I + J + K).

The Maple Implementation of the Algebraic Model for RBES
The algebraic model for RBES can be easily implemented in any computer algebra system (CAS). For instance, in the CAS Maple, the implementation is straightforward. Firstly the packages Groebner and Ore_algebra (that allow to define the polynomial ring where the computations will take place) have to be loaded.
Afterwards the polynomial variables have to be declared. For instance, in the case of Table 6, we can store the x, z, y, u variables and the conclusions (operation modes) GRID2LOAD, GRID2BAT, etc. in a sequence (denoted, for instance, SV).
Then the polynomial ring where computations have to take place and the ordering to be applied and the order between variables have to be declared, and the polynomial ideal I has to be defined. At this point we are ready to define the polynomial translation of the logic connectives as Maple functions, which is straightforward and needs just 6 lines of code (the complete code required can be found in Appendix A in order the acquainted reader to be able to reproduce the computations).
For instance, the expression mentioned above: is translated into Rule 2 of the RBES just by typing: R2: = (x3 &OR x4) &AND y1 &AND u1 &IMP GRID2BAT: which is very close to the usual notation in logic.

The Energy Management Nanogrid RBES Developed
The RBES developed will be described afterwards. It has been divided into 3 subsystems, each one dealing with the knowledge contained in one of the Tables 3-5.

Subsystem I
We have written 35 rules, similar to R2 in Section 5.3, that translate the knowledge contained in Table 6 (let as recall that this table is Table 3 with another notation). This translation can be made in several ways. The set (or list) of the negations of the chosen rules is a base of ideal J. Then we are ready to extract knowledge: if K is the ideal generated by the negation of the facts stated as true, the following two lines: Nevertheless, it is usually more convenient to directly determine which of the possible operation modes (GRID2LOAD, GRID2BAT,…, BAT2GRID) are recommended. A brief procedure, that we have denoted operation_mode, allows us to do this with a single order (see Appendix C for details).
Moreover, obtaining the operation modes is not restricted to a single cell. Other more complex tasks can be solved by the RBES (see Appendix C).
Finally, we could underline that it is possible to check that the rules developed correctly translate the knowledge summarized in Table 6 using a procedure developed ad hoc (see Appendix D).

Subsystem II
The variables considered in the five rows of Table 4 were denoted x1,...,x5 in Table 6. The variables in the upper part of Table 4 (SOCSC) are new, and are denoted v1,...,v5, respectively. Each column is divided into two columns, corresponding variables of which (high-price, low-price), were denoted z1 and z2, respectively, in Table 6.
In this case we have written 4 rules that translate the knowledge contained in Table  4. For instance, the first rule, R101, is: ( 1 ∨ 2) ∧ ( 4 ∨ 5) → 2 The corresponding code and the way knowledge extraction is performed is similar to Subsystem I (see Appendix E).

Subsystem III
The variables considered in the five rows of Table 5 were denoted x1,...,x5 in Table 6. Similarly, the variables in the upper part of Table 5 were denoted y1,...,y5 in Table 6. Each column is divided into two columns, corresponding variables of which (PNET positive or negative) will be denoted w1, w2, respectively.
In this case we have written 7 rules that translate the knowledge contained in Table  5. For instance, the first rule, R201, is: The corresponding code and the way knowledge extraction is performed is similar to Subsystem I (see Appendix F).

Simulations
The associated RBES acting as EMS to the NG under study which was defined in Section 2 is tested through simulation using MATLAB/Simulink. Figure 6a shows an hourly PV generation and load consumption profiles for the NG under study. These curves are considered quite realistic for a 4 kW peak power PV generation system during a sunny day. PNET is represented in Figure 6b. Positive and negative values of PNET take place along the day. Thus, surplus or deficit must be compensated by the HESS or by the main grid. For simplicity, supposing that the main grid cannot participate (PGRID = 0), PBAT is represented in Figure 6c. It corresponds to the filtered value of PNET. Meanwhile, the supercapacitors will compensate the peak power according to Equation (18) as depicted in Figure  6d. Subsequently, Figure 7a depicts PNET and its slope is produced by two hourly consecutive samples. These slopes can be positive or negative. At the same time, is displayed in Figure 7b.  From PNET, just the sign (positive or negative) of this value is required as RBES input. The value of is given a consideration according to Table 2. For our case of study, thresholds equal to 1.5 kW, 0.5 kW, −0.5 kW and −1.5 kW are selected as constants τ1, τ2, τ3 and τ4 respectively. Current values of the SOCBAT and SOCSC, calculated with Equations (15) and (16), define specific intervals according to Figure 4. These intervals will also feed the RBES back (the facts stated as true at each moment). Regarding the SOC for both the battery and the supercapacitor, the following levels: 80%, 65%, 35% and 20%, were chosen for k1, k2, k3 and k4.
Considering as initial SOCBAT equal to 50% and initial SOCSC equal to 35%, the control of the NG with the proposed EMS and its associated RBES, clearly improves the performance of the HESS. Figure 8 represents the corresponding SOC before (SOCBAT and SOCSC) and after considering the proposed control (SOCBAT and SOCŚC). Before the EMS activation, SOCBAT reaches almost 100% (around 20:00 p.m.) and falls 10% (around 10 a.m.). The maximum SOCSC corresponds to 14:30 p.m., with around 65%. On the other hand, at 7:30 a.m. the SOCSC is around 5%. As we can see in Figure 8, after applying the proposed control, both SOC are maintained close to 50% during the day. Thus, both SOC are kept within secure thresholds, guarantying a safety operation of the HESS. Finally, battery and supercapacitor powers before and after (PBAT and PŚC respectively) the EMS activation are represented in Figure 9a,b. Thanks to the EMS the system has a smoother response which also helps to improve the HESS lifespan.

Conclusions
This paper exposes the relevance of the EMS in the NG operation. A new approach to EMS for a NG was developed by designing a RBES step by step. The proposed approach has as its main advantage the reduction of the computational burden, while providing the possibility to straightforwardly move to a multivalued modal logic if the NG becomes more complex. At the same time, the possibility to concatenate the conclusions according to new variables or operation modes allows a modular design of the EMS. Further work will consider the presence of other energy sources in the NG, such as diesel generation, as well as the integration of some demand-side and peak load-shifting strategies. At the same time, environmental concerns are planned to be added in further extensions, as well as other energy required in the residential sector as thermal energy.

Appendix C. Subystem I-Simplifying Knowledge Extraction
Obtaining the operation modes can be simplified declaring them and using a simple procedure that performs the six questions and looks for the results equal to zero: (if we have a look at the first row of the table, BAT2LOAD is obtained in the first three odd columns and BAT2LOAD or BAT2GRID is obtained in the rest of the odd columns).

Appendix D. Subsystem I-Checking the Correctness of the Rules
A simple procedure that generates the columns of