import java.lang.*; import org.javasim.*; import org.javasim.streams.*; /* * Sample process managing setup and simulation of a system of reserveable resources * (modeled as semaphores) that serve a stream of clients generated by client generator Arrivals. */ public class Network extends SimulationProcess { public Network () { /* * Constructs a collection of resources with capacities and distributions of service times */ Q= new Semaphore[HarbourCount]; ServiceTime = new ExponentialStream[HarbourCount]; for(int i=0; i< HarbourCount; i++){ Q[i]= new Semaphore(2); } } public void run () { /* * Actual main flow of simulation */ try{ /* * Initialize and start the generation of payload. The payload will "own" the needed * service times that are generated during construction. * Pay attention to initialization of random streams. */ inter = new ExponentialStream(40); for (int i=0; i< HarbourCount; i++) { ServiceTime[i] = new ExponentialStream(30,i+1); } Arrivals A = new Arrivals(inter, ServiceTime, HarbourCount); monitor.activate(); A.activate(); /* * The actual simulation */ Simulation.start(); hold(5000); //warm up monitor.restart(); hold(5000); monitor.report(); System.out.println(ProcessedJobs+" "+ TotalResponseTime); Simulation.stop(); A.terminate(); //actually also the payload processes should be cleaned here before leaving the simulation monitor.terminate(); SimulationProcess.mainResume(); } catch (SimulationException e){} catch (RestartException e){} } public void Await () { this.resumeProcess(); SimulationProcess.mainSuspend(); } private static int HarbourCount = 6; public static Reporter monitor = new Reporter(10, 6); public static Semaphore[] Q; public static ExponentialStream[] ServiceTime; public static ExponentialStream inter; public static double TotalResponseTime = 0.0; public static long ProcessedJobs = 0; }