Week 14: Particle Swarm Optimization
- ainergyy
- Jan 19, 2022
- 3 min read
Updated: Jan 20, 2022

Initially, this week we started studying and structuring the optimization problem we decided to solve regarding the energy community. This problem consists in optimizing the energy usage in a full day (24 hours) by minimizing the energy costs without affecting to much the individual community's members' comfort. The day is divided into 24 periods that correspond to the 24 hours.
Because we were using the predicted consumption and production used by the machine learning algorithms, we assume that the comfort of the community (which can be seen as flexibility) was 15% of the total consumption predicted for each community member (this value is still being discussed with the expert).
The objective function was designed to reduce the financial cost at the end of the day. For this, the PSO algorithm will have to use the output variables in its favor which are: the individual consumption per community member and per period, the battery storage at the end of each period, and the energy balance for each period (where a positive value represents the purchase of energy and a negative value represents the sale of the energy).
The Cost (Eq. 1) is calculated using three formulas: the difference between the energy bought and sold times the energy price for each period; the penalty cost to pay by minimizing the comfort of the community members for each period; and the cost of the wear of the battery through the day, because the more we use the battery the more it degrades.

Equation 1 - Matemathical formula of the objective function
We can divide the Objective Function in three parts. Firstly, the its calculate the cost associated to each period i, 24 periods in total. For each period its calculated the difference between the Purchased Energy (Pi) and the Sold Energy (Si) times the Energy Price (Pei) of that period i. Inside each period we will add the cost of the confort penalty for each house j. That is calculated using the difference of the Maximum Consumption (Cmaxij) and the optimized Consumption (Cij) times the Confort Penalty Price (Pcij) for the period i and the house j. Reducing the confront of the community members has a different price depending on the period and the house. Lastly we have the Battery Wear (Bw) that calculates the wear of the battery for the whole set of periods.
For this formula to result, it is necessary that the output variables follow some requisits/restrictions, namely:
the battery charge and discharge rate have a velocity that must be respected (Eq. 2);
the quantity of available energy (production (Prod), battery discharge (Bat) and energy bought (PurchE)) must be equal to the quantity of energy spent (consumption (Cons), battery charge (Bat), energy sold(SoldE)) (Eq. 3).

Equation 2 - Battery Charge and Discharge rates requirement

Equation 3 - Equilibrium Formula between the available energy and the used energy.
Another matter that was discussed was the limit bounds for each output variable. Fo instance, for the community members’ consumption the lowest value possible is 85% of the energy predicted, and 100% for the highest value (this are the 15% given to the member’s confort). For the battery storage variable the lowest is 20% percent for bettery quality life reasons, and 100% for the highest value. And lastly, for the energy balance the lowest value is the least energy that can be bought which results in formula X. For the highest value is the highest quantity of energy that can be bought in each period, which results in formula Y.

Equation 4 - Lower bound for the Energy Balance output variable.

Equation 5 - Upper bound for the Energy Balance output variable.
After implementig the objective function, we made a hipotetic setting just for testing porpuses. The results can be seen in the image bellow.

Figure 1 - Table with the data used and the results of one case study.
As we can see in the image, the PSO algorithm is optimizing the battery to be used when the Market Price is higher and charge it when the market price is lower, which is a very good result.
For the Machine Learning project it were made some fixes to the dataset, this week, which increasing the R2. Furthermore, it was made the predictions for the first tow days of 2019 to be used later as input data in the Optimization project.
In PLNTDIA we were being prepered for the final exam of the chair, and studied the Game Theory algorithm and the Multi-Attribute algorithms. For the AAUT1IA classes we studied the KNN alorithm and the Neural Network algorithm.
For the next week the idea is to adjust the objetive function and the PSO parameters to get better results and finish the deliverables for the overall challenge.
Comments