home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-02-20 | 2.8 KB | 87 lines |
-
- package examples.network;
-
-
- import simula.* ;
- import simula.simset.* ;
- import simula.simset.simulation.* ;
- import simula.random.* ;
- /**
- * A queueing network model
- * @author Andrea Poltronieri
- * @version 1.0 12 Feb 1998
- */
-
- public class NetworkSimulation extends Simulation{
- // Global vars declaration ;
- /** Number of nodes*/
- public int n ;
- /** Seed for random generator*/
- public int seed ;
- /** Movements counter*/
- public int numthrough ;
- /** Node index*/
- public int i ;
- /** Total time of soujourn in a node*/
- public double sojourn;
- /** Simulation length*/
- public double simtime ;
- /** Arrays of stations*/
- public Station[] node;
- /** Random generator */
- public Uniform uniform ;
-
-
- /**
- * Perform a random selection from a set of alternatives.
- * @param n Upper bound for return
- * @param a Probabilities dor choiches. Elements must sum up to 1
- * @return 0 with probability a[0]...n with probability a[n]
- * @exception simula.SimulaException Any exception from Korretto API
- */
- public int choice(int n, double[] a) throws SimulaException{
- int i=0 ;
- double f,u ;
-
- f=a[0] ;
- u=uniform.draw().asReal() ;
- while( u>=f) {
- i++ ;
- f+=a[i] ;
- }
- return i ;
- }
- /**
- * Print credits on standar error.
- */
- private static void credits ( ) {
- System.err.println("***********************************************************") ;
- System.err.println("* Example for Korretto *") ;
- System.err.println("* A queueing network model *") ;
- System.err.println("* see 'Simulation techiniques for discrete event systems' *") ;
- System.err.println("* I. Mitrani -- Cambridge University press *") ;
- System.err.println("* example 3.4 *") ;
- System.err.println("***********************************************************") ;
- System.err.println("* author : Andrea Poltronieri *") ;
- System.err.println("* Verona University *") ;
- System.err.println("* e-mail : poltro@arena.sci.univr.it *") ;
- System.err.println("* http://arena.sci.univr.it/~poltro *") ;
- System.err.println("***********************************************************") ;
- return;
- }
- /**
- * Start the simualtion, instantiating a new Simulation and launching the main program
- * @param args[] Ignored
- * @see simula.simset.simulation.Simulation
- * @see simula.simset.simulation.SimulationMain
- */
- public static void main (String args[]) {
- try {
- credits();
- NetworkSimulation sim = new NetworkSimulation();
- NetworkMain main = new NetworkMain(sim);
- } catch (Exception e) {
- System.err.println ("Exception caught in Machine launcher :\n"+e) ;
- }
- }
- }