# Renewables and Advanced Storage in Power Systems: The Iberian Case
## Appendix A Optimization Model  
The formulation of the optimization problem of the generation mix is written below. These equations are taken from [30].  
Objective function  
\[\begin{array}{c}min_{Y}FCC^{CC}PCC+VCC\sum\limits_{t}P_{t}^{CC}+FCC^{OC}POC+VCC \sum\limits_{t}P_{t}^{OC}+FC^{W}P^{W}+VC^{W}\sum\limits_{t}P_{t}^{W}\\ +FC^{PV}P^{PV}+VC^{PV}\sum\limits_{t}P_{t}^{PV}+FC_{P}^{S}P^{S}+FC_{P}^{S}P^{S} +FC_{E}^{S}\end{array} \tag{11}\]  
subject to  
\[P_{t}^{CC}+P_{t}^{OC}+P_{t}^{W}+P_{t}^{PV}+P_{t}^{H}+P_{t}^{+}-P_{t}^{-}+P_{t}^ {P+}-P_{t}^{P-}=D_{t}^{*}\ \ \ \ \ \forall t \tag{12}\]  
\[E_{t}^{S}=E_{t-1}^{S}-\frac{1}{\eta^{+}}P_{t}^{+}+\eta^{-}P_{t}^{-} \tag{13}\]  
\[E_{t}^{PS}=E_{t-1}^{PS}-\frac{1}{\eta^{P+}}P_{t}^{P+}+\eta^{P-}P_{t}^{P-} \tag{14}\]  
\[E_{t}^{HS}=E_{t-1}^{HS}-\frac{1}{\eta^{H+}}P_{t}^{H+}+E_{t}^{in} \tag{15}\]  
\[\sum\limits_{t}\Big{(}P_{t}^{CC}+P_{t}^{OC}\Big{)}\leq(1-x_{ren})D_{TOT} \tag{16}\]  
\[P_{t}^{CC}+P_{t}^{OC}+P_{t}^{H+}\geq P_{DISP}\ \ \ \forall t \tag{17}\]  
\[P_{t}^{CC}-P_{t-1}^{CC}\leq k_{grad}^{CC}P^{CC}\ ;\ P_{t-1}^{CC}-P_{t}^{CC}\leq k_{ grad}^{CC}P^{CC}\ \ \ \forall t \tag{18}\]  
\[P_{t}^{OC}-P_{t-1}^{OC}\leq k_{grad}^{OC}P^{OC}\ ;\ P_{t-1}^{OC}-P_{t}^{OC} \leq k_{grad}^{OC}P^{OC}\ \ \ \forall t \tag{19}\]  
\[P_{t}^{H}-P_{t-1}^{H}\leq\Delta H^{max}\ \ ;\ P_{t-1}^{CC}-P_{t}^{CC}\leq \Delta H^{max}\ \ \ \forall t \tag{20}\]  
\[P_{t}^{CC}\leq p^{CC}\ \ ;\ \ P_{t}^{OC}\leq p^{OC}\ \ \ \forall t \tag{21}\]  
\[P_{t}^{W}\leq e^{W}P^{W}\ \ ;\ \ P_{t}^{PV}\leq p^{PV}P^{PV}\ \ \ \forall t \tag{22}\]  
\[P_{t}^{P+}\leq P^{P}\ \ ;\ \ \ P_{t}^{P-}\leq P^{P}\ ;\ \ P_{t}^{H+}\leq p^{H}\ \ \ \forall t \tag{23}\]  
\[P_{t}^{+}\leq P^{S}\ \ ;\ \ \ P_{t}^{-}\leq P^{S}\ \ \ \forall t \tag{24}\]  
\[E_{init}^{S}\leq E_{t}^{S}\leq E_{max}^{S}\ \ ;\ \ E_{init}^{PS}\leq E_{t}^{PS} \leq E_{max}^{PS}\ \ ;\ \ E_{init}^{HS}\leq E_{t}^{HS}\leq E_{max}^{HS}\ \ \ \forall t \tag{25}\]  
Equation (11) models the total costs, including investment, fuel and O&M. Equation (12) sets the equality of generation and demand. The residual demand has been calculated as the difference between consumed and the non-optimized renewable generation. Equations (13)-(15) models the stored energy balance from the different storage systems considered, namely batteries, hydro plants and hydro pumping plants. Equations (16) and (17) sets the renewable targets and the Spanish System Operator constraint of minimum dispatchable power. Equations (18)-(20) model the ramp limits of considered technologies, hydro plants included because of the impossibility of connecting a given number of hydro plants at the same time. Equations (11)-(15) sets the limits for the optimization variables. Wind and PVare also limited according to the existing resource at a given moment. Their production, however, can be spilled.  
The problem was programmed in MATLAB(r) and solved using the function linprog. The problem has 105,126 variables, 131,402 inequality constraints and 35,040 equality constraints. The average running time for each simulation is 962.745 s in a computer with 16 GB RAM and a 1.3 GHz processor.