# Optimal Power Flow Solutions for Power System Considering Electric Market and Renewable Energy
## 3 Jellyfish Search Algorithm for the Problem
### The Implementation of \(|\)SA for the Considered OPF Problem  
The section presents an iterative technique to apply JSA for the considered OPF problem with the presence of renewable energy and the consideration of different nodal prices. The implementation process is expressed as the following steps:  
Step 1: Generate initial solutions. Each solution \(SN_{j}\) of JSA is comprised of the set of control variables presented in Section 3.2.1. To produce a random initial population for JSA, the lower and upper boundaries of the solution \(SN_{j}\) are formed as follows: \(SN_{j}^{Min}\) and \(SN_{j}^{Max}\). The lower boundary \(SN_{j}^{Min}\) is comprised of the minimum value of all control variables meanwhile the upper boundary \(SN_{j}^{Max}\) is comprised of the maximum value of all control variables. In the first step, we randomly produce the population as follows:  
\[SN_{j}=dr_{3}\Big{(}SN_{j}^{Max}-SN_{j}^{Min}\Big{)}+SN_{j}^{Min};\ j=1,\ \ldots,\ S_{size} \tag{21}\]  
Step 2: Obtain all dependent variables and penalize their violation. In the second step, all remaining dependent variables are obtained by using Section 3.2.2. These variables are included in a set of dependent variables, which is mathematically modeled by \(DS_{j}\). Each dependent variable can be either within or beyond its allowable range, which is predetermined and normally is given in data of the system. Similar to the control set, the dependent set also has the lower and upper boundaries, which are represented by \(DS_{j}^{Min}\) and \(DS_{j}^{Max}\). The two boundaries are, respectively, comprised of the minimum and maximum values of all dependent variables. If the dependent variables have smaller value than the lower bound, they are penalized by calculating the deviation between the obtained value and the lower bound. For another case of violation, if the dependent variables have greater value than the upper bound, the deviation between the obtained value and the upper bound is calculated for the penalty. By using the way, penalty terms of all dependent variables are calculated as follows:  
\[\Delta DS_{j}= \begin{cases}\begin{array}{c}0\;\;\;\text{if}\;\Delta DS_{j} \in\left[DS_{j}^{Min};\;DS_{j}^{Max}\right]\\ \left(DS_{j}^{Min}-DS_{j}\right)\;\;\;\;\;\text{if}\;DS_{j}<DS_{j}^{Min}\\ \left(DS_{j}-DS_{j}^{Max}\right)\;\;\;\;\;\;\text{if}\;DS_{j}>DS_{j}^{Max}\\ \end{array}\end{cases}  \tag{22}\]  
Step 3: Calculate fitness function of all solutions. Currently, all variables of the problem are obtained and currently the objective function (1) can be calculated simply. The penalty terms above and the objective function are included in fitness function as follows:  
\[Fit_{j}=-Sys_{Profit,j}+\beta.\Big{(}\Delta DS_{j}\Big{)}^{2} \tag{23}\]  
where \(Sys_{Profit,j}\) is the objective function of the \(j\)th solution; and \(\beta\) is an intensification factor. \(\beta\) is used to make the violation of dependent variables greater and selected to be \(10^{4}\) in the paper by experiment. Step 4: Produce and correcting new control variables by using JSA. In this step, the search process of JSA in Section 3.1 is applied to find new solutions containing new control variables. However, all new obtained control variables can be within or beyond their predetermined boundaries. Before performing Matpower program for reaching dependent variables, the new variables must be repaired as follows:  
\[SN_{j}^{new}= \begin{cases}\begin{array}{c}SN_{j}^{new}\;\;\;\text{if}\;SN_{j }^{Min}\leq\;SN_{j}^{new}\leq\;SN_{j}^{Max}\\ \;SN_{j}^{Min}\;\;\;\;\;\;\text{if}\;SN_{j}^{Min}>SN_{j}^{new}\\ \;SN_{j}^{Max}\;\;\;\;\;\;\text{if}\;SN_{j}^{Max}<SN_{j}^{new}\\ \end{array}\end{cases}  \tag{24}\]  
Step 5: Implement selection of better-quality variables and find the best solution. Currently, there are two solutions corresponding to two sets of control variables for each individual in the population. In other words, there are two population, old and new. So, the \(j\)th old and the \(j\)th new variable set should be selected to abandon one set and keep one set.