## 5 Link and Node Removal Considering Residual Capacity and Traffic Demands (LNR-RCTD)
### LNR-RCTD Algorithm
If the desired path from detected link will be found, the algorithm constructs a new or partial new path and assign it to its respective flow \(f_{i,k}^{j}\). Finally, algorithm recomputes and modify the utilization of both old and new paths and append links to the set of free links \(F_{extra}\) if and on if their utilization becomes zero. (2) _Algorithm:_ The algorithm starts by assigning underutilized link's corresponding node \(v_{e_{l,m}}\) to a temporary variable \(v_{l}\) and then it finds an alternative underutilized-link free path through its all incident links. The loop on line 2 processes till it's finds an alternative path through its all available incident links. Set of all possible paths \(P_{f_{i,k}}^{j}\) between nodes \(v_{l}\) and \(v_{k}\) started from link \(e_{l,n}\) are computed by PathFinder (\(f_{i,k}^{j}\), \(e_{l,n},v_{l}\)) at line 3. From line 4 to line 11, it operates over a set of paths \(P_{f_{i,k}^{j}}\) to finds an alternative path. If a required alternative path found, algorithm computes new end-to-end path and redirect its respective flow over that new routing path. Along with this it re-computes capacities utilization of old and new path and construct set of extra link \(F_{extra}\). At line 12 the subroutine Underutilize (\(P_{l,K}\)) examines whether the path \(P_{l,K}\) contains any further underutilized links or not. From line 13 to line 19, algorithm computes and examines end-to-end delay, PLR and residual capacity of path. If it qualifies all these constraints it will be selected. After the desired path/sub-path selection, algorithm reconstructs its complete end-to-end routing path at line 6 according to Equation (22) and assigns it to its respective flow \(f_{i,k}^{j}\). Finally, algorithm assign link \(e_{l,m}\) to set of extra links \(F_{extra}\) and re-computes the utilization of old and new paths using _CapRecomp_ (\(f_{i,k}^{j}\), \(P_{l,K},NUP_{f_{l,k}^{j}}\)) as follows:  
\[cc\,_{est}\,=\,cc\,_{e_{s,t}}\,+f_{ij}\,\,and\,\,cc\,_{e_{sxt}}\,=\,cc\,_{e_{s,tt} }\,-f_{ij} \tag{20}\]  
where \(cc\,_{est}\) and \(cc\,_{e_{s,tt}}\) are the capacities of each link belonging to path \(P_{l,K}\) and \(NUP_{f_{l,k}^{j}}\), respectively. ```
1:\(v_{l}\,\leftarrow\,\,v_{e_{l}m}\)
2:while\(e_{l,n}\,\in\,l_{(v_{l})}\,\
eq\,\emptyset\,\&\,\&\,\,p_{alt}\,\
eq\,1\)do
3:\(p_{f_{l,k}^{j}}\,\leftarrow\,PathFinder\,(f_{l,k}^{j},\,e_{l,n}\,,v_{l})\)
4:for each \(P_{l,K}\,\in\,p_{f_{l,k}^{j}}\)do
5:if\(p_{alt}\,==\,1\)then
6:\(NUP_{f_{l,k}^{j}}\,=\,PP_{il-1,j}\,\cup\,\,P_{l,K}\)
7: Assign \((f_{l,k}^{j},P_{l,K})\)
8:\(CapRecomp\,(f_{l,k}^{j},P_{l,K},UP_{f_{l,k}^{j}})\)
9:\(F_{extra}\,\leftarrow\,\,e_{l,m}\)
10: break
11:endif
12:elseif(Underutilize (\(P_{l,K}\)) \(==\)0)then
13: Compute Delay of \(P_{l,K}\) by using Equation (4)
14:if(\(\,\tau(t)_{P_{l,K}}\leq d_{f_{l,k}^{j}}\,\))then
15: Compute Loss of \(P_{l,K}\) by using Equation (5)
16:if(\(\,l(t)_{P_{l,K}}\leq PLR_{f_{l,k}^{j}}\,\))then
17:for each \(e_{l}\,\in\,P_{l,K}\)do
18: Compute Residual-Cap by using Equation (1)
19:if(\(\,RC_{e_{l}}\,\leq f_{l,k}^{j}\,\)) then
20: break
21:endif
22:endfor
23:\(p_{alt}\,\leftarrow\,1\)
24:endif
25:endif
26:endif
27:endfor
28:endwhile
```  
**Algorithm 2**LINK-OPTIMIIZATION  
TOPOLOGY-OPTIMIIZATION removes the set of extra links \(F_{extra}\subseteq E\) from the original network topology and reconstruct the optimized end-to-end connected topology. Final optimized topology \(G\)' \(\left(V\)', \(E\)' \(\right)\subseteq G(V,E)\) also ensures the sufficient redundency to keep the origional design goal of WMNs. (3) _Algorithm:_ From line 1 to 3 the algorithm removes the set of extra links \(F_{extra}\subseteq E\) from the original topology. From line 4 to line 6 it examines the isolation of all WMRs and if some WMRs are found to be isolated, it will be added to the set of extra WMRs \(V_{extra}\). Finally, from line 8 to line 11 it removes all isolated WMRs. Note: A WMR \(v_{j}\) is said to be isolated if the sum of its all incident links will be zero.