home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / JSL.ZIP / JSL20 / examples / network / Station.java < prev   
Encoding:
Java Source  |  1998-02-20  |  1.6 KB  |  73 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. /**
  11.  * A class describing a node in the network
  12.  * @author Andrea Poltronieri
  13.  * @version 1.0 12 Feb 1998
  14.  */
  15.   
  16. public class Station {
  17.     /** Main simulation */
  18.     NetworkSimulation sim ;
  19.     
  20.     // declarations
  21.     /** Service rate */ 
  22.     double ser ;
  23.             
  24.     /**  array [0..N] routing probabilities */
  25.     double[] q ;
  26.     /** Nodes list */
  27.     Head queue ;
  28.     /** Server to run */
  29.     Server device ;
  30.     /** Node counter*/
  31.     int j ;    
  32.  
  33.  
  34. /**
  35. * Create a server, bind it to this station and initialize routing probability
  36. * @param _sim The active Simulation
  37. */
  38.  
  39.     public  Station (NetworkSimulation sim) {
  40.       super();
  41.       
  42.       
  43.         double sum = 0;
  44.       this.sim=sim ;
  45.         try {
  46.             // Should be [0..N] 
  47.             q = new double[sim.n+1] ;
  48.             
  49.             // actions 
  50.             Lang.outtext("Station Num. "+ sim.i +" initialization") ;
  51.                 
  52.             Lang.outtext("  service rate [jobs served per unit of time] ?") ;
  53.             ser=Lang.inreal() ;
  54.             for(j=0;j<=sim.n;j++){
  55.                 if (j == 0)
  56.                     Lang.outtext(" probability of getting out the network from this station [0,1] ?")    ;
  57.                 else 
  58.                     Lang.outtext(" probability of getting routed to station "+j+" from this station [0,"+(1.0 - sum)+"] ?")    ;
  59.                 q[j]=Lang.inreal() ;
  60.                 if (q[j] > (1.0 - sum)) q[j] = 1.0 - sum;
  61.                 sum += q[j];
  62.             }
  63.             queue=new Head() ;
  64.             device=new Server(sim,this) ;
  65.             sim.activate(device) ;
  66.  
  67.         } catch (Exception e ) { 
  68.             System.err.println ("Exception caught in " + this.toString() + " :\n" + e) ;
  69.             System.exit(1) ;
  70.         }
  71.  
  72.     }
  73. }