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("Index: " + indices.get(i));
//System.out.println("Size: " + blocks.get(i)); //System.out.println("Size: " + blocks.get(i));
} }
int bSize = 1;
int bestIndex = -1; int bestIndex = -1;
int bSize = blocks.get(0).intValue(); if(!blocks.isEmpty())
{
bSize = blocks.get(0).intValue();
}
//GET BEST INDEX //GET BEST INDEX
for(int i = 0; i < blocks.size(); i++) for(int i = 0; i < blocks.size(); i++)
@ -100,22 +102,27 @@ public class BestFitAlgorithm implements baseAlgorithm{
bestSizeIndex = this.getBestIndex(jobSize); 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)
{
while(bestSizeIndex == -1)
{ {
//Compact and try again //Compact and try again
//System.out.println("Compacting memory..."); //System.out.println("Compacting memory...");
this.compact(); this.compact();
bestSizeIndex = this.getBestIndex(jobSize); bestSizeIndex = this.getBestIndex(jobSize);
} }
else }
if(jobSize > memoryBlock.length)
{ {
//System.out.println("The size of the job is: " + jobSize); //System.out.println("Job is too large for current memory size");
//System.out.println("The best size index is: " + bestSizeIndex); }
if(bestSizeIndex != -1)
{
System.out.println("The size of the job is: " + jobSize);
System.out.println("The best size index is: " + bestSizeIndex);
synchronized(memoryBlock) synchronized(memoryBlock)
{ {
@ -128,7 +135,9 @@ public class BestFitAlgorithm implements baseAlgorithm{
//System.out.println("Successfully allocated! Starting job..."); //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; jobArray[jobID] = newJob;
@ -139,7 +148,8 @@ public class BestFitAlgorithm implements baseAlgorithm{
} }
catch (Exception e) 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 worstIndex = -1;
int wSize = blocks.get(0).intValue(); int wSize = -1;
if(!blocks.isEmpty())
{
wSize = blocks.get(0).intValue();
}
//GET WORST INDEX //GET WORST INDEX
@ -109,12 +114,15 @@ public class WorstFitAlgorithm implements baseAlgorithm{
} }
if(worstSizeIndex == -1) if(worstSizeIndex == -1)
{
while(worstSizeIndex == -1)
{ {
//Compact and try again //Compact and try again
//System.out.println("Compacting memory..."); //System.out.println("Compacting memory...");
this.compact(); this.compact();
worstSizeIndex = this.getWorstIndex(jobSize); worstSizeIndex = this.getWorstIndex(jobSize);
} }
}
else else
{ {
//System.out.println("The size of the job is: " + jobSize); //System.out.println("The size of the job is: " + jobSize);