jbessom
asked on
Bankers algorithm (coursework)
1. The job is to fill out the BankImpl.java file with hints given in the code.
2.Once things start working, I can use the TestHarness program that is included. To run it, type
Java TestHarness infile.txt 10 5 7
Or
Create a new project configuration from run ¿ set project configuration, and set arguments to be infile.txt 10 5 7.
If you input * and press Enter, it will tell you the current state of your bank (as output by your getState() method). If you type
RQ 0 2 2 2
then customer 0 will request two of each available resource. Likewise,
RL 0 2 2 2
will make customer 0 release two of each resource.
Here is an example output:
run:
*
Available
[10 5 7]
Allocation
[0 0 0]
[0 0 0]
[0 0 0]
[0 0 0]
[0 0 0]
Max
[7 5 3]
[3 2 2]
[9 0 2]
[2 2 2]
[4 3 3]
Need
[7 5 3]
[3 2 2]
[9 0 2]
[2 2 2]
[4 3 3]
RQ 4 2 3 5
*2*
*3*
*5*
Customer # 4 requesting 2 3 5 Available = 10 5 7 Approved
*
Available
[8 2 2]
Allocation
[0 0 0]
[0 0 0]
[0 0 0]
[0 0 0]
[2 3 5]
Max
[7 5 3]
[3 2 2]
[9 0 2]
[2 2 2]
[4 3 3]
Need
[7 5 3]
[3 2 2]
[9 0 2]
[2 2 2]
[2 0 -2]
RL 4 2 2 2
*2*
*2*
*2*
Customer # 4 releasing 2 2 2 Available = 10 4 4 Allocated = [0 1 3 ]*
Available
[10 4 4]
Allocation
[0 0 0]
[0 0 0]
[0 0 0]
[0 0 0]
[0 1 3]
Max
[7 5 3]
[3 2 2]
[9 0 2]
[2 2 2]
[4 3 3]
Need
[7 5 3]
[3 2 2]
[9 0 2]
[2 2 2]
[4 4 6]
RQ 0 1 0 2
*1*
*0*
*2*
Customer # 0 requesting 1 0 2 Available = 10 4 4 Denied
*
Available
[10 4 4]
Allocation
[0 0 0]
[0 0 0]
[0 0 0]
[0 0 0]
[0 1 3]
Max
[7 5 3]
[3 2 2]
[9 0 2]
[2 2 2]
[4 3 3]
Need
[7 5 3]
[3 2 2]
[9 0 2]
[2 2 2]
[4 4 6]
src.project3.zip
2.Once things start working, I can use the TestHarness program that is included. To run it, type
Java TestHarness infile.txt 10 5 7
Or
Create a new project configuration from run ¿ set project configuration, and set arguments to be infile.txt 10 5 7.
If you input * and press Enter, it will tell you the current state of your bank (as output by your getState() method). If you type
RQ 0 2 2 2
then customer 0 will request two of each available resource. Likewise,
RL 0 2 2 2
will make customer 0 release two of each resource.
Here is an example output:
run:
*
Available
[10 5 7]
Allocation
[0 0 0]
[0 0 0]
[0 0 0]
[0 0 0]
[0 0 0]
Max
[7 5 3]
[3 2 2]
[9 0 2]
[2 2 2]
[4 3 3]
Need
[7 5 3]
[3 2 2]
[9 0 2]
[2 2 2]
[4 3 3]
RQ 4 2 3 5
*2*
*3*
*5*
Customer # 4 requesting 2 3 5 Available = 10 5 7 Approved
*
Available
[8 2 2]
Allocation
[0 0 0]
[0 0 0]
[0 0 0]
[0 0 0]
[2 3 5]
Max
[7 5 3]
[3 2 2]
[9 0 2]
[2 2 2]
[4 3 3]
Need
[7 5 3]
[3 2 2]
[9 0 2]
[2 2 2]
[2 0 -2]
RL 4 2 2 2
*2*
*2*
*2*
Customer # 4 releasing 2 2 2 Available = 10 4 4 Allocated = [0 1 3 ]*
Available
[10 4 4]
Allocation
[0 0 0]
[0 0 0]
[0 0 0]
[0 0 0]
[0 1 3]
Max
[7 5 3]
[3 2 2]
[9 0 2]
[2 2 2]
[4 3 3]
Need
[7 5 3]
[3 2 2]
[9 0 2]
[2 2 2]
[4 4 6]
RQ 0 1 0 2
*1*
*0*
*2*
Customer # 0 requesting 1 0 2 Available = 10 4 4 Denied
*
Available
[10 4 4]
Allocation
[0 0 0]
[0 0 0]
[0 0 0]
[0 0 0]
[0 1 3]
Max
[7 5 3]
[3 2 2]
[9 0 2]
[2 2 2]
[4 3 3]
Need
[7 5 3]
[3 2 2]
[9 0 2]
[2 2 2]
[4 4 6]
src.project3.zip
It looks like you want us to answer your schoolworks...
Hint : You have to consider using a "permanent" storage to account each customers their allocated ressources.
Hint : You have to consider using a "permanent" storage to account each customers their allocated ressources.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Only partially correct
ASKER
The banker will only grant a request if it leaves the system in a safe state. It is denied if it is in an unsafe state
Please see attached jpg
Test the banker interface by using testharness.java file uploaded earlier. It expects the the interface to be called BankImp1 and requires an input file containing the maximum demand of each resource type for each customer. Example, if there are 5 customers and three resource types the input might be like:
7,5,3
3,2,2
9,0,2
2,2,2
4,3,3
The max demands for customer 0 is 7,5,3; customer 1 is 3,2,2, etc.
TestHarness.java requires the initial number number of resources available in the bank. Example, if there are initially 10, 5, and 7 resources, we invoke test harness as:
java TestHarness infile.txt 10 5 7
Bank.jpg