## 4 Methodology and Methods
### Planning of Rebalancing Operations by Means of Association Rules  
In this section, we describe how the mined association rules are used to plan at a given time \(t_{new}\) the rebalancing actions to apply in the next \(t_{reb}\) time. This phase is composed of two steps: (i) identification of critical stations at time \(t_{new}\) and (ii) definition of the rebalancing operations needed to address the identified critical situations. Let \(\mathcal{B}\) be a batch of records containing the (new) online information about the status of all the stations of the system at timestamp \(t_{new}\). \(\mathcal{B}\) is gathered using a streaming real-time system. First, for each station \(s_{i}\in\mathcal{B}\), its critical rate at timestamp \(t_{new}\) is computed and the set of positively and negatively critical stations are identified. The set of critical stations at \begin{table}
\begin{tabular}{c c c} \hline \hline
**Id** & **Neighbourhood** \\ \hline
1 & \(s_{45},s_{22},s_{6},s_{87}\) \\
2 & \(s_{4},s_{7},s_{11},s_{91}\) \\
3 & \(s_{103},s_{1},s_{47}\) \\
4 & \(s_{11},s_{7},s_{134}\) \\
5 & \(s_{10},s_{40},s_{91},s_{52}\) \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Example of neighbourhoods definition. \begin{table}
\begin{tabular}{c c c c} \hline \hline
**\#** & **Extracted Rules** & **Support** & **Confidence** \\ \hline
1 & \(+s_{6},+s_{45},+s_{22}\to+s_{87}\) & 30\% & 73\% \\
2 & \(+s_{4},+s_{7}\to-s_{11}\) & 60\% & 80\% \\
3 & \(+s_{103},+s_{47},+s_{31},+s_{72}\to\) & 23\% & 90\% \\
4 & \(-s_{10},-s_{40},-s_{91}\to-s_{52}\) & 82 timestamp \(t_{new}\), with the associated critical status, is denoted as \(CS_{t_{new}}\). Each element in \(CS_{t_{new}}\) is a pair \((s,cs)\) where \(s\) is a station and \(cs\) is the critical status of \(s\) at time \(t_{new}\). Now we have the set of stations for which a rebalancing operation should be planned at time \(t_{new}\) and executed in at most \(t_{reb}\) time. To define the rebalancing operations we consider the association rules mined in the training phase. Let \(\mathcal{R}_{i}\) be the sorted list of association rules extracted from partition \(P_{i}\) to which \(t_{new}\) is associated (e.g., if we are using the day of the week partitioning strategy, the day of the week of timestamp \(t_{new}\) is used to decide which contextualised partition of the historical data and which set of rules must be considered). For each rule \(r\in\mathcal{R}_{i}\), we search whether all the items (i.e., all the pairs (station, critical status)) belonging to the rule are contained in \(CS_{t_{new}}\). In such case, the rule \(r\) can be used to define a rebalancing operation that fixes the critical situations of the stations in \(r\). A rule that satisfies such constraint is defined as applicable rule. Specifically, rule \(r\) represents a recurrent frequent critical pattern: by moving bikes from positively critical to negatively critical stations it is possible to fix critical situations. Movements are allowed only from stations in the antecedent to stations in the consequent or vice versa. The strength of the pattern is numerically represented by the support and confidence values of the extracted rule. For example, suppose stations \(s_{4}\) and \(s_{7}\) are positively critical at timestamp \(t_{new}\) while station \(s_{11}\) is negatively critical at the same timestamp. Suppose that those stations are in the same neighbourhood and the rule \(+s_{4}\), \(+s_{7}\rightarrow-s_{11}\) has been extracted from the historical data. This rule can be used to plan a rebalancing operation that fixes the critical situations of stations \(s_{4}\), \(s_{7}\), and \(s_{11}\), moving bicycles from \(s_{4}\) and \(s7\) to \(s_{11}\). Since the extracted patterns are frequent, we can suppose that, with a high probability, the stations that are in a critical situation at time \(t_{new}\) will still be in the same critical status in the next \(t_{reb}\) minutes.