Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "HRRN.h"
- static queue_object* HRRN_queue;
- //You can add more global variables and structs here
- int current_time; //die zeit die bisher vergangen ist
- float get_ratio(queue_object* queue){ // ratio = (wartezeit + bedienzeit) / bedienzeit ; bedienzeit = time_left ; wartezeit = current_time - start_time
- process* current_process = queue->object;
- int start_time = current_process->start_time;
- int left_time = current_process->time_left;
- int wait_time = current_time - start_time;
- float rr = (wait_time + left_time)/left_time;
- return rr;
- }
- void* queue_poll_hrr(queue_object* queue){
- void* obj;
- float max_rr = 0.0;
- queue_object* prev_el = queue;
- queue_object* current_el = queue->next;
- queue_object* prev_old; //das element vor dem zu loeschenden element
- queue_object* old; //das zu loeschende element
- if(current_el == NULL){//wenn queue leer
- return NULL;
- }
- if(current_el->next == NULL){ //queue besitzt nur ein element
- return queue_poll(HRRN_queue);
- }
- else{
- while (current_el!=NULL){
- float current_ratio = get_ratio(current_el);
- if (current_ratio >= max_rr){
- max_rr = current_ratio;
- prev_old = prev_el;
- old = current_el;
- }
- prev_el=prev_el->next;
- current_el=current_el->next;
- }
- obj = old->object;
- prev_old->next = old->next;
- free(old);
- return obj;
- }
- }
- process* HRRN_tick (process* running_process){
- current_time++;
- if (running_process == NULL || running_process->time_left == 0){
- running_process = queue_poll_hrr(HRRN_queue);
- }
- if (running_process!=NULL){
- running_process->time_left--;//eine Zeiteinheit vergangen - andere waerendessen warten
- }
- return running_process;
- }
- int HRRN_startup(){
- current_time = -1;
- HRRN_queue=new_queue();
- if (HRRN_queue==NULL){
- return 1;
- }
- return 0;
- }
- process* HRRN_new_arrival(process* arriving_process, process* running_process){
- if(arriving_process!=NULL){
- queue_add(arriving_process, HRRN_queue);
- }
- return running_process;
- }
- void HRRN_finish(){
- free_queue(HRRN_queue);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement