Optimal Electrification Using Renewable Energies: Microgrid Installation Model with Combined Mixture k-Means Clustering Algorithm, Mixed Integer Linear Programming, and Onsset Method

: Optimal planning and design of microgrids are priorities in the electrification of off-grid


Introduction
Controlling today's global warming is, on the one hand, a subject of common interest worldwide and one in which all sectors are involved.On the other hand, the need to supply people with electricity off-grid necessitates the development of small-scale technologies for supplying renewable electrical energy.Fernando Antonanzas-Torres et al. [1] recommend mini-grid systems for the electrification of countries where the electrification rate has not yet reached 100%, in line with the United Nations Sustainable Development Goal 7 (SDG7): access to electricity for all [2,3].Such systems should be implemented with the consideration of environmental constraints [4,5].Furthermore, according to Sedzro et al. [6], microgrids, or mini-grids, are a potential solution to macro-grids for restoring electricity networks after disasters.In short, microgrids make it possible to reduce losses on supply lines and improve local power supply reliability and energy efficiency while offering a sustainable and efficient system [7].They can also be utilized to avoid blackouts of the entire power grid (macro-grid) when it is split into mini-grids.The classification of microgrids, therefore, depends on their configuration and applicability [8,9].
However, microgrids present challenges related to stochastic variation in demand and fluctuations in voltage and frequency [7] and intermittent weather conditions that sometimes affect reliability and economic behavior.Among these challenges, the modeling of microgrids is an important factor.The optimization of microgrids is one of the most important research objectives.These methods are often limited to a single objective: optimizing the various systems to exploit various resources such as solar systems, wind systems, hydro systems, battery systems, and biodiesel systems.The aim of these studies is to find the best compromise in the optimal choice of these different technologies, using a number of different problem-solving methods.Among these challenges, the modeling of microgrids is an important factor.Indeed, according to Fahad Saleh Al-Ismail [10], to overcome these challenges, microgrids need to be studied and modeled before being implemented and applied.
According to the U.S. Department of Energy's Microgrid Exchange Group [11], microgrids are electrical energy systems composed of one or more energy resources with a group of loads interconnected within clearly defined electrical boundaries and are able to act as single controllable entities.Referring to the definition of microgrids and their classifications [8,11], this paper proposes an optimal microgrid model that first considers microgrid clustering and the minimization of the centroid distance from the loads.Secondly, this work proposes the optimal management of energy resources as a function of the average levelized cost according to the different technologies [7].Then, in a third step, this paper presents an optimal model based on optimal load connections, following the definition proposed in [11] by the US Department of Energy.Finally, in a fourth step, optimal microgrid planning using the onsset method is proposed for the particular case of Togo.This study is an optimization study of the installation of a microgrid that would reduce losses and costs as much as possible, in technical and economic terms, for power grid operators.
This work is not limited to a single objective, as previously mentioned, but is the result of a combination of several objectives.The paper, therefore, proposes to define the electrification strategy in four steps: step 1, physical allocation of microgrid centers to obtain the coordinates of the centroid; step 2, definition of the optimal choice of technologies depending on the availability of resources; step 3, definition of optimal load connections points to the electrical microgrid available in the study area; and in step 4, planning electrification strategies.
The remainder of the paper is structured into four sections: the state of the art in Section 2; materials and methods in Section 3; results and discussion in Section 4; and, finally, conclusions in Section 5.

Theoretical Background
This section describes the theoretical background of the various technologies that can constitute the microgrid and the different scientific methods applied for its optimal installation.

Scientific Models of Microgrid Technologies
Models of the various components of microgrids, such as solar photovoltaic systems, wind systems, hydroelectric systems, battery systems, biodiesel systems, and load modeling are expressed: The maximum power produced by a photovoltaic solar panel can be directly calculated as a function of irradiation using the following formula [12,13]: With direct measurement of wind speed, we can express the wind power of the site under consideration using the following equation [12,14]: Hydroelectricity production, which depends on the average water flow (m 3 /s) over a period of time t, the difference in height between the entry and exit points (h) in m, the acceleration due to gravity (g) in m/s 2 and the density of the water and the yield [13,15,16], is expressed by Battery state of charge and power [17][18][19][20] at each simulation time are formulated as follows: Storage at a given time t is formulated as follows: The bi-directional converter is given by Aside from the technological models of microgrids, the electrical load models of the microgrid are formulated as follows [21][22][23]: In this work, the deployment of microgrid technologies required a number of measures, such as methods using machine learning techniques based on unsupervised learning, the method for determining the number of clusters (elbow method), the calculation of distance between the centroid and the various loads, the haversine method and the onsset method for optimal national planning of the various technologies.These methods are described below.

Scientific Methods for Microgrid Deployment
The various techniques applied, such as the k-means clustering technique, the elbow method, and the haversine method, are presented.

Clustering Techniques k-Means Clustering Model
The clustering technique refers to the notion of measuring similarity between two vectors.This method makes it possible to recognize and group sets called clusters.The clustering technique is presented in [24,25].The most commonly used measures of similarity are distance measures.The k-means clustering technique first groups the different variables xi in a certain set (cluster formation) and then, in a second step, minimizes the distance between the centroid and the clusters formed.
Assume the following space of n vector points of dimension p with j ⊂ p : These n points can be grouped into cclusters such that c < n with the vectors.
minimizing the distance between centroids and their respective clusters consists of assigning each nearest centroid to clusters such that

Elbow Method
The elbow method is used to determine the number of clusters in a given data set.It allows us to plot the variation explained as a function of the number of clusters and to choose the elbow of the curve as the number of clusters to exploit.It is formulated and simulated using 100 data points and normalized to [0; 1] in [25,26].

Open-Source Spatial Planning for Electrification Method: Onsset
The Open-Source Spatial Planning Model (onsset) is a free programming algorithm that uses spatial information data to propose a particular model for a given case study.It is, therefore, a model that enables the selection of different technologies according to four different scenarios, taking into account the costs and availability of these resources not far from localities.The electrification planning model, therefore, considers the minimization of system costs (operating costs, investment costs, and maintenance costs), the evolution and level of the population, and the different technology configurations according to resource availability.The mathematical formulation of the model is given by [29], and a global study for all of the four scenarios for the case of Togo was conducted in [30].In effect, this model informs the general planning of a country's overall electrification.
In this study, the developed microgrid model made it possible to specifically define the technologies to be implemented according to their cost and annual availability for a given site.Then, with onsset, a general configuration of the implementation of these technologies was obtained according to the locality for the whole country.

Bibliographical Reviews
Optimizing microgrids is one of the most important and challenging objectives in this field of research [31].Several studies have been carried out in the literature using different methods.
Li Bei et al. [32] exploited evolutionary algorithm methods and mixed integer linear programming for the optimal sizing of microgrids.Alessandra Parisio et al. [33] presented a study on the application of a model predictive control approach to the problem of efficiently optimizing microgrid operations while satisfying time-varying demand and operating constraints; the overall problem was formulated using integer linear programming with MATLAB as the solution tool.Li Guo et al. [34] presented a two-stage optimal planning and design method for a combined cooling, heat, and power microgrid system to simultaneously minimize total net present cost and carbon dioxide emission.In [35], the authors proposed microgrid optimization based on a hybridization system of renewable energy resources.Mah AXY et al. presented the optimized design and operation of an autonomous microgrid with electric and hydrogen loads, showing a significant reduction in load costs [36].Moreover, a strategy for controlling and managing the energy supply of a microgrid in order to achieve higher efficiency, reliability, and economy was proposed in [37,38].Aiswariya L. et al. [39] proposed optimal battery sizing using the simulated annealing method based on the probabilistic method [39,40], and stochastic methods for the planning, operation, and economic control of microgrids were presented in [41].
Among all these different methods are linear programming [51,52] and the mixed integer linear (PLNEM) solver (PLNEM) [32,33], which provide a suitable framework for obtaining high-quality solutions [53] with acceptable computational effort and good convergence properties.The mixed integer linear programming solution method is, therefore, widely employed for HRESs (Hybrid Renewable Energy Systems) and is characterized by good convergence [54,55].
In this work, the mixed integer linear programming method was extensively utilized.

Materials and Methods
The material used and the methodology are described in the following sections.

Materials
Python programming language version 3.10 was used.The optimization problem was formulated as a mixed integer linear instance.

Methods
The model of the microgrid with the different optimized parts is presented.The mathematical formulations of the different optimization problems are also presented.

Microgrid System Model
The proposal for a microgrid model, inspired by existing models [56][57][58][59], is presented.Different technologies such as PV, wind, hydraulic, storage and others (biodiesel, etc.) are shown first.Secondly, the positions of the unit central and the loads (Figure 1) are presented.

Methods
The model of the microgrid with the different optimized parts is presented.The mathematical formulations of the different optimization problems are also presented.

Microgrid System Model
The proposal for a microgrid model, inspired by existing models [56][57][58][59], is presented.Different technologies such as PV, wind, hydraulic, storage and others (biodiesel, etc.) are shown first.Secondly, the positions of the unit central and the loads (Figure 1) are presented.Three different methods were used.The first is an optimization formulation, which initially consists of minimizing the distance between the centroid, considered as the substation, and the various nodes representing the different electrical loads.The second is an optimal microgrid sizing method based on technology selection, minimization of overall cost, and availability of energy resources.In this method, a function is performed, which minimizes not only the microgrid connection distance but also the load shedding or supply of the loads to be connected (Step 3).In the second method formulated using mixed integer programming, two objective functions are presented.One function minimizes the investment cost for technology selection, and the other optimizes connections.Finally, the third method, based on onsset (described in Section 2.2.3), enables us to model the planning of national electrification spatially and optimally by implementing different technologies according to their cost and availability in each locality.Two scenarios are considered: short and long term.Three different methods were used.The first is an optimization formulation, which initially consists of minimizing the distance between the centroid, considered as the substation, and the various nodes representing the different electrical loads.The second is an optimal microgrid sizing method based on technology selection, minimization of overall cost, and availability of energy resources.In this method, a function is performed, which minimizes not only the microgrid connection distance but also the load shedding or supply of the loads to be connected (Step 3).In the second method formulated using mixed integer programming, two objective functions are presented.One function minimizes the investment cost for technology selection, and the other optimizes connections.Finally, the third method, based on onsset (described in Section 2.2.3), enables us to model the planning of national electrification spatially and optimally by implementing different technologies according to their cost and availability in each locality.Two scenarios are considered: short and long term.

Optimizations Problem Formulation
Three objective functions with constraints are clearly identified.First, a formulation of the optimization problem of minimizing the distance between the centroid and the various vectors that constitute the loads; then, a formulation of the optimization problem of selecting technologies as a function not only of the annual availability of natural resources but also of the various related costs, is presented; and finally, the minimization of the distance between the centroid considered as the substation and its various loads is formulated.
The various formulations described are presented.
In step 1: minimization of deviation between centroid and loads (k-means clustering method) Objective function Energies 2024, 17, 3022 This is subject to the following: In fact, the distance of each vector point from the centroid is evaluated in such a way that the minimization of this distance is total.The coordinates of the centroid of the cluster obtained will allow an optimal physical localization of the centroid.After this step, the formulation of the technology selection is necessary.
Step 2: technologies selection (microgrid sizing) Objective function: Energies 2024, 17, 3022 8 of 27 The problem formulated is an optimization problem, which consists of minimizing the various technology costs as a function of the annual availability of existing resources.If the resource exists, the coefficient j is equal to 1; otherwise, it is zero.The formulation of the problem is, therefore, seen under different constraints linked to the different production and storage limits.
Once the optimal technologies have been selected, a further step in solving the optimization problem is carried out, linked to the optimal load connections.
Step 3: Optimal load selection based on distances and substation capacity Objective function: For a fixed j (27) This is subject to the following: Knowing that the optimal connection of loads to the source substation is a function not only of their distance but also of the substation's available capacity, objective function 3 should minimize this distance.For a fixed j corresponding to the substation, the various loads i will be optimally selected under the various constraints mentioned above.
The various detailed flowcharts for implementing the resolutions of the different optimization problem formulations are presented.
The clustering algorithm is presented (step 1): • Enter data for each vector

•
Initialize the position of the centers:  T is set to 12 for the twelve months of the year.Figure 3 shows the flowchart for the formulation of objective function 3: connection optimization (step 3).T is set to 12 for the twelve months of the year.Figure 3 shows the flowchart for the formulation of objective function 3: connection optimization (step 3).

Data
Only average and annual variations in the various energy resources of South Togo are presented.In fact, this area contains all the country's available resources.
Statistical analyses of the data presented are based on the minimum value of the data used, the maximum value (36), the mean (37) and the standard deviation (38): The statistical data on energy resources in South Togo are shown in Table 1.

Data
Only average and annual variations in the various energy resources of South Togo are presented.In fact, this area contains all the country's available resources.
Statistical analyses of the data presented are based on the minimum value of the data used, the maximum value (36), the mean (37) and the standard deviation (38): The statistical data on energy resources in South Togo are shown in Table 1.Tables 2 and 3 below show the random statistical data for the load positions considered in the simulations and the parameters used in the simulations, respectively.The different results obtained following the formulation of the various optimization problems are presented.

Results for Cluster Formation: Physical Allocation of Microgrid Centers
The results of the elbow method applied to the xi data to determine the number of clusters are shown in Figure 4.
The number of clusters obtained, as shown in Figure 4, is 3.The graphical representation of these clusters is shown in Figure 5a,b using the k-means clustering technique.
This clustering technique was used to determine the coordinates of the various centroids (3).This clustering technique was used to determine the coordinates of the various centroids (3).Table 4 shows the coordinates obtained.
Indicate the number of clusters (3)   Subsequently, a special study was carried out on cluster 3. Table 3 shows a centroid for this cluster with the coordinates (x; y): (0.29246429; 0.48892857).
Figure 6 shows the corresponding cluster 3. Two nodes of centroid 1 are also shown for reference (connection).Subsequently, a special study was carried out on cluster 3. Table 3 shows a centroid for this cluster with the coordinates (x; y): (0.29246429; 0.48892857).
Figure 6 shows the corresponding cluster 3. Two nodes of centroid 1 are also shown for reference (connection).The number of load nodes defined for this centroid 3 is 40.The total capacity defined for study for these load nodes is assumed to be 40,000 W or 40 kW.
The results of the optimal simulations are presented.

Renewable Energy Resource Availability Results
To define energy potential, the case of Togo is taken into account.A previous study of the availability and mapping of the country's renewable resources is presented by Kabe et al. [30].The various intermittent energy potentials are presented for a capacity of around 1 kW.Only solar, wind, and hydraulic potentials are shown.According to Rafat Al Afif et al. [61], specific impacts from extreme events would not affect biomass power generation; it follows that biomass power generation is possible at any desired period and is therefore not taken into account in the simulation.
Figure 7 below shows these potentialities.The number of load nodes defined for this centroid 3 is 40.The total capacity defined for study for these load nodes is assumed to be 40,000 W or 40 kW.
The results of the optimal simulations are presented.

Renewable Energy Resource Availability Results
To define energy potential, the case of Togo is taken into account.A previous study of the availability and mapping of the country's renewable resources is presented by Kabe et al. [30].The various intermittent energy potentials are presented for a capacity of around 1 kW.Only solar, wind, and hydraulic potentials are shown.According to Rafat Al Afif et al. [61], specific impacts from extreme events would not affect biomass power generation; it follows that biomass power generation is possible at any desired period and is therefore not taken into account in the simulation.
Figure 7 below shows these potentialities.This figure shows the unequal annual distribution of Togo's potential energy mix.This unequal distribution requires an optimal combination of these resources.Optimal management of these resources is only possible with optimal management optimization models, hence this study.
Data from different variations of these resources are considered for the study.This figure shows the unequal annual distribution of Togo's potential energy mix.This unequal distribution requires an optimal combination of these resources.Optimal management of these resources is only possible with optimal management optimization models, hence this study.
Data from different variations of these resources are considered for the study.

Optimization Results for Technology Selection
The results of the optimum selection of renewable resources and the optimum power ratings obtained are shown in Figure 8 and Figure 10, respectively.This figure shows the unequal annual distribution of Togo's potential energy mix.This unequal distribution requires an optimal combination of these resources.Optimal management of these resources is only possible with optimal management optimization models, hence this study.
Data from different variations of these resources are considered for the study.

Optimization Results for Technology Selection
The results of the optimum selection of renewable resources and the optimum power ratings obtained are shown in Figure 8 and Figure 10, respectively.Figure 8 shows the optimal annual variation in renewable energy resource profiles for the microgrid under consideration.It can be seen from this figure that only photovoltaic, storage, and wind power systems are considered and, therefore, recommended.The hydraulic resource is neglected.In addition, the most available resource is the solar Figure 8 shows the optimal annual variation in renewable energy resource profiles for the microgrid under consideration.It can be seen from this figure that only photovoltaic, storage, and wind power systems are considered and, therefore, recommended.The hydraulic resource is neglected.In addition, the most available resource is the solar resource, the annual variation of which would allow optimal choices of technologies depending on the period.The wind resource is not neglected either.Figure 9 shows the energy storage.
Energies 2024, 17, x FOR PEER REVIEW 16 of 28 resource, the annual variation of which would allow optimal choices of technologies depending on the period.The wind resource is not neglected either.Figure 9 shows the energy storage.This optimization of resources makes it possible to define the appropriate technologies for each month when installing the microgrid.Now, the maximum capacity of the storage system is estimated to be 135 kWh.Details of the power of the various resources, which may be low or high depending on the period, are shown in Figure 10.This optimization of resources makes it possible to define the appropriate technologies for each month when installing the microgrid.Now, the maximum capacity of the storage system is estimated to be 135 kWh.Details of the power of the various resources, which may be low or high depending on the period, are shown in Figure 10.This optimization of resources makes it possible to define the appropriate technologies for each month when installing the microgrid.Now, the maximum capacity of the storage system is estimated to be 135 kWh.Details of the power of the various resources, which may be low or high depending on the period, are shown in Figure 10.The solar capacity considered ranges from 30 to 42 kW, while the maximum wind capacity is estimated to be 3 kW.Solar capacity represents 80% of the total load of the microgrid under consideration against 7.5% for wind power.Solar is the most favored resource, but wind can also be considered for its exploitation.The battery system capacity is 5 kW (12.5% of the total load capacity).The solar capacity considered ranges from 30 to 42 kW, while the maximum wind capacity is estimated to be 3 kW.Solar capacity represents 80% of the total load of the microgrid under consideration against 7.5% for wind power.Solar is the most favored resource, but wind can also be considered for its exploitation.The battery system capacity is 5 kW (12.5% of the total load capacity).
The total annual optimal value of the objective function is USD 1,389,578.75999646.The maximum optimal value is obtained in August and is equal to USD 177,942.34.The various power and energy values are shown in Table 5.

Cost (USD) P (kW) E (kWh) P (kW) P (kW) P (kW)
Table 5 shows monthly data for a year of optimization of renewable energy systems with battery energy storage.According to the results, the battery systems were first injected into the mini-grid in January, February, and March, then in November and December, in order to compensate for electrical loads.The maximum injection is 5.95 kW.From April to October, the battery system acts as a load, consuming electrical energy for storage.Total storage energy is estimated to be 133 kWh.These injection and storage periods for the battery system depend on the availability of renewable resources: solar and wind power.Hydro are neglected.Maximum solar power is estimated to be 42 kW, and maximum wind power is estimated to be 3 kW.The maximum cost of all technologies is estimated to be USD 177,942.34.
It should also be noted that in Togo [30], the main resource is solar power.However, other renewable energy resources, such as wind power in the south of the country, hydropower, and biomass, depending on the study area, are not neglected.
The transformer capacity of the microgrid under consideration is estimated to be around 50 kVA.

Capacity and Connection Optimization Results
To evaluate the optimization results of the microgrid study, two scenarios were considered.The first scenario was based on the influence of the distance of the load node connection, and the second scenario was based on the influence of the variation in the capacity of the load nodes.This figure shows the variation in voltage ratio as a function of load node location.This figure shows a perfect correlation between the satisfaction rates.Indeed, in this figure, the location of the loads in relation to the substation demonstrates the non-homogeneous trend of the voltage ratio.As the admissible limit value is 0.1, nodes 41 and 42 are outside the voltage ratio limit, as their distance influences the defined limits.
Figure 12 shows the total connection of centroid three load nodes when substation and load capacities are in balance.These nodes are unlike the load nodes of centroid 1, which are switched off.This equation expresses, in percentage terms, the satisfaction rate due to the availability of substation capacity in relation to load capacity.It expresses energy satisfaction due either to a balance between supply and demand or to a lack of energy at the substation due to an imbalance between supply and demand.
This figure shows the variation in voltage ratio as a function of load node location.This figure shows a perfect correlation between the satisfaction rates.Indeed, in this figure, the location of the loads in relation to the substation demonstrates the non-homogeneous trend of the voltage ratio.As the admissible limit value is 0.1, nodes 41 and 42 are outside the voltage ratio limit, as their distance influences the defined limits.
Figure 12 shows the total connection of centroid three load nodes when substation and load capacities are in balance.These nodes are unlike the load nodes of centroid 1, which are switched off.This figure shows the variation in voltage ratio as a function of load node location.This figure shows a perfect correlation between the satisfaction rates.Indeed, in this figure, the location of the loads in relation to the substation demonstrates the non-homogeneous trend of the voltage ratio.As the admissible limit value is 0.1, nodes 41 and 42 are outside the voltage ratio limit, as their distance influences the defined limits.
Figure 12 shows the total connection of centroid three load nodes when substation and load capacities are in balance.These nodes are unlike the load nodes of centroid 1, which are switched off.However, the variation in the satisfaction rate does not influence the voltage rate but influences the connection.Figure 13a,b show the results obtained.Depending on the satisfaction rate, certain load nodes are not connected (in reality, these loads are switched off).This satisfaction rate reflects the energy insufficiency of the substation and would lead to optimal load shedding according to load capacity.The greater the energy shortfall, the fewer loads are connected (as shown in Figure b, where load shedding is higher).
However, if energy is injected into the microgrids, the loads will be connected back initially (as in the previous figure, where τs = 100%), and loads that are too far away will not be connected, regardless of the substation's capacity (as in the case of the two load nodes of centroid 1).
(b) Scenario 2: influence of load capacity Depending on the satisfaction rate, certain load nodes are not connected (in reality, these loads are switched off).This satisfaction rate reflects the energy insufficiency of the substation and would lead to optimal load shedding according to load capacity.The greater the energy shortfall, the fewer loads are connected (as shown in Figure b, where load shedding is higher).
Energies 2024, 17, 3022 18 of 27 However, if energy is injected into the microgrids, the loads will be connected back initially (as in the previous figure, where τ s = 100%), and loads that are too far away will not be connected, regardless of the substation's capacity (as in the case of the two load nodes of centroid 1).Depending on the satisfaction rate, certain load nodes are not connected (in reality, these loads are switched off).This satisfaction rate reflects the energy insufficiency of the substation and would lead to optimal load shedding according to load capacity.The greater the energy shortfall, the fewer loads are connected (as shown in Figure b, where load shedding is higher).
However, if energy is injected into the microgrids, the loads will be connected back initially (as in the previous figure, where τs = 100%), and loads that are too far away will not be connected, regardless of the substation's capacity (as in the case of the two load nodes of centroid 1).
(b) Scenario 2: influence of load capacity Variations in load capacity have a significant influence on the voltage ratio profile.The results are shown in Figure 14.If the 40 load nodes in the initial study satisfied the voltage ratio condition, it is obvious that their load variations would cause them to malfunction.Figure 14 illustrates the influence of load capacity on voltage ratio.In fact, as loads increase in capacity, the voltage drop rate also increases and surpasses the admissible limit.
In response to this fault, loads are disconnected regardless of their proximity to the substation.Figure 15 illustrates optimal load shedding.If the 40 load nodes in the initial study satisfied the voltage ratio condition, it is obvious that their load variations would cause them to malfunction.Figure 14 illustrates the influence of load capacity on voltage ratio.In fact, as loads increase in capacity, the voltage drop rate also increases and surpasses the admissible limit.
In response to this fault, loads are disconnected regardless of their proximity to the substation.Figure 15 illustrates optimal load shedding.Although some load nodes are closer than others, and because they are more heavily loaded, they will be less connected than less heavily loaded load nodes located at a reasonable distance but further away.In Figure 15, some closer load nodes are unloaded, while some more distant, less-loaded load nodes are supplied (while still complying with the voltage drop rate condition).Although some load nodes are closer than others, and because they are more heavily loaded, they will be less connected than less heavily loaded load nodes located at a reasonable distance but further away.In Figure 15, some closer load nodes are unloaded, while some more distant, less-loaded load nodes are supplied (while still complying with the voltage drop rate condition).
A comparison of the variation in load capacity is shown in Figure 16.Although some load nodes are closer than others, and because they are more heavily loaded, they will be less connected than less heavily loaded load nodes located at a reasonable distance but further away.In Figure 15, some closer load nodes are unloaded, while some more distant, less-loaded load nodes are supplied (while still complying with the voltage drop rate condition).
A comparison of the variation in load capacity is shown in Figure 16.The comparison of the initial state, where load capacities are lower than in the variable state, shows the impact of load capacity on the microgrid.
The optimal national planning of microgrid systems and stand-alone photovoltaic systems in the short and long term is presented.

Results of Microgrid Formation Evaluation Studies in Togo
The results of the open-source spatial planning tool onsset were used to optimize the planning of general electrification in Togo based on various technologies, such as standalone photovoltaic systems and microgrids.Figure 17a,b illustrate the planning process.
The results in Figure 16a for the short term suggest microgrid systems with an electrification rate of 70%, compared with an electrification rate of 100% for the long term (Figure 17b).For the long term, in addition to the microgrid systems considered, standalone photovoltaic systems are also recommended if electrification is to be achieved throughout the country.
Table 6 presents the results of the different costs according to the scenario.Table 5 shows the results of two different scenarios.For the short term, i.e., scenario 2, stand-alone photovoltaic systems with a capacity of 20 MW are recommended and are estimated to cost USD 184 million.Scenario 2 also opts for hybrid PV mini-grids with a capacity of 320 MW at a cost of USD 564 million versus hydraulic mini-grids with an estimated cost of USD 1.12 million.On the other hand, for the long term (scenario 4), PV systems are proposed with a capacity of 62 MW and an investment of 280 million.Minigrids are also recommended at an estimated total cost of USD 1374 million for a capacity of 721 MW.However, scenario 4 shows the possibility of achieving total electrification of the country by estimating a global capacity of 1.06 GW for an investment of USD 2.6 billion.The results in Figure 16a for the short term suggest microgrid systems wit trification rate of 70%, compared with an electrification rate of 100% for the l (Figure 17b).For the long term, in addition to the microgrid systems considere alone photovoltaic systems are also recommended if electrification is to be throughout the country.
Table 6 presents the results of the different costs according to the scenario.

Discussion
Microgrid installation requires not only optimization methods to minimize investment costs but also automated voltage stability methods to ensure stability and resilience in accordance with connections.In this study, the elbow and k-means clustering methods were used to determine the number of clusters required for autonomous microgrid management and to determine the coordinates of the corresponding centroid, respectively; this strategy is necessary for the initial steps of a microgrid installation.Secondly, the intermittency of renewable resources led us to optimize the complementary management of these resources in order to contribute to the total energy satisfaction of electrical loads estimated to be 40 kW.This resulted in the solar resource being the most favored for satisfying these electrical loads, with a rate of 80% compared with 7.5% for the wind resource and 12.5% for battery capacity.In areas with very low wind and water resources, solar power and battery systems may be the preferred option.Nevertheless, a careful study is needed before a microgrid can be installed in a given locality; hence, the results that enabled us to evaluate the formation of microgrids using an open-source spatial optimal electrification planning system: onsset.In this study for Togo, two types of isolated or hybrid mini-grid systems were recommended: solar mini-grid systems and hydraulic mini-grid systems.Stand-alone photovoltaic systems were also proposed.The optimal investment costs for the short and long term are estimated to be around USD 567 million for an energy production capacity of around 321 MW, compared with USD 2.6 billion for a capacity of around 1 GW.However, it should be pointed out that wind systems based on mini-aerogenerators and biodiesel are not negligible, as their feasibility studies are essential for any microgrid installation project.In this study, the case of the wind mini-grid is proposed and is therefore not neglected.
In addition, a technical proposal for one of the options for installing a microgrid based on photovoltaic systems would be to exploit either the roofs of houses or to consider other methods, such as agri-photovoltaics (photovoltaics combined with agriculture).
Finally, this study enabled us to limit load connections according either to their capacity or their position relative to the microgrid substation, crucially ensuring the stability of the microgrid.On the one hand, it was found that high load capacity leads to network instability and, therefore, to the shedding of higher loads in favor of lower ones in order to keep the microgrid more stable.On the other hand, the fact that the loads are located far from the substation has an impact on the voltage stability of the network, which also results in load shedding.The variation in load capacity in a microgrid and its positioning in relation to its connection can have a significant impact on grid performance, resulting in voltage instability, hence the need for pre-feasibility studies when installing a microgrid.
The study also showed that a substation's energy deficiency would optimally lead to the shedding of certain loads.

Conclusions
The study of the installation of microgrids is important because it allows us to optimally manage the implementation of all the components of a system and to ensure the system's stability.As a first step, we, therefore, carried out feasibility studies on the availability of the country's annual renewable energy resources.Secondly, optimal management of these resources is proposed for the optimal sizing of the microgrid energy systems to be installed, taking into account their costs and availability according to their intermittency.In the optimum results obtained, solar systems account for 80% of the maximum load considered, compared with 7.5% for wind systems and 12.5% for battery systems.Finally, a study of optimal load selectivity according to its effect on the voltage stability (connections or load shedding) of the mini-grid was carried out.The results of this study were conclusive and enabled us to obtain the optimal model required for the installation of the microgrid being considered.In addition, a specific study of the overall planning of Togo's electrification using the spatial optimal planning tool generated solar, hydraulic, and hybrid mini-grid systems.The estimated overall cost for the short and long term during the planning phase is in the order of USD 567 million for a capacity of 321 MW in the short term and USD 1374 million for a capacity of 721 MW in the long term.
However, in this sizing study, the application of wind mini-systems was demonstrated as the feasibility study showed that wind-based hybrid systems were not neglected in the case of South Togo.However, the biodiesel system was not taken into account in this simulation.In summary, the results obtained are satisfactory and highly conclusive, indicating that we optimally simulated the dimensioning of a microgrid through the optimal management of energy resources, the optimal connection or load shedding of its loads, and the optimal planning of electrification.This study is an optimization study of the installation of a microgrid that would reduce losses and costs as much as possible, in technical and economic terms, for power grid operators.

• 28 -
Calculate mk averages of vectors in cluster k -Until there are no more changes in the mk -Assign each Vi point to the nearest cluster -Calculate new mk -End As long as The flowchart for the formulation of objective function 2, resource optimization, is shown in Figure 2 below (step 2): Energies 2024, 17, x FOR PEER REVIEW 10 of Until there are no more changes in the mk -Assign each Vi point to the nearest cluster -Calculate new mk -End As long as The flowchart for the formulation of objective function 2, resource optimization, is shown in Figure 2 below (step 2):

Figure 4 .Figure 5 .
Figure 4. Elbow method for determining the number of clusters.The number of clusters obtained, as shown in Figure4, is 3.The graphical representation of these clusters is shown in Figure5a,b using the k-means clustering technique.

Figure 4 .
Figure 4. Elbow method for determining the number of clusters.

Figure 4 .Figure 5 .Figure 5 .
Figure 4. Elbow method for determining the number of clusters.The number of clusters obtained, as shown in Figure4, is 3.The graphical representation of these clusters is shown in Figure5a,b using the k-means clustering technique.

Figure 7 .
Figure 7. Energy resources of 1 kW in power.

Figure 7 .
Figure 7. Energy resources of 1 kW in power.

Figure 7 .
Figure 7. Energy resources of 1 kW in power.

Figure 8 .
Figure 8. Optimal profile of renewable resources.

Figure 8 .
Figure 8. Optimal profile of renewable resources.

Figure 10 .
Figure 10.Optimum performance of renewable resources.

Figure 10 .
Figure 10.Optimum performance of renewable resources.
(a) Scenario 1: results for voltage rate profile/distance Simulation results for the influence of load distance from the substation (centroid) and for the influence of the satisfaction rate are shown in Figure 11.The following equation translates the satisfaction rate equation: P station P load × 100 = τ s Energies 2024, 17, x FOR PEER REVIEW 18 of 28due either to a balance between supply and demand or to a lack of energy at the substation due to an imbalance between supply and demand.

Figure 11 .
Figure 11.Voltage drop profile as a function of satisfaction rate and distance.

Figure 11 .
Figure 11.Voltage drop profile as a function of satisfaction rate and distance.

Figure 11 .
Figure 11.Voltage drop profile as a function of satisfaction rate and distance.

Figure 12 .Figure 13 .
Figure 12.Optimum connection for τ s = 100%.However, the variation in the satisfaction rate does not influence the voltage rate but influences the connection.Figure13a,bshow the results obtained.Energies 2024, 17, x FOR PEER REVIEW 19 of 28
(b) Scenario 2: influence of load capacity Variations in load capacity have a significant influence on the voltage ratio profile.The results are shown in Figure 14.

Figure 14 .
Figure 14.Voltage rate profile as a function of load capacity.Figure 14.Voltage rate profile as a function of load capacity.

Figure 14 .
Figure 14.Voltage rate profile as a function of load capacity.Figure 14.Voltage rate profile as a function of load capacity.

Figure 16 .
Figure 16.Comparison of initial state and transitional state of load capacity.Figure 16.Comparison of initial state and transitional state of load capacity.

Figure 16 .
Figure 16.Comparison of initial state and transitional state of load capacity.Figure 16.Comparison of initial state and transitional state of load capacity.

Table 1 .
Statistical data on energy resources in South Togo.

Table 1
presents data linking the various renewable resources.The table shows monthly solar irradiation, temperature, relative humidity, and wind data.These data are, in effect, inputs for the power extraction of different technologies, such as solar panels (solar irradiation and temperature), hydro-generators (dependent on relative humidity), and wind turbines (dependent on wind speed).
Table 4 shows the coordinates obtained.

Table 4 .
Summary of cluster centroid values.

Table 5 .
Optimal values per month for different resources.

Table 6 .
Summary of results for short-and long-term scenarios.