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

  1.  
  2. package examples.network;
  3.  
  4.  
  5. import simula.*;
  6. import simula.simset.* ;
  7. import simula.simset.simulation.*;
  8. import simula.random.* ;
  9. /**
  10.  * The process that brings jobs into the system
  11.  * @author Andrea Poltronieri
  12.  * @version 1.0 12 Feb 1998
  13.  */
  14.  
  15. public class  Arrivals extends simula.simset.simulation.Process {
  16.  
  17.  
  18.  
  19. /**
  20. * @param _sim The active Simulation
  21. */
  22.  
  23.     public  Arrivals (Simulation _sim) {
  24.       super(_sim);
  25.     }
  26. /**     
  27.   * Executes actions for this object. Called by simulation on activate
  28.   * @see simula.simset.simulation.Simulation
  29. */
  30.  
  31.  
  32.     public void run()  {
  33.         NetworkSimulation sim = (NetworkSimulation)this.sim ;
  34.         double sum = 0;
  35.         try {
  36.             double arr ;
  37.             double[] q= new double[sim.n+1] ;
  38.             Job newjob ;
  39.             int j ;
  40.             
  41.             // actions 
  42.             Lang.outtext("Arrivals manager initialization") ;
  43.             Lang.outtext("  Arrival rate [arrivals per unit of time]?") ;
  44.             arr=Lang.inreal() ;
  45.             Negexp negexp=new Negexp(sim.seed,arr) ;
  46.             for(j=0;j<=sim.n;j++){
  47.                 if (j == 0)
  48.                     Lang.outtext("  Probability of not even entering the network [0,1]?");
  49.                 else
  50.                     Lang.outtext("  Probability of entering the network at station "+j+" [0," + (1.0 - sum) + "]?") ;
  51.  
  52.                 q[j]=Lang.inreal() ;
  53.                 if (q[j] > (1.0 - sum)) q[j] = 1.0 - sum;
  54.                 sum = sum + q[j];
  55.             }    
  56.             while (true) {
  57.                 sim.hold(negexp.draw().asReal()) ;
  58.                 newjob = new Job(sim) ;
  59.                 newjob.arrtime=sim.time() ;
  60.                 newjob.move(sim.n,q) ;
  61.             }
  62.         } catch (Exception e ) { 
  63.             System.err.println ("Exception caught in " + this.toString() + " :\n" + e) ;
  64.             System.exit(1) ;
  65.         }
  66.     }
  67. }