home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / JSL.ZIP / JSL20 / examples / prepriosys / PrePrioSysMain.java < prev    next >
Encoding:
Java Source  |  1998-02-20  |  2.3 KB  |  90 lines

  1.  
  2. package examples.prepriosys;
  3.  
  4.  
  5. import simula.*;
  6. import simula.simset.simulation.* ;
  7. import simula.Lang ;
  8. /**
  9.  * Main program for preemptive priority system
  10.  * @author Andrea Poltronieri
  11.  * @version 1.0 12 Feb 1998
  12.  */
  13.  
  14. public class PrePrioSysMain extends SimulationMain {
  15.  
  16.  
  17.  
  18.  
  19. /**
  20. * @param _simulation The active Simulation
  21. * @exception simula.SimulaException Any exception from Korretto API
  22. */
  23.     public PrePrioSysMain(Simulation _simulation) throws SimulaException {
  24.       super(_simulation);
  25.     }
  26. /**     
  27.   * Executes the main program for the simulation
  28. */
  29.     public void run() {
  30.         try {
  31.             PrePrioSysSimulation sim=(PrePrioSysSimulation)this.sim ;
  32.             //Local variables 
  33.                 
  34.             Lang.outtext("Number of types of customer?") ;
  35.             sim.k = Lang.inint() ;
  36.             Lang.outtext("Number of servers ?") ;
  37.             sim.c = Lang.inint() ;
  38.                 
  39.             //Dimension arrays
  40.             // Should be [1..k]; index 0 is ignored
  41.             sim.numthrough = new int[sim.k + 1] ;            
  42.             // Should be [1..k]
  43.             sim.sojourn = new double[sim.k + 1] ;            
  44.                 
  45.                 
  46.             // Should be [1..k]
  47.             sim.queue = new simula.simset.Head[sim.k + 1] ;            
  48.             
  49.             // Should be [1..k]
  50.             sim.busy = new simula.simset.Head[sim.k + 1] ;            
  51.                 
  52.             // main program actions start here 
  53.             Lang.outtext("Random generator seed (odd) ?") ;
  54.             sim.seed = Lang.inint() ;
  55.             Lang.outtext("Simulation length ?") ;
  56.             sim.simtime = Lang.inreal() ;
  57.             sim.top = 1 ;
  58.  
  59.             // Activate arrivals processes
  60.             for (sim.i=1; sim.i<=sim.k; sim.i++){
  61.                 sim.queue[sim.i] = new simula.simset.Head() ;
  62.                 sim.activate (new Arrivals(sim, sim.i)) ;
  63.                 sim.busy[sim.i]=new simula.simset.Head() ;
  64.             }
  65.             sim.available = new simula.simset.Head() ;
  66.  
  67.             // Activate servers
  68.             for(sim.i=1; sim.i<=sim.c; sim.i++) {    
  69.                 sim.activate (new Server(sim)) ;
  70.             }
  71.  
  72.             //System.out.println("Holding main!");
  73.             sim.hold(sim.simtime) ;
  74.             //System.out.println("Simulation complete!");
  75.  
  76.             for (sim.i=1; sim.i<=sim.k; sim.i++){
  77.                 Lang.outtext("The average sojourn for type") ;
  78.                 Lang.outint(sim.i,3) ;
  79.                 Lang.outtext("Customer is") ;
  80.                 Lang.outfix(((double)(sim.sojourn[sim.i])/((double)(sim.numthrough[sim.i]))),3,10) ;
  81.                 Lang.outimage() ;
  82.              } 
  83.             sim.end() ;
  84.             System.exit(0) ;
  85.         } catch(SimulaException e) {
  86.             Lang.outtext(" Exception :> " + e+e.getMessage());
  87.          System.exit(1);
  88.         }
  89.     }
  90. }