home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / JSL.ZIP / JSL20 / examples / network / NetworkSimulation.java < prev    next >
Encoding:
Java Source  |  1998-02-20  |  2.8 KB  |  87 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.  * A queueing network model
  11.  * @author Andrea Poltronieri
  12.  * @version 1.0 12 Feb 1998
  13.  */
  14.  
  15. public class NetworkSimulation extends Simulation{
  16.     // Global vars declaration ;
  17.     /** Number of nodes*/
  18.     public int n ;
  19.     /** Seed for random generator*/
  20.     public int seed ;
  21.     /** Movements counter*/
  22.     public int numthrough ;
  23.     /** Node index*/
  24.     public int i ;
  25.     /** Total time of soujourn in a node*/
  26.     public double sojourn;
  27.     /** Simulation length*/
  28.     public double simtime ;
  29.     /** Arrays of stations*/
  30.     public Station[] node;
  31.     /** Random generator */
  32.     public Uniform uniform ;    
  33.  
  34.  
  35. /**     
  36.   * Perform a random selection from a set of alternatives.
  37.   * @param  n Upper bound for return
  38.   * @param  a Probabilities dor choiches. Elements must sum up to 1
  39.   * @return 0 with probability a[0]...n with probability a[n] 
  40.   * @exception simula.SimulaException Any exception from Korretto API
  41. */
  42.     public int choice(int n, double[] a) throws SimulaException{
  43.         int i=0 ;
  44.         double f,u ;
  45.         
  46.         f=a[0] ;
  47.         u=uniform.draw().asReal() ;
  48.         while( u>=f) {
  49.             i++ ;
  50.             f+=a[i] ;
  51.         }
  52.         return i ;
  53.     }
  54. /**
  55.  * Print credits on standar error.
  56.  */
  57. private static void credits ( ) {
  58.     System.err.println("***********************************************************") ;
  59.     System.err.println("*                    Example for Korretto                 *") ;
  60.     System.err.println("*  A queueing network model                               *") ;
  61.     System.err.println("* see 'Simulation techiniques for discrete event systems' *") ;
  62.     System.err.println("*      I. Mitrani -- Cambridge University press           *") ;
  63.     System.err.println("* example 3.4                                             *") ;
  64.     System.err.println("***********************************************************") ;
  65.     System.err.println("*  author : Andrea Poltronieri                            *") ;
  66.     System.err.println("*  Verona University                                      *") ;
  67.     System.err.println("*    e-mail : poltro@arena.sci.univr.it                     *") ;
  68.     System.err.println("*  http://arena.sci.univr.it/~poltro                      *") ;
  69.     System.err.println("***********************************************************") ;
  70.     return;
  71. }
  72. /**     
  73.   * Start the simualtion, instantiating a new Simulation and launching the main program
  74.   * @param  args[] Ignored
  75.   * @see simula.simset.simulation.Simulation
  76.   * @see simula.simset.simulation.SimulationMain
  77. */
  78.     public static void main (String args[]) {
  79.         try {
  80.             credits();
  81.             NetworkSimulation sim = new NetworkSimulation();
  82.             NetworkMain main = new NetworkMain(sim);
  83.         } catch (Exception e) { 
  84.             System.err.println ("Exception caught in Machine launcher :\n"+e) ;
  85.         }    
  86.     }
  87. }