mirror of
				https://github.com/bspeice/itcs3146-project
				synced 2025-11-04 10:30:27 -05:00 
			
		
		
		
	Merge branch 'master' of https://github.com/DjBushido/itcs3146-project
Conflicts: memoryManagement.java
This commit is contained in:
		@ -3,6 +3,7 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.File;
 | 
					import java.io.File;
 | 
				
			||||||
 | 
					import java.io.PrintWriter;
 | 
				
			||||||
import java.util.Random;
 | 
					import java.util.Random;
 | 
				
			||||||
import java.util.Scanner;
 | 
					import java.util.Scanner;
 | 
				
			||||||
import java.util.StringTokenizer;
 | 
					import java.util.StringTokenizer;
 | 
				
			||||||
@ -15,6 +16,7 @@ public class memoryManagement{
 | 
				
			|||||||
	public static void main(String args[])throws Exception{
 | 
						public static void main(String args[])throws Exception{
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
		File file = new File("null");
 | 
							File file = new File("null");
 | 
				
			||||||
 | 
							PrintWriter out = new PrintWriter(new File("log.txt"));
 | 
				
			||||||
		Scanner keyboard = new Scanner(System.in);
 | 
							Scanner keyboard = new Scanner(System.in);
 | 
				
			||||||
		Scanner fileScan;
 | 
							Scanner fileScan;
 | 
				
			||||||
		StringTokenizer token;
 | 
							StringTokenizer token;
 | 
				
			||||||
@ -22,7 +24,7 @@ public class memoryManagement{
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		String read = null;
 | 
							String read = null;
 | 
				
			||||||
		int jobLength = 0;
 | 
							int jobLength = 0;
 | 
				
			||||||
		long timeStart, timeEnd;
 | 
							long[] timeStart = new long[5], timeEnd = new long[5];
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		//*Job Info*
 | 
							//*Job Info*
 | 
				
			||||||
		int[] id = new int[JOBAMOUNT];
 | 
							int[] id = new int[JOBAMOUNT];
 | 
				
			||||||
@ -30,12 +32,11 @@ public class memoryManagement{
 | 
				
			|||||||
		int[] time = new int[JOBAMOUNT];
 | 
							int[] time = new int[JOBAMOUNT];
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		//******Add your algorithm class here******//
 | 
							//******Add your algorithm class here******//
 | 
				
			||||||
		//baseAlgorithm alg = new dummyAlgorithm(MEMORYSIZE);
 | 
							threadedAllocation threadedFit = new threadedAllocation(MEMORYSIZE);
 | 
				
			||||||
		threadedAllocation Bradlee_Speice = new threadedAllocation(MEMORYSIZE);
 | 
							FirstFit firstFit = new FirstFit();
 | 
				
			||||||
		//FirstFit David01 = new FirstFit();
 | 
							NextFit nextFit = new NextFit();
 | 
				
			||||||
		//NextFit David02 = new NextFit();
 | 
							BestFitAlgorithm bestFit = new BestFitAlgorithm(MEMORYSIZE);
 | 
				
			||||||
                BestFitAlgorithm David_Weber_BestFit = new BestFitAlgorithm(MEMORYSIZE);
 | 
							WorstFitAlgorithm worstFit = new WorstFitAlgorithm(MEMORYSIZE);
 | 
				
			||||||
                WorstFitAlgorithm David_Weber_WorstFit = new WorstFitAlgorithm(MEMORYSIZE);
 | 
					 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		//Gets a file name, else creates five random jobs
 | 
							//Gets a file name, else creates five random jobs
 | 
				
			||||||
		do{							
 | 
							do{							
 | 
				
			||||||
@ -52,8 +53,8 @@ public class memoryManagement{
 | 
				
			|||||||
			jobLength = JOBAMOUNT;
 | 
								jobLength = JOBAMOUNT;
 | 
				
			||||||
			for(int i = 0; i < jobLength; i++){
 | 
								for(int i = 0; i < jobLength; i++){
 | 
				
			||||||
				id[i] = i+1;
 | 
									id[i] = i+1;
 | 
				
			||||||
				size[i] = rand.nextInt(5)+1;
 | 
									size[i] = rand.nextInt(MEMORYSIZE / 10)+1;
 | 
				
			||||||
				time[i] = rand.nextInt(1000)+2001;
 | 
									time[i] = rand.nextInt(5000)+ 101;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			System.out.println("complete");
 | 
								System.out.println("complete");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -71,42 +72,67 @@ public class memoryManagement{
 | 
				
			|||||||
			System.out.println(jobLength+" jobs found on file");
 | 
								System.out.println(jobLength+" jobs found on file");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
                
 | 
					 | 
				
			||||||
                
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		//Send jobs to algorithm, time is calculated and printed out after completion
 | 
							//Send jobs to algorithm, time is calculated and printed out after completion
 | 
				
			||||||
		System.out.print("Sending jobs to threaded allocation algorithm...");
 | 
					 | 
				
			||||||
		timeStart = System.currentTimeMillis();
 | 
					 | 
				
			||||||
		//Note that we use `jobLength - 1` to compensate for the id above
 | 
							//Note that we use `jobLength - 1` to compensate for the id above
 | 
				
			||||||
		for(int i = 0; i < jobLength - 1; i++){
 | 
							//Threaded Fit
 | 
				
			||||||
			Bradlee_Speice.allocate(id[i], size[i], time[i]);
 | 
							System.out.print("Sending jobs to threaded allocation algorithm...");
 | 
				
			||||||
			//David01.allocate(id[i], size[i], time[i]);
 | 
							timeStart[0] = System.currentTimeMillis();
 | 
				
			||||||
			//David02.allocate(id[i], size[i], time[i]);
 | 
							for(int i = 0; i < jobLength - 1; i++)
 | 
				
			||||||
		}
 | 
								threadedFit.allocate(id[i], size[i], time[i]);
 | 
				
			||||||
		timeEnd = System.currentTimeMillis() - timeStart;
 | 
							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 +                                           
 | 
							System.out.println("Elapsed time for threaded allocation algorithm to complete " + jobLength + " jobs is " + timeEnd[0] + " milliseconds");
 | 
				
			||||||
              " jobs is " + timeEnd + " milliseconds");
 | 
					 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		//***Best Fit (David Weber)***
 | 
							//Best Fit
 | 
				
			||||||
                timeStart = System.currentTimeMillis();  
 | 
							System.out.print("Sending jobs to best fit allocation algorithm...");
 | 
				
			||||||
                for(int i = 0; i < jobLength - 1; i++){
 | 
							timeStart[1] = System.currentTimeMillis();
 | 
				
			||||||
			David_Weber_BestFit.allocate(id[i], size[i], time[i]);
 | 
							for(int i = 0; i < jobLength - 1; i++)
 | 
				
			||||||
		}
 | 
								bestFit.allocate(id[i], size[i], time[i]);
 | 
				
			||||||
 | 
							timeEnd[1] = System.currentTimeMillis() - timeStart[1];
 | 
				
			||||||
 | 
							System.out.println("complete");
 | 
				
			||||||
 | 
							System.out.println("Elapsed time for best fit allocation algorithm to complete " + jobLength + " jobs is " + timeEnd[1] + " milliseconds");
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
                timeEnd = System.currentTimeMillis() - timeStart;  
 | 
							//Worst Fit
 | 
				
			||||||
		System.out.println("Elapsed time for best fit allocation algorithm to complete " + jobLength + " jobs is " + timeEnd + " milliseconds");
 | 
							System.out.print("Sending jobs to worst fit allocation algorithm...");
 | 
				
			||||||
 | 
							timeStart[2] = System.currentTimeMillis();
 | 
				
			||||||
 | 
							for(int i = 0; i < jobLength - 1; i++)
 | 
				
			||||||
 | 
								worstFit.allocate(id[i], size[i], time[i]);
 | 
				
			||||||
 | 
							timeEnd[2] = System.currentTimeMillis() - timeStart[2];
 | 
				
			||||||
 | 
							System.out.println("complete");
 | 
				
			||||||
 | 
							System.out.println("Elapsed time for worst fit allocation algorithm to complete " + jobLength + " jobs is " + timeEnd[2] + " milliseconds");
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
                //***Worst Fit (David Weber)***
 | 
							//First Fit
 | 
				
			||||||
                timeStart = System.currentTimeMillis();  
 | 
							System.out.print("Sending jobs to first fit allocation algorithm...");
 | 
				
			||||||
                for(int i = 0; i < jobLength - 1; i++){
 | 
							timeStart[3] = System.currentTimeMillis();
 | 
				
			||||||
			David_Weber_WorstFit.allocate(id[i], size[i], time[i]);
 | 
							for(int i = 0; i < jobLength - 1; i++)
 | 
				
			||||||
		}
 | 
								firstFit.allocate(id[i], size[i], time[i]);
 | 
				
			||||||
 | 
							timeEnd[3] = System.currentTimeMillis() - timeStart[3];
 | 
				
			||||||
 | 
							System.out.println("complete");
 | 
				
			||||||
 | 
							System.out.println("Elapsed time for first fit allocation algorithm to complete " + jobLength + " jobs is " + timeEnd[3] + " milliseconds");
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
                timeEnd = System.currentTimeMillis() - timeStart;  
 | 
							//Next Fit
 | 
				
			||||||
		System.out.println("Elapsed time for worst fit allocation algorithm to complete " + jobLength + " jobs is " + timeEnd + " milliseconds");
 | 
							System.out.print("Sending jobs to next fit allocation algorithm...");
 | 
				
			||||||
 | 
							timeStart[4] = System.currentTimeMillis();
 | 
				
			||||||
 | 
							for(int i = 0; i < jobLength - 1; i++)
 | 
				
			||||||
 | 
								nextFit.allocate(id[i], size[i], time[i]);
 | 
				
			||||||
 | 
							timeEnd[4] = System.currentTimeMillis() - timeStart[4];
 | 
				
			||||||
 | 
							System.out.println("complete");
 | 
				
			||||||
 | 
							System.out.println("Elapsed time for next fit allocation algorithm to complete " + jobLength + " jobs is " + timeEnd[4] + " milliseconds");
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
                //Put other algorithms here.
 | 
							System.out.println("Printing to log...");
 | 
				
			||||||
 | 
							out.println("Memory Management Log");
 | 
				
			||||||
 | 
							out.println("---------------------------");
 | 
				
			||||||
 | 
							out.println("Job Amount: " + jobLength);
 | 
				
			||||||
 | 
							out.println("Memory Size: " + MEMORYSIZE);
 | 
				
			||||||
 | 
							out.println("---------------------------");
 | 
				
			||||||
 | 
							out.println("Final Times (All times in milliseconds)");
 | 
				
			||||||
 | 
							out.println("Threaded time: " + timeEnd[0]);
 | 
				
			||||||
 | 
							out.println("Best fit time: " + timeEnd[0]);
 | 
				
			||||||
 | 
							out.println("Worst fit time: " + timeEnd[0]);
 | 
				
			||||||
 | 
							out.println("First fit time: " + timeEnd[0]);
 | 
				
			||||||
 | 
							out.println("Next fit time: " + timeEnd[0]);
 | 
				
			||||||
 | 
							out.close();
 | 
				
			||||||
 | 
							System.out.println("complete");
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		System.out.println("Completed Successfully");
 | 
							System.out.println("Completed Successfully");
 | 
				
			||||||
		//Forcibly close down all threads
 | 
							//Forcibly close down all threads
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user