Sizing and Sitting of DERs in Active Distribution Networks Incorporating Load Prevailing Uncertainties Using Probabilistic Approaches

: In this study, a microgrid scheme encompassing photovoltaic panels, an energy storage system, and a diesel generator as a backup supply source is designed, and the optimal placement for installation is suggested. The main purpose of this microgrid is to meet the intrinsic demand without being supplied by the upstream network. Thus, the main objective in the design of the microgrid is to minimize the operational cost of microgrid’s sources subject to satisfy the loads by these sources. Therefore, the considered problem in this study is to determine the optimal size and placement for generation sources simultaneously for a microgrid with the objectives of minimization of cost of generation resources along with mitigation of power losses. In order to deal with uncertainties of PV generation and load forecasting, the lognormal distribution model and Gaussian process quantile regression (GPQR) approaches are employed. In order to solve the optimization problem, the lightning attachment procedure optimization (LAPO) and artiﬁcial bee colony (ABC) methods are employed, and the results are compared. The results imply the more effectiveness and priority of the LAPO approach in comparison with ABC in convergence speed and the accuracy of solution-ﬁnding.


Introduction
In recent years, the increase in electrical demand, the rise of crude oil and natural gas prices, restructuring and the growth of privatization, and the advent of modern technologies have been led to revolutionary changes in the electricity industry and the assumption of specific attention to distributed generation (DG) technologies [1][2][3]. DG sources or small-scale electricity sources can generate power in the range of 1 kW to 10 MW in the location of the load or in the vicinity of consumption centers. DG technologies bring tangible benefits such as peak clipping (peak shaving), improvement of reliability indices, reduction in power losses due to being close to consumption places, alleviation of voltage drops and improvement of voltage profile, etc., for distribution networks. In addition, the integration of renewable clean energy sources, such as solar, wind, and fuel cell sources, has promoted the power system planners and experts to use these DG units as much as possible [4,5]. The increase in the pervasiveness of DGs and the combined use of various types of DG sources has resulted in the emergence of the microgrid concept. The microgrids are generally defined as small-scale power systems in distribution voltage level encompassing some DGs and some electrical and thermal loads usually accompanied by energy storage systems (ESS) [6,7]. novel method to deal with the uncertainty of load forecasts as well as the uncertainty of renewable generation sources to solve a placement problem. Similar studies are conducted in which the uncertainty of load, price, and renewable sources are investigated [35][36][37].
In this paper, a hybrid energy system is designed, which is regarded as a microgrid in a distribution network. The costs of operation, maintenance, and investment are also taken into account. In order to deal with uncertain variables of solar generation, the lognormal distribution model is employed to exploit the trends and patterns of solar irradiance. In addition, the Gaussian process quantile regression is applied as the forecasting approach to deal with uncertainties of load forecasting. A novel optimization algorithm is employed in order to optimize the performance and to find the optimal location for the installation of DGs. It is supposed that the microgrid is connected to the upstream network. Hence, the cost of energy exchange with the main grid is also taken into consideration in the objective function. The proposed scheme is implemented on the 69-bus IEEE test system in order to evaluate the effectiveness of the model. In Section 2, the problem outlines are described. In this section, the objective function and the constraints of the problem are expressed. In Section 3, the employed optimization algorithm is explained, and in Section 4, the simulation and results are discussed. Ultimately, in the last section, the conclusions are drawn.

Problem Outlines
As declared, the purpose of this study is to design a microgrid scheme subject to supply the loads in a distribution feeder or network. This microgrid consists of a PV panel, an energy storage system, and a diesel generator as a backup source of energy. The primary goal of this study is to determine the optimal size of the PV panel, diesel generator, and the sufficient quantity of batteries to maintain an uninterrupted supply for the loads with respect to the objective function of the problem. Hence, at first, the demand for the microgrid must be specified.

Microgrid's Demand
The contemplated microgrid is a local distribution network that has a variable load during a day. With regard to the incremental trend of consumption of residential and industrial loads at the early hours of the evening, the peak of the demand curve is supposed to be in the evening. In addition, with regard to the consumption pattern of industrial loads, another peak exists around midday hours. Thus, in order to consider the load pattern of the microgrid, a 24 h load profile with two peaks is taken into account as figured out as follows. Figure 1 demonstrates the normalized demand of the microgrid. It is noteworthy to assert that the load of the distribution network is also determined in a similar way.

Microgrid's Supply Strategy
The first goal of size determination of microgrid's generation sources is to supply the loads in this micro-scale grid. The PV panels have a vital role in power provision for the loads. However, when PV panels cannot generate sufficient power, the energy storage unit and diesel generator unit are responsible for meeting the loads. Thus, the optimal supply strategy can be express as follows:

Enjoying Photovoltaic Panel's Power
A. If the PV generation is more than the grid's demand and the batteries are not fully charged, the excess PV generation should be stored in the batteries; B. If the PV generation is more than the grid's demand and the batteries are fully charged, the excess generation of PV panels must be sold to the distribution network; C. If the PV generation is lower than the grid's demand, a portion of the loads will be supplied through PV generation, and the rest of the demand must be procured through the energy storage system; D. If the PV generation is lower than the grid's demand and the battery system is not adequate to supply the loads entirely, the loads will be satisfied by PV panels and energy storage units as much as possible, and the rest of the loads must be met by the diesel generator; E. If the total generation by PV panels, batteries, and the diesel generator is not sufficient for satisfying the load, the load-shedding measure must be imposed for the excessive demand.

Being Deprived of PV Generation
A. If the batteries' capacity is adequate to supply the demand, the loads will be served by the batteries solely; B. If the batteries' capacity is not sufficient to supply the demand, the rest of the loads must be served by the diesel generator; C. If the demand is more than the combined capacity of PV panels and the diesel generator, the rest of the loads must be remained unsupplied by load shedding.
It should be noted that the unsupplied load cannot be higher than 25% of the total demand of the grid. In addition, the capacity of the diesel generator must be so determined that it is not allowed to operate less than 20% of its maximum capable generation.

The Objective Function
When the suggested capacities for the generation sources are adequate to supply the microgrid's loads properly, the excess generated power can be sold to the distribution network. However, it must be determined which bus in the distribution network must be chosen, from which the excess generation will be injected into the distribution grid. The injection point has a considerable impact on the performance of the distribution grid. Thus, the location of the microgrid is an important item. Hence, the optimal placement of the microgrid must be investigated. The objective function for the optimal placement of the microgrid can be expressed as follows:

Power Losses
In order to model the power losses, the losses are supposed to be as a power, which must be bought from the upstream network. Thus, it is modeled as a cost in the overall objective function equation. This objective can be expressed as follows: In the above equation, ρ t,d denotes the price of electricity on the day of d at hour t, and P i,t,d loss stands for the number of losses on the day of d at hour t in the ith line. It is noticeable that the price of electricity at peak, mid-peak, and off-peak hours is different.

The Cost Related to the Photovoltaic System
Deployment of solar energy incurs installation cost of PV panels, operation and maintenance cost, and replacement cost. Thus, the cost pertaining to PV panels can be modeled as below. The subscript of PV a is a symbol for a photovoltaic unit, O&M addresses operation and maintenance cost, inv indicates investment cost, and rep corresponds with replacement cost.

The Battery Cost
The energy storage facility in this work is a set of batteries that have similar costs, such as the PV panel, and can be formulated as Equation (4). The subscript of bat stands for battery energy storage system, O&M addresses operation and maintenance cost, inv indicates investment cost, and rep corresponds with replacement cost.

The Cost Pertaining to Diesel Generator
The cost of such equipment consists of investment cost, maintenance cost, and replacement cost. The subscript of dg stands for the diesel generator, O&M addresses operation and maintenance cost, inv indicates investment cost, and rep corresponds with replacement cost.

The Cost Pertaining to Load Shedding
If the load-shedding measure has to be imposed, this matter incurs a cost to the model, which must be included in the objective function of the problem.

The Profit Yielded by Excess Generation Selling
If the power generated by the PV panel is higher than the demand of the microgrid and charging capability of batteries, the excess power can be sold to the distribution network and earn a profit. The obtainable benefit (profit) can be calculated by the following equation: In above, B ex is the benefit (profit) gain by the sale of surplus generation, and P t,d ex shows the amount of surplus power on the day of d and at hour t.

Constraints
The optimization problem is accompanied by a set of technical constraints that restrict the solution space and must be considered in the model. These constraints can be defined as follows: The power balance equality constraint during all intervals of a day: The maximum permissible load shedding in the microgrid: Generation balance in the distribution network must be observed. 24 ∑ t=1 P t g + P t ex + P t slack − P t loss − P t D_dis = 0 The boundaries of the photovoltaic panel and diesel generator must be met.
The voltage of buses must be restricted within their permissible range.
The power flow passing through the lines must be restricted.
In the above equations, P t PV , P t dg , and P t bat represent power generation of PV panel, diesel generator, and batteries, respectively. Moreover, P t D_mic indicates the consumption of the microgrid at hour t. The shed load of the microgrid is shown by P t sh . In addition, P t g , P t ex , P t slack , P t loss , and P t D_dis represent the power generated by the generators in the distribution network, the exchanged power of the microgrid with the distribution network, the power maintains from the slack bus of the distribution network, the power losses in the distribution network, and the consumption of the distribution network at hour t. Moreover, P t PV , P t dg , V, V min , V max , F b , and Limit b stand for the maximum capable power generation by PV panel, the maximum capable power generation by a diesel generator, bus voltage, the minimum and maximum permissible voltage of buses, the flow passing through branch b, and the thermal limit of branch b.
The prevailing constraints of the problem can be divided into two general categories of network constraints and storage constraints that must always be observed when seeking for optimal point in the solution space. Network constraints include the following two constraints: As the thermal limit constraints express, the feeder power flow is not allowed to violate a specific cap.
The hourly constraints pertaining to the energy storage unit consist of two constraints of the maximum storage capacity and charge/discharge rate limits. This limitation expresses that the storage charge level must always be below the maximum storage capacity and can be formulated as follows: In this equation, t represents the time, P ch and P dch denote the charge and discharge rates, and SoC stands for the state of charge of the storage unit that has a maximum storage capacity limit and a minimum storage capacity boundary owing to the long-run operation and maintenance facets. Each storage unit can be charged or discharged by a limited amount within an hour. The last equation also ensures that the storage unit cannot operate at charge and discharging modes simultaneously. In this equation, I(t) is a binary variable.

The Uncertainty Modeling for PV Sources
The nature of solar power and photovoltaic irradiance can be represented by various types of distribution functions. One of the most efficient types for this purpose is the lognormal probability distribution function (PDF), which effectively and precisely characterizes the intensity of irradiance on a typical day. The PDF of solar irradiance (ζ s ) trailing the lognormal distribution function with a mean value of µ s and standard deviation of σ s that is presented in Equation (20).
The solar power generation (P PV ) depends on the solar radiation intensity, also known as solar irradiance, which is shown by ζ s . The generation curve can be different based on different items such as the location and type of installation, the technology of solar panels, as well as the ambient temperature. A typical photovoltaic irradiance-power curve is given in Equation (21).
The amount of power generation by a solar panel depends on different factors, which can be estimated by Equations (21) and (22). Above, η stands for efficiency, and T a denotes the ambient temperature.
In order to model the intermittencies, a dataset of historical records associated with the solar radiation. Such irradiance datasets can effectively be matched with a lognormal or Weibull distribution function. These distribution models usually have high mathematical compatibility with various natural phenomena. The PDF helps to generate randomly derived samples within the occurrence range while specifying a confidence range to eliminate low-probable cases. For each scenario, a random value is derived from the lognormal model. If the number of scenarios is high, various scenario reduction techniques can be employed that merge similar cases into one class. Based on the model objectives, the operation state can be adjusted within the confidence range with respect to the level of risk chosen by the operator. The operator can arrange the operation point in a risk-averse zone to ensure a reliable and secure operation, although it incurs higher costs. On the other hand, the operation of the grid, with respect to the whole uncertainties, can be stated in a high-risk zone by ignoring less-probable incidences to boost the profitability and the economy of the model.

Load Forecast Uncertainty
Load forecasting is a critical item in many planning applications in power systems. Load forecasting can also be performed in different intervals for various purposes. Load forecasts are dependent on weather conditions (temperature, humidity, air brightness, wind speed). In addition, each day of the week has its own load curve. Load consumption curves on holidays and non-holidays are also different from each other. In different seasons of the year, according to the factors specific to each season, such as day length, the load consumption pattern will be different. Short-term load forecasting is a pivotal data needed for running a day-ahead market. The results of STLF are employed by GENCOs to discover prices with regard to the way other market participants may act. Price forecast signals are also applied to bidding strategy techniques to maximize profitability. The system operator will clear the market for the next-day delivery according to the forecasted values along with the bids from GENCOs. ISO is responsible for balancing the market between generation level and the forecasted demand at each interval. However, with regard to the inaccuracy of forecasts, there is always a violation that must be redressed by storage units or other controlling actions such as load shedding.
There are multiple approaches to deal with load forecasting. The most common methods are the time series method, regression methods, and intelligent methods. Intelligent methods are also classified into several categories such as artificial neural networks, fuzzy logic-based methods, also ANFIS models, wavelet transformation methods, as well as support vector machines. In order to deal with uncertainties, probabilistic models can be integrated into the employed load forecasting paradigm. In this study, the Gaussian process quantile regression (GPQR) is employed to deal with uncertainties [38]. Due to the stochastic nature of load patterns as well as various external factors such as weather conditions, calendar effects, and seasonal factors, the power demand signals exhibit intermittent and volatile characteristics. Hence, a prediction scheme is needed to provide the most probable distribution of power demand patterns rather than a crisp value. A Gaussian process model is a set of random variables, in which any member corresponds with a probability distribution that can be represented by the following function: In this equation, µ(l) and COV(l,l ) denote the mean and covariance functions that can be calculated as follows: The covariance function illustrates the similarity between data points. One of the most widely-used functions for describing covariance is the squared exponential (SE) model that can be represented as follows: The parameters θ f and θ l control the scale and length. With regard to the differentiability of this covariance, which implies that the Gaussian process is very smooth, a simplified alternative, known as Matern covariance, can be replaced because, in practice, no phenomena do not reflect such a strong smoothness.
In the above, B v represents the modified Bessel function, in which v and i are both positive hyperparameters. To simplify this covariance function, the value of v is supposed to be v = p + 1/2. In this parameter, p is a non-negative integer. The value of v is set as 5/2 or 3/2 in most previously conducted research studies, which subsequently and, respectively, are named Mat5 and Mat3. The probabilistic prediction model also has another covariance function named the period covariance, which is useful to model periodic phenomena and can be described as follows: Typically, the load forecasts are highly influenced by a variety of features that can be defined by Equation (29). According to this equation, load at time t depends on the similar hours (t∈{0, 24}) throughout the historical records, the day of the year (d∈{1, . . . , 365}), the value of the load at similar intervals, the value of weather variables such as temperature, and the price at similar intervals.ŷ GPQR method seeks for the relationships and correlation between inputs and output based on a probabilistic framework. Quantile regression (QR) delineates a type of regression analysis that detects and exploits the relationships between quantiles of the conditional distribution of a response variable and input variables. The least absolute deviations regression integrates the median of the conditional distribution, which is called the norm regression case of quantile regression shown by L 1 . Unlike least-squares regression and norm regression, the quantile regression encompasses minimization of the summation of asymmetrically weighted absolute residuals. Hence, QR can find more sophisticated relationships between inputs and outputs with better precision. QR has more flexibility and compatibility to deal with large datasets, such as market analysis or econometrics. With regard to the accuracy of predictions, the loss function can be described as follows: The required quantile is defined by τ∈[0, 1] and ε i = y i −ŷ i so that y i is the actual model andŷ i denotes the predicted quantile model. So far, different linear programming methods are employed to achieve the desired quantiles through direct loss function minimization, which leads to the maximization of a likelihood. To solve this drawback, the Gaussian process is incorporated into the QR model. The density function of loss based on this model can be represented as follows: where τ∈[0, 1] is responsible for shaping and controlling the skewness of the distribution curve, µ stands for the mean value, and σ denotes the standard deviation, which should always be positive. The binary variable I takes the value of 1 when the condition is true; otherwise, it takes 0.
In Equation (32), q denotes the predicted value of the τ quantile, Z is the normalization constant. Afterward, a Gaussian process is placed on the QR function: The GPQR model training can be conducted by integral maximization. The expectation propagation algorithm can be employed to locally approximate this integral.
Suppose a dataset of historical load records as l = {x 1 , x 2 , . . . , x N }, which are independently distributed samples. The estimated shape of this distribution function can be obtained through a Gaussian kernel density estimator model.
Mean absolute percentage errors (MAPE) and root mean squared error (RMSE) are two employed evaluation metrics that can exhibit the performance of the forecasting model.

Energy Management Paradigm by Microgrid's Controller
The controlling framework of a microgrid is a vital element in this planning scheme. The microgrid controller, also known as the microgrid operator, is responsible for collecting raw data and analyzing them to find the optimum operation point with respect to all operational constraints of both sides. In other words, it has to provide an accurate estimation of generation sources for all intervals and take a sensible range of risk for being preserved from the detrimental zone. Then it can dedicate the level of power exchange with the upstream grid for various hours. To implement such an intelligent autonomous mechanism, a smart environment is needed that is only feasible through IoT infrastructures [39]. The following flowchart concisely describes the proposed scheme. The paradigm of the proposed scheme is depicted in Figure 2.

Lightning Attachment Procedure Optimization (LAPO) Method
This algorithm was inspired by the procedure of lightning the attachment process to the ground or any type of earthed object. In order to simulate this optimization algorithm, at first, some test points are considered on a cloud or the ground as the initial population. By increasing the electric field at the points on the cloud, the streamer channels begin to break down the air and move toward the ground, which is called a downward leader. As these downward leaders move toward the ground, the opposite charges will be enhanced in the ground and produce upward leaders. The striking point at the final jump step is a point where the upward leader collides with the downward leader [40][41][42]. The algorithm is composed of some sections that will be presented as follows:

Initialization
At first, the test points on the surface of a cloud as well as on the ground are defined. These dedicated charges are called the initial population.

The Next Jumping Node
Each branch of the lightning has some probable points in front of itself, which can move toward one of them. The choice of the next jumping point of the lightning is highly correlated with the intensity of the electric field between the point and the probable points. Of course, the next jump will not necessarily be toward the point with the maximum field, and part of the process of selecting the next point will occur randomly. For the mathematical modeling of this section, a random node is selected for each node in the search space. If the electric field in this point (merit value of the point or the fitness value at the intended point) is greater than the background field (which is supposed to be the mean field), the lightning moves toward this point; otherwise, the path of lightning will be in another direction. It is noticeable that the term opposite direction does not imply an upward movement exclusively rather than an angled motion toward this point. Hence, for determining the next jump, the following equation can be employed:

Streaming Forward and Elimination of Branches
When a new lightning branch is formed, this branch can stream downward until the branch's charge cuts down and becomes lower than a specific value (critical value). The critical value is assigned to be 1 µC because the air cannot be broken down for the lower levels of charges, and the branch will be faded.

Upward Leader Propagation
When the branches start to move downward, the upward leaders start to move upward. The motion speed of the upward leader is correlated with the amount of charge aggregated at this point as well as the total charge of the downward branch. The distribution of charge in the downward branch is so that there are fewer charges near the cloud and more charge at the tip of the leader. This is why the tip of the leader is brighter. This incremental charge aggregation over the branch can be considered as a linear or exponential function. Here, the branch's charge is considered exponentially, as pointed out by the following two equations: Above, C C denotes the branch's charge, X min is the charge of the branch in the tip of the leader, X max indicates the branch's charge at the beginning point. The upward leaders will be propagated according to the following equation:

Convergence
When an upward leader reaches a downward leader, the collision point of the lightning will be determined. In other words, when the optimum point is specified, the algorithm will be terminated. The abovementioned procedure will be iteratively executed until the optimum point is found.

Simulation and Results
In this section, the optimal placement for the microgrid is carried out on the targeted test system. The targeted system is a radial 69-bus IEEE test system, which is depicted in Figure 3 in the form of a single-line diagram. In addition, in order to have a better appraisal of the effectiveness of the proposed method, the proposed method is also tested on a radial 33-bus IEEE test system, which is depicted in Figure 4. However, the input data is the same for both grids. In this paper, all the methods are implemented in MATLAB 2018a in a Core i5 PC with 3 GHz processing frequency of CPU and 8 GB of RAM. The convergence behavior is another aspect with which the methods are compared to each other.  The characteristics corresponded with the lines and the buses of this system refer to [43,44], respectively. The normalized demand of the microgrid is shown in Figure 5. The demand for this microgrid at the peak is considered to be 250 kW. The peak of the load curve of the grid is supposed to be the mid-peak demand obtained from [43,44]. Moreover, the hourly solar insulation profile is normalized and illustrated in Figure 6.  The maximum generation capability of the PV panel per month is shown in Table 1. The placement mechanism is executed in the worst condition. Thus, the calculations are conducted for the month of August. This month indicates the lowest level of mean solar radiation. The economic data for different sources were extracted from reference [44]. The investment cost of the PV panel is considered to be 7.44 €/kW, and the O&M cost is supposed to be 40 €/year. The cost of each battery is determined as 0.283 €/Ah, and each battery incurs 50 €/year for O&M costs. The operation cost and maintenance cost of the diesel generator is 0.55 €/W and 0.2 €/h, respectively.
The demand in the targeted microgrid is supposed to be composed of residential and industrial loads. Table 2 delineates the price of electricity corresponded with the types of loads and the demand level.

The IEEE Test Systems (33-Bus and 69-Bus)
The optimization for the 33-bus test network is conducted with regard to the acquired economic data. The results are demonstrated in Table 3. In addition, the convergence behavior of two targeted methods in reaching the optimal solution is illustrated in Figure 7. Accordingly, the LAPO method has reached the optimal solution with fewer iteration. In terms of accuracy, the results of LAPO are better than the ABC algorithm. As can be seen, at the early hours of the time horizon (at midnight), when there is no solar power generation, a battery energy storage unit can supply the demand of internal loads of the microgrid as it is clear that the battery power is negative during these hours, which indicates that it is discharged. The battery starts charging after 8:00 and reaches its maximum charge level at 11:00. Therefore, no power is stored in it until it starts discharging again at 18:00. It is recharged at 19:00 and fully discharged at 20:00 due to the high volume of consumption. The diesel generator commits at 8:00 and stops power exchange at 9:00. These conditions continue until 20:00, and after that, it continues to serve the loads until midnight. Due to the significant amount of solar production, a large volume of this production is sold to the distribution network, and the obtained profit improves the objective function. As it is evident, the network is designed in such a way that no load is interrupted during the day and all the loads are completely satisfied.  With regard to the economic data provided in the previous section, the optimization problem is simulated on the 69-bus test system. The optimized results of the simulation are presented in Table 3. In addition, the convergence behavior of both optimization techniques employed in this study is depicted in Figure 8. As can be seen, it is evident that the LAPO approach not only has reached the optimal solution in less iteration, but also it has found a better solution in comparison with the ABC method. The behavior of the microgrid in August is illustrated in Figure 9. As can be perceived, in the early hours at midnight, while the sunrise has not occurred, the battery is responsible for maintaining power for the microgrid. Thus, the power battery is negative in these hours, which implies that the battery is discharging. The battery starts to be charged at 8:00 in the morning, and it will be fully charged at 11:00. Hence, the batteries will not be charged anymore and remain idle until 18:00. At 18:00, the batteries are to some extent discharged. However, they are charged again at 19:00. With regard to the high level of consumption at 20:00, the batteries deliver all of their stored energy to the microgrid. The diesel generator is connected to the microgrid at 8:00, and it is disconnected at 9:00. It continues until 19:00. Again, at 19:00, the diesel generator starts to supply the load until the end of the time horizon of this study (24:00). With respect to the high level of solar generation, a considerable share of this production is sold to the distribution grid. The obtained economic benefit has improved the objective function. As it is clear, the microgrid is so designed that the loads are supplied entirely and load shedding has not occurred. The microgrid behavior in August is depicted in Figure 9. The power purchased from the main grid is shown in Figure 7. As it shows, during the day hours when there is solar energy, the demanded power from the upstream grid is drastically reduced. It should also be noted that the network losses and the corresponding costs were 1061 kW and 55.86 € per day, which reached the values of 956.79 kW and 51.78 € per day, after the installation of microgrids in the network, respectively. Figure 8 shows the amount of load shedding in the distribution network at different times of the day. The results figure out that during the hours when there is solar energy, solar unit injects power into the distribution network, the amount of shed load has reached zero, which is very beneficial in terms of cost and efficiency for the distribution network as well as reliability improvement from microgrid point of view. The model is also tested on the 69-bus test system. The results imply that the bought power from the main grid by the 69-bus distribution network is illustrated in Figure 10. As it is evident, during the hours that the PV panel can generate power, the absorbed power from the sub-transmission grid is considerably diminished. The power losses of the distribution grid and the subsequent cost of them were about 1350 kW equivalent with 65.76 €/day before the implementation of the microgrid scheme, and it is alleviated to 989.32 and 56.28 €/day after implementation of the microgrid. In Figure 11, the hourly shed load in the distribution network is shown. It is obvious that whenever the PV generation exists, all of the loads in the distribution grid are satisfied, and no load-shedding measure in the distribution network is executed. This matter significantly improves the performance of the distribution network.

Incorporation of Uncertainty in the Model
The demand for a grid and the daily radiation intensity are not deterministic parameters, and they usually have uncertainties. Hence, these parameters must be forecasted, and the scheduling must be conducted based on the forecasts. Therefore, the existence of forecasting error is inevitable, and the error must be included in the optimization model in order to mitigate the risk. A common way to model the uncertainties corresponded with solar radiation and demand of the grid is to employ a normal probability distribution. In other words, the mean value and the standard deviation of these parameters are calculated, and the design and the scheduling must be carried out based on these forecasts. The most famous and the most accurate approach for dealing with uncertainties and probabilistic problems is the Monte Carlo algorithm. In this approach, a large number of probabilistic samples are defined within a specified range, and the scheduling is performed for all of these samples. Then, the probability density function of targeted parameters is extracted. In this study, an upper and a lower boundary are dedicated for the demand of microgrid and distribution network along with the daily solar radiation. It is supposed that the radiation and demand will be materialized within the defined range. These boundaries are depicted in Figures 12-14.   In order to solve the stochastic problem, the Monte Carlo approach is employed. In this respect, for each uncertain parameter, 1000 stochastic samples are generated randomly. To solve the stochastic problem, the following step-by-step procedure is considered:

•
Step 1-Generation of 1000 samples for each uncertain optimization variable.

•
Step 2-The stochastic generation of a set of solutions for optimization variables.

•
Step 3-The selection of a set of optimization variables.

•
Step 4-Test the grid's performance for 1000 samples using the Monte Carlo approach and checking all constraints for 1000 plausible scenarios.

•
Step 5-The calculation of the objective function (if the constraints are met).

•
Step 6-Check convergence and termination conditions. If it is converged, then go to step 9.

•
Step 7-The change of optimization variables based on the optimization method.

•
Step 9-End. Table 4 outlines the results of the design of the microgrid with the incorporation of uncertainties. In the case of the 33-bus test system, the cost of power generation is greatly increased. This increase is due to the conditions in which the load may be maximum and production may be minimum. Therefore, these conditions must also be taken into account in the problem. However, as can be seen, the cost has increased by nearly 49% compared to the case where uncertainty is not considered. Thus, it should be considered that in the presence of sources of intermittency, the cost of power supply from the network may increase remarkably, which conveys the importance of stochastic solution.
The increase in the system cost pertaining to the uncertainty will be 27%, which is nearly 20% less than the previous case. Therefore, the uncertainties are applied to the model using the average intermittencies in the system cost in all possible scenarios as an objective function. As can be seen, in the stochastic model, the cost of the system has increased by 26% compared to the deterministic case.
As the results of the 69-bus test system figure out, the cost of supply in this condition is significantly increased. This increase conveys a condition that the demand is at a high level and the solar radiation is at a low level. Therefore, the worst conditions must be contemplated in the design of the microgrid. However, as it is evident, the cost is drastically increased by 50% in comparison with the case of the deterministic model (regardless of uncertainties). Thus, it should be noted that the overall cost of the microgrid scheme may be enhanced extensively for uncertain problems.
It is important to pay attention to a critical question. The cost of supply has increased by 50% in order to include uncertainties. It conveys a high level of consumption and a low level of generation. The occurrence of such generation and consumption levels for this system at the targeted time is not a definitive and certain event. The question is whether it is sensible to increase the cost of the system by 50% for a forecast that has an occurrence probability of 10%.
In the procedure of seeking the optimum solution of uncertain parameters, for each suggested answer provided by the optimization program, all possible scenarios are taken into account, and the highest cost incurred to the system, among all scenarios, is regarded as the cost of the suggested answer. If the suggested answer does not satisfy even one or more constraints, that answer should be dismissed. Such a procedure profoundly mounts the system cost.
In order to tackle this problem, no answer should be dismissed, and the system cost must be obtained for all answers in as scenarios, even when they were unable to meet some constraints. Finally, the average cost of all scenarios is dedicated to the answer. Hence, if the suggested answer does not meet the constraints in some scenarios, the answer will not be dismissed. It is obvious that, for the problems with a few scenarios, the inclusion of scenarios, which used to be disregarded, does not have a remarkable impact on the solution of the problem. With consideration of the proposed condition, the optimal results of the simulation can be expressed in Table 5. This assumption has been led to an increase of 26% in the system cost for the incorporation of uncertainties in the model. It is just over 20% fewer than the normal approach. Thus, the uncertainties can be included in the design by incorporation of the average cost of the system. As can be seen, the system cost has increased by 26% in comparison with the deterministic approach. Table 5. The results of optimal sizing of test grids incorporating uncertainties of demand and solar radiation and the consideration of the average cost of stochastic scenarios as the objective function.

Conclusions
In this study, a microgrid scheme including loads, PV panels, energy storage system, and the backup supply system of a diesel generator was designed. The object of the design was to minimize the cost of supply. In this microgrid, it was intended to not absorb any power from the distribution grid. However, if there is an excess of generation by intrinsic power resources of the microgrid, the excess power would be sold to the distribution network. The costs pertaining to PV panels, batteries, and diesel generator consists of purchasing and installation cost, operation and maintenance cost, and replacement cost. If the proposed scheme cannot supply the loads (generation deficiency) at some hours, the load-shedding measure must be imposed for the surplus demand. Just the same, the excess generation must be injected into the upstream network. In order to boost the performance of the design, the placement of the microgrid is so determined that the network power losses are minimized. Thus, the optimal design of the microgrid was performed at the same time as the placement of the microgrid. The problem solution was targeted to be stochastic. Hence, two upper and lower boundaries were dedicated to the amount of demand and solar irradiance. In order to solve the problem, the Monte Carlo approach with 6222 random samples is employed. The results of the 33-bus test system imply that the incorporation of uncertainties in the model has drastically increased the supply cost by about 49%. In order to avoid unnecessary risks, the averaging method is deployed, which boosts the risk-averse scheduling. In this case, the system cost has increased by 27% in comparison with the deterministic approach. The results of the 69-bus test system imply that the incorporation of uncertainties in the model has drastically increased the supply cost by about 50%. In order to avoid unnecessary risks, the averaging method is deployed, which boosts the risk-averse scheduling. In this case, the system cost has increased by 26% in comparison with the deterministic approach. The optimization is solved using the LAPO method, and the results are compared with the ABC algorithm. The results indicate the proper performance of the suggested algorithm in terms of convergence speed and accuracy.