mirror of
https://github.com/bspeice/itcs3146-project
synced 2024-12-22 14:48:21 -05:00
-Added code to allocate best fit and worst fit
This commit is contained in:
parent
0928f69c77
commit
f0213a37a4
@ -19,8 +19,8 @@ public class BestFitAlgorithm implements baseAlgorithm{
|
|||||||
|
|
||||||
public int getBestSizeIndex(int jobSize)
|
public int getBestSizeIndex(int jobSize)
|
||||||
{
|
{
|
||||||
int bestSize = 0;
|
int bestSize;
|
||||||
int bestSizeIndex = 0;
|
int bestSizeIndex;
|
||||||
|
|
||||||
ArrayList<Integer> candidates = new ArrayList<Integer>(); //Dynamically resizable array list for allocation candidates (interleaved with index and memory size)
|
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);
|
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
|
//Try compacting, then attempt to get an index again
|
||||||
compact();
|
compact();
|
||||||
@ -95,11 +96,13 @@ public class BestFitAlgorithm implements baseAlgorithm{
|
|||||||
//TODO .....
|
//TODO .....
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
//Allocate the memory
|
|
||||||
for(int i = bestSizeIndex; i < jobSize; i++)
|
|
||||||
{
|
{
|
||||||
memoryBlock[i] = jobID;
|
//Allocate the memory
|
||||||
|
for(int i = bestSizeIndex; i < jobSize; i++)
|
||||||
|
{
|
||||||
|
memoryBlock[i] = jobID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,8 @@ public class memoryManagement{
|
|||||||
threadedAllocation Bradlee_Speice = new threadedAllocation(MEMORYSIZE);
|
threadedAllocation Bradlee_Speice = new threadedAllocation(MEMORYSIZE);
|
||||||
//FirstFit David01 = new FirstFit();
|
//FirstFit David01 = new FirstFit();
|
||||||
//NextFit David02 = new NextFit();
|
//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
|
//Gets a file name, else creates five random jobs
|
||||||
do{
|
do{
|
||||||
@ -82,8 +84,26 @@ public class memoryManagement{
|
|||||||
System.out.println("complete");
|
System.out.println("complete");
|
||||||
System.out.println("Elapsed time for threaded allocation algorithm to complete " + jobLength +
|
System.out.println("Elapsed time for threaded allocation algorithm to complete " + jobLength +
|
||||||
" jobs is " + timeEnd + " milliseconds");
|
" 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");
|
System.out.println("Completed Successfully");
|
||||||
//Forcibly close down all threads
|
//Forcibly close down all threads
|
||||||
|
Loading…
Reference in New Issue
Block a user