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

  1.  
  2. package examples.network;
  3.  
  4.  
  5. import simula.*;
  6. import simula.random.* ;
  7. import simula.simset.* ;
  8. import simula.simset.simulation.* ;
  9. import simula.Lang ;
  10. /**
  11.  * Main program for network simulation
  12.  * @author Andrea Poltronieri
  13.  * @version 1.0 12 Feb 1998
  14.  */
  15.  
  16. public class NetworkMain extends SimulationMain {
  17.  
  18.  
  19.  
  20.  
  21. /**
  22. * @param _simulation The active Simulation
  23. * @exception simula.SimulaException Any exception from Korretto API
  24. */
  25.  
  26.     public NetworkMain(Simulation _simulation) throws SimulaException {
  27.       super(_simulation);
  28.     }
  29. /**     
  30.   * Executes the main program for the simulation
  31. */
  32.     public void run() {
  33.         try {
  34.             NetworkSimulation sim=(NetworkSimulation)(this.sim) ;
  35.             
  36.             // actions of main program ;                
  37.             Lang.outtext("Number of nodes") ;
  38.             sim.n=Lang.inint() ;
  39.             // dimension global arrays
  40.             // should be [1..N] 
  41.             sim.node=new Station[sim.n+1] ;
  42.             
  43.             Lang.outtext("Simulation length [units of time]?") ;
  44.             sim.simtime=Lang.inint() ;
  45.             
  46.             Lang.outtext("Seed for random generator (odd) ?") ;
  47.             sim.seed=Lang.inint() ;
  48.             sim.uniform=new Uniform(sim.seed,0,1) ;
  49.             Lang.outtext("");
  50.             for (sim.i=1;sim.i<=sim.n;sim.i++) {
  51.                 sim.node[sim.i]= new Station(sim) ;
  52.                 Lang.outtext("");
  53.             }
  54.             sim.activate (new Arrivals(sim)) ;
  55.             sim.hold(sim.simtime) ;
  56.             Lang.outtext("");
  57.             Lang.outtext("The average sojourn time is [units of time]");
  58.             //System.err.println("sojourn = "+sim.sojourn) ;
  59.             //System.err.println("numthrough = "+sim.numthrough) ;
  60.             if (sim.numthrough>0) 
  61.                 Lang.outfix((double)(sim.sojourn)/(double)(sim.numthrough),3,10) ;
  62.             else
  63.                 Lang.outtext("No throughs performed") ;
  64.             Lang.outimage() ;
  65.             sim.end() ;
  66.             System.exit(0) ;
  67.         } catch(SimulaException e) {
  68.             Lang.outtext(" Exception :> " + e+e.getMessage());
  69.          System.exit(1);
  70.         }
  71.     }
  72. }