-Added code to allocate best fit and worst fit

This commit is contained in:
David Weber 2012-11-17 02:24:16 -05:00
parent 0928f69c77
commit f0213a37a4
2 changed files with 33 additions and 10 deletions

View File

@ -19,8 +19,8 @@ public class BestFitAlgorithm implements baseAlgorithm{
public int getBestSizeIndex(int jobSize)
{
int bestSize = 0;
int bestSizeIndex = 0;
int bestSize;
int bestSizeIndex;
ArrayList<Integer> candidates = new ArrayList<Integer>(); //Dynamically resizable array list for allocation candidates (interleaved with index and memory size)
@ -83,7 +83,8 @@ public class BestFitAlgorithm implements baseAlgorithm{
{
int bestSizeIndex = getBestSizeIndex(jobSize);
if(bestSizeIndex == -1) //No candidates found
//No candidates found
if(bestSizeIndex == -1)
{
//Try compacting, then attempt to get an index again
compact();
@ -95,11 +96,13 @@ public class BestFitAlgorithm implements baseAlgorithm{
//TODO .....
}
}
//Allocate the memory
for(int i = bestSizeIndex; i < jobSize; i++)
else
{
memoryBlock[i] = jobID;
//Allocate the memory
for(int i = bestSizeIndex; i < jobSize; i++)
{
memoryBlock[i] = jobID;
}
}
}

View File

@ -34,6 +34,8 @@ public class memoryManagement{
threadedAllocation Bradlee_Speice = new threadedAllocation(MEMORYSIZE);
//FirstFit David01 = new FirstFit();
//NextFit David02 = new NextFit();
BestFitAlgorithm David_Weber_BestFit = new BestFitAlgorithm(MEMORYSIZE);
WorstFitAlgorithm David_Weber_WorstFit = new WorstFitAlgorithm(MEMORYSIZE);
//Gets a file name, else creates five random jobs
do{
@ -82,8 +84,26 @@ public class memoryManagement{
System.out.println("complete");
System.out.println("Elapsed time for threaded allocation algorithm to complete " + jobLength +
" jobs is " + timeEnd + " milliseconds");
//***Best Fit (David Weber)***
timeStart = System.currentTimeMillis();
for(int i = 0; i < jobLength - 1; i++){
//David_Weber_BestFit.allocate(id[i], size[i], time[i]);
}
timeEnd = System.currentTimeMillis() - timeStart;
System.out.println("complete");
System.out.println("Elapsed time for threaded best fit allocation algorithm to complete " + jobLength + " jobs is " + timeEnd + " milliseconds");
//***Worst Fit (David Weber)***
timeStart = System.currentTimeMillis();
for(int i = 0; i < jobLength - 1; i++){
//David_Weber_WorstFit.allocate(id[i], size[i], time[i]);
}
timeEnd = System.currentTimeMillis() - timeStart;
System.out.println("complete");
System.out.println("Elapsed time for threaded worst fit allocation algorithm to complete " + jobLength + " jobs is " + timeEnd + " milliseconds");
//Put other algorithms here.
//Put other algorithms here.
System.out.println("Completed Successfully");
//Forcibly close down all threads