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.
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.
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:
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.
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.