Actuall fix David's code

This commit is contained in:
Bradlee Speice 2012-11-27 18:04:07 -05:00
parent db95b35afe
commit 365e071558
3 changed files with 24 additions and 13 deletions

View File

@ -66,6 +66,7 @@ public class BestFitAlgorithm implements baseAlgorithm{
}
int bSize = 1;
int bestIndex = -1;
if(!blocks.isEmpty())
{
bSize = blocks.get(0).intValue();
@ -121,8 +122,8 @@ public class BestFitAlgorithm implements baseAlgorithm{
if(bestSizeIndex != -1)
{
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)
{
@ -135,7 +136,7 @@ public class BestFitAlgorithm implements baseAlgorithm{
//System.out.println("Successfully allocated! Starting job...");
System.out.println("Job time: " + jobTime);
//System.out.println("Job time: " + jobTime);
Job newJob = new Job(jobTime, jobID, jobSize, bestSizeIndex, deallocateMethod, this);

View File

@ -74,16 +74,16 @@ public class WorstFitAlgorithm implements baseAlgorithm{
wSize = blocks.get(0).intValue();
}
//GET WORST INDEX
for(int i = 0; i < blocks.size(); i++)
{
//Get largest possible free block to allocate to
if((blocks.get(i).intValue() >= wSize && blocks.get(i).intValue() >= jobSize) || blocks.get(i).intValue() > -1)
if(blocks.get(i).intValue() >= wSize || blocks.get(i).intValue() > -1)
{
worstIndex = indices.get(i).intValue();
}
//"Worst fit"....same size as job size
else if(blocks.get(i).intValue() == jobSize)
{
@ -91,6 +91,13 @@ public class WorstFitAlgorithm implements baseAlgorithm{
//System.out.println("Worst Case");
worstIndex = indices.get(i).intValue();
}
else
{
if(!blocks.isEmpty())
{
worstIndex = indices.get(i).intValue();
}
}
}
//System.out.println("bestIndex: " + bestIndex);
@ -118,15 +125,16 @@ public class WorstFitAlgorithm implements baseAlgorithm{
while(worstSizeIndex == -1)
{
//Compact and try again
//System.out.println("Compacting memory...");
System.out.println("Compacting memory...");
this.compact();
worstSizeIndex = this.getWorstIndex(jobSize);
}
}
else
if(worstSizeIndex != -1)
{
System.out.println("Phew");
//System.out.println("The size of the job is: " + jobSize);
//System.out.println("The best size index is: " + bestSizeIndex);
//System.out.println("The worst size index is: " + worstSizeIndex);
synchronized(memoryBlock)
{
for(int i = worstSizeIndex; i < jobSize + worstSizeIndex; i++)
@ -137,10 +145,10 @@ public class WorstFitAlgorithm implements baseAlgorithm{
}
//System.out.println("Successfully allocated! Starting job...");
Job newJob = new Job(jobSize, jobID, jobSize, worstSizeIndex, deallocateMethod, this);
Job newJob = new Job(jobTime, jobID, jobSize, worstSizeIndex, deallocateMethod, this);
System.out.println("Job started!");
jobArray[jobID] = newJob;
System.out.println("The size of the job array is: " + jobArray.length);
newJob.start();
//System.out.println("Job started!");
@ -148,7 +156,8 @@ public class WorstFitAlgorithm implements baseAlgorithm{
}
catch (Exception e)
{
//System.out.println("Could not allocate job with ID " + jobID);
e.printStackTrace();
System.exit(-1);
}
}
/*

View File

@ -42,6 +42,7 @@ public class memoryManagement{
do{
System.out.println("Type filename to load jobs from a file or just press enter for random jobs");
read = keyboard.nextLine();
read = read.trim();
file = new File(read + ".txt");
if(!read.equals("") && !file.exists())
System.out.println("File not found, try again");