which algo is much memory efficient and has better performance in traffic control system RMS or EDF?

So guys I want to get your opinion on this. I want to implement a task scheduling algorithm to control a traffic light system with three colors: red, yellow, and green. We can use two different algorithms: Algorithm 1: Rate Monotonic Scheduling (RMS)
#include <stdio.h>

#define RED_LIGHT 0
#define YELLOW_LIGHT 1
#define GREEN_LIGHT 2

void task_red_light(int period) {
printf("Red light ON\n");
}

void task_yellow_light(int period) {
printf("Yellow light ON\n");
}

void task_green_light(int period) {
printf("Green light ON\n");
}

void task_scheduler_rms() {
// Schedule tasks based on priority and period
task_red_light(10);
//high priority 10ms, period
task_yellow_light(5);
//medium priority, 5ms period
task_green_light(15);
// low priority, 15ms period
}

int main() {
task_scheduler_rms();
return 0;
}
#include <stdio.h>

#define RED_LIGHT 0
#define YELLOW_LIGHT 1
#define GREEN_LIGHT 2

void task_red_light(int period) {
printf("Red light ON\n");
}

void task_yellow_light(int period) {
printf("Yellow light ON\n");
}

void task_green_light(int period) {
printf("Green light ON\n");
}

void task_scheduler_rms() {
// Schedule tasks based on priority and period
task_red_light(10);
//high priority 10ms, period
task_yellow_light(5);
//medium priority, 5ms period
task_green_light(15);
// low priority, 15ms period
}

int main() {
task_scheduler_rms();
return 0;
}
Algorithm 2: Earliest Deadline First (EDF) Algorithm
#include <stdio.h>

#define RED_LIGHT 0
#define YELLOW_LIGHT 1
#define GREEN_LIGHT 2

void task_red_light_edf(int deadline) {
printf("Red light ON\n");
}

void task_yellow_light_edf(int deadline) {
printf("Yellow light ON\n");
}

void task_green_light_edf(int deadline) {
printf("Green light ON\n");
}

void task_scheduler_edf() {
// Schedule tasks based on deadline and priority
task_red_light_edf(10);
//deadline 10ms, high priority
task_yellow_light_edf(5);
//deadline 5ms, medium priority
task_green_light_edf(15);
// deadline 15ms, low priority
}

int main() {
task_scheduler_edf();
return 0;
}
#include <stdio.h>

#define RED_LIGHT 0
#define YELLOW_LIGHT 1
#define GREEN_LIGHT 2

void task_red_light_edf(int deadline) {
printf("Red light ON\n");
}

void task_yellow_light_edf(int deadline) {
printf("Yellow light ON\n");
}

void task_green_light_edf(int deadline) {
printf("Green light ON\n");
}

void task_scheduler_edf() {
// Schedule tasks based on deadline and priority
task_red_light_edf(10);
//deadline 10ms, high priority
task_yellow_light_edf(5);
//deadline 5ms, medium priority
task_green_light_edf(15);
// deadline 15ms, low priority
}

int main() {
task_scheduler_edf();
return 0;
}
Both algorithm achieves the Same goal but with different approaches. I know I am just printing strings to console , but in a real life scenario which is much memory efficient and has better performance in a traffic control system? RMS or EDF? @Middleware & OS
2 Replies
Enthernet Code
Enthernet Code8mo ago
@Marvee Amasi For a traffic light system, Earliest Deadline First is actually a better choice than Rate Monotonic Scheduling. Let me tell you why: 1) Traffic light timing is more deadline-driven: - In traffic lights, ensuring smooth traffic flow relies on lights turning green at specific times (deadlines) to avoid congestion. - EDF prioritizes tasks with the earliest deadlines, aligning better with this need. 2) RMS prioritizes shorter periods, which might not be ideal: - RMS prioritizes tasks with shorter periods (execution times) like the yellow light. - In traffic control, prioritizing a longer green light (allowing more traffic flow) might be more important than a short yellow light. Well although know that -EDF requires calculating deadlines for each light cycle, which might be more complex to implement. In Here's a real-world scenario to consider: Imagine rush hour traffic. With EDF, the green light has an earlier deadline to ensure smooth flow. If a sensor detects heavy traffic, the deadline for the green light can be adjusted dynamically in EDF, allowing it to stay on longer. This flexibility might be beneficial in a way
Marvee Amasi
Marvee Amasi8mo ago
Thanks @Enthernet Code , so EDF would be much effective for my project .
Want results from more Discord servers?
Add your server