Updated memoryManagement

This commit is contained in:
Michael 2012-11-06 19:30:50 -05:00
parent 5af6502951
commit f8a83cff2b

View File

@ -3,7 +3,6 @@
*/ */
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;
@ -11,21 +10,25 @@ import java.util.StringTokenizer;
public class memoryManagement{ public class memoryManagement{
public static void main(String args[])throws Exception{ public static void main(String args[])throws Exception{
final int JOBAMOUNT = 1000; final int JOBAMOUNT = 1000;
final int MEMORYSIZE = 10000;
File file = new File("null"); File file = new File("null");
Scanner keyboard = new Scanner(System.in); Scanner keyboard = new Scanner(System.in);
Scanner fileScan; Scanner fileScan;
StringTokenizer token; StringTokenizer token;
//PrintWriter output = new PrintWriter(new File("out.txt"));
Random rand = new Random(); Random rand = new Random();
String read = null; String read = null;
int jobLength = 0, tempSize, tempTime; int jobLength = 0;
long timeStart, timeEnd; long timeStart, timeEnd;
//*Job Info*
int[] id = new int[JOBAMOUNT];
int[] size = new int[JOBAMOUNT];
int[] time = new int[JOBAMOUNT];
//******Add your algorithm class here******// //******Add your algorithm class here******//
//Algorithm alg = new Algorithm(); baseAlgorithm alg = new dummyAlgorithm(MEMORYSIZE);
Job[] jobs = new Job[JOBAMOUNT];
//Gets a file name, else creates five random jobs //Gets a file name, else creates five random jobs
do{ do{
@ -40,8 +43,11 @@ public class memoryManagement{
if(read.equals("")){ if(read.equals("")){
System.out.print("Creating "+JOBAMOUNT+" random jobs..."); System.out.print("Creating "+JOBAMOUNT+" random jobs...");
jobLength = JOBAMOUNT; jobLength = JOBAMOUNT;
for(int i = 0; i < jobLength; i++) for(int i = 0; i < jobLength; i++){
jobs[i] = new Job(rand.nextInt(1000)+1,rand.nextInt(100)+1); //Job(size, time) id[i] = i+1;
size[i] = rand.nextInt(1000)+1;
time[i] = rand.nextInt(1000)+1;
}
System.out.println("complete"); System.out.println("complete");
} }
else{ else{
@ -49,9 +55,9 @@ public class memoryManagement{
fileScan = new Scanner(file); fileScan = new Scanner(file);
for(jobLength = 0; fileScan.hasNextLine() ; jobLength++){ for(jobLength = 0; fileScan.hasNextLine() ; jobLength++){
token = new StringTokenizer(fileScan.nextLine(),","); token = new StringTokenizer(fileScan.nextLine(),",");
tempSize = Integer.parseInt(token.nextToken()); id[jobLength]++;
tempTime = Integer.parseInt(token.nextToken()); size[jobLength] = Integer.parseInt(token.nextToken());
jobs[jobLength] = new Job(tempSize, tempTime); time[jobLength] = Integer.parseInt(token.nextToken());
} }
fileScan.close(); fileScan.close();
System.out.println("complete"); System.out.println("complete");
@ -62,21 +68,12 @@ public class memoryManagement{
System.out.print("Sending jobs to algorithm..."); System.out.print("Sending jobs to algorithm...");
timeStart = System.currentTimeMillis(); timeStart = System.currentTimeMillis();
for(int i = 0; i < jobLength; i++){ for(int i = 0; i < jobLength; i++){
//alg.allocate(jobs[i]); //Uncomment this line to get your algorithm to work alg.allocate(id[i], size[i], time[i]);
} }
timeEnd = System.currentTimeMillis() - timeStart; timeEnd = System.currentTimeMillis() - timeStart;
System.out.println("complete"); System.out.println("complete");
System.out.println("Elapsed time for algorithm to complete "+ jobLength+" jobs is "+timeEnd+" milliseconds"); System.out.println("Elapsed time for algorithm to complete "+ jobLength+" jobs is "+timeEnd+" milliseconds");
/*
//This will be updated to print out timing information and other useful info
System.out.print("Writing gathered data to file...");
for(int i = 0; i < jobLength; i++)
output.println(jobs[i]);
System.out.println("complete");
*/
System.out.println("Completed Successfully"); System.out.println("Completed Successfully");
//output.close();
} }
} }