mirror of
				https://github.com/bspeice/itcs3146-project
				synced 2025-11-03 18:10:29 -05:00 
			
		
		
		
	-Added code to allocate best fit and worst fit
This commit is contained in:
		@ -19,8 +19,8 @@ public class BestFitAlgorithm implements baseAlgorithm{
 | 
			
		||||
    
 | 
			
		||||
    public int getBestSizeIndex(int jobSize)
 | 
			
		||||
    {
 | 
			
		||||
        int bestSize = 0;
 | 
			
		||||
        int bestSizeIndex = 0;
 | 
			
		||||
        int bestSize;
 | 
			
		||||
        int bestSizeIndex;
 | 
			
		||||
        
 | 
			
		||||
        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);
 | 
			
		||||
        
 | 
			
		||||
        if(bestSizeIndex == -1) //No candidates found
 | 
			
		||||
        //No candidates found
 | 
			
		||||
        if(bestSizeIndex == -1) 
 | 
			
		||||
        {
 | 
			
		||||
            //Try compacting, then attempt to get an index again
 | 
			
		||||
            compact(); 
 | 
			
		||||
@ -95,11 +96,13 @@ public class BestFitAlgorithm implements baseAlgorithm{
 | 
			
		||||
                //TODO .....
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        //Allocate the memory
 | 
			
		||||
        for(int i = bestSizeIndex; i < jobSize; i++)
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            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);
 | 
			
		||||
		//FirstFit David01 = new FirstFit();
 | 
			
		||||
		//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
 | 
			
		||||
		do{							
 | 
			
		||||
@ -82,9 +84,27 @@ public class memoryManagement{
 | 
			
		||||
		System.out.println("complete");
 | 
			
		||||
		System.out.println("Elapsed time for threaded allocation algorithm to complete " + jobLength +
 | 
			
		||||
							" jobs is " + timeEnd + " milliseconds");
 | 
			
		||||
		
 | 
			
		||||
		//Put other algorithms here.
 | 
			
		||||
		
 | 
			
		||||
		//***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.
 | 
			
		||||
         
 | 
			
		||||
                
 | 
			
		||||
		System.out.println("Completed Successfully");
 | 
			
		||||
		//Forcibly close down all threads
 | 
			
		||||
		System.exit(0);
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user