## 5 Energy Management
### Optimization Model  
In the following, we propose a Mixed-Integer Linear Programming (MILP) formulation for a general optimization model that can be implemented in the OSU. The use of MILP models is a common practice in energy management optimization systems [45; 46] thanks to their easy implementation in modern computational systems. In fact, this kind of mathematical program can be nowadays solved quite efficiently (despite their theoretical complexity) by means of black-box solvers, such as _Cplex_[47] or _Gurobi_[48]. Let us define \(T\) as the set of time slots composing the considered optimization time horizon, \(L\) as the set of loads characterized by power consumption profiles, and \(G\) as the set of generators characterized by power generation profiles. Moreover, we call \(P_{l}\) (\(P_{g}\)) the set of feasible working profiles for each load \(l\in L\) (\(g\in G\)). For each time slot \(t\in T\), \(q_{lp}^{t}\) (\(q_{gp}^{t}\)) represents the power required by \(l\in L\) (available from \(g\in G\)) working with profile \(p\in P_{l}\) (\(p\in P_{g}\)), \(c_{lp}^{t}\) represents the comfort level associated with \(l\in L\) working with profile \(p\in P_{l}\), \(f^{t}\) is the unitary price of the power purchased from the grid, and \(v^{t}\) is the unitary gain deriving from the power fed to the utility. The maximum power than can be taken from (fed to) the grid, if no DR requests are considered, in the time slot \(t\in T\) is \(E_{max}^{t}\) (\(V_{max}^{t}\)), and the external non-electric costs associated with using profile \(p\in P_{l}\) of \(l\in L\) (profile \(p\in P_{g}\) of \(g\in G\)) is \(F_{lp}\) (\(F_{gp}\)). Finally, \(a_{g}\) is the unitary incentive granted to the power generated by \(g\in G\). The participation in DSM schemes is modelled by defining \(D=D_{Vmax}\cup D_{Vmin}\cup D_{Emax}\cup D_{Emin}\) as the set of DR requests provided to the prosumer, where \(D_{Vmax}\) and \(D_{Vmin}\) are the sets of DR requests associated with the maximum and minimum values of power that can be taken from the grid, respectively, whereas \(D_{Emax}\) and \(D_{Emin}\) are the sets of DR requests associated with the maximum and minimum values of power that can be fed to the grid, respectively. Moreover, let \(T^{d}\) (\(\subset T\)) be the set of time slots which correspond to the temporal domain of the demand-response \(d\in D\). In each time slot \(t\in T^{d}\), \(r_{Emin}^{dt}\) (\(r_{Vmin}^{dt}\)) represents the minimum power that can be taken from (fed to) the grid according to DR request \(d\in D_{Emin}\) (\(d\in D_{Vmin}\)), whereas \(r_{Emax}^{dt}\) (\(r_{Vmax}^{dt}\)) represents the maximum power that can be taken from (fed to) the grid according to the DR request \(d\in D_{Emax}\) (\(d\in D_{Vmax}\)). Finally, \(B^{d}\) is the total incentive paid to the prosumer if the negotiable profile is respected for \(d\in D\). The decision variables of the model are defined as follows:  
* \(E^{t}\) (\(V^{t}\)) represents the power that must be taken from (fed to) the grid in the time slot \(t\in T\);
* \(y_{lp}\) (\(y_{gp}\)) is a binary variable taking value 1 if profile \(p\in P_{l}\) (\(p\in P_{g}\)) is chosen for \(l\in L\) (\(g\in G\)), and 0 otherwise;
* \(\lambda_{E}^{t}\) (\(\lambda_{V}^{t}\)) is a binary variable taking value 1 if the power taken from (fed to) the grid is strictly positive in time slot \(t\in T\), and 0 otherwise;
* \(w^{dt}\) is a binary variable taking value 1 if, in time slot \(t\in T^{d}\), the system complies with the request \(d\in D\), and 0 otherwise;
* \(z^{d}\) is a binary variable taking value 1 if request \(d\in D\) is satisfied, and 0 otherwise.