# Differential Evolution and Fuzzy-Logic-Based Predictive Algorithm for V2G Charging Stations
## 2 Materials and Methods
### The Optimization Algorithm  
To run the algorithm, it is necessary to generate an initial population, namely, \(Pop_{1}\). It is composed of individuals who essentially represent the current \(I_{b}\). Despite being a randomly generated population, each individual that composes it must respect the restrictions imposed by (1) and (3). Therefore, according to the flowchart presented in Figure 2, for every generated individual, after constraint (1) is met and using the photovoltaic (PV) generation data, one may find \(I_{g}\). In turn, \(I_{g}\) must obey restriction (3). Additionally, other important restrictions must be considered. First, it is important to point out that a time interval of 120 min was defined to evaluate the obtained currents. This value was chosen assuming that it represented a good prediction range for \(I_{PV}\) and \(\beta\) in practical applications. That is, according to (4) and (5), each generated individual must be evaluated in this time interval to guarantee that the pre-established budget (\(\mu\)) is not exceeded and that, according to (6), the batteries' state of charge (\(\theta_{i}\)) does not reach physically impossible values, a restriction imposed by (7). It is valid to inform that in (6), \(K_{1}\) encodes the battery capacity, a fundamental quantity to convert the current that flows to the battery into the state of charge. \(K_{1}\) is adjusted according to the capacity of the bank under analysis. \[\sum_{t=z}^{119+z}\left(I_{git}\times\beta_{t}\right)=cost_{i} \tag{4}\]  
\[cost_{i}\leq\mu \tag{5}\]  
\[\theta_{i}=\theta_{i-1}+K_{1}\times I_{bi} \tag{6}\]  
\[0\leq\theta_{i}\leq 100 \tag{7}\]  
Figure 1: The building blocks that compose the V2G charging station, along with the possible directions of energy flow as indicated by the currents. Once all restrictions have been met, the evaluated individual is considered able to be part of \(Pop_{1}\). The cost function (8), associated with each individual of \(Pop_{1}\), depends on the costs associated with the consumed energy \(\left(I_{git}\times\beta_{t}\right)\), the costs associated with the photovoltaic generation (\(I_{PVt}\)), and the remaining energy in the battery bank \(\left(\theta_{i}-100\right)\). The \(K_{3}\) value depends on the energy tariff and the fixed and variable costs associated with the PV modules and equipment used in the photovoltaic generation. For a self-sustained electric charging station, disregarding the fixed implementation costs and considering that the maintenance costs are very low, \(K_{3}\) can be considered zero. On the other hand, \(K_{4}\) has a crucial role in (8). The value chosen for this constant defines the priority of charging the batteries over selling the stored energy. For this reason, simulations on the influence of \(K_{4}\) were performed, and an expert system was designed to dynamically adapt this constant. Therefore, the priority of charging the battery bank was defined based on the cost of electricity and the photovoltaic energy availability. \[Fc_{target}=K_{4}\left(\theta_{i}-100\right)^{2}+\sum_{t=z}^{119+z}\left(I_{git }\times\beta_{t}+I_{PVt}\times K_{3}\right) \tag{8}\]  
As per the differential evolution (DE) algorithm, the initial population is improved genetically at every iteration [23]. To be effective, the usage of this evolutionary algorithm must rely on randomness of the genetic modifications. Since each individual in the population had a single feature to be updated, the crossover and mutation phases were integrated into a single step. Therefore, the crossover constant \"\(cr\)\", with a value between 0 and 1, was compared to a random number (\(rand\)) also between 0 and 1. The larger the \"\(cr\)\", the greater the chance of crossover. The target individual (\(Ind_{target}\)) is the one that will potentially be replaced by a new individual, called the test individual (\(Ind_{test}\)). It is important to mention that all individuals in the population, one by one, will be targeted at some point. On the other hand, \(Ind_{test}\) will exist in case \(rand\leq cr\).