/** * The HeuristicScheduler class encompasses all Schedulers that create their * schedules on the fly. Examples include the TwoHeapScheduler and the * InOrderScheduler. Its sibling, the other extension of Scheduler, is the * PreCompScheduler. */ import java.io.*; abstract class HeuristicScheduler extends Scheduler { // Public --------------- // Constructor public HeuristicScheduler( Process[] processes, int availMem ) { super( processes, availMem ); } public void makeFiles( String procfile ) throws IOException { if ( !procfile.endsWith(".proc") ) { System.out.println("File must be a process file ending with " + ".proc"); System.exit(1); } String name = procfile.substring ( procfile.lastIndexOf("/") + 1, procfile.lastIndexOf(".") ); run( name ); } public abstract void run( String name ) throws IOException; // Each process prints its current CPU total to file protected void cpusToFile( PrintStream out ) throws IOException { for( int loop = 0; loop < _processes.length; loop++ ) { out.print( _processes[loop].getQuanta() + " "); } out.println(); } // Each process prints its current received share to file protected void sharesToFile( PrintStream shareOut, PrintStream integralOut ) throws IOException { double actualShare; for( int loop = 0; loop < _processes.length; loop++ ) { /* if( _cpuCount != 0 ) { actualShare = (double)_processes[loop].getQuanta() / _cpuCount; } else { actualShare = 0; } */ actualShare = _processes[loop].averagedShare(); shareOut.print( actualShare + " "); integralOut.print( actualShare -_processes[loop].getShareFrom1() + " "); } shareOut.println(); integralOut.println(); } }