# Project Robust Scheduling Based on the Scattered Buffer Technology
## 4 Unit activity Slack Algorithm (UAS)
### Resource Allocation Algorithm with Maximum Use of the Precedence Relations (MPRRA)
#### 4.2.3 Resource Allocation Algorithm  
In this algorithm, as shown in Algorithm 1, the resource allocation in the first process is the focus, which determines the additional constraints of the whole schedule. In the design of the first process in this algorithm, based on the principle that the total amount of the resource allocation in each stage is a constant, namely the sum of the resource that the activity pair with the precedence relation gets and the resource that the activity pair in non-precedence relation gets is a fixed value, the allocation strategy with the maximum use of the precedence relation is adopted in each stage in this paper, i.e., the saturated resource allocation, which can minimize the amount of resource that is allocated  
Figure 5: The baseline schedule and the resource allocation: (**a**) the baseline schedule and (**b**) the unsaturated resource allocation and (**c**) the saturated allocation.  
through the non-precedence relation. The resource allocation in the second process is to balance the resource imbalance after the first process. Because the resource allocation of the activity pairs with the precedence relations has been finished in the first process, more additional constraints are generated among the activity pairs in non-precedence relations in this process. The pseudo code of Algorithm 1 is as follows.  
```
begin /* process 1 */  Divide stage by activity completion time for\(k\gets 1\) to stage do \(P_{k}\leftarrow\{\ i\ |\ s_{k}=st_{i}+t_{i}\wedge i\in jq(j)\}\) \(S_{k}^{0}\leftarrow\Big{\{}\ j\ |\ s_{k}=st_{j}\wedge i\in jh(i)\Big{\}}\) \(S_{k}^{lag}\leftarrow\Big{\{}\ j\ |\ s_{k}<st_{j}\wedge i\in jh(i)\Big{\}}\) for\(j\in S_{k}^{0}\)do while\(length(jq(j))=1\)do \(q(i,j)\leftarrow\underset{i\in jq(j)}{min}\Big{(}c_{i},c_{j}\Big{)}\) \(P_{k}\gets P_{k}\backslash\Bigg{\{}\ i\lor j\ |\underset{i\in j(j)}{min}\Big{(}c_{i},c_{j}\Big{)}\Bigg{\}}\) \(S_{k}^{0}\gets S_{k}^{0}\backslash\Bigg{\{}\ i\lor j\ |\underset{i\in j(j)}{min}\Big{(}c_{i},c_{j}\Big{)}\Bigg{\}}\) for\(i\in P_{k}\)do while\(length(jq(j))=1\)do \(q(i,j)\leftarrow\underset{j\in jh(i)}{min}\Big{(}c_{i},c_{j}\Big{)}\) \(P_{k}\gets P_{k}\backslash\Bigg{\{}\ i\lor j\ |\underset{j\in jh(i)}{min}\Big{(}c_{i},c_{j}\Big{)}\Bigg{\}}\) \(S_{k}^{0}\gets S_{k}^{0}\backslash\Bigg{\{}\ i\lor j\ |\underset{j\in j(i)}{min}\Big{(}c_{i},c_{j}\Big{)}\Bigg{\}}\) /* process 2 */  Sort all activities in ascending order according to activity completion time for\(i\in J\)do \(B_{i}\leftarrow\Big{\{}\ j\ |\ s_{i}+t_{i}\leq st_{j}\wedge i\in J\Big{\}}\) for\(j\in B_{i}\)do while\(c_{i}\
eq 0\wedge c_{j}\
eq 0\)do \(q(i,j)\leftarrow\underset{i,j\in J}{min}\Big{(}c_{i},c_{j}\Big{)}\)  end for
```  
**Algorithm 1**Maximize the use of precedence relations for resource allocation.  
In the above code, \(s_{k}\) is the time point in the stage of \(k\), \(jq\) is the set of the immediate predecessors, \(jh\) is the set of the immediate successors, \(P_{k}\) is the set of sending activities that have precedence relations with receiving activities in the stage of \(k\), \(S_{k}^{0}\) is the set of receiving activities that have the zero interval precedence relations with sending activities in the stage of \(k\), \(c_{i}\) is the amount of remaining resources that the sending activity \(i\) can distribute, \(c_{j}\) is the amount of resources that the receiving activity \(j\) needs, \(q(i,j)\) is the amount of resources that is allocated by the activity pair \((i,j)\), \(J\) is the set of activities that is generated in the ascending order according to the completion time of the activity, and \(B_{i}\) is the set of subsequence activities \(j\