# Efficient Resource Allocation in Blockchain-Assisted Health Care Systems
## 4 Proposed Technique
### Allocation of Data Blocks to Mining Machines
#### 4.2.1 Algorithm for Load Balancing  
In this section, an algorithm for the LBM is proposed for when the total size of the data blocks received by the LBM is less than the available caching capacity of all the associated mining machines. Suppose there are \(M\) nodes used for the mining of blockchain data. The cache limit of each fog node is \((B_{lim})\). There are \(N\) blocks of data, and the size of each block \(B\) is different from. To find out the optimal allocation of the blocks of data to the fog mining machines, we calculate the maximum load that has been assigned to a mining machine among all machines.The optimal value for the block distribution is computed in the following two ways:  
1. Calculate the mean value by dividing the total size of the data blocks by the total number of mining machines. The optimum value \((Opt_{1})\) in this case can be given as \[Opt_{1}\geq 1/M\times\sum_{j=1}^{N}B_{j}\] (3) \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Data Block Number** & **Priority Category/Level** & **Total Time in Cache** & **Priority Value (\(P_{V}\))** \\ \hline \(A\) & Low & 13 & 260 \\ \hline \(B\) & Medium & 16 & 800 \\ \hline \(C\) & High & 21 & 4200 \\ \hline \(D\) & Low & 26 & 520 \\ \hline \(E\) & Medium & 31 & 1550 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Data block priority. 2. There is the possibility that there is one data block whose size is larger than the other data blocks. In this case, a larger block size is allocated to one machine, and the smaller blocks are placed on other fog nodes. In this case, the optimum load assignment \((Opt_{2})\) will be at least the size of the largest data block and is calculated as \[Opt_{2}\geq maxB_{j}\quad 1\leq j\leq N\] (4) Based on the two scenarios described above, the optimum allocation of data block size \((S_{Opt})\) is formulated as: \[B_{Opt}\geq max(1/M\times\sum_{j=1}^{N}B_{j},maxB_{j})\] (5) The objective of any load balancing technique is to allocate data blocks to minimize the \(B_{Opt}\) of the assigned mining machines. Suppose there are \(X\) mining nodes in the coverage area of a load balancer with different numbers of blocks of data pending in their cache list. The load balancer allocates the most valuable data blocks to the mining nodes by following the below-mentioned criteria. \[min[CAP_{i}-(AL_{i}+\frac{TL_{i}\times 100}{TC_{i}})]\ldots\ldots\ldots\forall iEX\] Here, \[CAP_{i}\] is the total cache capacity of node \[i\] \[AL_{i}\] is the currently available cache limit of node \[i\] \[TL_{i}\] is the time elapsed in computing the under-process nonce by node \[i\] \[Opt_{2}\geq maxB_{j}\quad 1\leq j\leq N\]0 is the expected time for computing the nonce by node \[Opt_{2}\geq maxB_{j}\quad 1\leq j\leq N\]1 To achieve this goal, the well-known greedy algorithm is modified by incorporating the longest job first (LJF) algorithm, so that the load allocation to the mining nodes can be made efficient. The salient features of the modified greedy algorithms are * All the received data blocks are sorted in descending order, as per the size of the data; * Allocate these data blocks to mining machines with the most caching space available. The complete algorithm of our proposed load balancing scheme for the LBM is shown in Algorithm 1. ```
**Algorithm 1**Load balancing algorithm
```
1 Mining computing task scheduling Inputs: \(Number\ of\ blocks\ of\ data=N\) Data block \(Sizes=B_{1},B_{2},B_{3}



#### 4.2.2 Knapsack Optimization Algorithm

The knapsack algorithm (0/1 type) can be used to fill a sack with items that are of the highest value, such that the total capacity of the sack is exceeded. In this work, the scrutinized problem was formulated as a knapsack problem, as we needed to allocate the most valuable data blocks to the mining machines, within their caching capacity. The mapping of our problem as a 0/1 knapsack problem is shown in Table 2 and its algorithm is given in Algorithm 2.