Revert "Added braces to loops in main class"

This reverts commit 74a3b51404.
This commit is contained in:
Michael 2012-11-27 16:31:41 -05:00
parent 74a3b51404
commit fa6606f754
3 changed files with 37 additions and 56 deletions

View File

@ -56,21 +56,18 @@ public class BestFitAlgorithm implements baseAlgorithm{
} }
} }
} }
System.out.println("Size of indices array: " + indices.size()); //System.out.println("Size of indices array: " + indices.size());
System.out.println("Size of sizes array: " + blocks.size()); //System.out.println("Size of sizes array: " + blocks.size());
for(int i = 0; i < blocks.size(); i++) for(int i = 0; i < blocks.size(); i++)
{ {
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;
if(!blocks.isEmpty()) int bSize = blocks.get(0).intValue();
{
bestIndex = indices.get(0).intValue();
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++)
@ -81,17 +78,16 @@ public class BestFitAlgorithm implements baseAlgorithm{
//Best possible fit. You're done. //Best possible fit. You're done.
//System.out.println("Best Case"); //System.out.println("Best Case");
bestIndex = indices.get(i).intValue(); bestIndex = indices.get(i).intValue();
return bestIndex;
} }
else if((blocks.get(i).intValue() <= bSize && blocks.get(i).intValue() >= jobSize) || blocks.get(i).intValue() > -1) else if((blocks.get(i).intValue() <= bSize && blocks.get(i).intValue() >= jobSize) || blocks.get(i).intValue() > -1)
{ {
bestIndex = indices.get(i).intValue(); bestIndex = indices.get(i).intValue();
return bestIndex;
} }
} }
//System.out.println("bestIndex: " + bestIndex); //System.out.println("bestIndex: " + bestIndex);
//System.out.println("bSize: " + bSize); //System.out.println("bSize: " + bSize);
return bestIndex; return bestIndex;
} }
@ -112,7 +108,7 @@ public class BestFitAlgorithm implements baseAlgorithm{
if(bestSizeIndex == -1) if(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);
} }
@ -125,12 +121,12 @@ public class BestFitAlgorithm implements baseAlgorithm{
{ {
for(int i = bestSizeIndex; i < jobSize + bestSizeIndex; i++) for(int i = bestSizeIndex; i < jobSize + bestSizeIndex; i++)
{ {
System.out.println("Writing jobID: " + jobID + " to position " + i + " in memory block that has a pre-existing value of: " + this.memoryBlock[i]); //System.out.println("Writing jobID: " + jobID + " to position " + i + " in memory block!");
this.memoryBlock[i] = jobID; this.memoryBlock[i] = jobID;
} }
} }
System.out.println("Successfully allocated! Starting job..."); //System.out.println("Successfully allocated! Starting job...");
Job newJob = new Job(jobSize, jobID, jobSize, bestSizeIndex, deallocateMethod, this); Job newJob = new Job(jobSize, jobID, jobSize, bestSizeIndex, deallocateMethod, this);
@ -138,14 +134,12 @@ public class BestFitAlgorithm implements baseAlgorithm{
newJob.start(); newJob.start();
System.out.println("Job started!"); //System.out.println("Job started!");
} }
} }
catch (Exception e) catch (Exception e)
{ {
System.out.println("Oops"); //System.out.println("Could not allocate job with ID " + jobID);
e.printStackTrace();
System.exit(-1);
} }
} }
/* /*
@ -197,10 +191,9 @@ public class BestFitAlgorithm implements baseAlgorithm{
{ {
synchronized(memoryBlock) synchronized(memoryBlock)
{ {
for (int x = 0; x < jobSize; x++) for(int i = beginningLocation; i < jobSize + beginningLocation; i++)
{ {
System.out.println("Deallocating job at: " + "Location: " + beginningLocation + " Position: " + x); memoryBlock[i] = 0;
memoryBlock[beginningLocation + x] = 0;
} }
} }
} }

View File

@ -140,8 +140,7 @@ public class WorstFitAlgorithm implements baseAlgorithm{
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(); //System.out.println("Could not allocate job with ID " + jobID);
System.exit(-1);
} }
} }
/* /*
@ -191,9 +190,9 @@ public class WorstFitAlgorithm implements baseAlgorithm{
{ {
synchronized(memoryBlock) synchronized(memoryBlock)
{ {
for (int x = 0; x < jobSize; x++) for(int i = beginningLocation; i < jobSize + beginningLocation; i++)
{ {
memoryBlock[beginningLocation + x] = 0; memoryBlock[i] = 0;
} }
} }
} }

View File

@ -44,9 +44,7 @@ public class memoryManagement{
read = keyboard.nextLine(); read = keyboard.nextLine();
file = new File(read + ".txt"); file = new File(read + ".txt");
if(!read.equals("") && !file.exists()) if(!read.equals("") && !file.exists())
{
System.out.println("File not found, try again"); System.out.println("File not found, try again");
}
}while(!read.equals("") && !file.exists()); }while(!read.equals("") && !file.exists());
//Create random jobs or read from the file and create jobs //Create random jobs or read from the file and create jobs
@ -77,23 +75,19 @@ public class memoryManagement{
//Send jobs to algorithm, time is calculated and printed out after completion //Send jobs to algorithm, time is calculated and printed out after completion
//Note that we use `jobLength - 1` to compensate for the id above //Note that we use `jobLength - 1` to compensate for the id above
//Threaded Fit //Threaded Fit
System.out.print("Sending jobs to threaded allocation algorithm..."); System.out.print("Sending jobs to threaded allocation algorithm...");
timeStart[0] = System.currentTimeMillis(); timeStart[0] = System.currentTimeMillis();
for(int i = 0; i < jobLength - 1; i++) { for(int i = 0; i < jobLength - 1; i++)
threadedFit.allocate(id[i], size[i], time[i]); threadedFit.allocate(id[i], size[i], time[i]);
}
timeEnd[0] = System.currentTimeMillis() - timeStart[0]; timeEnd[0] = System.currentTimeMillis() - timeStart[0];
System.out.println("complete"); System.out.println("complete");
System.out.println("Elapsed time for threaded allocation algorithm to complete " + jobLength + " jobs is " + timeEnd[0] + " milliseconds"); System.out.println("Elapsed time for threaded allocation algorithm to complete " + jobLength + " jobs is " + timeEnd[0] + " milliseconds");
//Best Fit //Best Fit
System.out.print("Sending jobs to best fit allocation algorithm...\n"); System.out.print("Sending jobs to best fit allocation algorithm...");
timeStart[1] = System.currentTimeMillis(); timeStart[1] = System.currentTimeMillis();
for(int i = 0; i < jobLength - 1; i++) { for(int i = 0; i < jobLength - 1; i++)
System.out.println("**********NEXT ITERATION***********");
bestFit.allocate(id[i], size[i], time[i]); bestFit.allocate(id[i], size[i], time[i]);
}
timeEnd[1] = System.currentTimeMillis() - timeStart[1]; timeEnd[1] = System.currentTimeMillis() - timeStart[1];
System.out.println("complete"); System.out.println("complete");
System.out.println("Elapsed time for best fit allocation algorithm to complete " + jobLength + " jobs is " + timeEnd[1] + " milliseconds"); System.out.println("Elapsed time for best fit allocation algorithm to complete " + jobLength + " jobs is " + timeEnd[1] + " milliseconds");
@ -101,9 +95,8 @@ public class memoryManagement{
//Worst Fit //Worst Fit
System.out.print("Sending jobs to worst fit allocation algorithm..."); System.out.print("Sending jobs to worst fit allocation algorithm...");
timeStart[2] = System.currentTimeMillis(); timeStart[2] = System.currentTimeMillis();
for(int i = 0; i < jobLength - 1; i++) { for(int i = 0; i < jobLength - 1; i++)
worstFit.allocate(id[i], size[i], time[i]); worstFit.allocate(id[i], size[i], time[i]);
}
timeEnd[2] = System.currentTimeMillis() - timeStart[2]; timeEnd[2] = System.currentTimeMillis() - timeStart[2];
System.out.println("complete"); System.out.println("complete");
System.out.println("Elapsed time for worst fit allocation algorithm to complete " + jobLength + " jobs is " + timeEnd[2] + " milliseconds"); System.out.println("Elapsed time for worst fit allocation algorithm to complete " + jobLength + " jobs is " + timeEnd[2] + " milliseconds");
@ -111,9 +104,8 @@ public class memoryManagement{
//First Fit //First Fit
System.out.print("Sending jobs to first fit allocation algorithm..."); System.out.print("Sending jobs to first fit allocation algorithm...");
timeStart[3] = System.currentTimeMillis(); timeStart[3] = System.currentTimeMillis();
for(int i = 0; i < jobLength - 1; i++) { for(int i = 0; i < jobLength - 1; i++)
firstFit.allocate(id[i], size[i], time[i]); firstFit.allocate(id[i], size[i], time[i]);
}
timeEnd[3] = System.currentTimeMillis() - timeStart[3]; timeEnd[3] = System.currentTimeMillis() - timeStart[3];
System.out.println("complete"); System.out.println("complete");
System.out.println("Elapsed time for first fit allocation algorithm to complete " + jobLength + " jobs is " + timeEnd[3] + " milliseconds"); System.out.println("Elapsed time for first fit allocation algorithm to complete " + jobLength + " jobs is " + timeEnd[3] + " milliseconds");
@ -121,9 +113,8 @@ public class memoryManagement{
//Next Fit //Next Fit
System.out.print("Sending jobs to next fit allocation algorithm..."); System.out.print("Sending jobs to next fit allocation algorithm...");
timeStart[4] = System.currentTimeMillis(); timeStart[4] = System.currentTimeMillis();
for(int i = 0; i < jobLength - 1; i++) { for(int i = 0; i < jobLength - 1; i++)
nextFit.allocate(id[i], size[i], time[i]); nextFit.allocate(id[i], size[i], time[i]);
}
timeEnd[4] = System.currentTimeMillis() - timeStart[4]; timeEnd[4] = System.currentTimeMillis() - timeStart[4];
System.out.println("complete"); System.out.println("complete");
System.out.println("Elapsed time for next fit allocation algorithm to complete " + jobLength + " jobs is " + timeEnd[4] + " milliseconds"); System.out.println("Elapsed time for next fit allocation algorithm to complete " + jobLength + " jobs is " + timeEnd[4] + " milliseconds");
@ -131,12 +122,10 @@ public class memoryManagement{
System.out.print("Printing to log..."); System.out.print("Printing to log...");
out.println("Memory Management Log"); out.println("Memory Management Log");
out.println("---------------------------"); out.println("---------------------------");
if(read.equals("")) { if(read.equals(""))
out.println("Job Assignment: Random"); out.println("Job Assignment: Random");
} else
else {
out.println("Job Assignment: " + read + ".txt"); out.println("Job Assignment: " + read + ".txt");
}
out.println("Job Amount: " + jobLength); out.println("Job Amount: " + jobLength);
out.println("Memory Size: " + MEMORYSIZE); out.println("Memory Size: " + MEMORYSIZE);
out.println("---------------------------"); out.println("---------------------------");