Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b2e45ff

Browse files
committedDec 10, 2023
removing comments and printfs
1 parent 61731f9 commit b2e45ff

27 files changed

+435
-721
lines changed
 

‎CMakeLists.txt

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ cmake_minimum_required(VERSION 3.0)
22
project(multitasking-scheduling-algorithm-simulation-system C)
33
set(CMAKE_C_STANDARD 99)
44

5-
# Adding Raylib
65
include(FetchContent)
76
set(FETCHCONTENT_QUIET FALSE)
8-
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples
9-
set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # don't build the supplied example games
7+
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
8+
set(BUILD_GAMES OFF CACHE BOOL "" FORCE)
109

1110
FetchContent_Declare(
1211
raylib
@@ -18,7 +17,6 @@ FetchContent_Declare(
1817

1918
FetchContent_MakeAvailable(raylib)
2019

21-
# adding raygui
2220
FetchContent_Declare(
2321
raygui
2422
GIT_REPOSITORY "https://github.com/raysan5/raygui.git"
@@ -27,18 +25,4 @@ FetchContent_Declare(
2725
GIT_SHALLOW 1
2826
)
2927

30-
FetchContent_MakeAvailable(raygui)
31-
32-
# Adding our source files
33-
# file(GLOB_RECURSE PROJECT_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/sources/*.c") # Define PROJECT_SOURCES as a list of all source files
34-
# set(PROJECT_INCLUDE "${CMAKE_CURRENT_LIST_DIR}/sources/") # Define PROJECT_INCLUDE to be the path to the include directory of the project
35-
36-
# Declaring our executable
37-
# add_executable(${PROJECT_NAME})
38-
# target_sources(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCES})
39-
# target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_INCLUDE})
40-
# target_link_libraries(${PROJECT_NAME} PRIVATE raylib)
41-
42-
# Setting ASSETS_PATH
43-
# target_compile_definitions(${PROJECT_NAME} PUBLIC ASSETS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/assets/") # Set the asset path macro to the absolute path on the dev machine
44-
#target_compile_definitions(${PROJECT_NAME} PUBLIC ASSETS_PATH="./assets") # Set the asset path macro in release mode to a relative path that assumes the assets folder is in the same directory as the game executable
28+
FetchContent_MakeAvailable(raygui)

‎build/algorithms/FIFO

21.7 KB
Binary file not shown.

‎build/algorithms/SRT

26.2 KB
Binary file not shown.

‎build/algorithms/multilevel

30.3 KB
Binary file not shown.

‎build/algorithms/multilevel_v2

31 KB
Binary file not shown.
26.3 KB
Binary file not shown.

‎build/algorithms/preemptive_priority

26.3 KB
Binary file not shown.

‎build/algorithms/round_robin

21.7 KB
Binary file not shown.

‎build/algorithms/sjf

26.2 KB
Binary file not shown.

‎build/algorithms/static_priority

26.2 KB
Binary file not shown.

‎build/main

1.61 MB
Binary file not shown.

‎makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ update:
2929
@echo 'MSASS has been updated successfully !'
3030

3131
run:
32-
@./build/main
33-
@echo 'Welcome to MSASS !'
32+
@echo 'Welcome to MSASS !'
33+
@./build/main

‎processes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0

‎src/includes/data_structures/priority_queue.h

Lines changed: 12 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
#include <stdbool.h>
44
#include "../utils/process.h"
55
#include "../utils/ReadyQueueElements.h"
6-
// structure to represent the priority queue
76
typedef struct {
8-
void** data; // table of void* elements in order to make a generic pirority_queue
9-
int size; // size of the priority_queue
10-
int capacity; // maximum size of the priority_queue
11-
int dataSize; // size of each element to be added to the priority_queue
12-
int (*compare)(const void *, const void *); // function pointer for custom comparison function
7+
void** data;
8+
int size;
9+
int capacity;
10+
int dataSize;
11+
int (*compare)(const void *, const void *);
1312
} PriorityQueue;
1413

1514
int compare_process_runTime(const void *a, const void *b) {
@@ -28,7 +27,6 @@ int compare_process_priority(const void *a, const void *b);
2827
ReadyQueueElements getPriorityQueueElements(PriorityQueue* pq);
2928
void free_created_array_from_pq(ReadyQueueElements readyqueue);
3029

31-
// function to initialize an empty priority queue
3230
PriorityQueue *init_priority_queue(int capacity, int dataSize, int (*compare)(const void *, const void *)) {
3331
PriorityQueue *pq = (PriorityQueue *)malloc(sizeof(PriorityQueue)); // allocating the priority_queue
3432
pq->data = (void **)malloc(sizeof(void*) * (capacity)); // allocating the data table
@@ -39,31 +37,26 @@ PriorityQueue *init_priority_queue(int capacity, int dataSize, int (*compare)(co
3937
return pq;
4038
}
4139

42-
// function to swap two elements in the priority queue
4340
void swap_pq(void **a, void **b) {
4441
void *temp = *a;
4542
*a = *b;
4643
*b = temp;
4744
}
4845

49-
// function to push an element into the priority queue
5046
void push(PriorityQueue *pq, void *data) {
5147
if (pq->size == pq->capacity) {
5248
printf("Priority queue overflow\n");
5349
return;
5450
}
55-
pq->data[pq->size] = malloc(pq->dataSize); // allocating needed memory for the new element to be pushed
56-
memcpy(pq->data[pq->size], data, pq->dataSize); // copy the data into the priority_queue
57-
// perform heapify-up to maintain the heap property
51+
pq->data[pq->size] = malloc(pq->dataSize);
52+
memcpy(pq->data[pq->size], data, pq->dataSize);
5853
int i = pq->size;
5954
while (i > 0 && pq->compare(pq->data[i], pq->data[(i-1) / 2]) > 0) {
6055
swap_pq(&pq->data[i], &pq->data[(i-1) / 2]);
6156
i = (i-1) / 2;
6257
}
63-
pq->size++; // incrementing the size of the priority_queue
58+
pq->size++;
6459
}
65-
66-
// function to check if the priority_queue is empty
6760
bool is_empty_pq(PriorityQueue* pq) {
6861
return !pq->size;
6962
}
@@ -78,7 +71,6 @@ ReadyQueueElements getPriorityQueueElements(PriorityQueue* pq) {
7871
}
7972
for(int i=0;i<idx;i++) {
8073
push(pq, i[array]);
81-
// push(pq, array[i]);
8274
}
8375
return (ReadyQueueElements){array, pq->size};
8476
}
@@ -88,16 +80,14 @@ void free_created_array_from_pq(ReadyQueueElements readyqueue) {
8880
}
8981
free(readyqueue.readyQueue);
9082
}
91-
// function to pop the element with the highest priority from the priority_queue
9283
void* pop(PriorityQueue *pq) {
9384
if (is_empty_pq(pq)) {
9485
printf("Priority queue underflow\n");
9586
exit(0);
9687
}
97-
pq->size--; // decrementing the size of the priority_queue
98-
swap_pq(&pq->data[0], &pq->data[pq->size]); // swap the root with the last element
99-
void* poppedData = pq->data[pq->size]; // store the poppedData
100-
// perform heapify-down to maintain the heap property
88+
pq->size--;
89+
swap_pq(&pq->data[0], &pq->data[pq->size]);
90+
void* poppedData = pq->data[pq->size];
10191
int i = 0;
10292
while (1) {
10393
int leftChild = 2 * i + 1;
@@ -130,7 +120,6 @@ void* top(PriorityQueue* pq) {
130120
return pq->data[0];
131121
}
132122

133-
// function to free the memory allocated for the priority_queue
134123
void free_priority_queue(PriorityQueue *pq) {
135124
for (int i = 0; i < pq->size; ++i) {
136125
free(pq->data[i]);
@@ -139,45 +128,10 @@ void free_priority_queue(PriorityQueue *pq) {
139128
free(pq);
140129
}
141130

142-
// example custom comparison function for integers
143131
int compare_int(const void *a, const void *b) {
144132
return (*(int *)a - *(int *)b);
145133
}
146134

147-
// example custom comparison function for process priority
148135
int compare_process_priority(const void *a, const void *b) {
149136
return ((Process*)a)->priority > ((Process*)b)->priority;
150-
}
151-
152-
153-
154-
155-
156-
// int main(void) {
157-
// // PriorityQueue *pq = init_priority_queue(11, sizeof(int), compare_int);
158-
// PriorityQueue *pq = init_priority_queue(11, sizeof(Process), compare_process_priority);
159-
160-
// // int values[] = {50, 19, 0, 14, 6, 3, 8, 16};
161-
// Process values[] = {{"pqrs", 0, 7, 8}, {"a", 5, 4, 2}, {"b", 12, 15, 88}, {"c", 8, 14, 3}, {"d", 10, 17, 18}, {"e", 5, 4, 0}};
162-
163-
// for (int i = 0; i < sizeof(values) / sizeof(values[0]); ++i) {
164-
// push(pq, &values[i]); // push elements into the priority_queue
165-
// }
166-
// ReadyQueueElements readyqueue = getPriorityQueueElements(pq);
167-
// for(int i=0;i<readyqueue.readyQueueSize;i++) {
168-
// void* e = readyqueue.readyQueue[i];
169-
// printf("Popped: value=%s %d %d %d\n", ((Process *)e)->processName, ((Process *)e)->arrivalTime, ((Process *)e)->runTime, ((Process *)e)->priority);
170-
// // printf("Popped: value=%d\n", *((int*)e));
171-
// }
172-
// printf("\n");
173-
// while(pq->size) {
174-
// void* e = pop(pq); // pop element from the priority_queue
175-
// printf("Popped: value=%s %d %d %d\n", ((Process *)e)->processName, ((Process *)e)->arrivalTime, ((Process *)e)->runTime, ((Process *)e)->priority);
176-
// // printf("Popped: value=%d\n", *((int*)e));
177-
// free(e); // don't forget to free the popped element
178-
// }
179-
180-
// free_priority_queue(pq); // free the priority_queue
181-
// free_created_array_from_pq(readyqueue); // free the created array from pq
182-
// return 0;
183-
// }
137+
}

‎src/includes/data_structures/queue.h

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include "../utils/process.h"
33

44

5-
//------------ Define structures
65
typedef struct Node {
76
Process data;
87
struct Node* next;
@@ -25,12 +24,10 @@ int size_q(Queue* queue);
2524
char** create_array_from_queue(Queue* queue, int size);
2625
void free_queue(Queue* q);
2726

28-
//------------ Check if the queue is empty or not
2927
int is_empty_q(Queue* queue){
3028
return (queue->front == NULL);
3129
}
3230

33-
//------------ Initialize an empty queue
3431
Queue* create_queue(){
3532

3633
Queue* queue = (Queue*)malloc(sizeof(Queue));
@@ -43,7 +40,6 @@ Queue* create_queue(){
4340
return queue;
4441
}
4542
}
46-
//------------ Create a node for the queue
4743
Node* create_node(Process process){
4844
Node* new_node = (Node*)malloc(sizeof(Node));
4945
if(!new_node){
@@ -56,7 +52,6 @@ Node* create_node(Process process){
5652
return new_node;
5753
}
5854
}
59-
//------------ Add an element to the queue
6055
void enqueue(Queue* queue, Process process) {
6156
Node* new_node = create_node(process);
6257
if(is_empty_q(queue)){
@@ -69,7 +64,6 @@ void enqueue(Queue* queue, Process process) {
6964
}
7065
}
7166

72-
//------------ Remove an element from the queue and return its data ( whish is a process)
7367
Process dequeue(Queue* queue) {
7468
if(is_empty_q(queue)){
7569
printf("[ERROR] : Queue is already empty\n");
@@ -84,14 +78,12 @@ Process dequeue(Queue* queue) {
8478
}
8579
};
8680

87-
// Function to swap two processes
8881
void swap_q( Process* a, Process* b){
8982
Process temp = *a;
9083
*a = *b;
9184
*b = temp;
9285
}
9386

94-
//------------- Sort the array by Arrival time
9587
void sort_by_arrival_time(Process* processes, int numProcesses){
9688
for (int i = 0; i < numProcesses - 1; i++) {
9789
for (int j = 0; j < numProcesses - i - 1; j++){
@@ -102,7 +94,6 @@ void sort_by_arrival_time(Process* processes, int numProcesses){
10294
}
10395
}
10496

105-
//------------ Create a queue from an array
10697
Queue* create_queue_from_array( Process* processes,int numProcesses){
10798
Process* copy_from_processes = (Process*)malloc(numProcesses * sizeof(Process));
10899
memcpy(copy_from_processes, processes, numProcesses * sizeof(Process));
@@ -141,34 +132,4 @@ void free_queue(Queue* q) {
141132
dequeue(q);
142133
}
143134
free(q);
144-
}
145-
// An example where we define a static table of processes and then we create a queue from it. We add( enqueue)
146-
// another process and then we dequeue them all while reading the processes names
147-
// #include<stdio.h>
148-
// #include<stdlib.h>
149-
// #include "./queue.h"
150-
// int main(void){
151-
// Process processes[] = {
152-
// {"Process1", 2, 10, 1},
153-
// {"Process2", 5, 8, 2},
154-
// {"Process3", 1, 15, 3},
155-
// {"Process4", 10, 15, 3},
156-
// {"Process5", 7, 5, 13},
157-
// {"Process6", 5, 4, 3},
158-
// {"Process7", 3, 7, 2},
159-
// {"Process8", 9, 4, 3},
160-
// };
161-
// Queue* q = create_queue_from_array(processes,8);
162-
// enqueue(q,(Process){"Process9",14, 4, 3});
163-
// char**t = create_array_from_queue(q,size_q(q));
164-
// for(int i=0;i<size_q(q);i++){
165-
// printf(t[i]);
166-
// }
167-
// while(!is_empty_q(q)){
168-
// Process p = dequeue(q);
169-
// printf("%s arrives at %d \n",p.processName , p.arrivalTime);
170-
// }
171-
// return 0;
172-
// }
173-
174-
135+
}

‎src/includes/utils/ProcessesTable.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
#include <string.h>
55
#include "../utils/process.h"
66

7-
// This C program will be :
8-
// 1- parsing the processes file
9-
// 2- Generate a static table of a convenient format of the Process details
107

118
struct processesTable {
129
int processesNumber;
@@ -20,12 +17,10 @@ Process* getTableOfProcesses(const char* file_path);
2017
void freeProcesses();
2118

2219
int getNbProcesses(const char* file_path) {
23-
// if(processesTable.processesNumber != -1) return processesTable.processesNumber;
2420
FILE *fPointer= fopen(file_path,"r");
2521
char content[255];
2622

2723
if (fPointer != NULL ) {
28-
//Getting the number of processes
2924
fgets(content,255,fPointer);
3025
return processesTable.processesNumber = atoi(content);
3126
}
@@ -37,17 +32,14 @@ int getNbProcesses(const char* file_path) {
3732
}
3833

3934

40-
//The function that tokenizes a string and return a Process struct.
4135
Process tokenize (char ch[255],char del[]) {
4236
Process result;
4337
ch[strcspn(ch, "\n")] = '\0';
4438

4539
char *token;
4640

47-
//an integer to determine which Process Attribute we are parsing;
4841
int nb=1;
4942

50-
// Tokenize the string using strtok
5143
token = strtok(ch, del);
5244

5345
while (token != NULL) {
@@ -72,28 +64,21 @@ Process tokenize (char ch[255],char del[]) {
7264

7365

7466
Process *getTableOfProcesses(const char* file_path) {
75-
// if(processesTable.processes != NULL) return processesTable.processes;
76-
77-
//Choosing the seperator character
7867
char sep[] = ";";
7968

80-
//The size of the processes table
8169
int sizeTable;
8270
int i=0;
8371

8472
FILE *fPointer= fopen(file_path,"r");
8573
char content[255];
8674

8775
if (fPointer != NULL ) {
88-
//Getting the number of processes
8976
fgets(content,255,fPointer);
9077
sizeTable = atoi(content);
9178
Process* processes = (Process*)malloc(sizeTable * sizeof(Process));
92-
//printf("Size of the table is : %d \n",sizeTable);
9379

9480
while(!feof(fPointer) && i < sizeTable){
9581
fgets(content,255,fPointer);
96-
// tokenize(content, sep, &processes[i]);
9782
processes[i]=tokenize(content,sep);
9883
i++;
9984
}

0 commit comments

Comments
 (0)
Please sign in to comment.