diff --git a/examples/src/SimkitOpenDis7Examples/SimpleServerOpenDis7.java b/examples/src/SimkitOpenDis7Examples/SimpleServerOpenDis7.java new file mode 100644 index 0000000000000000000000000000000000000000..de9824ebc3f69956b8d6467020b886b1d1fe5e9e --- /dev/null +++ b/examples/src/SimkitOpenDis7Examples/SimpleServerOpenDis7.java @@ -0,0 +1,203 @@ +package SimkitOpenDis7Examples; + +import edu.nps.moves.dis7.enumerations.DisPduType; +import edu.nps.moves.dis7.pdus.EntityStatePdu; +import edu.nps.moves.dis7.utilities.DisChannel; +import edu.nps.moves.dis7.utilities.PduFactory; +import simkit.Priority; +import simkit.SimEntityBase; +import simkit.random.RandomVariate; + +/** + * Simple Server component. Instances of this class cannot be used on their own, + * but require another SimEntity to schedule Arrival events. If it is desired to + * listen to an event of another name,use an Adapter instance. + * + * The StartService is schedule with a positive priority, which will ensure it + * will occur ahead of any simultaneously scheduled Arrival events, as long as + * they have the default priority of 0.0. + * + * @author abuss@nps.edu + */ +public class SimpleServerOpenDis7 extends SimEntityBase +{ + // Utility constructor method: initial descriptor and verboseness of disNetworkInterface, pduRecorder + private final DisChannel disChannel = new DisChannel("TwoCraneBerthsOpenDis7", false, true); + + PduFactory pduFactory = new PduFactory(); + EntityStatePdu espduCrane = (EntityStatePdu) pduFactory.createPdu(DisPduType.ENTITY_STATE); + + /** + * Total number of servers + */ + private int totalNumberServers; + + /** + * Generates service times + */ + private RandomVariate serviceTimeGenerator; + + /** + * number of available servers at any time + */ + protected int numberAvailableServers; + + /** + * number in queue at any time + */ + protected int numberInQueue; + + /** + * Number customers served + */ + protected int numberServed; + + /** + * Zero-argument constructor + */ + public SimpleServerOpenDis7() { + } + + /** + * Creates a new instance of SimpleServer with the given parameters + * + * @param totalNumberServers Total number of servers + * @param serviceTimeGenerator Service time generator. Must be RandomVariate + * instance that only generates non-negative values. + */ + public SimpleServerOpenDis7(int totalNumberServers, RandomVariate serviceTimeGenerator) { + setTotalNumberServers(totalNumberServers); + setServiceTimeGenerator(serviceTimeGenerator); + } + + /** + * Set numberAvailable servers to total number servers, numberInQueue to 0, + * numberServed to 0. + */ + @Override + public void reset() { + super.reset(); + numberInQueue = 0; + numberAvailableServers = totalNumberServers; + numberServed = 0; + } + + /** + * Just fires PropertyChange events + */ + public void doRun() { + firePropertyChange("numberInQueue", getNumberInQueue()); + firePropertyChange("numberAvailableServers", getNumberAvailableServers()); + firePropertyChange("numberServed", getNumberServed()); + } + + /** + * Increment number in queue. If a server is available, schedule + * StartService immediately with priority of 1.0 + */ + public void doArrival() { + int oldNumberInQueue = numberInQueue; + numberInQueue = numberInQueue + 1; + firePropertyChange("numberInQueue", oldNumberInQueue, getNumberInQueue()); + if (getNumberAvailableServers() > 0) { + waitDelay("StartService", 0.0, Priority.HIGH); + } + } + + /** + * Decrement numberInQueue and numberAvailableServers Schedule EndService + * after service time delay + */ + public void doStartService() { + int oldNumberInQueue = numberInQueue; + numberInQueue = numberInQueue - 1; + firePropertyChange("numberInQueue", oldNumberInQueue, numberInQueue); + int oldNumberAvailableServers = numberAvailableServers; + numberAvailableServers = numberAvailableServers - 1; + firePropertyChange("numberAvailableServers", oldNumberAvailableServers, numberAvailableServers); + +// double serviceTime = getServiceTimeGenerator().generate(); +// firePropertyChange("serviceTime", serviceTime); + + waitDelay("EndService", serviceTimeGenerator); + + } + + /** + * Increment numberAvailableServers If customers in queue, schedule + * StartService immediately with HIGH priority + */ + public void doEndService() { + int oldNumberAvailableServers = numberAvailableServers; + numberAvailableServers = numberAvailableServers + 1; + firePropertyChange("numberAvailableServers", oldNumberAvailableServers, numberAvailableServers); + + int oldNumberServed = numberServed; + numberServed = numberServed + 1; + firePropertyChange("numberServed", oldNumberServed, numberServed); + + if (getNumberInQueue() > 0) { + waitDelay("StartService", 0.0, Priority.HIGH); + } + } + + /** + * accessor method to get a state variable + * @return the numberAvailableServers + */ + public int getNumberAvailableServers() { + return numberAvailableServers; + } + + /** + * accessor method to get a state variable + * @return the numberInQueue + */ + public int getNumberInQueue() { + return numberInQueue; + } + + /** + * accessor method to set a state variable + * @param totalNumberServers total number of servers + * @throws IllegalArgumentException if totalNumberServers < 0 + */ + public void setTotalNumberServers(int totalNumberServers) { + if (totalNumberServers <= 0) { + throw new IllegalArgumentException("Need positive number of servers: " + totalNumberServers); + } + this.totalNumberServers = totalNumberServers; + } + + /** + * accessor method to get a state variable + * @return the serviceTimeGenerator + */ + public RandomVariate getServiceTimeGenerator() { + return this.serviceTimeGenerator; + } + + /** + * accessor method to set a state variable + * @param serviceTimeGenerator the serviceTimeGenerator to set + */ + public void setServiceTimeGenerator(RandomVariate serviceTimeGenerator) { + this.serviceTimeGenerator = serviceTimeGenerator; + } + + /** + * accessor method to get a state variable + * @return the totalNumberServers + */ + public int getTotalNumberServers() { + return this.totalNumberServers; + } + + /** + * accessor method to get a state variable + * @return the numberServed + */ + public int getNumberServed() { + return this.numberServed; + } +} diff --git a/examples/src/SimkitOpenDis7Examples/TwoCraneBerthsOpenDis7.java b/examples/src/SimkitOpenDis7Examples/TwoCraneBerthsOpenDis7.java index 7314d3e7f5ad735a30fc0a427801a5c520de46d6..6482e6ef272c099d03fa88f81c99008ff8ebeba0 100644 --- a/examples/src/SimkitOpenDis7Examples/TwoCraneBerthsOpenDis7.java +++ b/examples/src/SimkitOpenDis7Examples/TwoCraneBerthsOpenDis7.java @@ -26,7 +26,10 @@ import simkit.SimEntityBase; public class TwoCraneBerthsOpenDis7 extends SimEntityBase { // Utility constructor method: initial descriptor and verboseness of disNetworkInterface, pduRecorder - private final DisChannel disChannel = new DisChannel("TwoCraneBerthsOpenDis7", false, true); + private final DisChannel disChannel = new DisChannel("TwoCraneBerthsOpenDis7", false, true); + + PduFactory pduFactory = new PduFactory(); + EntityStatePdu espduCrane = (EntityStatePdu) pduFactory.createPdu(DisPduType.ENTITY_STATE); /** * Queue of Ships waiting to go into the berth @@ -76,10 +79,10 @@ public class TwoCraneBerthsOpenDis7 extends SimEntityBase /** * Only PropertyChangeEvents */ - public void doRun() { - disChannel.setVerboseComments(true); + public void doRun() + { disChannel.setVerboseComments(true); - // TODO what is happening? not seen in logs... + disChannel.setVerboseDisNetworkInterface(true); firePropertyChange("queue", getQueue()); firePropertyChange("berth", getBerth()); @@ -209,9 +212,6 @@ public class TwoCraneBerthsOpenDis7 extends SimEntityBase waitDelay("EndUnloadingOneCrane", ship.getRemainingUnloadingTime(), ship); } - // can be member variables (for efficiency, move above) or else embdedded within method (move below) - PduFactory pduFactory = new PduFactory(); - EntityStatePdu espduCrane = (EntityStatePdu) pduFactory.createPdu(DisPduType.ENTITY_STATE); /** * Perform crane container unloading operations and send PDUs to report progress @@ -272,7 +272,7 @@ public class TwoCraneBerthsOpenDis7 extends SimEntityBase espduCrane.setEntityLocation(pierDistanceForCraneOffload, 0.0, 0.0); disChannel.sendSinglePdu(disTimeStamp, espduCrane); disChannel.sendCommentPdu(disTimeStamp, VariableRecordType.CARGO, - "Crane at position " + pierDistanceForCraneOffload + "m for offload after " + craneTravelDuration + " seconds"); + "Crane moved to position " + pierDistanceForCraneOffload + "m for offload after " + craneTravelDuration + " seconds"); // 4. repeat until done: Crane rotates, lift container, rotates, lower container for (int containerIndex = 1; containerIndex <= numberContainers; containerIndex++) @@ -281,14 +281,15 @@ public class TwoCraneBerthsOpenDis7 extends SimEntityBase double craneRotationDelay = 90.0 / craneRotationRate; // units analysis: degrees / (degrees/second) = seconds espduCrane.setEntityOrientation(orientationToShip); disChannel.sendSinglePdu(disTimeStamp, espduCrane); - disChannel.sendCommentPdu(disTimeStamp, VariableRecordType.CARGO, "Crane oriented to ship after " + craneRotationDelay + " seconds"); + disChannel.sendCommentPdu(disTimeStamp, VariableRecordType.CARGO, "Crane oriented to ship after " + craneRotationDelay + " seconds" + + " with craneRotationRate=" + craneRotationRate + " degrees/second"); // // 4.b announce next step without further delay, then perform container hookup - disChannel.sendCommentPdu(disTimeStamp, VariableRecordType.CARGO, "Hooking up Container " + containerIndex + " to crane "); // TODO + whichCrane + disChannel.sendCommentPdu(disTimeStamp, VariableRecordType.CARGO, "Hooking up Container " + containerIndex + " to crane has started..."); // TODO + whichCrane disTimeStamp += containerHookupDuration; // disChannel.sendSinglePdu(disTimeStamp, espduCrane); // superfluous, crane hasn't moved - disChannel.sendCommentPdu(disTimeStamp, VariableRecordType.CARGO, "Hooked up: Container " + containerIndex + " to crane " // TODO + whichCrane + disChannel.sendCommentPdu(disTimeStamp, VariableRecordType.CARGO, "Hooked up: Container " + containerIndex + " to crane" // TODO + whichCrane + " after " + craneRotationDelay + " seconds"); // 4.c crane rotates to pier @@ -296,12 +297,12 @@ public class TwoCraneBerthsOpenDis7 extends SimEntityBase espduCrane.setEntityOrientation(orientationToPier); disChannel.sendSinglePdu(disTimeStamp, espduCrane); disChannel.sendCommentPdu(disTimeStamp, VariableRecordType.CARGO, "Crane oriented to pier after " + craneRotationDelay + " seconds" + - " (" + craneRotationRate + " degrees/second)"); + " with craneRotationRate=" + craneRotationRate + " degrees/second"); // 4.d crane unhooks container disTimeStamp += containerDetachDuration; // disChannel.sendSinglePdu(disTimeStamp, espduCrane); // superfluous, crane hasn't moved - disChannel.sendCommentPdu(disTimeStamp, VariableRecordType.CARGO, "Detached: Container " + containerIndex + " on pier" // TODO + whichCrane + disChannel.sendCommentPdu(disTimeStamp, VariableRecordType.CARGO, "Crane detached: Container " + containerIndex + " on pier" // TODO + whichCrane + " after " + containerDetachDuration + " seconds"); // send PDUs accordingly diff --git a/examples/src/SimkitOpenDis7Examples/run/RunSimpleServer.java b/examples/src/SimkitOpenDis7Examples/run/RunSimpleServer.java index 4e7e54a79f1b913c469fb6e54a3eab77178dd890..bcd76af54119b1e7c3c27b9a7b73751762cd2497 100644 --- a/examples/src/SimkitOpenDis7Examples/run/RunSimpleServer.java +++ b/examples/src/SimkitOpenDis7Examples/run/RunSimpleServer.java @@ -36,14 +36,15 @@ public class RunSimpleServer * Run a simple program and compute statistical measurement of results. * @param args the command line arguments */ - public static void main(String args[]) { - String rvName = "Uniform"; + public static void main(String args[]) + { + String rvName = "Uniform"; // TODO is enumeration available? double lower = 0.9; double upper = 2.2; RandomVariate interarrivalTimeGenerator = RandomVariateFactory.getInstance(rvName, lower, upper); ArrivalProcess arrival = new ArrivalProcess(interarrivalTimeGenerator); - rvName = "Gamma"; + rvName = "Gamma"; // TODO is enumeration available? double alpha = 1.7; double beta = 1.8; diff --git a/examples/src/SimkitOpenDis7Examples/run/RunSimpleServerOpenDis7.java b/examples/src/SimkitOpenDis7Examples/run/RunSimpleServerOpenDis7.java index 067cf51b7fb88ab778c4fbb83735758f7a9bc9fc..26dc0a87104c52e1a7938153bb7db41b5cc1c1e9 100644 --- a/examples/src/SimkitOpenDis7Examples/run/RunSimpleServerOpenDis7.java +++ b/examples/src/SimkitOpenDis7Examples/run/RunSimpleServerOpenDis7.java @@ -53,13 +53,13 @@ public class RunSimpleServerOpenDis7 RandomVariate interarrivalTimeGenerator = RandomVariateFactory.getInstance(rvName, lower, upper); ArrivalProcessOpenDis7 arrival = new ArrivalProcessOpenDis7(interarrivalTimeGenerator); - rvName = "Gamma"; + rvName = "Gamma"; // TODO is enumeration available? double alpha = 1.7; double beta = 1.8; RandomVariate serviceTimeGenerator = RandomVariateFactory.getInstance(rvName, alpha, beta); - int numServ = 2; - SimpleServerOpenDis7 server = new SimpleServer(numServ, serviceTimeGenerator); + int numServ = 1; + SimpleServerOpenDis7 server = new SimpleServerOpenDis7(numServ, serviceTimeGenerator); arrival.addSimEventListener(server); SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(); diff --git a/examples/src/SimkitOpenDis7Examples/run/RunSimpleServerOpenDis7Log.txt b/examples/src/SimkitOpenDis7Examples/run/RunSimpleServerOpenDis7Log.txt index 332809acd9c605e73fb10034a271b2f828ff8b2c..fbc63d4c924cd51a326c20e1c97b88cedd2ef3ff 100644 --- a/examples/src/SimkitOpenDis7Examples/run/RunSimpleServerOpenDis7Log.txt +++ b/examples/src/SimkitOpenDis7Examples/run/RunSimpleServerOpenDis7Log.txt @@ -1,20 +1,22 @@ -ant -f C:\\x-nps-gitlab\\NetworkedGraphicsMV3500\\examples -Dnb.internal.action.name=run.single -Djavac.includes=SimkitOpenDis7Examples/run/RunSimpleServerOpenDis7.java -Drun.class=SimkitOpenDis7Examples.run.RunSimpleServerOpenDis7 run-single +ant -f C:\\x3d-nps-gitlab\\NetworkedGraphicsMV3500\\examples -Dnb.internal.action.name=run.single -Djavac.includes=SimkitOpenDis7Examples/run/RunSimpleServerOpenDis7.java -Drun.class=SimkitOpenDis7Examples.run.RunSimpleServerOpenDis7 run-single init: -Deleting: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties +Deleting: C:\x3d-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties deps-jar: -Updating property file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties -Compiling 1 source file to C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\classes +Updating property file: C:\x3d-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties +Compiling 1 source file to C:\x3d-nps-gitlab\NetworkedGraphicsMV3500\examples\build\classes +warning: [options] system modules path not set in conjunction with -source 17 +1 warning compile-single: run-single: -[DisChannel] thisHostName=IT160907-UWALPP -[DisThreadedNetworkInterface] using network interface PANGP Virtual Ethernet Adapter +[DisChannel] thisHostName=IT160907-INFLPP +[DisThreadedNetworkInterface] using network interface Intel(R) Wi-Fi 6E AX210 160MHz [DisThreadedNetworkInterface] datagramSocket.joinGroup address=239.1.2.3 port=3000 isConnected()=false createDatagramSocket() complete. [DisThreadedNetworkInterface] createThreads() receiveThread.isAlive()=true [DisThreadedNetworkInterface] createThreads() sendingThread.isAlive()=true [DisChannel] Network confirmation: address=239.1.2.3 port=3000 [DisChannel] Beginning pdu save to directory ./pduLog -[PduRecorder] Recorder log file open: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog3.dislog -[DisThreadedNetworkInterface] using network interface PANGP Virtual Ethernet Adapter +[PduRecorder] Recorder log file open: C:\x3d-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog22.dislog +[DisThreadedNetworkInterface] using network interface Intel(R) Wi-Fi 6E AX210 160MHz [DisThreadedNetworkInterface] datagramSocket.joinGroup address=239.1.2.3 port=3000 isConnected()=false createDatagramSocket() complete. [DisThreadedNetworkInterface] createThreads() receiveThread.isAlive()=true [DisThreadedNetworkInterface] createThreads() sendingThread.isAlive()=true @@ -23,18 +25,19 @@ run-single: [DisThreadedNetworkInterface DisChannel] [sending 1] DisPduType 22 COMMENT, size 80 bytes) [DisThreadedNetworkInterface DisChannel] [receipt 1] DisPduType 22 COMMENT, size 80 bytes) [DisThreadedNetworkInterface PduRecorder] [receipt 1] DisPduType 22 COMMENT, size 80 bytes) -[DisChannel] *** [CommentPdu narrative sent: OTHER] [ArrivalProcessOpenDis7 initialized] +[DisChannel] *** [CommentPdu OTHER] [ArrivalProcessOpenDis7 initialized] +[DisChannel] thisHostName=IT160907-INFLPP ArrivalProcessOpenDis7.1 interarrivalTimeGenerator = Uniform (0.900, 2.200) -SimpleServer.2 - totalNumberServers = 2 +SimpleServerOpenDis7.2 + totalNumberServers = 1 serviceTimeGenerator = Gamma (1.700, 1.800) Simulation ended at time 100,000.000 -There have been 64,475 arrivals -There have been 64,472 customers served -Average number in queue 15.9655 -Average utilization 0.9819 +There have been 64,526 arrivals +There have been 32,790 customers served +Average number in queue 15912.7375 +Average utilization 1.0000 Execution complete. *** setKillSentinelAndInterrupts() killed=true sendingThread.isInterrupted()=true receiveThread.isInterrupted()=true [DisThreadedNetworkInterface PduRecorder] close(): pdus2send.size()=0 baos.size()=0 dos.size()=0 @@ -43,5 +46,11 @@ Execution complete. *** killThread() status: receiveThread.isAlive()=false receiveThread.isInterrupted()=true *** Thread close status: sendingThread.isAlive()=false receiveThread.isAlive()=false -PduRecorder.stop() closing recorder log file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog3.dislog -BUILD SUCCESSFUL (total time: 5 seconds) +PduRecorder.stop() closing recorder log file: C:\x3d-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog22.dislog +*** setKillSentinelAndInterrupts() killed=true sendingThread.isInterrupted()=true receiveThread.isInterrupted()=true +[DisThreadedNetworkInterface DisChannel] close(): pdus2send.size()=0 baos.size()=0 dos.size()=80 +[DisThreadedNetworkInterface DisChannel] datagramSocket.leaveGroup address=239.1.2.3 port=3000 isClosed()=true close() complete. +*** killThread() status: sendingThread.isAlive()=false sendingThread.isInterrupted()=true +*** killThread() status: receiveThread.isAlive()=false receiveThread.isInterrupted()=true +*** Thread close status: sendingThread.isAlive()=false receiveThread.isAlive()=false +BUILD SUCCESSFUL (total time: 10 seconds) diff --git a/examples/src/SimkitOpenDis7Examples/run/RunTwoCraneBerthsLog.txt b/examples/src/SimkitOpenDis7Examples/run/RunTwoCraneBerthsLog.txt index 31c40868a738be9268bd0a2394e3d9a68568b272..437f9dc4c5a5f926fc48a85f663a0e8f0313d76e 100644 --- a/examples/src/SimkitOpenDis7Examples/run/RunTwoCraneBerthsLog.txt +++ b/examples/src/SimkitOpenDis7Examples/run/RunTwoCraneBerthsLog.txt @@ -1,9 +1,11 @@ -ant -f C:\\x-nps-gitlab\\NetworkedGraphicsMV3500\\examples -Dnb.internal.action.name=run.single -Djavac.includes=SimkitOpenDis7Examples/run/RunTwoCranesBerth.java -Drun.class=SimkitOpenDis7Examples.run.RunTwoCranesBerth run-single +ant -f C:\\x3d-nps-gitlab\\NetworkedGraphicsMV3500\\examples -Dnb.internal.action.name=run.single -Djavac.includes=SimkitOpenDis7Examples/run/RunTwoCraneBerths.java -Drun.class=SimkitOpenDis7Examples.run.RunTwoCraneBerths run-single init: -Deleting: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties +Deleting: C:\x3d-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties deps-jar: -Updating property file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties -Compiling 1 source file to C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\classes +Updating property file: C:\x3d-nps-gitlab\NetworkedGraphicsMV3500\examples\build\built-jar.properties +Compiling 1 source file to C:\x3d-nps-gitlab\NetworkedGraphicsMV3500\examples\build\classes +warning: [options] system modules path not set in conjunction with -source 17 +1 warning compile-single: run-single: ShipArrivalProcess.1 @@ -20,4 +22,4 @@ Average # in queue: 0.6834 Average # busy berths: 1.1737 Average time in system: 1.3207 Average delay in queue: 0.4857 -BUILD SUCCESSFUL (total time: 3 seconds) +BUILD SUCCESSFUL (total time: 6 seconds) diff --git a/examples/src/SimkitOpenDis7Examples/run/RunTwoCraneBerthsOpenDis7Log.txt b/examples/src/SimkitOpenDis7Examples/run/RunTwoCraneBerthsOpenDis7Log.txt index aba711da01084e011e06b8f5942e90fb9a725c2e..84d6808b7f615e7a8ce352220840024de2503fd3 100644 Binary files a/examples/src/SimkitOpenDis7Examples/run/RunTwoCraneBerthsOpenDis7Log.txt and b/examples/src/SimkitOpenDis7Examples/run/RunTwoCraneBerthsOpenDis7Log.txt differ diff --git a/examples/src/SimkitOpenDis7Examples/run/RunTwoCranesBerth.java b/examples/src/SimkitOpenDis7Examples/run/RunTwoCranesBerth.java deleted file mode 100644 index ba18b328370c4e2751306f05a6dcd01e19e73e79..0000000000000000000000000000000000000000 --- a/examples/src/SimkitOpenDis7Examples/run/RunTwoCranesBerth.java +++ /dev/null @@ -1,92 +0,0 @@ -package SimkitOpenDis7Examples.run; - -import SimkitOpenDis7Examples.ShipArrivalProcess; -import SimkitOpenDis7Examples.TwoCraneBerths; -import simkit.Schedule; -import simkit.random.RandomVariate; -import simkit.random.RandomVariateFactory; -import simkit.stat.CollectionSizeTimeVaryingStats; -import simkit.stat.SimpleStatsTally; - -/** - * Run simple two-berth model for 10 years (3650 days). - * <h2>Output:</h2><pre> -ShipArrivalProcess.1 - unloadTimeGenerator = Uniform (0.500, 1.500) - interarrivalTimeGenerator = Exponential (0.700) -TwoCraneBerths.2 - -Simulation ended at time 3,650.0 - -Number of ships arriving: 5,135 -Number of ships unloaded: 5,129 -Maximum # in queue: 11 -Average # in queue: 0.6834 -Average # busy berths: 1.1737 -Average time in system: 1.3207 -Average delay in queue: 0.4857 -</pre> -* - * @author abuss@nps.edu - */ -public class RunTwoCranesBerth -{ - /** Default constructor */ - public RunTwoCranesBerth() - { - // default constructor - } - /** - * Run a simple program and compute statistical measurement of results. - * @param args the command line arguments - */ - public static void main(String[] args) { - RandomVariate interarrivalTimeGenerator = - RandomVariateFactory.getInstance("Exponential", 0.7); - RandomVariate unloadingTimeGenerator = - RandomVariateFactory.getInstance("Uniform", 0.5, 1.5); - ShipArrivalProcess shipArrivalProcess = - new ShipArrivalProcess(interarrivalTimeGenerator, - unloadingTimeGenerator); - - TwoCraneBerths twoCraneBerths = new TwoCraneBerths(); - shipArrivalProcess.addSimEventListener(twoCraneBerths); - - SimpleStatsTally delayInQueueStat = new SimpleStatsTally("delayInQueue"); - SimpleStatsTally timeInSystemStat = new SimpleStatsTally("timeInSystem"); - CollectionSizeTimeVaryingStats numberInQueueStat = - new CollectionSizeTimeVaryingStats("queue"); - CollectionSizeTimeVaryingStats numberInBerthStat = - new CollectionSizeTimeVaryingStats("berth"); -// SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(); -// twoCraneBerths.addPropertyChangeListener(simplePropertyDumper); - - twoCraneBerths.addPropertyChangeListener(delayInQueueStat); - twoCraneBerths.addPropertyChangeListener(timeInSystemStat); - twoCraneBerths.addPropertyChangeListener(numberInQueueStat); - twoCraneBerths.addPropertyChangeListener(numberInBerthStat); - - System.out.println(shipArrivalProcess); - System.out.println(twoCraneBerths); - - double stopTime = 10 * 365; - Schedule.stopAtTime(stopTime); - Schedule.setVerbose(false); - - Schedule.reset(); - Schedule.startSimulation(); - - System.out.printf("%nSimulation ended at time %,.1f%n%n", - Schedule.getSimTime()); - - System.out.printf("Number of ships arriving:\t%,d%n", shipArrivalProcess.getNumberArrivals()); - System.out.printf("Number of ships unloaded:\t%,d%n", timeInSystemStat.getCount()); - System.out.printf("Maximum # in queue:\t\t%.0f%n", numberInQueueStat.getMaxObs()); - System.out.printf("Average # in queue:\t\t%.4f%n", numberInQueueStat.getMean()); - System.out.printf("Average # busy berths:\t\t%.4f%n", numberInBerthStat.getMean()); - System.out.printf("Average time in system:\t\t%.4f%n", - timeInSystemStat.getMean()); - System.out.printf("Average delay in queue:\t\t%.4f%n", - delayInQueueStat.getMean()); } - -}