mirror of
https://github.com/bspeice/itcs3146-project
synced 2024-12-22 14:48:21 -05:00
Added code to run jobs
This commit is contained in:
parent
c062724071
commit
25fbca314c
@ -4,6 +4,8 @@
|
|||||||
this class sets up a First Fit memory scheme
|
this class sets up a First Fit memory scheme
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.lang.reflect.*;
|
||||||
|
|
||||||
//this section sets up the Car class
|
//this section sets up the Car class
|
||||||
class FirstFit implements baseAlgorithm
|
class FirstFit implements baseAlgorithm
|
||||||
{
|
{
|
||||||
@ -15,7 +17,7 @@ class FirstFit implements baseAlgorithm
|
|||||||
startLoc,
|
startLoc,
|
||||||
endLoc,
|
endLoc,
|
||||||
blkSize,
|
blkSize,
|
||||||
memSize,
|
memSize = memoryManagement.MEMORYSIZE,
|
||||||
active,
|
active,
|
||||||
noJobs=0,
|
noJobs=0,
|
||||||
s1=0,
|
s1=0,
|
||||||
@ -26,9 +28,8 @@ class FirstFit implements baseAlgorithm
|
|||||||
private int[] memory = new int[memSize];
|
private int[] memory = new int[memSize];
|
||||||
|
|
||||||
//this is a no argument constructor
|
//this is a no argument constructor
|
||||||
public FirstFit(int memSize)
|
public FirstFit()
|
||||||
{
|
{
|
||||||
this.memSize = memSize;
|
|
||||||
memTable[0][0]=0; //job number
|
memTable[0][0]=0; //job number
|
||||||
memTable[0][1]=0; //job size
|
memTable[0][1]=0; //job size
|
||||||
memTable[0][2]=0; //start location in memory
|
memTable[0][2]=0; //start location in memory
|
||||||
@ -47,6 +48,12 @@ class FirstFit implements baseAlgorithm
|
|||||||
noJobs++;
|
noJobs++;
|
||||||
s1=0;
|
s1=0;
|
||||||
|
|
||||||
|
//Bradlee's code ***********************************************************************************
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Method deallocateMethod = this.getClass().getMethod("deallocate", new Class[]{int.class, int.class});
|
||||||
|
|
||||||
|
|
||||||
//checks to see if the job will fit in memory
|
//checks to see if the job will fit in memory
|
||||||
if(jobSize>memSize)
|
if(jobSize>memSize)
|
||||||
{
|
{
|
||||||
@ -70,7 +77,9 @@ class FirstFit implements baseAlgorithm
|
|||||||
memTable[s1][3] = jobSize-1;
|
memTable[s1][3] = jobSize-1;
|
||||||
memTable[s1][4] = memTable[0][3]-memTable[0][2]+1;
|
memTable[s1][4] = memTable[0][3]-memTable[0][2]+1;
|
||||||
memTable[s1][5] = 1;
|
memTable[s1][5] = 1;
|
||||||
|
Job newJob = new Job(jobTime, jobId, jobSize, memTable[s1][2], deallocateMethod, this);
|
||||||
fillMemory(jobId, jobSize, memTable[s1][2]);
|
fillMemory(jobId, jobSize, memTable[s1][2]);
|
||||||
|
newJob.start();
|
||||||
memTable[s1+1][0] = 0;
|
memTable[s1+1][0] = 0;
|
||||||
memTable[s1+1][1] = 0;
|
memTable[s1+1][1] = 0;
|
||||||
memTable[s1+1][2] = memTable[s1][3]+1;
|
memTable[s1+1][2] = memTable[s1][3]+1;
|
||||||
@ -78,6 +87,7 @@ class FirstFit implements baseAlgorithm
|
|||||||
memTable[s1+1][4] = memSize-memTable[s1+1][2];
|
memTable[s1+1][4] = memSize-memTable[s1+1][2];
|
||||||
memTable[s1+1][5] = -1;
|
memTable[s1+1][5] = -1;
|
||||||
tableEntries++;
|
tableEntries++;
|
||||||
|
System.out.println(toString());
|
||||||
s1=memSize*2;
|
s1=memSize*2;
|
||||||
}
|
}
|
||||||
//runs after the first job and if the only available slot is at the end of memory
|
//runs after the first job and if the only available slot is at the end of memory
|
||||||
@ -89,7 +99,9 @@ class FirstFit implements baseAlgorithm
|
|||||||
memTable[s1][3] = jobSize+memTable[s1][2]-1;
|
memTable[s1][3] = jobSize+memTable[s1][2]-1;
|
||||||
memTable[s1][4] = memTable[s1][3]-memTable[s1][2]+1;
|
memTable[s1][4] = memTable[s1][3]-memTable[s1][2]+1;
|
||||||
memTable[s1][5] = 1;
|
memTable[s1][5] = 1;
|
||||||
|
Job newJob = new Job(jobTime, jobId, jobSize, memTable[s1][2], deallocateMethod, this);
|
||||||
fillMemory(jobId, jobSize, memTable[s1][2]);
|
fillMemory(jobId, jobSize, memTable[s1][2]);
|
||||||
|
newJob.start();
|
||||||
memTable[s1+1][0] = 0;
|
memTable[s1+1][0] = 0;
|
||||||
memTable[s1+1][1] = 0;
|
memTable[s1+1][1] = 0;
|
||||||
memTable[s1+1][2] = memTable[s1][3]+1;
|
memTable[s1+1][2] = memTable[s1][3]+1;
|
||||||
@ -97,6 +109,7 @@ class FirstFit implements baseAlgorithm
|
|||||||
memTable[s1+1][4] = memSize-memTable[s1+1][2];
|
memTable[s1+1][4] = memSize-memTable[s1+1][2];
|
||||||
memTable[s1+1][5] = -1;
|
memTable[s1+1][5] = -1;
|
||||||
tableEntries++;
|
tableEntries++;
|
||||||
|
System.out.println(toString());
|
||||||
s1=memSize*2;
|
s1=memSize*2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,7 +119,10 @@ class FirstFit implements baseAlgorithm
|
|||||||
memTable[s1][0] = jobId;
|
memTable[s1][0] = jobId;
|
||||||
memTable[s1][1] = jobSize;
|
memTable[s1][1] = jobSize;
|
||||||
memTable[s1][5] = 1;
|
memTable[s1][5] = 1;
|
||||||
|
Job newJob = new Job(jobTime, jobId, jobSize, memTable[s1][2], deallocateMethod, this);
|
||||||
fillMemory(jobId, jobSize, memTable[s1][2]);
|
fillMemory(jobId, jobSize, memTable[s1][2]);
|
||||||
|
newJob.start();
|
||||||
|
System.out.println(toString());
|
||||||
s1=memSize*2;
|
s1=memSize*2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -123,7 +139,13 @@ class FirstFit implements baseAlgorithm
|
|||||||
compMem();
|
compMem();
|
||||||
allocate(ID, size, jobTime);
|
allocate(ID, size, jobTime);
|
||||||
}
|
}
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Could not allocate job with ID " + jobId);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//this method is used if you want to deallocate a job by jobId
|
//this method is used if you want to deallocate a job by jobId
|
||||||
public void removeJob(int ID)
|
public void removeJob(int ID)
|
||||||
@ -147,6 +169,8 @@ class FirstFit implements baseAlgorithm
|
|||||||
deallocate(jobSize, startLoc);
|
deallocate(jobSize, startLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//this method removes a job it does not check to see if the job exisits
|
//this method removes a job it does not check to see if the job exisits
|
||||||
public void deallocate(int jobSize, int beginningLocation)
|
public void deallocate(int jobSize, int beginningLocation)
|
||||||
//public void removeJob(int ID)
|
//public void removeJob(int ID)
|
||||||
@ -165,6 +189,7 @@ class FirstFit implements baseAlgorithm
|
|||||||
s1=memSize*2;
|
s1=memSize*2;
|
||||||
jobId=-1;
|
jobId=-1;
|
||||||
noJobs--;
|
noJobs--;
|
||||||
|
System.out.println("removed job "+memTable[s1][0]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -178,6 +203,7 @@ class FirstFit implements baseAlgorithm
|
|||||||
//this method compacts the memory
|
//this method compacts the memory
|
||||||
public void compMem()
|
public void compMem()
|
||||||
{
|
{
|
||||||
|
//System.out.println("Compacting Memory");
|
||||||
compMemTest=tableEntries;
|
compMemTest=tableEntries;
|
||||||
for(int c=0; c<=compMemTest; c++)
|
for(int c=0; c<=compMemTest; c++)
|
||||||
{
|
{
|
||||||
|
24
NextFit.java
24
NextFit.java
@ -4,6 +4,8 @@
|
|||||||
this class sets up a First Fit memory scheme
|
this class sets up a First Fit memory scheme
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.lang.reflect.*;
|
||||||
|
|
||||||
//this section sets up the Car class
|
//this section sets up the Car class
|
||||||
class NextFit implements baseAlgorithm
|
class NextFit implements baseAlgorithm
|
||||||
{
|
{
|
||||||
@ -50,6 +52,12 @@ class NextFit implements baseAlgorithm
|
|||||||
s1=0;
|
s1=0;
|
||||||
loopCount=0;
|
loopCount=0;
|
||||||
|
|
||||||
|
//Bradlee's code ***********************************************************************************
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Method deallocateMethod = this.getClass().getMethod("deallocate", new Class[]{int.class, int.class});
|
||||||
|
|
||||||
|
|
||||||
//checks to see if the job will fit in memory
|
//checks to see if the job will fit in memory
|
||||||
if(jobSize>memSize)
|
if(jobSize>memSize)
|
||||||
{
|
{
|
||||||
@ -74,7 +82,9 @@ class NextFit implements baseAlgorithm
|
|||||||
memTable[currentPosition][3] = jobSize-1;
|
memTable[currentPosition][3] = jobSize-1;
|
||||||
memTable[currentPosition][4] = memTable[0][3]-memTable[0][2]+1;
|
memTable[currentPosition][4] = memTable[0][3]-memTable[0][2]+1;
|
||||||
memTable[currentPosition][5] = 1;
|
memTable[currentPosition][5] = 1;
|
||||||
|
Job newJob = new Job(jobTime, jobId, jobSize, memTable[currentPosition][2], deallocateMethod, this);
|
||||||
fillMemory(jobId, jobSize, memTable[currentPosition][2]);
|
fillMemory(jobId, jobSize, memTable[currentPosition][2]);
|
||||||
|
newJob.start();
|
||||||
memTable[currentPosition+1][0] = 0;
|
memTable[currentPosition+1][0] = 0;
|
||||||
memTable[currentPosition+1][1] = 0;
|
memTable[currentPosition+1][1] = 0;
|
||||||
memTable[currentPosition+1][2] = memTable[currentPosition][3]+1;
|
memTable[currentPosition+1][2] = memTable[currentPosition][3]+1;
|
||||||
@ -95,7 +105,9 @@ class NextFit implements baseAlgorithm
|
|||||||
memTable[currentPosition][3] = jobSize+memTable[currentPosition][2]-1;
|
memTable[currentPosition][3] = jobSize+memTable[currentPosition][2]-1;
|
||||||
memTable[currentPosition][4] = memTable[currentPosition][3]-memTable[currentPosition][2]+1;
|
memTable[currentPosition][4] = memTable[currentPosition][3]-memTable[currentPosition][2]+1;
|
||||||
memTable[currentPosition][5] = 1;
|
memTable[currentPosition][5] = 1;
|
||||||
|
Job newJob = new Job(jobTime, jobId, jobSize, memTable[currentPosition][2], deallocateMethod, this);
|
||||||
fillMemory(jobId, jobSize, memTable[currentPosition][2]);
|
fillMemory(jobId, jobSize, memTable[currentPosition][2]);
|
||||||
|
newJob.start();
|
||||||
memTable[currentPosition+1][0] = 0;
|
memTable[currentPosition+1][0] = 0;
|
||||||
memTable[currentPosition+1][1] = 0;
|
memTable[currentPosition+1][1] = 0;
|
||||||
memTable[currentPosition+1][2] = memTable[currentPosition][3]+1;
|
memTable[currentPosition+1][2] = memTable[currentPosition][3]+1;
|
||||||
@ -114,7 +126,9 @@ class NextFit implements baseAlgorithm
|
|||||||
memTable[currentPosition][0] = jobId;
|
memTable[currentPosition][0] = jobId;
|
||||||
memTable[currentPosition][1] = jobSize;
|
memTable[currentPosition][1] = jobSize;
|
||||||
memTable[currentPosition][5] = 1;
|
memTable[currentPosition][5] = 1;
|
||||||
|
Job newJob = new Job(jobTime, jobId, jobSize, memTable[currentPosition][2], deallocateMethod, this);
|
||||||
fillMemory(jobId, jobSize, memTable[currentPosition][2]);
|
fillMemory(jobId, jobSize, memTable[currentPosition][2]);
|
||||||
|
newJob.start();
|
||||||
currentPosition++;
|
currentPosition++;
|
||||||
positionToCompress=currentPosition;
|
positionToCompress=currentPosition;
|
||||||
s1=memSize*2;
|
s1=memSize*2;
|
||||||
@ -142,8 +156,17 @@ class NextFit implements baseAlgorithm
|
|||||||
positionToCompress=0;
|
positionToCompress=0;
|
||||||
allocate(ID, size, jobTime);
|
allocate(ID, size, jobTime);
|
||||||
}
|
}
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Could not allocate job with ID " + jobId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//this method is used if you want to deallocate a job by jobId
|
//this method is used if you want to deallocate a job by jobId
|
||||||
public void removeJob(int ID)
|
public void removeJob(int ID)
|
||||||
{
|
{
|
||||||
@ -197,7 +220,6 @@ class NextFit implements baseAlgorithm
|
|||||||
//this method compacts the memory
|
//this method compacts the memory
|
||||||
public void compMem()
|
public void compMem()
|
||||||
{
|
{
|
||||||
System.out.println("***********************enter compress************************");
|
|
||||||
compMemTest=tableEntries;
|
compMemTest=tableEntries;
|
||||||
for(int c=0; c<=compMemTest; c++)
|
for(int c=0; c<=compMemTest; c++)
|
||||||
{
|
{
|
||||||
|
@ -9,7 +9,7 @@ import java.util.StringTokenizer;
|
|||||||
|
|
||||||
public class memoryManagement{
|
public class memoryManagement{
|
||||||
|
|
||||||
static final int JOBAMOUNT = 1000;
|
static final int JOBAMOUNT = 30;
|
||||||
static final int MEMORYSIZE = 10000;
|
static final int MEMORYSIZE = 10000;
|
||||||
|
|
||||||
public static void main(String args[])throws Exception{
|
public static void main(String args[])throws Exception{
|
||||||
@ -31,7 +31,9 @@ public class memoryManagement{
|
|||||||
|
|
||||||
//******Add your algorithm class here******//
|
//******Add your algorithm class here******//
|
||||||
//baseAlgorithm alg = new dummyAlgorithm(MEMORYSIZE);
|
//baseAlgorithm alg = new dummyAlgorithm(MEMORYSIZE);
|
||||||
threadedAllocation Bradlee_Speice = new threadedAllocation(MEMORYSIZE);
|
//threadedAllocation Bradlee_Speice = new threadedAllocation(MEMORYSIZE);
|
||||||
|
//FirstFit David01 = new FirstFit();
|
||||||
|
NextFit David02 = new NextFit();
|
||||||
|
|
||||||
//Gets a file name, else creates five random jobs
|
//Gets a file name, else creates five random jobs
|
||||||
do{
|
do{
|
||||||
@ -72,7 +74,9 @@ public class memoryManagement{
|
|||||||
timeStart = System.currentTimeMillis();
|
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++){
|
for(int i = 0; i < jobLength - 1; i++){
|
||||||
Bradlee_Speice.allocate(id[i], size[i], time[i]);
|
//Bradlee_Speice.allocate(id[i], size[i], time[i]);
|
||||||
|
//David01.allocate(id[i], size[i], time[i]);
|
||||||
|
David02.allocate(id[i], size[i], time[i]);
|
||||||
}
|
}
|
||||||
timeEnd = System.currentTimeMillis() - timeStart;
|
timeEnd = System.currentTimeMillis() - timeStart;
|
||||||
System.out.println("complete");
|
System.out.println("complete");
|
||||||
|
Loading…
Reference in New Issue
Block a user