## 4 Methodology and Methods
### Pattern-Based Model Training
#### 4.1.2 Transactional Dataset Generation and Rule Extraction  
The proposed methodology uses the association rules mined from historical data as a model of recurrent behaviours to plan the rebalancing operations. However, since the itemset and association rule mining algorithms operate on transactional datasets, the original data needs to be manipulated to obtain the input in a transactional format. Each partition \(\mathcal{P}_{i}\) must be mapped to a transactional dataset \(\mathcal{TR}_{i}\). Specifically, for each partition \(\mathcal{P}_{i}\) and for each distinct timestamp \(t\) in \(\mathcal{P}_{i}\), we generate a transaction \(tr_{t}\) that is stored in the transactional dataset \(\mathcal{TR}_{i}\). The transaction \(tr_{t}\) contains all the stations that are in a critical status at time \(t\) and their critical status. In particular, we associate the plus sign (\(+\)) to station \(s\) if the station is positively critical at time \(t\) and the minus sign (\(-\)) if it is negatively critical. A single transaction in \(\mathcal{TR}_{i}\) thus represents the list of positively and negatively critical stations present in partition \(\mathcal{P}_{i}\) at timestamp \(t\).  
For instance, suppose that at timestamp \(t_{1}\) the stations \(s_{4}\) and \(s_{7}\) are positively critical, station \(s_{11}\) is negatively critical, and all the other stations in \(\mathcal{S}\) are not in a critical status. It follows that the following transaction \(tr_{t_{1}}=\{+s_{4},+s_{7},-s_{11}\}\) will be inserted in the transactional dataset.  
Given the N transactional datasets, the FP-growth algorithm is used to extract frequent itemsets and the set of association rules, given a minimum support threshold _minSupport_ and a minimum confidence threshold _minConfidence_. Specifically, a set \(\mathcal{R}_{i}\) of association rules is extracted from each transactional dataset \(\mathcal{TR}_{i}\), i.e., a set of contextualised rules is mined for each (temporal) context.  
The extracted rules are characterized by a set of stations, with the associated critical status, in the antecedent and one single station, with its critical status, in the consequent. Some examples of neighbourhoods and mined rules are reported in Tables 1 and 2.  
Among the extracted rules, only a subset of them can be used to plan local rebalancing operations. Specifically, only the rules (i) that contain only stations belonging to the same neighbourhood and (ii) such that the critical status of the stations in the antecedent of the rule is of opposite sign with respect to the critical status of the station in the consequent of the rule are useful for planning local rebalancing operations. We refer to the rules satisfying the second constraint as discordant rules. The interesting rules must contain only nearby stations because, as we introduced in the problem statement, we want to apply only local rebalancing operations. Moreover, they must be discordant because only if the critical status of the stations is opposite we can plan to move bicycles from positively critical stations to the negatively critical ones to remove the critical situations.  
Let us consider the extracted rules reported in Table 2. Rule 2 and 5 are the only discordant rules. Rule 2 has support 60% and confidence 80% and it can be interpreted as \"the combination \(\{+s_{4},+s_{7},-s_{11}\}\) is present in 60% of the input transactions and in 80% of the cases when \(s_{4}\) and \(s_{7}\) are both positively critical, it follows that \(s_{11}\) is negatively critical\". Stations \(s_{4},s_{7},s_{11}\) belong to neighbourhood 2 (Table 1). Hence, Rule 2 satisfies also the first condition and it can be used to plan a local rebalancing operation. Rule 5 is very similar to Rule 2, but it is discarded by our approach because a neighbourhood containing the stations \(s_{1},s_{4},s_{7},s_{11}\) does not exist. All the other example rules are discarded because they are not discordant rules.