Optimizing O ﬀ -Grid Generation in Large-Scale Electriﬁcation-Planning Problems: A Direct-Search Approach

: O ﬀ -grid systems play a prominent role in rural electriﬁcation planning. The problem of optimizing the generation design of a single o ﬀ -grid system has received a signiﬁcant amount of attention in the literature, and several software tools and algorithms have addressed it. However, methods and tools designed for individual mini-grids are not directly applicable to regional planning, where it is necessary to estimate the generation cost of potentially thousands of mini-grids. Conversely, most regional planning tools estimate the generation cost of mini-grids with rules of thumb or analytical expressions. These estimations are useful, but they lack the accuracy necessary to develop a rural electriﬁcation plan. This paper presents a method to estimate the generation cost of any potential o ﬀ -grid system in a large-scale rural electriﬁcation planning problem, which is currently implemented in the Reference Electriﬁcation Model (REM). The method uses a master-slave decomposition that exploits the structure of the problem and combines continuous and discrete variables. The algorithm is illustrated with a case study that shows that a direct application of a discrete model may lead to suboptimal results in large-scale planning.


Introduction
Universal access to energy is one of the main challenges of our time. There are approximately 840 million people without access to electricity [1], most of them located in rural areas of Sub-Saharan Africa. Electricity access is a crucial enabling factor for human development, and the seventh United Nations Sustainable Development Goal for 2030 acknowledge its relevance. Substantial progress is necessary to meet this target [2].
Making progress in the electrification of developing countries requires the combined efforts of financial, technological, regulatory, sociological, and political-economic factors in this complex problem [3]. A sound electrification plan must start with a quantitative assessment of needs and the adequate combination of suitable alternatives. The primary purpose of an electrification plan is twofold: It must establish the least-cost electrification mode for the region that meets some minimum standards of service, i.e., which zones in the least-cost electrification solution consists of extending the grid and, conversely, in which areas should mini-grids or standalone systems be built. On the other hand, any electrification plan should provide a reasonable approximation to the overall cost, the necessary bill of materials, and cost-comparisons with alternative electrification solutions and sensitivity analyses to help the planner in the decision-making process.
A comprehensive rural electrification plan needs to be data-driven to achieve the two objectives of electrification planning. Accurate data are indispensable, although there is generally a scarcity Reference [30] introduces an early version of REM, and several improvements are presented in [31]. Reference [32] describes the current state of REM, and reference [33] applies REM to study the importance of demand in planning. This paper presents the novel approach to optimize generation designs that was developed for REM. Specifically, the paper discusses the potential problems caused by modelling all the mini-grid components with discrete variables and introduces two methods to overcome such problems.
The rest of this paper is structured as follows. Section 2 describes the rural electrification problem in more detail and provides some context for our method. Section 3 describes our algorithm for generation sizing and compares it to a straightforward approach. Results and conclusions are provided in Sections 4 and 5, respectively.

The Role of Generation Designs in REM
This section provides a context for generation sizing in the rural electrification problem as implemented in REM, which is described in detail in reference [32].
The starting data for regional rural electrification planning include the location and demand of consumers, the location, energy cost, and reliability of the existing power grid as well as the network and generation catalogues and some techno-economic parameters such as discount rates and hourly solar irradiance.
REM works at the level of individual buildings, so it needs to group the consumers into minigrids. Large mini-grids benefit from economies of scale in generation equipment, but they have higher network costs. It is crucial to ponder the trade-offs between generation and network costs when grouping the consumers into mini-grids. Figure 1 shows the projection onto Google Earth Pro of two groupings of consumers into mini-grids. The minimum-cost grouping depends on the tradeoff between the generation cost and the network cost. REM groups the consumers into mini-grids (this will be referred to as off-grid clustering) in a process that starts with every consumer being an isolated cluster, and then joined with nearby REM groups the consumers into mini-grids (this will be referred to as off-grid clustering) in a process that starts with every consumer being an isolated cluster, and then joined with nearby clusters In configuration 1, the nearby clusters are electrified with separated off-grid systems, with each system having an independent generation site. In configuration 2, the nearby clusters are electrified together with the same mini-grid, locating the shared generation site in the cluster with higher peak demand. Hence, it is necessary to obtain the generation and network costs of three off-grid systems (two separated systems in configuration 1, and the larger mini-grid in configuration 2) each time REM performs a cost-comparison.
The most straightforward approach to calculate the generation costs needed in the off-grid clustering would be to optimize from scratch the generation designs of the off-grid systems that appear in configurations 1 and 2 each time REM performs a cost comparison. However, the number of cost comparisons in a regional planning case is unmanageably large, and this strategy would require an unaffordable computation time. Instead, REM balances accuracy with computation speed by calculating generation designs de novo for only a reduced subset of mini-grids (look-up table), which should be representative of the case study. The generation cost for the remaining mini-grids, if needed in the off-grid clustering, is approximated using multi-linear interpolation or extrapolation.
Each type of load is assigned a demand profile to develop this procedure. This allows expressing each mini-grid as a combination of its types of loads, and the representative mini-grids are the vertices of a rectangular mesh where the interpolation and extrapolation procedures are performed. Error! Reference source not found.Error! Reference source not found. shows an example with three ty pes of loads, where the representative mini-grids are obtained as combinations of 0, 300, 700, and 1000 residential consumers, 0, 1, 5, and 10 hospitals, and 0, 1, 5, and 10 schools. REM would calculate generation designs for 4 × 4 x 4 = 64 representative off-grid systems, which correspond to the points in the figure. In configuration 1, the nearby clusters are electrified with separated off-grid systems, with each system having an independent generation site. In configuration 2, the nearby clusters are electrified together with the same mini-grid, locating the shared generation site in the cluster with higher peak demand. Hence, it is necessary to obtain the generation and network costs of three off-grid systems (two separated systems in configuration 1, and the larger mini-grid in configuration 2) each time REM performs a cost-comparison.
The most straightforward approach to calculate the generation costs needed in the off-grid clustering would be to optimize from scratch the generation designs of the off-grid systems that appear in configurations 1 and 2 each time REM performs a cost comparison. However, the number of cost comparisons in a regional planning case is unmanageably large, and this strategy would require an unaffordable computation time. Instead, REM balances accuracy with computation speed by calculating generation designs de novo for only a reduced subset of mini-grids (look-up table), which should be representative of the case study. The generation cost for the remaining mini-grids, if needed in the off-grid clustering, is approximated using multi-linear interpolation or extrapolation.
Each type of load is assigned a demand profile to develop this procedure. This allows expressing each mini-grid as a combination of its types of loads, and the representative mini-grids are the vertices of a rectangular mesh where the interpolation and extrapolation procedures are performed. Figure 3 shows an example with three types of loads, where the representative mini-grids are obtained as combinations of 0, 300, 700, and 1000 residential consumers, 0, 1, 5, and 10 hospitals, and 0, 1, 5, and 10 schools. REM would calculate generation designs for 4 × 4 x 4 = 64 representative off-grid systems, which correspond to the points in the figure.
Energies 2019, 12, x FOR PEER REVIEW 5 of 22 Figure 3. Example of representative mini-grids whose generation designs are calculated.
A drawback of this approach is that the number of representative mini-grids increases significantly with the number of load types as each load type is associated with an axis of the lookup table, which limits the types of loads that can be included in a case study. A different source of computational problems derives from modelling the capacities of all generation components with discrete variables, as discussed in Section 3.  A drawback of this approach is that the number of representative mini-grids increases significantly with the number of load types as each load type is associated with an axis of the look-up table, which limits the types of loads that can be included in a case study. A different source of computational problems derives from modelling the capacities of all generation components with discrete variables, as discussed in Section 3.

Efficient Generation Sizing for a Given Mini-grid
The problem of optimizing the generation design of a single mini-grid has been thoroughly studied in the literature [12] and available software tools [21]. One of the procedures used to deal with this problem consists of the application of classical optimization modelling techniques such as mixed-integer linear programming [34]. However, these methods are computationally intense, and may require substantial resources to optimize a significant number of generation designs (which is usually the case when REM's look-up table has several dimensions). Moreover, a planner would expect that generation designs that meet similar aggregated demands are similar in terms of generation elements and capacities, but the operation of mini-grids is non-linear, which implies that solutions obtained with an optimization method may fail to capture this property. This condition is relevant regarding project implementation, as it would not be reasonable, for example, to perform substantial changes repeatedly in the generation design of a village as demand grows (such as adding a diesel generator when the demand grows slightly only to remove it again when demand grows past a certain point).
REM applies a direct-search method to size the generation of the representative off-grid systems, yielding solutions that are more stable when concerned with demand variations. It also presents a reasonable balance between the accuracy of the design and computation time. The rest of this section introduces a method that calculates the generation design for each representative mini-grid of the look-up table, modelling all the generation components as discrete elements. Then, the potential issues of this approach are discussed, and solutions are proposed to overcome them. Figure 4 shows the architecture that REM considers for off-grid systems. Note that only solar energy is currently used as a renewable source, but other sources such as wind, mini-hydro, and biomass are under analysis, and they could be integrated similarly in the optimization process.

3.1.A Master-Slave Decomposition
Error! Reference source not found. shows the architecture that REM considers for off-grid s ystems. Note that only solar energy is currently used as a renewable source, but other sources such as wind, mini-hydro, and biomass are under analysis, and they could be integrated similarly in the optimization process. The algorithm presented in this section considers a tridimensional search space where each axis corresponds to one off-grid technology (solar, diesel, and battery storage), optimizing their respective capacities. The charge controller and the inverter that better suit the design, if needed, are selected afterwards.
There is a significant difference between the diesel generator and the other two off-grid technologies (solar panels and battery). It is possible to combine solar panels on one side and batteries on the other in parallel racks to provide (approximately) any desired capacity. The use of diesel generators in parallel, however, involves a much higher degree of complexity regarding installation and operation, so REM does not allow this possibility.
Therefore, the capacities of solar panels and batteries take values that are multiples of a small The algorithm presented in this section considers a tridimensional search space where each axis corresponds to one off-grid technology (solar, diesel, and battery storage), optimizing their respective capacities. The charge controller and the inverter that better suit the design, if needed, are selected afterwards.
There is a significant difference between the diesel generator and the other two off-grid technologies (solar panels and battery). It is possible to combine solar panels on one side and batteries on the other in parallel racks to provide (approximately) any desired capacity. The use of diesel generators in parallel, however, involves a much higher degree of complexity regarding installation and operation, so REM does not allow this possibility.
Therefore, the capacities of solar panels and batteries take values that are multiples of a small solar panel or battery, whereas the available capacities of the diesel generator are limited to the ones provided by the user. REM handles this difference among the off-grid technologies with a master-slave decomposition where the master level controls the diesel capacity, and the slave level explores a solar-battery plane with a fixed diesel capacity, from an adequate starting search point provided by the master level. The strategy of exploiting the structure of an optimization problem with a nested decomposition has been successfully applied to other problems in the literature [35,36].
The basic algorithm starts with a 100% renewable solution (no diesel), and the slave problem finds the least-cost design in the no-diesel plane. Then, the master problem increases the diesel capacity to the next diesel generator available on the catalogue, and the slave problem finds the combination of solar and battery that better fits the demand for that diesel generator. This procedure continues until the master problem has considered all diesel generators available in the diesel search space, which includes all diesel generators between the no-diesel solution and the smallest diesel generator that can meet all the demand. The starting search point in terms of solar and battery capacity is the best solution obtained at the previous iteration (for the previous diesel generator).  Candidate generation designs that the algorithm considers. As the diesel capacity increases, candidate designs have fewer solar panels and batteries. Figure 6 shows the flow diagram of the master problem. The master problem performs an exhaustive search as it goes through all the available diesel generators in the diesel search space, which may consume a significant amount of time.   . Candidate generation designs that the algorithm considers. As the diesel capacity increases, candidate designs have fewer solar panels and batteries. Figure 6 shows the flow diagram of the master problem. The master problem performs an exhaustive search as it goes through all the available diesel generators in the diesel search space, which may consume a significant amount of time.  The slave problem searches in the neighborhood of an initial point provided by the master problem, moving towards the point with minimum cost. If no neighboring point improves the current solution, the algorithm reduces the step size until its value is below a pre-specified threshold. Figure 7 shows an example of the slave problem, which corresponds to the first iterations for the no-diesel plane shown in Figure 5. The slave problem searches in the neighborhood of an initial point provided by the master problem, moving towards the point with minimum cost. If no neighboring point improves the current solution, the algorithm reduces the step size until its value is below a pre-specified threshold. Figure  7 shows an example of the slave problem, which corresponds to the first iterations for the no-diesel plane shown in Figure 5. Error! Reference source not found. shows the flow diagram of the slave problem. The slave p roblem, in practice, behaves as a gradient-descent method with discrete derivatives since it always moves in the lowest-cost direction. There is another level of embedded optimization in the process since, for each generation mix (size of diesel, solar panels, and batteries), the "best" possible dispatch is found. REM allows the use of alternative dispatch strategies, each one with different trade-offs concerning prediction ability, control strategy, or technical constraints. This is an interesting aspect of REM, but not the subject of this paper. In the cases presented in this paper, REM applies a load-following dispatch strategy [37] when computing the total cost of a generation design. In the load-following strategy, the order of components used to meet demand is solar panels, batteries, and the diesel generator (in that order). If there is enough solar power to meet all the demand at a specific hour, then the remaining solar energy is used to charge the battery (if possible) in that hour. The diesel generator is not used to charge the battery in the load-following dispatch strategy. REM simulates the hourly operation of the system for the whole year for each candidate generation design following this strategy, which allows the model to deal with photovoltaic seasonalities. Since REM penalizes the non-served energy, the optimal generation design should use either batteries or a diesel generator to ensure that there is not a significant drop in the amount of demand served in periods of lower solar production.

A First Approach to Detailed Regional Planning
When operating at a high level of spatial granularity (consumer-by-consumer) in regional planning, it is necessary to group consumers into mini-grids. The best grouping of consumers depends on the trade-offs between the costs involved, the generation cost being one of them. If the estimations of the generation costs used to group consumers into mini-grids fail to capture the economies of scale in generation equipment, the resulting combination of consumers into mini-grids may be far from optimal.
We now provide an illustrative example with one load type (residential) that shows the limitations of the method presented in Section 3.1 for regional planning. Any tool or method that aims at optimizing the generation design with discrete generation components, such as those that There is another level of embedded optimization in the process since, for each generation mix (size of diesel, solar panels, and batteries), the "best" possible dispatch is found. REM allows the use of alternative dispatch strategies, each one with different trade-offs concerning prediction ability, control strategy, or technical constraints. This is an interesting aspect of REM, but not the subject of this paper. In the cases presented in this paper, REM applies a load-following dispatch strategy [37] when computing the total cost of a generation design. In the load-following strategy, the order of components used to meet demand is solar panels, batteries, and the diesel generator (in that order). If there is enough solar power to meet all the demand at a specific hour, then the remaining solar energy is used to charge the battery (if possible) in that hour. The diesel generator is not used to charge the battery in the load-following dispatch strategy. REM simulates the hourly operation of the system for the whole year for each candidate generation design following this strategy, which allows the model to deal with photovoltaic seasonalities. Since REM penalizes the non-served energy, the optimal generation design should use either batteries or a diesel generator to ensure that there is not a significant drop in the amount of demand served in periods of lower solar production.

A First Approach to Detailed Regional Planning
When operating at a high level of spatial granularity (consumer-by-consumer) in regional planning, it is necessary to group consumers into mini-grids. The best grouping of consumers depends on the trade-offs between the costs involved, the generation cost being one of them. If the estimations of the generation costs used to group consumers into mini-grids fail to capture the economies of scale in generation equipment, the resulting combination of consumers into mini-grids may be far from optimal.
We now provide an illustrative example with one load type (residential) that shows the limitations of the method presented in Section 3.1 for regional planning. Any tool or method that aims at optimizing the generation design with discrete generation components, such as those that deal with a single mini-grid or village, would present the same limitations. The problems found, the solutions proposed, and the overall conclusions are fully applicable to cases with more types of loads, but they are not used here for the sake of simplicity.
There are two diesel generators available with capacities of 10 kW and 100 kW, and the representative mini-grids correspond to 1, 5, 10, 50, 100, 150, 200, 250, 300, and 500 residential consumers. Although the number of available diesel generators may seem low, it is realistic. The logistics of dealing with an extensive catalogue of diesel generators in a regional planning project complicates the implementation phase, and some planners prefer to limit the available diesel options, purchase specific generators in bulk, and benefit from volume discount pricing. Figure 9 shows the minimum cost per consumer for these representative combinations of residential consumers, showing the partial optima obtained for the three diesel options (0, 10, and 100 kW) and the minimum cost curve (i.e., the minimum-cost design for each point). deal with a single mini-grid or village, would present the same limitations. The problems found, the solutions proposed, and the overall conclusions are fully applicable to cases with more types of loads, but they are not used here for the sake of simplicity. There are two diesel generators available with capacities of 10 kW and 100 kW, and the representative mini-grids correspond to 1, 5, 10, 50, 100, 150, 200, 250, 300, and 500 residential consumers. Although the number of available diesel generators may seem low, it is realistic. The logistics of dealing with an extensive catalogue of diesel generators in a regional planning project complicates the implementation phase, and some planners prefer to limit the available diesel options, purchase specific generators in bulk, and benefit from volume discount pricing. Figure 9 shows the minimum cost per consumer for these representative combinations of residential consumers, showing the partial optima obtained for the three diesel options (0, 10, and 100 kW) and the minimum cost curve (i.e., the minimum-cost design for each point). This case illustrates the two main undesirable effects of having discrete diesel options. The first one is the instability of the generation mix concerning the demand. In this case, mini-grids with less than 50 consumers do not include a diesel generator and mini-grids with a range of consumers that lay between 50 and 100 consumers include a 10 kW diesel generator. However, mini-grids between 100 and 150 consumers do not include the diesel generator, because the 10 kW diesel generator is too small, while the 100 kW diesel generator is too big and expensive in this particular range of consumers. For mini-grids larger than 150 consumers, the generation solution includes the 100 kW diesel generator.
The second effect is that the unitary generation cost is not a monotonically decreasing function of the number of residential consumers, which is something expected due to the economies of scale in generation. This second effect causes issues in REM's bottom-up clustering algorithm. When trying to join two clusters into a larger one, the algorithm considers the trade-off between the additional network cost and the generation savings (due to economies of scale). Hence, if the generation cost per consumer starts increasing at some point, the algorithm would not find the best solution. In the case shown in Figure 9, the algorithm would stop at sizes of about 50 households, missing the economies of scale that happen beyond 150 households.
To overcome this difficulty, we can smooth the generation-cost curve by adjusting the coefficients of a family of curves that guarantee monotonic behavior, so that the generation cost per This case illustrates the two main undesirable effects of having discrete diesel options. The first one is the instability of the generation mix concerning the demand. In this case, mini-grids with less than 50 consumers do not include a diesel generator and mini-grids with a range of consumers that lay between 50 and 100 consumers include a 10 kW diesel generator. However, mini-grids between 100 and 150 consumers do not include the diesel generator, because the 10 kW diesel generator is too small, while the 100 kW diesel generator is too big and expensive in this particular range of consumers. For mini-grids larger than 150 consumers, the generation solution includes the 100 kW diesel generator.
The second effect is that the unitary generation cost is not a monotonically decreasing function of the number of residential consumers, which is something expected due to the economies of scale in generation. This second effect causes issues in REM's bottom-up clustering algorithm. When trying to join two clusters into a larger one, the algorithm considers the trade-off between the additional network cost and the generation savings (due to economies of scale). Hence, if the generation cost per consumer starts increasing at some point, the algorithm would not find the best solution. In the case shown in Figure 9, the algorithm would stop at sizes of about 50 households, missing the economies of scale that happen beyond 150 households.
To overcome this difficulty, we can smooth the generation-cost curve by adjusting the coefficients of a family of curves that guarantee monotonic behavior, so that the generation cost per consumer always decreases when the number of consumers increases. Equation (1) defines this family of curves.
where x is the number of residential consumers; α, β, γ are non-negative parameters that REM adjusts, and P α,β,γ (x) is the approximated unitary generation cost for x residential consumers. Each curve of the form P α,β,γ (x) is a decreasing convex function. Note that the smooth curves must be replaced by smooth hypersurfaces in cases with more types of loads.
It is important to stress that the model uses the smooth curve only to determine the candidate mini-grids for a given case, and never to compute the final generation cost of the off-grid systems in the final electrification solution. REM always calculates the latter in an exact manner.

The Continuous-Component Implementation
Smoothing the cost values has some limitations. It may be difficult to smooth generation costs if we are working on a case with several types of loads. For example, it is debatable whether all types of loads should have equal importance when smoothing their generation costs. Residential loads are more frequent, but productive loads have a substantial impact on the final electrification solution.
It can be concluded from Section 3.2 that the use of discrete diesel generators in the master problem is problematic, and the computation time that the master problem needs to go through all the generators in the diesel space may be excessive for large mini-grids. Hence, we propose a new logic for the master problem that treats the diesel capacity as a continuous variable. The search is performed by trisecting an interval (i.e., dividing an interval into three segments of the same length with four points), which is shortened, discarding the diesel capacity that is further from the current best design and trisected again. The process continues until the length of the interval is lower than a pre-specified tolerance. The slave problem presented in Section 3.2 has performed well so far, so it has not been necessary to modify it.
It is clear that, when the diesel capacity is treated as a continuous variable, the results of the master problem are not so heavily influenced by the diesel generators available as the algorithm can interpolate among them to obtain a diesel generator of any desired capacity. Moreover, the number of diesel generators that the master level considers when calculating a generation design depends only on the demand of the representative mini-grid and the pre-specified tolerance considered to stop trisecting intervals on the master level. Therefore, the computation time needed is not conditioned to the number of diesel generators available, as opposed to the master logic described in Section 3.1, which requires all the generators in the diesel search space to be gone through.
A similar trisection procedure is applied in [38] to determine the optimal point of the I-V and P-V characteristics of a solar panel. It is essential to highlight that the continuous diesel generators are only considered to estimate the generation costs used to group the consumers into mini-grids, but they are not used to calculate the generation costs included in the final electrification solution.
We present an illustrative example in Figure 10. In this case, we assume that the pre-specified tolerance is 2 kW and the minimum capacity that meets the aggregated demand is 12 kW, so the boundaries of the diesel capacity are (0 kW, 12 kW). The first set of points is evaluated by trisecting this interval, which yields the 4 kW and 8 kW generators, and we assume that the lowest-cost point corresponds to the 4 kW diesel generator. Hence, the highest-capacity generator (12 kW) is discarded and the second set of points is obtained trisecting the interval (0 kW, 8 kW), which yields the 2.67 kW and 5.34 kW generators, and we assume that the lowest-cost solution for the second set of points corresponds to the 5.34 kW diesel generator. The lowest-capacity generator (0 kW) is therefore discarded, and the interval (2.67 kW, 8 kW) is trisected to obtain the third set of points, yielding the 4.45 kW and 6.22 kW generators. The lowest-cost point of the third set of points is the 4.45 kW generator, which is the final solution provided by the algorithm since |4.45 -2.67| < 2. The slave problem only needs to calculate generation designs for two different diesel capacities for each iteration, since the first and the last points of the i-th set of points also belong to the (i-1)-th set of points. Figure 11 shows the flow diagram of the master problem presented in this section.

Case Application
The method presented in Section 3 was applied to a case study located in the region of Cajamarca, in Northern Peru. This region has an area of approximately 400 km 2 , around 6700 buildings, and several potential connection points to the projected network of 11 kV. The Ministry of Energy and Mines approved the National Plan for Rural Electrification in Peru, which has the goal of achieving universal access by the end of 2022. The slave problem only needs to calculate generation designs for two different diesel capacities for each iteration, since the first and the last points of the i-th set of points also belong to the (i-1)-th set of points. Figure 11 shows the flow diagram of the master problem presented in this section. The slave problem only needs to calculate generation designs for two different diesel capacities for each iteration, since the first and the last points of the i-th set of points also belong to the (i-1)-th set of points. Figure 11 shows the flow diagram of the master problem presented in this section.

Case Application
The method presented in Section 3 was applied to a case study located in the region of Cajamarca, in Northern Peru. This region has an area of approximately 400 km 2 , around 6700 buildings, and several potential connection points to the projected network of 11 kV. The Ministry of Energy and Mines approved the National Plan for Rural Electrification in Peru, which has the goal of achieving universal access by the end of 2022.

Case Application
The method presented in Section 3 was applied to a case study located in the region of Cajamarca, in Northern Peru. This region has an area of approximately 400 km 2 , around 6700 buildings, and several potential connection points to the projected network of 11 kV. The Ministry of Energy and Mines approved the National Plan for Rural Electrification in Peru, which has the goal of achieving universal access by the end of 2022.
The location of the buildings was obtained by manual identification using images from Google Earth (see Figure 12), and the location of the projected network of 11 kV comes from the National Rural Electrification Plan of Cajamarca, although we do not consider the possibility of extending the power grid for this case study. The network catalogue is based on [39], where a similar case was analyzed using REM. All the consumers have the demand profile shown in Figure 13 (also used in the previous example in Section 3), which was estimated dividing the aggregated demand profile presented in reference [40] by the corresponding total number of consumers.
The capacities of diesel generators available are 10 kW, 100 kW (as in the previous example in Section 3), 200 kW, 600 kW, and 1500 kW (we included more capacities to cover the possibility of having mini-grids with more than 500 consumers). The generation designs calculated correspond to 1, 5, 10, 50, 100, 150, 200, 250, 300, 500 (as in the previous example in Section 3), 1000, 3000, and 7500 residential consumers. Tables 1 and 2 show the look-up table obtained with discrete and continuous diesel capacities, respectively. As shown in Table 1 and Figure 9, using discrete capacities is translated into non-monotonic behavior in the size of diesel generators in the range from 50 to 200 households. In contrast, the diesel capacity increases consistently with the number of residential consumers when handled as a continuous variable. The location of the buildings was obtained by manual identification using images from Google Earth (see Figure 12), and the location of the projected network of 11 kV comes from the National Rural Electrification Plan of Cajamarca, although we do not consider the possibility of extending the power grid for this case study. The network catalogue is based on [39], where a similar case was analyzed using REM. All the consumers have the demand profile shown in Figure 13 (also used in the previous example in Section 3), which was estimated dividing the aggregated demand profile The capacities of diesel generators available are 10 kW, 100 kW (as in the previous example in Section 3), 200 kW, 600 kW, and 1500 kW (we included more capacities to cover the possibility of having mini-grids with more than 500 consumers). The generation designs calculated correspond to 1, 5, 10, 50, 100, 150, 200, 250, 300, 500 (as in the previous example in Section 3), 1000, 3000, and 7500 residential consumers. Table 1 and 2 show the look-up table obtained with discrete and continuous diesel capacities, respectively. As shown in Table 1 and Figure 9, using discrete capacities is translated into nonmonotonic behavior in the size of diesel generators in the range from 50 to 200 households. In contrast, the diesel capacity increases consistently with the number of residential consumers when handled as a continuous variable.    Figure 14 shows the minimum cost design curve (obtained with the algorithm described in Section 3.1 and performing linear interpolation), the smoothed curve (obtained applying the procedure described in Section 3.2 to the minimum cost design curve), and the continuous results (obtained with the method presented in Section 3.3 and performing linear interpolation). The continuous implementation better captures the trend of economies of scale in generation.   Figure 14 shows the minimum cost design curve (obtained with the algorithm described in Section 3.1 and performing linear interpolation), the smoothed curve (obtained applying the procedure described in Section 3.2 to the minimum cost design curve), and the continuous results (obtained with the method presented in Section 3.3 and performing linear interpolation). The continuous implementation better captures the trend of economies of scale in generation. Figure 14. Generation cost obtained with the methods described in Section 3. Figure 15 and 16 show the cost breakdown of the generation designs obtained with discrete and continuous diesel capacities, respectively. As expected, designs that included a diesel generator had an OPEX that accounted for a much more significant amount of the generation cost. This effect especially stands out in Figure 15 as the design for 50 consumers includes a 10 kW diesel generator but designs for 100 and 150 residential consumers do not include a diesel generator.  Figures 15 and 16 show the cost breakdown of the generation designs obtained with discrete and continuous diesel capacities, respectively. As expected, designs that included a diesel generator had an OPEX that accounted for a much more significant amount of the generation cost. This effect especially stands out in Figure 15 as the design for 50 consumers includes a 10 kW diesel generator but designs for 100 and 150 residential consumers do not include a diesel generator.   Figure 17 shows the sizes of candidate mini-grids obtained with discrete diesel capacities, the corresponding smooth curve, and continuous diesel capacities. The candidate mini-grids obtained with the smooth curve and continuous generators are similar, but they are significantly different when generation costs are estimated directly from a look-up table calculated with discrete diesel capacities.   Figure 17 shows the sizes of candidate mini-grids obtained with discrete diesel capacities, the corresponding smooth curve, and continuous diesel capacities. The candidate mini-grids obtained with the smooth curve and continuous generators are similar, but they are significantly different when generation costs are estimated directly from a look-up table calculated with discrete diesel capacities.  Figure 17 shows the sizes of candidate mini-grids obtained with discrete diesel capacities, the corresponding smooth curve, and continuous diesel capacities. The candidate mini-grids obtained with the smooth curve and continuous generators are similar, but they are significantly different when generation costs are estimated directly from a look-up table calculated with discrete diesel capacities. Histogram that shows the number of clusters for each cluster size obtained with the different generation algorithms. There are also 14 clusters with more than 100 consumers in the smoothed case (the biggest one has 965 consumers) and 12 clusters with more than 100 consumers in the continuous case (the biggest one has 813 consumers), which are not shown for the sake of clarity.
All candidate mini-grids had less than 100 consumers when generation designs obtained with discrete diesel capacities. In the discrete-diesel-capacities case, the generation design for 100 residential consumers had a higher cost per consumer than the generation design for 50 consumers, which caused the clustering algorithm to reach a local optimum and larger mini-grids with lower unitary generation costs were never created. This issue, however, did not happen when the smoothed curve or continuous diesel capacities were used. Indeed, there were a few candidate mini-grids with almost 1000 residential consumers in those cases (beyond this point, the economies of scale in generation are negligible).
The candidate mini-grids that the clustering algorithm provides heavily influence results. Figure  18 shows the electrification solutions obtained when the generation costs considered in the calculation of candidate mini-grids were obtained with discrete capacities, the smoothed curve, and continuous capacities. All the solutions used mini-grids to electrify the vast majority of the consumers, but their sizes were significantly smaller when discrete diesel capacities were considered to group the consumers into mini-grids. Figure 17. Histogram that shows the number of clusters for each cluster size obtained with the different generation algorithms. There are also 14 clusters with more than 100 consumers in the smoothed case (the biggest one has 965 consumers) and 12 clusters with more than 100 consumers in the continuous case (the biggest one has 813 consumers), which are not shown for the sake of clarity.
All candidate mini-grids had less than 100 consumers when generation designs obtained with discrete diesel capacities. In the discrete-diesel-capacities case, the generation design for 100 residential consumers had a higher cost per consumer than the generation design for 50 consumers, which caused the clustering algorithm to reach a local optimum and larger mini-grids with lower unitary generation costs were never created. This issue, however, did not happen when the smoothed curve or continuous diesel capacities were used. Indeed, there were a few candidate mini-grids with almost 1000 residential consumers in those cases (beyond this point, the economies of scale in generation are negligible).
The candidate mini-grids that the clustering algorithm provides heavily influence results. Figure 18 shows the electrification solutions obtained when the generation costs considered in the calculation of candidate mini-grids were obtained with discrete capacities, the smoothed curve, and continuous capacities. All the solutions used mini-grids to electrify the vast majority of the consumers, but their sizes were significantly smaller when discrete diesel capacities were considered to group the consumers into mini-grids. Table 3 shows the electrification costs obtained with the methods described in Section 3. The generation costs used to compute the final cost of the mini-grids that appear in Figure 18 always correspond to the discrete diesel capacities shown in Table 1 (linear interpolations is Table 3 shows the electrification costs obtained with the methods described in Section 3. The generation costs used to compute the final cost of the mini-grids that appear in Figure 18 always correspond to the discrete diesel capacities shown in Table 1 (linear interpolations is used among these designs if needed), and the smoothed curve and continuous diesel capacities are used only to group consumers into mini-grids.  As expected, the final electrification cost was higher when REM grouped consumers into mini-grids, considering discrete diesel capacities, and it was lower when REM grouped consumers into mini-grids, considering continuous diesel capacities. Although the exact numbers depend on the network or generation catalogue, the crucial point is to notice that grouping the consumers into mini-grids using generation costs based on a model with only discrete generation components may be problematic.

Conclusions
Access to electricity is one of the most significant challenges of our time, and the consideration of off-grid systems as an alternative to the traditional grid extensions is crucial in rural electrification planning. Several methodologies and software tools deal with the problem of optimizing the generation design of a single off-grid system, but they cannot be easily applied to regional planning as opposed to the smaller scopes for which they were developed (i.e., village-based). On the other hand, most regional planning tools estimate the generation cost of off-grid systems with rules of thumb or analytic expressions that lack the accuracy needed for in-the-field implementation.
Closing the gap between the first-pass estimations that the majority of regional planning tools provide and an implementable rural electrification plan requires working at a higher level of temporal and spatial granularity. When a model operates at the consumer level, it needs to group the consumers into mini-grids. Larger mini-grids usually benefit from economies of scale in generation components at the expense of having a more substantial network cost, so the best way of grouping consumers into mini-grids emerges from the trade-offs between these two costs.
As the range of feasible sizes (understanding size as a combination consumer numbers and aggregated load) for off-grid systems can be enormous in a large-scale project (i.e., we could have isolated consumers but also mini-grids of thousands of consumers), it could be necessary to estimate the generation cost of many off-grid systems to properly group consumers into candidate mini-grids.
This paper presented a method that calculated the generation cost of any potential off-grid system in a large-scale rural electrification planning case, balancing accuracy with computation speed. The method optimized the generation design of a reduced set of representative off-grid systems, and the generation cost of the remaining ones was obtained by performing interpolation. The generation costs that the method estimated were later used to group the consumers into mini-grids, so it was essential to capture the savings resulting from the economies of scale in generation equipment.
Some mini-grids components such as solar panels and batteries behave in a quasi-continuous manner, and any desired capacity can be approximated with a parallel rack of elements available in the catalogue. Other components such as diesel generators have a more discrete behavior since their parallel operation involves a high degree of complexity, which implies that some capacities may not be approximated with the elements available in the catalogue. It is critical to apply a master-slave decomposition that deals with the different nature of components. It can be concluded that components with discrete behavior could distort economies of scale in generation, which hinders grouping the consumers into mini-grids.
The paper introduced two procedures that mitigated the impact of components with discrete behavior on economies of scale. The first one approximated the generation costs with a smooth curve, and the second one modelled the capacity of elements that could alter the economies of scale with continuous variables. Both methods ensured that larger mini-grids benefited from economies of scale in generation when grouping the consumers into mini-grids, but the method based on continuous variables was directly applicable to cases with several types of loads.
The case study shows that a straightforward application of any model based only on discrete components (such as single-system methods or tools) could lead to suboptimal solutions when the consumers are grouped into mini-grids. It could be concluded that the two procedures introduced in this paper led to the better grouping of consumers into mini-grids.
Regarding future research, the method presented in the paper has two significant limitations. Firstly, the number of generation technologies was limited to solar panels and diesel generators, and renewable energies such as wind or hydro should be included in future developments. However, the addition of generation technologies involves dealing with more dimensions when optimizing the generation design of an off-grid system from scratch, which would increase the computation time. Secondly, demand profiles are considered deterministic input parameters, whereas there is much uncertainty about demand in developing countries. Hence, future research should aim at developing a more robust method that can deal with uncertainties.