home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-02-20 | 1.8 KB | 72 lines |
-
- package examples.network;
-
-
- import simula.*;
- import simula.random.* ;
- import simula.simset.* ;
- import simula.simset.simulation.* ;
- import simula.Lang ;
- /**
- * Main program for network simulation
- * @author Andrea Poltronieri
- * @version 1.0 12 Feb 1998
- */
-
- public class NetworkMain extends SimulationMain {
-
-
-
-
- /**
- * @param _simulation The active Simulation
- * @exception simula.SimulaException Any exception from Korretto API
- */
-
- public NetworkMain(Simulation _simulation) throws SimulaException {
- super(_simulation);
- }
- /**
- * Executes the main program for the simulation
- */
- public void run() {
- try {
- NetworkSimulation sim=(NetworkSimulation)(this.sim) ;
-
- // actions of main program ;
- Lang.outtext("Number of nodes") ;
- sim.n=Lang.inint() ;
- // dimension global arrays
- // should be [1..N]
- sim.node=new Station[sim.n+1] ;
-
- Lang.outtext("Simulation length [units of time]?") ;
- sim.simtime=Lang.inint() ;
-
- Lang.outtext("Seed for random generator (odd) ?") ;
- sim.seed=Lang.inint() ;
- sim.uniform=new Uniform(sim.seed,0,1) ;
- Lang.outtext("");
- for (sim.i=1;sim.i<=sim.n;sim.i++) {
- sim.node[sim.i]= new Station(sim) ;
- Lang.outtext("");
- }
- sim.activate (new Arrivals(sim)) ;
- sim.hold(sim.simtime) ;
- Lang.outtext("");
- Lang.outtext("The average sojourn time is [units of time]");
- //System.err.println("sojourn = "+sim.sojourn) ;
- //System.err.println("numthrough = "+sim.numthrough) ;
- if (sim.numthrough>0)
- Lang.outfix((double)(sim.sojourn)/(double)(sim.numthrough),3,10) ;
- else
- Lang.outtext("No throughs performed") ;
- Lang.outimage() ;
- sim.end() ;
- System.exit(0) ;
- } catch(SimulaException e) {
- Lang.outtext(" Exception :> " + e+e.getMessage());
- System.exit(1);
- }
- }
- }