# Energy Communities Design Optimization in the Italian Framework
## 2 Materials and Methods  
### Energy Community Model  
The modeling of energy communities has been introduced in [8], wherein the approach proposed was limited to the electrical fluxes. As previously mentioned, in order to make ECs effectively contribute to the decarbonization of the energy system, it is necessary to adopt a multi-energy approach, wherein the objective is to maximize the synergies among different energy sectors (e.g., electricity and heating). To this aim, the advanced mathematical tools typically used in the field of multi-energy systems (MES) or district-energy systems (DES) [9; 10; 11] can be of help. Such tools are based on optimization algorithms capable of selecting the proper mix of technologies and their sizes to meet multiple different energy demands in multiple locations in the most efficient and economically sustainable manner. In this study, one of such optimization models has been devised to identify the optimal design of the energy production and storage systems to be installed in an energy community, so as to guarantee the maximization of the economic benefits for the members coming from the rational use of energy sources to match the electricity, heating, and cooling needs of its members and the remuneration of the self-consumption, as it is now foreseen by the Italian regulatory framework. The optimization problem has been formulated as a two-stage MILP problem, involving investment decisions (first stage) and operation decisions (second stage). This two-stage structure is represented by the following compact formulation:  
\[\underset{x_{u}^{(1)},x_{u,t}^{(2)}}{\text{min}}T\text{AC}=\sum_{u\in U}C^{ INV}\cdot x_{u}^{(1)}+\sum_{u\in U}\sum_{t\in T}C^{OP}\cdot x_{u,t}^{(2)} \tag{1}\]  
Subject to  
\[A^{(1)}x_{u}^{(1)}=b_{u}^{(1)}\quad\quad\forall\ u \tag{2}\]  
\[A^{(2)}x_{u,t}^{(2)}+A^{(2)}y_{u,t}^{(2)}=b_{t}^{(2)}\quad\quad\forall\ u,\ \forall\ t \tag{3}\]  
\[A^{(1)}x_{u}^{(1)}+A^{(2)}x_{u,t}^{(2)}+A^{(2)}y_{u,t}^{(2)}=b_{u,t}^{(1,2)} \quad\quad\forall\ u,\ \forall\ t \tag{4}\]  
\[x_{u}^{(1)}\in\mathbb{R},\ y_{u,t}^{(1)}\in\{0,1\},\ x_{u,t}^{(2)}\in\mathbb{R }\,,\ y_{u,t}^{(2)}\in\{0,1\} \tag{5}\]  
where TAC is the total annualized costs (CAPEX + OPEX), \(u\in U\) is the set of energy conversion and storage units, and \(t\in T\) is the set of time steps considered in the operation. \(x^{(1)}\) and \(y^{(1)}\) are the continuous (unit size, storage capacity) and binary (unit yes/no installation) investment variables, and \(x^{(2)}\) and \(y^{(2)}\) are the continuous (unit load and consumption, storage level, exchange between the multiple locations) and binary (unit on/off status) operation variables. There are constraints that account only for the investment stage (Equation (2)), and they can be the available locations and space for units' installation. There are also constraints referring only to the operation stage, as in Equation (3): the balances between the energy production and demand. Finally, there are constraints that bind the first and the second stage variables, as in Equation (4), e.g., the maximum and minimum loads of the units, which depend on their size. For more details about the energy conversion and storage technologies comprised in the model, see [12; 13; 14]. To reduce the computational complexity of the problem, instead of optimizing all the hourly time steps in a year (which would be the ideal approach), five representative days have been considered in this study, each one to represent a typical period/condition: extreme winter, winter, mid-season, summer, and extreme summer (for further details, see the following sections). It is worth noticing that, with this approach, in terms of inter-temporal constraints, the operation of the energy conversion and storage systems is cyclical on a daily basis; that is, the last time step of the day is linked to the first one (for the energy storage system, this implies the same initial and final value).