## 4 Results and Validation
### Use Case Description
Equations (3)-(6) outline the energy conservation laws and constitute the constraints of the optimization problem:  
\[P_{int}^{i}=P_{gen}^{i}+P_{BBdis}^{i}-P_{load}^{i}+FI\times SC_{l,i}^{+}-FI \times SC_{l,i}^{-}-P_{BBch}^{i} \tag{3}\]  
\[P_{gen}^{i}=\sum_{1}^{k}(P_{gen}^{i,k}) \tag{4}\]  
\[P_{load}^{i}=\sum_{1}^{l}(P_{load}^{i,l}) \tag{5}\]  
\[P_{int}^{i}=P_{gen}^{i}+P_{BBdis}^{i}-P_{load}^{i}+FI\times SC_{l,i}^{+}-FI \times SC_{l,i}^{-} \tag{6}\]  
where \(FI\) indicates the flexibility index derived from the flexibility matrix and thermal comfort matrix, \(SC_{l,i}^{+}\) and \(SC_{l,i}^{-}\) indicate the amount of power consumption for the specific \(i\)-hour, shifted by each household at each time-step and the amount of power consumption that has previously been shifted and is now consumed, respectively. Additionally, \(P_{gen}^{i}\) indicates the total LEM production, \(P_{BBdis}^{i}\) and \(P_{BBch}^{i}\) indicate the battery's discharging and power, respectively, and \(P_{load}^{i}\) indicates the LEM's load profile. The notations of \(k\), \(l\) and \(n\) indicate the number of producers, consumers and storage owners, respectively:  
\[0\leq P_{in}^{i}\leq P_{in}^{max} \tag{7}\]  
\[0\leq P_{out}^{i}\leq P_{out}^{max} \tag{8}\]  
The allowed bounds of energy exchange between the LEM and the grid are defined by constraints (7) and (8):  
\[\varepsilon_{BB}^{n,i}=\varepsilon_{BB}^{n,i-1}+\eta_{ch}^{n}P_{BBch}^{n,i} \times\Delta t-(1/\eta_{dis}^{n})\times P_{BBdis}^{n,i}\,\times\Delta t \tag{9}\]  
Figure 6:0  
Figure 6:1  
Figure 6:2  
Figure 6:3  
Equations (9)-(13) denote the storage energy state update, in which \(e_{BB}^{n,i}\) denotes the battery's energy state and \(\eta_{ch}^{n}\) and \(\eta_{dis}^{n}\) show charging and discharging efficiency levels, respectively. Lastly, \(P_{BBch,max}^{n}\) and \(P_{BBdis,max}^{n}\) denote the maximum and minimum storage charging rate while \(e_{BB,max}^{n}\) and \(SD_{l}\) define the maximum storage capacity and shifted demand, respectively,Figure 6:4  
Figure 6:5  
Figure 6:6  
Demand can be shifted by one hour at a fixed rate determined for each tenant based on their preferences. Constraint (14) assures that the amount of the shifted demand does not exceed the maximum residential load, by restricting the amount of shifted demand to the residential load for the specific time step plus the shifted demand in the previous time step. Equation (15) guarantees that the already shifted demand is either consumed in the current time-step or shifted further. The shifted demand at the end of the time horizon for the optimization problem in Equation (16) should equal zero, ensuring that the demand will not be shifted to the next day's optimization problem:  
Figure 6:7  
Figure 6:8  
Figure 6:9  
Equations (17)-(19) denote the probability of the actual production to be in a specific range, where \(\tilde{P}_{gen}^{i}\) is equal to the forecasted generation value plus the forecast error \(\epsilon_{i}\). Finally, \(\alpha^{{}^{\prime}}\) and \(\beta^{{}^{\prime}}\) denote the probabilities of upper and lower bounds, respectively. The proposed method in [50] is applied in order to transform the probabilistic chance constraints into deterministic values that can be used as input to the optimization procedure. The maximum PV forecasting error \(\epsilon_{i}\) is considered equal to 20% following the normal distribution \(\mathrm{N}(0,\sigma^{2})\), with a 99.7% confidence interval achieved in \([-3\sigma,+3\sigma]\) range. At time interval \(i\), \(\sigma\) is equal to \(0.1P_{Fgen}^{i}\), which is the forecasted PV generation. Moreover, \(\epsilon_{i}\) is constrained between maximum installed capacity \(P_{gen}^{max}\) and the forecasted value \(P_{Fgen}^{i}\); therefore, the error distribution \(\epsilon_{i}\) belongs within the range \([-P_{Fgen}^{i},P_{gen}^{max}-P_{FPV}^{i}]\).