## 4 Distributed BS Assignment Algorithm
### Procedures at the Mobile Device  
As shown in Algorithm 2, each device initially computes a candidate set, denoted to as \(cs\), with the set of BSs offering a path-loss within the margin between minimum offered path-loss and a path-loss margin (PLM). Next, once the device receives association prices from BSs, it computes for each BS on its \(cs\) the radio cost, utility, backhaul cost and weighted utility metrics. Subsequently, the device \(i\) selects the most appropriate BS \(j^{*}\) according to the maximum weighted utility (step 8-9). The BS \(j^{*}\) is the BS that offers the best relation of utility minus the association prices. After that, device \(i\) sends an association request to BS \(i\), which includes the costs and utility metrics (step 10). The stopping criterion is reached when the device has already tried to be associated with each BS on its \(cs\).  
```
1 Device \(i\) computes its candidate set as: \(cs_{i}\subset PL_{ij}\), such that \(\forall j\in PL_{ij}|(PL_{i1}-PL_{ij})\leq PLM\)
2 First phase
3 Device \(i\) receives association prices \(\lambda_{j}\) and \(\mu_{j}\) from each BS \(j\). for each BS \(j\in cs_{i}\) computedo
4\(u_{ij}\), \(\alpha_{ij}\), \(\beta_{ij}\), and \(w_{ij}\)
5 end for
6 Find the most valuable BS \(j^{*}\) which satisfies the following: \(j^{*}=\operatorname*{argmax}_{j}\{w_{ij}\}\)
7 Send an association request to BS \(j^{*}\) including utility \(u_{ij^{*}}\) and cost \(\alpha_{ij^{*}}\). Stopping criterion: if each device has already send an association request to each BS on its \(cs\).
8 end for
9 Second phase
10 Device \(i\) in outage determines if it can be associated with any BS on its \(cs_{i}\) for each BS \(j\in cs_{i}\) computedo
11\(u_{ij}\), \(\alpha_{ij}\), \(\beta_{ij}\), and \(w_{ij}\)
12 end for
13 Find the BS which satisfies: \(j^{+}=\operatorname*{argmax}(u_{ij})\)\(s.t.\)\((\phi^{{}^{\prime}}_{j}+\alpha_{ij})\leq 1\) and \((\pi^{{}^{\prime}}_{j}+\beta_{ij})\leq 1\), \(\forall j\in cs_{i}\)
14 Send an association request to BS \(j^{+}\) including: \(u_{ij^{+}}\), \(\alpha_{ij^{+}}\), \(\beta_{ij^{+}}\)
15 Stopping criterion: if each device has already send an association request to each BS on its \(cs\).
16 end for
```  
**Algorithm 2**Device algorithm  
The second phase has been proposed to improve (if possible) the assignment solution found in phase 1. This is possible if there are available resources at BSs, and an improvement in the system utility is observed. Thus, each device receives current total radio and backhaul costs from all BSs, and determines whether it can improve its utility by being associated with another of the BSs on its \(cs\). For that, the device checks whether the addition of its cost with the total cost of the BS does not exceed the maximum capacity on both radio and backhaul costs. Subsequently, for each BS on its candidate set computes the utility, radio cost, and backhaul cost (step 15-17). The device determines the appropriated BS in which is observed an utility improvement and where the costs constraints are satisfied (step 18-19). Next, an association request is send to the BS \(j^{+}\), which includes the metrics of utility and costs (step 20). The stopping criterion of this phase is reached when the device has tried to be associated with all pf the BSs on its candidate set.