Begin LTR

This commit is contained in:
Zach S-B 2021-08-25 22:05:23 +10:00
parent 0f36bb2440
commit dfd34ddb2c

View File

@ -3,11 +3,11 @@ import java.io.*;
public class Scheduler {
//Address of File name relative to code. Replace with request for filename?
String fileName = "datafiles/datafile2.txt";
String fileName = "datafiles/datafile1.txt";
LinkedList<Process> processList = new LinkedList<Process>();
LinkedList<Integer> randomNum = new LinkedList<>();
int randomNumConsumed = -1; //Counter to track which "random numbers" have been used thus far.
//Initialise Dispatcher time variable
int disp;
@ -49,6 +49,34 @@ public class Scheduler {
}
System.out.println("End Random.");
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
algorithmLTR();
}
/**
@ -155,4 +183,95 @@ public class Scheduler {
//e.printStackTrace(); //Optional, shows more data.
}
}
public void algorithmFCFS()
{
}
public void algorithmSRT()
{
}
public void algorithmFBV()
{
}
public void algorithmLTR()
{
// counter: used to track if weve found the winner yet
int counter = 0;
int totalTickets = 0;
int winner = -1;
//count the total number of tickets in play
for (int i = 0; i < processList.size() ; i++)
{
totalTickets += processList.get(i).getTickets();
}
// winner: use some call to a random number generator to
// get a value, between 0 and the total # of tickets
int winnerValue = returnRandomNum(totalTickets);
for (int i = 0; i < processList.size(); i++)
{
counter = processList.get(i).getTickets();
if(counter > winnerValue)
{
winner = i;
break;
}
}
if(winner == -1)
{
System.out.println("No winner");
}
else
{
System.out.println("Winner: " + processList.get(winner).getId());
}
// current: use this to walk through the list of jobs
//node_t *current = head;
/*
while (current)
{
counter = counter + current->tickets;
if (counter > winner)
{
break; // found the winner
}
current = current->next;
// 'current' is the winner: schedule it...
}
*/
}
public int returnRandomNum(int totalTickets)
{
int randomValue = 0;
//Loop back to begining. Probably could remove each consumed random number from the linked list.... but I don't want to right now.
if((randomNumConsumed+1) >= randomNum.size())
{
randomNumConsumed = 0;
}
else
{
randomNumConsumed += 1;
}
randomValue = randomNum.get(randomNumConsumed) % totalTickets;
return randomValue;
}
}