## 3 Optimal Model for Scheduling Virtual Microgrids Topology
### Model without Demand Flexibility
Equation (9), the power not-delivered (\(\delta^{p}_{i,t}\)), bound the virtual power \(\lambda^{p}_{i,t}\) which represents the remaining power that it is needed to meet the total power load (see Equation (2)). Therefore, if the power generation is insufficient to provide the power required, the virtual power (\(\lambda^{p}_{i,t}\)) variable fulfills this gap, being penalized in the objective function, if and only if this gap is equal to or lower than the power not supplied (\(\delta^{p}_{i,t}\)) in the node \(i\). Constraints (10) and (11) describe the same logic except for the reactive power load. Active and reactive power limits together with the voltage security constraints are considered in Equations (12)-(14); therefore, \(\forall i\in\mathbb{B},\forall k\in\mathbb{G}_{type}\),  
\[(V^{min}_{i})^{2} \leq vs_{i,t}\leq(V^{max}_{i})^{2}, \tag{12}\] \[U^{g}_{l}PG^{min}_{k,t} \leq pg^{k}_{i,t}\leq U^{g}_{l}PG^{max}_{k,t},\] (13) Figure 1:0  
Equation (12) makes sure that the voltage in each node and at every period is within the limits allowed. The parameters are squared due to the change of variable needed to linearize the original power flow equation. Constraints (13) establish the limits for the power injected by the DG in the node through two different parameters; \(U^{g}_{l}\) corresponds to the total power capacity installed and \(PG^{max}_{k,t}\) is the power generated by the DG in a certain period, which is a normalized power generation curve. Therefore, Equation (13) establishes the maximum power that can be injected in Equation (2) at every hour, where \(PG^{max}_{k,t}\) follows the power generation behavior of a photovoltaic panel (PV)/wind turbine (WT), and it allows for including the stochastic behavior of the DG into the OPF constraints. The sets of constraints (15)-(18) represent a linear version of the apparent power limit; therefore, \(\forall(i,j)\in\mathbb{L},\forall t\in\mathbb{T},\forall r\in\mathbb{R}\),  
Figure 1:1 Figure 1:2  
where:  
Figure 1:3  
Figure 1:4  
Equations (15) and (16) emerge as a set of constraints which represent a polygon formed by \(r\in\mathbb{R}\) lines that define a feasible region approximation of the original apparent power limit, which is a circle. Thus, the bigger the set \(\mathbb{R}\), the closer the polygon will be to the circle. To model the behavior of the batteries, the following constraints are added. Therefore, \(\forall i\in\mathbb{B}\), \(\forall t\in\ T,\forall l\in\mathbb{B}_{type}\),  
Figure 1:5  
Figure 1:6Figure 1:7  
Figure 1:8  
Figure 1:9  
The state of charge (SOC) for battery type \(l\) is defined in Equation (19) and is composed of the SOC of the previous period plus the energy injected and absorbed from the system with their respective efficiency factors. In order to maintain the structure of the formulation of our previous work [13], the SOC is in MWh and not in percentage, as usual; thus, the SOC represented in Equation (19) is bounded by \(SOC^{max}_{l}/SOC^{min}_{l}\) which are in % and are multiplied by the total capacity installed. In this way, the \(soc^{l}_{i,t}\) belongs only to the capacity range operation of the battery. Therefore, for a capacity of 10 MWh and a 90%/10% as operational limits, the \(soc^{l}_{i,t+1}\) will not be less than 1 MWh or greater than 9 MWh. On the other hand, the maximum power injected or taken from the DN for a certain period is explained in constraints (21) and (22) through \(M^{l}\) which is multiplied by a binary variable representing when the battery is charging or discharging. In the case that the battery is discharging, i.e., \(w^{l}_{i,t}=0\), the maximum energy discharged must be equal to or lower than \(M^{l}\) because the parameter \(Y^{l}_{i}\) is one when there is a battery in the node. Otherwise, if \(Y^{l}_{i}\) (a binary parameter) is zero, the constraints (23) are zero and all the Equations (19)-(22).