14,643,391 members
Articles » General Programming » Algorithms & Recipes » Algorithms
Article
Posted 27 Jul 2014

18.4K views
14 bookmarked

Corporate projects & human resource management using Banker's algorithm

Rate this:
27 Jul 2014CPOL
This will show the simple and useful way to implement Banker's algorithm in managing & scheduling projects,their resources & to give effective solution.

Introduction

Normally, Banker's algorithm is used to  manage operating system process & their resources. Same idea is used here. Process are treated as "Projects" and resources are treated as "Project resources". for e.g. In "P1" project, 3 c++, 2 Java, 4 dot net resources are required & so on. This code takes "Claimed resources","Allocated resources" & "Available resources" as Input and gives proper project completion sequence as output. If unsafe state is occurred then, program will give you suggestion to hire number of employees of particular resources based on logic so that minimum number of resources have to be hired.

Background

The Banker's algorithm is a resource allocation and deadlock avoidance algorithm developed by Edsger Dijkstra that tests for safety by simulating the allocation of predetermined maximum possible amounts of all resources, and then makes an "s-state" check to test for possible deadlock conditions for all other pending activities, before deciding whether allocation should be allowed to continue.

Output

In the following output, code takes the number of processes,  number of resources, for each process required/claimed resources, allocated resources for each project, available resources as input & gives the proper sequence of completion of all projects as output (Following is an example of safe state).

In the following output,  code evaluates the allocated & claimed resources & evaluates unsafe state. It tells user to hire particular number of employees to complete projects in the efficient & proper sequence.

Using the code

Following code gives the logic to schedule project:

```for(i=0;i<np;i++)
{
if(chkpcmp[i]==0) {  // Do for those projects for who has not completed yet

for(int j=0;j<nr;)
{

for(int y=0;y<nr;y++)
{
if(clm[i][y]==0)
count++;
else {count=0;break;}
}

if(count==nr) {count=0;break;}

if((clm[i][j]-allo[i][j])<=avl[j])  //If required resources are available
{

if(j==nr-1)
{
flag=1;
fc++;
for(int k=0;k<nr;k++)       //After completion,transfer resources into available resources
{avl[k]=avl[k]+allo[i][k];}

for(int k=0;k<nr;k++)     //After completion, make allocated resources as zero
{allo[i][k]=0;}

for(int k=0;k<nr;k++)    //After completion, make claimed resources as zero
{clm[i][k]=0;}

cout<<"\nProject "<<"P"<<i+1<<" is completed\n";    ```

In the unsafe state, claimed/required resources are greater than the available. In such cases, we have to  hire more resources to complete the projects. Following code snippet suggests to hire minimum number of employees in order to complete all the projects.

```for(cp=0;cp<np;cp++)
{

if(chkpcmp[cp]==0)          // Do for those projects who has not completed yet
{

for(int j=0;j<nr;j++)     // Summation of all resources
{

if(clm[cp][j]>allo[cp][j]+avl[j])
a=a+clm[cp][j]-(allo[cp][j]+avl[j]);

}

if(flag2==1)
{minc=a+1;flag2=0;}  //Find minimum sum so that to hire minimum number of employees

if(a<=minc)
{
minc=a;

for(int t=0;t<nr;t++)      //Store it as per resources
{
if(clm[cp][t]>allo[cp][t]+avl[t])
tempr[t]=clm[cp][t]-(allo[cp][t]+avl[t]);

}

}

}
}
```

Points of Interest

We can use this in real life managing Human Resources. In large scale, we can create HTML page as front-end and can use drop down menu to select project & resources and can use SQL/Oracle database to store the project information as back-end. This will be very useful & simple to use.

In unsafe state, current program gives the suggestion to hire new resources. We can also add few more option to this.
For e.g. transfer resources from other projects in balanced way. i.e. if we transfer resources from only one project then, it may have some problem, we can not complete projects with the help of few resources. So, job is to tranfer resources from all the projects.

References

http://en.wikipedia.org/wiki/Banker's_algorithm

Share

 Software Developer India
No Biography provided

 First Prev Next
 My vote of 5 Ștefan-Mihai MOGA13-Aug-14 3:17 Ștefan-Mihai MOGA 13-Aug-14 3:17
 This is a great inspiring article. I am pretty much pleased with your good work. You put really very helpful information. Keep it up once again.
 Re: My vote of 5 Rakesh Waghulde13-Aug-14 23:44 Rakesh Waghulde 13-Aug-14 23:44
 My vote of 5 Matth Moestl28-Jul-14 10:21 Matth Moestl 28-Jul-14 10:21
 Re: My vote of 5 Rakesh Waghulde28-Jul-14 19:34 Rakesh Waghulde 28-Jul-14 19:34
 Images missing Snorri Kristjansson27-Jul-14 23:51 Snorri Kristjansson 27-Jul-14 23:51
 Re: Images missing Rakesh Waghulde28-Jul-14 0:01 Rakesh Waghulde 28-Jul-14 0:01
 Re: Images missing Rakesh Waghulde28-Jul-14 8:15 Rakesh Waghulde 28-Jul-14 8:15
 Last Visit: 30-Sep-20 0:11     Last Update: 30-Sep-20 0:11 Refresh 1