diff --git a/BestFitAlgorithm.java b/BestFitAlgorithm.java index 53a9eec..945785f 100644 --- a/BestFitAlgorithm.java +++ b/BestFitAlgorithm.java @@ -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 candidates = new ArrayList(); //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; + } } } diff --git a/memoryManagement.java b/memoryManagement.java index e7f28f8..0f6db30 100644 --- a/memoryManagement.java +++ b/memoryManagement.java @@ -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,9 +84,27 @@ public class memoryManagement{ System.out.println("complete"); System.out.println("Elapsed time for threaded allocation algorithm to complete " + jobLength + " jobs is " + timeEnd + " milliseconds"); - - //Put other algorithms here. - + //***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. + + System.out.println("Completed Successfully"); //Forcibly close down all threads System.exit(0);