Purchase Solution

Banker's algorithm

Not what you're looking for?

Ask Custom Question

Specification
Implement the Banker's algorithm described in Section 8.5.3 using C/C++. Your program should ...

1) Prompt user to enter the size of matrix n and m. Your program should accept any n x m matrix and m vectors where n and m are positive integer less than 10.
2) Read in Allocation, Max, and Available from allocation.txt, max.txt, and available.txt, respectively. You can assume that each entry of the matrix (or vector) in the input files is separated with ' ' or 'n'. That is, the input files

7 5 3 3 2 2 9 0 2 2 2 2

and

7 5 3
3 2 2
9 0 2
2 2 2

are considered to be identical entries, and they can be interpreted as 1x12, 2x6, 3x4, 4x3, and etc depending on the user input n and m. Obviously, your program needs to handle the error when the total number of entries in matrix exceeding the total number of entries in input files.

3) Properly perform Safety algorithm to report user if the initial state is in safe state. If state is safe, report a safe sequence and go to step 4. If not, terminate the program.

4) Prompt user for new Requesti, perform Resource-Request algorithm, and perform Safety algorithm to report if the current state is safe. If state is safe, report a safe sequence. If state is unsafe, output "unsafe"

5) Repeat step 4 above until user terminates the program.

Purchase this Solution

Solution Summary

Implement the Banker's algorithm

Solution Preview

Try the following program. It has basic structure what you are looking for.

#include <iostream>
#define M 3
#define N 5
using namespace std;

void readMax(int max[N][M]);
void printMax(int max[N][M]);
bool lessEqNeedWork(int index, int need[N][M], int work[M]);
void printSafeStatus(int work[M], bool finish[N], int step);
void printRequestStatus(int request[M], int available[M], int step);
bool isSafe(int max[N][M], int allocation[N][M], int system[N], int need[N][M], int available[M]);

int main(int argc, char **argv)
{

int i, j, k;
int max[N][M]={ {7,5,3},
{3,2,2},
{9,0,2},
{2,2,2},
{4,3,3}
};
int allocation[N][M]={
{0,1,0},
{2,0,0},
{3,0,2},
{2,1,1},
{0,0,2}
};
int available[M]={3,3,2};
int need[N][M]={
{7,4,3},
{1,2,2},
{6,0,0},
{0,1,1},
{4,3,1}
};
int system[N]={10, 5, 7};
int work[M]={0};
int request[N][M]={
{0, 2, 0},
{1, 0, 2},
{1, 0, 0},//request that can be granted immediatly
{0, 2, 1},//request that can't be granted immediatly
{3, ...

Purchase this Solution


Free BrainMass Quizzes
Javscript Basics

Quiz on basics of javascript programming language.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.