## 4 Methodology and Methods
### Planning of Rebalancing Operations by Means of Association Rules
Hence, the rebalancing operation planned at time \(t_{new}\) would be probably applicable and useful when the truck will actually reach the critical stations. Since each rule is composed solely of neighbouring stations, our methodology performs local rebalancing operations (Figure 2) such that the final occupancy rate of every station present in the rule is the same across stations in the neighbourhood. Thus, the goal of our framework is to flatten the occupancy rate of identified critical neighbourhoods by moving bicycles from positively critical to negatively critical stations or vice versa, fixing critical situations. Each bike station is visited only once during the operation. Figure 3 shows the framework's structure at reallocation time. Figure 2: Example of local rebalancing. The extracted rule \(r\) contains 4 stations: 3 in the body of the rule and \(1\) in the head. Blue stations are positively critical; the red station is negatively critical. Once such pattern is detected in the new batch of data \(\mathcal{B}\), the frameworks suggests to move bicycles from blue stations to the red stations such that the final occupancy rate of the 4 stations is the same. The list of applicable rules represents potential rebalancing operations that should be planned at timestamp \(t_{new}\) and executed in at most \(t_{reb}\) time to fix imbalanced situations across stations. However, due to the limited amount of trucks, operators and time, not all critical stations \(CS_{t_{new}}\) can be fixed and thus a priority needs to be defined. Such priority is determined by the quality indices of the mined and applicable association rules. Specifically, we consider the applicable extracted association rules in descending order using the following quality indices: confidence, support, and length of the rule. The higher the confidence, the stronger the pattern is among the training data. Hence, given two rules, the confidence is initially considered and the one with the highest confidence is selected first. Given two rules with equal confidence, the one with higher support (i.e., the rule which is more frequent in the historical data) is considered first. In case also the support value is the same among the two considered rules, the length of the rule is considered. If also the length is the same, the lexicographical order is considered. We decided to impose the number of rebalancing operations planned at time \(t_{new}\) to be equal to the number of trucks \(N_{t}\) available, i.e., among all the extracted association rules, only the top \(N_{t}\) applicable rules with highest priority will be applied. Moreover, since the trucks used for the actual rebalance require time to travel from the deposit to critical neighbourhoods, we distinguish between the operation planning time \(t_{new}\) and the actual rebalancing operation time, namely the reallocation time, which must be at most \(t_{reb}\) minutes after \(t_{new}\). Specifically, we define as the operation planning time the time \(t_{new}\) in which the system analyses the online data \(\mathcal{B}\) collected by the stations, computes the occupancy rate and performs the match operations between the extracted rules and identified critical stations to select the top \(N_{t}\) applicable rules. During the bicycles reallocation, due to the system being online, the status of the bike stations involved in the rebalancing operation may change within \(t_{reb}\) minutes. For such reason, the system checks whether the planned rebalancing operation is still applicable at reallocation time (i.e., when the truck reaches the stations to rebalance) and in case it is not, the system tries to identify the largest subset of stations for which the rule still holds, i.e., identify a subset of critical stations to rebalance. If no subset is found, the rule is not applied. Consequently, the association rules extracted at training time are used as an associative classifier to detect at test time recurrent critical neighbourhoods that need to be fixed.