Fixes for David Weber's code

This commit is contained in:
Bradlee Speice 2012-11-27 17:36:40 -05:00
parent fa6606f754
commit db95b35afe
2 changed files with 38 additions and 20 deletions

View File

@ -64,10 +64,12 @@ public class BestFitAlgorithm implements baseAlgorithm{
//System.out.println("Index: " + indices.get(i));
//System.out.println("Size: " + blocks.get(i));
}
int bSize = 1;
int bestIndex = -1;
int bSize = blocks.get(0).intValue();
if(!blocks.isEmpty())
{
bSize = blocks.get(0).intValue();
}
//GET BEST INDEX
for(int i = 0; i < blocks.size(); i++)
@ -100,22 +102,27 @@ public class BestFitAlgorithm implements baseAlgorithm{
bestSizeIndex = this.getBestIndex(jobSize);
if(bestSizeIndex == -1)
{
while(bestSizeIndex == -1)
{
//Compact and try again
//System.out.println("Compacting memory...");
this.compact();
bestSizeIndex = this.getBestIndex(jobSize);
}
}
if(jobSize > memoryBlock.length)
{
//System.out.println("Job is too large for current memory size");
}
if(bestSizeIndex == -1)
if(bestSizeIndex != -1)
{
//Compact and try again
//System.out.println("Compacting memory...");
this.compact();
bestSizeIndex = this.getBestIndex(jobSize);
}
else
{
//System.out.println("The size of the job is: " + jobSize);
//System.out.println("The best size index is: " + bestSizeIndex);
System.out.println("The size of the job is: " + jobSize);
System.out.println("The best size index is: " + bestSizeIndex);
synchronized(memoryBlock)
{
@ -128,7 +135,9 @@ public class BestFitAlgorithm implements baseAlgorithm{
//System.out.println("Successfully allocated! Starting job...");
Job newJob = new Job(jobSize, jobID, jobSize, bestSizeIndex, deallocateMethod, this);
System.out.println("Job time: " + jobTime);
Job newJob = new Job(jobTime, jobID, jobSize, bestSizeIndex, deallocateMethod, this);
jobArray[jobID] = newJob;
@ -139,7 +148,8 @@ public class BestFitAlgorithm implements baseAlgorithm{
}
catch (Exception e)
{
//System.out.println("Could not allocate job with ID " + jobID);
e.printStackTrace();
System.exit(-1);
}
}
/*

View File

@ -67,7 +67,12 @@ public class WorstFitAlgorithm implements baseAlgorithm{
}
int worstIndex = -1;
int wSize = blocks.get(0).intValue();
int wSize = -1;
if(!blocks.isEmpty())
{
wSize = blocks.get(0).intValue();
}
//GET WORST INDEX
@ -110,10 +115,13 @@ public class WorstFitAlgorithm implements baseAlgorithm{
if(worstSizeIndex == -1)
{
//Compact and try again
//System.out.println("Compacting memory...");
this.compact();
worstSizeIndex = this.getWorstIndex(jobSize);
while(worstSizeIndex == -1)
{
//Compact and try again
//System.out.println("Compacting memory...");
this.compact();
worstSizeIndex = this.getWorstIndex(jobSize);
}
}
else
{