Skip to content

Commit be138d2

Browse files
committed
Delete resource allocation code
1 parent 63fccc6 commit be138d2

File tree

4 files changed

+90
-44
lines changed

4 files changed

+90
-44
lines changed
Binary file not shown.

Resource Allocation Graph/rag.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
int getCountOfResourceCollisions(int numberOfProcesses, vector<int> processes,
7+
int numberOfRows, int numberOfColumns, vector<vector<int>> resources, int resourceToCheck) {
8+
int countOfCollisions = 0;
9+
for (int i = 0; i < numberOfRows; ++i) {
10+
for (int j = 0; j < numberOfColumns; ++j) {
11+
if (resources[i][j] == resourceToCheck) {
12+
++countOfCollisions;
13+
}
14+
}
15+
}
16+
return countOfCollisions;
17+
}
18+
19+
int main() {
20+
int numberOfProcesses, numberOfRows, numberOfColumns, resourceToCheck;
21+
cout << "I have implemented a matrix for resource allocation" << endl;
22+
cout << "Enter the number of processes: " ;
23+
cin >> numberOfProcesses;
24+
vector<int> processes(numberOfProcesses);
25+
cout << "Enter Process Numbers (0-" << numberOfProcesses-1 << " with spaces): " ;
26+
for (int i = 0; i < numberOfProcesses; ++i) {
27+
cin >> processes[i];
28+
}
29+
cout << "Enter number of rows for resource array: ";
30+
cin >> numberOfRows;
31+
cout << "Enter number of columns for resource array: ";
32+
cin >> numberOfColumns;
33+
vector<vector<int>> resources(numberOfRows, vector<int>(numberOfColumns));
34+
cout << "Enter resources (with spaces): " << endl;
35+
for (int i = 0; i < numberOfRows; ++i) {
36+
for (int j = 0; j < numberOfColumns; ++j) {
37+
cin >> resources[i][j];
38+
}
39+
}
40+
41+
cout << "Enter a resource to check if collision happens" << endl;
42+
cin >> resourceToCheck;
43+
44+
int countOfCollisions = getCountOfResourceCollisions(numberOfProcesses, processes,
45+
numberOfRows, numberOfColumns, resources, resourceToCheck);
46+
47+
cout << "Counts of deadlock = " << countOfCollisions << endl;
48+
return 0;
49+
}

Resource Allocation Graph/rag.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## Summary
2+
The code snippet is a function called `getCountOfResourceCollisions` that takes in the number of processes, a vector of process numbers, the number of rows and columns in a resource matrix, the resource matrix itself, and a resource to check for collisions. The function counts the number of collisions between the resource to check and the resources in the matrix, and returns the count.
3+
4+
## Example Usage
5+
```cpp
6+
I have implemented a matrix for resource allocation
7+
Enter the number of processes: 3
8+
Enter Process Numbers (0-2 with spaces): 0 1 2
9+
Enter number of rows for resource array: 2
10+
Enter number of columns for resource array: 3
11+
Enter resources (with spaces):
12+
1 2 3
13+
4 5 6
14+
Enter a resource to check if collision happens
15+
2
16+
Counts of deadlock = 1
17+
```
18+
19+
## Code Analysis
20+
### Inputs
21+
- `numberOfProcesses`: an integer representing the number of processes
22+
- `processes`: a vector of integers representing the process numbers
23+
- `numberOfRows`: an integer representing the number of rows in the resource matrix
24+
- `numberOfColumns`: an integer representing the number of columns in the resource matrix
25+
- `resources`: a 2D vector of integers representing the resource matrix
26+
- `resourceToCheck`: an integer representing the resource to check for collisions
27+
___
28+
### Flow
29+
1. The user is prompted to enter the number of processes.
30+
2. The user is prompted to enter the process numbers.
31+
3. The user is prompted to enter the number of rows and columns for the resource matrix.
32+
4. The user is prompted to enter the resources in the matrix.
33+
5. The user is prompted to enter a resource to check for collisions.
34+
6. The `getCountOfResourceCollisions` function is called with the inputs.
35+
7. The function iterates through the resource matrix and counts the number of collisions with the resource to check.
36+
8. The count of collisions is returned.
37+
9. The count of collisions is printed.
38+
___
39+
### Outputs
40+
- `countOfCollisions`: an integer representing the number of collisions between the resource to check and the resources in the matrix.
41+
___

rag/rag.cpp

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)