## 3 The RNN-Based Algorithm for Resource Allocation
### Task Assignment Algorithm Based on the RNN Model
**Algorithm Description:**  
1. Initialization: initialize (a) \(R_{rem}\) to \(R\); (b) \(S\) to empty; (c) \(K_{cur}(v),\ \ v\in V\); (d) the fail probability \(L(r,v)\) for each neuron, \(r\in R,v\in V\); (e) the cost \(C(r,v)\) for each neuron, \(r\in R,v\in V\); (f) \(q(r,v)\) for \(r\in R,v\in V\) to zero: assume that all possible assignments have no effect on the cost of the objective function at the beginning. 2. Compute the RNN parameters, \(\Lambda(r,v)\), \(\lambda(r,v)\), \(w^{-}(r,v;r^{\prime},v)\), \(w^{-}(r,v;r,v^{\prime})\) and \(f(r,v)\), and construct a neural network for \(r\in R_{rem}\) and \(v\in V\). 3. Iteratively compute \(q(r,v)\) for \(r\in R_{rem}\) and \(v\in V\) based on Equation (17) until \(q(r,v)\) converges for all neurons. ```
initialize \(R_{rem}=R\); \(S=\emptyset\); \(K_{cur}(v)=K(v)\)\(v\in V\); \(L(r,v)\)\(r\in R,v\in V\); \(C(r,v)\)\(r\in R,v\in V\); \(q_{pre}(r,v)=q(r,v)=0\)\(r\in R,v\in V\); for each possible assignment pairs \((r,v)\in[neurons]\)do \(b(r,v)=K(v)(1-L(r,v))-C(r,v)\); \(\Lambda(r,v)=max\{0,b(r,v)\}\); \(\lambda(r,v)=max\{0,-b(r,v)\}\); \(w^{-}(r,v;r^{\prime},v)=max\{0,b(r,v)\}\), \(if\)\(r\
eq r^{\prime}\); \(w^{-}(r,v;r,v^{\prime})=max\{0,b(r,v)\}\), \(if\)\(v\
eq v^{\prime}\); endfor for each possible assignment pairs \((r,v)\in[neurons]\)do \(f(r,v)=\sum_{r^{\prime},v^{\prime}}w^{-}(r,v;r^{\prime},v^{\prime})\); endfor for each possible assignment pairs \((r,v)\in[neurons]\)do \(q(r,v)=\Lambda(r,v)/[\lambda(r,v)+f(r,v)+\sum_{r^{\prime}\
eq r}q(r^{\prime},v)w^{-}(r^{\prime},v;r,v)+\sum_{v^{\prime}\
eq v}q(r,v^{\prime})w^{-}(r,v^{ \prime};r,v)]\); endfor ifconvergenceforallneuronsthen // select the most excited neuron (line 20); else // continue iterating until convergence (line 12); endif  initialize maxValue = 0; for each possible assignment pairs \((r^{*},v^{*})\in[neurons]\)do if\(q(r^{*},v^{*})>maxValue\)then \(maxValue=q(r^{*},v^{*})\);  select rescuer-victim pair \((r^{*},v^{*})\); endif endfor  update \(S=S\bigcup(r^{*},v^{*})\), \(R_{rem}=R_{rem}\setminus r^{*}\), \(K_{cur}(v^{*})=K_{cur}(v^{*})L(r^{*},v^{*})\); if\(R_{rem}\) is not empty then \(//\) allocate next rescuer (line 2); else  stop; endif
```  
**Algorithm 1** Task assignment for optimal emergency management. Select a rescuer-victim pair \((r^{*},v^{*})\) that has the highest probability of being active; if all \(q(r,v)=0\) for \(r\in R_{rem}\) and \(v\in V\), then stop: there is no assignment that can reduce the cost of the objective function. Update the solution set, \(S\), by adding new rescuer-victim pair \((r^{*},v^{*})\) into it. Update the remaining rescuers set, \(R_{rem}\), by removing rescuer \(r^{*}\) from \(R_{rem}\). 7. Reduce the penalty of the victim, \(v^{*}\), by the expected reduction: \(K_{cur}(v^{*})=K_{cur}(v^{*})-K_{cur}(v^{*})\)\((1-L(r^{*},v^{*}))=K_{cur}(v^{*})L(r^{*},v^{*})\). 8. Check the remaining rescuers set \(R_{rem}\), and if \(R_{rem}\) is not empty, then go to step (2); otherwise, stop: all rescuers have tasks. Note that using this algorithm, the assignments in solution set \(S\) always result in reducing the cost of the objective function [27], since an assignment may be selected if \(q(r,v)>0\) or \(\Lambda(r,v)>0\) (see Line 22) (_i.e._, \(b(r,v)>0\)), otherwise, if \(q(r,v)=\Lambda(r,v)=0\) (_i.e._, \(b(r,v)\leq 0\)), the allocation will not be executed. For example, a network of four fully connected neurons is modelled in Figure 1a with two rescuers (\(r_{1}\), \(r_{2}\)) and two victims (\(v_{1}\), \(v_{2}\)). If neuron \((r_{1},v_{1})\) has the highest active probability, \(q\), it will be selected. Then, the neurons, including rescuer \(r_{1}\), are removed from the network, and the RNN parameters of other neurons are updated by the current penalty of victim \(v_{1}\). An updated neural network will be constructed (Figure 1b). Next, do the calculation again and select the most excited neuron.