diff --git a/examples/src/SimkitExamples/ArrivalProcess.java b/examples/src/SimkitExamples/ArrivalProcess.java new file mode 100644 index 0000000000000000000000000000000000000000..b9511b71fceba0c54428457580d3715efc17b8d3 --- /dev/null +++ b/examples/src/SimkitExamples/ArrivalProcess.java @@ -0,0 +1,94 @@ +package SimkitExamples; + +import simkit.SimEntityBase; +import simkit.random.RandomVariate; + +/** + * One of the simplest non-trivial Event Graph models. A series of Arrival + * events is scheduled based on an inter arrival time random variate. The state + * variable, simply counts the number of these arrivals. + * + * @author ahbuss + */ +public class ArrivalProcess extends SimEntityBase { + + /** + * Generates interarrival times + */ + private RandomVariate interarrivalTimeGenerator; + + /** + * State variable that counts the number of Arrival events + */ + protected int numberArrivals; + + /** + * Instantiate an ArrivalProcess with the given interarrivalTimeGenerator + * + * @param interarrivalTimeGenerator Given RandomVariate for interarrival + * times + */ + public ArrivalProcess(RandomVariate interarrivalTimeGenerator) { + this.setInterarrivalTimeGenerator(interarrivalTimeGenerator); + } + + /** + * If the ArrivalProcess is instantiated using the zero-argument + * constructor, be sure the set the interarrivalTimeGenerator with an + * explicit call to its setter method. + */ + public ArrivalProcess() { + } + + /** + * Initialize numberArrivals to 0 + */ + public void reset() { + super.reset(); + numberArrivals = 0; + } + + /** + * Schedule the first Arrival event with delay generated by + * interarrivalTimeGenerator + */ + public void doRun() { + firePropertyChange("numberArrivals", getNumberArrivals()); + + waitDelay("Arrival", interarrivalTimeGenerator); + } + + /** + * Increment numberArrivals<br> + * Schedule next Arrival event with delay generated by + * interarrivalTimeGenerator + */ + public void doArrival() { + int oldNumberArrivals = getNumberArrivals(); + numberArrivals += 1; + firePropertyChange("numberArrivals", oldNumberArrivals, getNumberArrivals()); + + waitDelay("Arrival", interarrivalTimeGenerator); + } + + /** + * @return the interarrivalTimeGenerator + */ + public RandomVariate getInterarrivalTimeGenerator() { + return interarrivalTimeGenerator; + } + + /** + * @param interarrivalTimeGenerator the interarrivalTimeGenerator to set + */ + public void setInterarrivalTimeGenerator(RandomVariate interarrivalTimeGenerator) { + this.interarrivalTimeGenerator = interarrivalTimeGenerator; + } + + /** + * @return the numberArrivals + */ + public int getNumberArrivals() { + return numberArrivals; + } +} diff --git a/examples/src/SimkitExamples/README.md b/examples/src/SimkitExamples/README.md new file mode 100644 index 0000000000000000000000000000000000000000..367551f01de57b1b5e902b7607f4dcaf5c86b7ed --- /dev/null +++ b/examples/src/SimkitExamples/README.md @@ -0,0 +1,28 @@ +# Simkit DIS Examples + +This directory includes simple Simkit programs which are getting modified to +utilize opendis7-java libraries for PDU output. + +## Design Goals + +* Orient DIS code to share state changes from Simkit entities. +* Establish reference examples with corresponding output logs for test confirmation. +* Build interoperability mechanisms for distributed simulation in MOVES. + +## References + +* https://github.com/ahbuss/Simkit +* https://gitlab.nps.edu/abuss/MV3302ClassCode + +## SimkitExamples + +a. SimpleServer + * [SimpleServer.java](SimpleServer.java) + * [run.RunSimpleServer.java](run/RunSimpleServer.java) + +b. Two Crane Berths + * [ArrivalProcess.java](ArrivalProcess.java) + * [Ship.java](Ship.java) + * [ShipArrivalProcess.java](ShipArrivalProcess.java) + * [TwoCraneBerths.java](TwoCraneBerths.java) + * [run.RunTwoCranesBerth.java](run/RunTwoCranesBerth.java) diff --git a/examples/src/SimkitExamples/Ship.java b/examples/src/SimkitExamples/Ship.java new file mode 100644 index 0000000000000000000000000000000000000000..6f7d8becb24a86d0401867ac10aec3bb9fe933ce --- /dev/null +++ b/examples/src/SimkitExamples/Ship.java @@ -0,0 +1,51 @@ +package SimkitExamples; + +import simkit.Entity; + +/** + * @author ahbuss + */ +public class Ship extends Entity { + + /** + * Remaining time to unload ship at unit rate + */ + protected double remainingUnloadingTime; + + /** + * + * @throws IllegalArgumentException if remainingUnloadingTime ≤ 0.0 + * @param remainingUnloadingTime Given initial unloading time + */ + public Ship(double remainingUnloadingTime) { + super("Ship"); + if (remainingUnloadingTime <= 0.0) { + throw new IllegalArgumentException( + "remainingUnloadingTime must be > 0.0: " + + remainingUnloadingTime); + } + this.remainingUnloadingTime = remainingUnloadingTime; + } + + /** + * Decrement remainingUnloadingTime by the elapsed time at the given rate + * + * @param rate Given rate of unloading + */ + public void work(double rate) { + remainingUnloadingTime -= getElapsedTime() * rate; + } + + /** + * + * @return The remainingUnloadingTime + */ + public double getRemainingUnloadingTime() { + return remainingUnloadingTime; + } + + @Override + public String toString() { + return super.toString() + String.format(" %.3f", getRemainingUnloadingTime()); + } +} diff --git a/examples/src/SimkitExamples/ShipArrivalProcess.java b/examples/src/SimkitExamples/ShipArrivalProcess.java new file mode 100644 index 0000000000000000000000000000000000000000..65af487fa3eb169f5c63b44a50eb5eb3b9a98fc3 --- /dev/null +++ b/examples/src/SimkitExamples/ShipArrivalProcess.java @@ -0,0 +1,59 @@ +package SimkitExamples; + +import simkit.random.RandomVariate; + +/** + * @author ahbuss + */ +public class ShipArrivalProcess extends ArrivalProcess { + + /** + * Generates the initial unloading times for the Ships + */ + private RandomVariate unloadTimeGenerator; + + /** + * Zero-argument constructor + */ + public ShipArrivalProcess() { + } + + /** + * + * @param interarrivalTimeGenerator Given generator for interarrival times + * @param unloadTimeGenerator Given generator for total unloading times + */ + public ShipArrivalProcess( + RandomVariate interarrivalTimeGenerator, + RandomVariate unloadTimeGenerator) { + this(); + this.setInterarrivalTimeGenerator(interarrivalTimeGenerator); + this.setUnloadTimeGenerator(unloadTimeGenerator); + } + + /** + * Instantiate a new Ship and Schedule Arrival(Ship) + */ + @Override + public void doArrival() { + super.doArrival(); + Ship ship = new Ship(unloadTimeGenerator.generate()); + waitDelay("Arrival", 0.0, ship); + } + + /** + * @return the unloadTimeGenerator + */ + public RandomVariate getUnloadTimeGenerator() { + return unloadTimeGenerator; + } + + /** + * @param unloadTimeGenerator the unloadTimeGenerator to set + */ + public void setUnloadTimeGenerator(RandomVariate unloadTimeGenerator) { + this.unloadTimeGenerator = unloadTimeGenerator; + } + + +} diff --git a/examples/src/SimkitExamples/SimpleServer.java b/examples/src/SimkitExamples/SimpleServer.java new file mode 100644 index 0000000000000000000000000000000000000000..a5c30c85740a893f8dd28733168660dd8cef2e70 --- /dev/null +++ b/examples/src/SimkitExamples/SimpleServer.java @@ -0,0 +1,191 @@ +package SimkitExamples; + +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 ahbuss + */ +public class SimpleServer extends SimEntityBase { + + /** + * 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 SimpleServer() { + } + + /** + * 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 SimpleServer(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); + } + } + + /** + * + * @return the numberAvailableServers + */ + public int getNumberAvailableServers() { + return numberAvailableServers; + } + + /** + * + * @return the numberInQueue + */ + public int getNumberInQueue() { + return numberInQueue; + } + + /** + * + * @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; + } + + /** + * @return the serviceTimeGenerator + */ + public RandomVariate getServiceTimeGenerator() { + return this.serviceTimeGenerator; + } + + /** + * @param serviceTimeGenerator the serviceTimeGenerator to set + */ + public void setServiceTimeGenerator(RandomVariate serviceTimeGenerator) { + this.serviceTimeGenerator = serviceTimeGenerator; + } + + /** + * + * @return the totalNumberServers + */ + public int getTotalNumberServers() { + return this.totalNumberServers; + } + + /** + * + * @return the numberServed + */ + public int getNumberServed() { + return this.numberServed; + } +} diff --git a/examples/src/SimkitExamples/TwoCraneBerths.java b/examples/src/SimkitExamples/TwoCraneBerths.java new file mode 100644 index 0000000000000000000000000000000000000000..3e07e91ed9347f366f0ffd3495b031883b1b4b4e --- /dev/null +++ b/examples/src/SimkitExamples/TwoCraneBerths.java @@ -0,0 +1,242 @@ +package SimkitExamples; + +import java.util.SortedSet; +import java.util.TreeSet; +import simkit.Priority; +import simkit.SimEntityBase; + +/** + * @author ahbuss + */ +public class TwoCraneBerths extends SimEntityBase { + + /** + * Queue of Ships waiting to go into the berth + */ + protected SortedSet<Ship> queue; + + /** + * Contains 0, 1, or two Ships being unloaded + */ + protected SortedSet<Ship> berth; + + /** + * Time in the system for each Ship + */ + protected double timeInSystem; + + /** + * Delay in the queue for each Ship + */ + protected double delayInQueue; + + /** + * Instantiate queue and berth containers + */ + public TwoCraneBerths() { + this.queue = new TreeSet<>(); + this.berth = new TreeSet<>(); + } + + /** + * Clear queue and berth containers + */ + @Override + public void reset() { + super.reset(); + queue.clear(); + berth.clear(); + timeInSystem = Double.NaN; + delayInQueue = Double.NaN; + } + + /** + * Only PropertyChangeEvents + */ + public void doRun() { + firePropertyChange("queue", getQueue()); + firePropertyChange("berth", getBerth()); + firePropertyChange("timeInSystem", getTimeInSystem()); + firePropertyChange("delayInQueue", getDelayInQueue()); + } + + /** + * Add the given Ship to queue<br> + * If berths is empty, schedule StartUnloadingTwoCranes<br> + * If berths has 1 Ship, schedule SwitchToOneCrane + * + * @param ship Given Ship arriving to harbor + */ + public void doArrival(Ship ship) { + + ship.stampTime(); + + SortedSet<Ship> oldQueue = getQueue(); + queue.add(ship); + firePropertyChange("queue", oldQueue, getQueue()); + + if (berth.isEmpty()) { + waitDelay("StartUnloadingTwoCranes", 0.0, Priority.HIGH); + } + + if (berth.size() == 1) { + waitDelay("SwitchToOneCrane", 0.0); + } + } + + /** + * Remove the first Ship from queue<br> + * DelayInQueue is elapsedTime of that Ship<br> + * Add the ship to berth container<br> + * Schedule EndUnloadingTwoCranes at half the remaining time + */ + public void doStartUnloadingTwoCranes() { + SortedSet<Ship> oldQueue = getQueue(); + Ship ship = queue.first(); + queue.remove(ship); + firePropertyChange("queue", oldQueue, getQueue()); + + delayInQueue = ship.getElapsedTime(); + firePropertyChange("delayInQueue", getDelayInQueue()); + + ship.stampTime(); + + SortedSet<Ship> oldBerth = getBerth(); + berth.add(ship); + firePropertyChange("berth", oldBerth, getBerth()); + + waitDelay("EndUnloadingTwoCranes", 0.5 * ship.getRemainingUnloadingTime()); + } + + /** + * Remove the (one) Ship from berth<br> + * TimeInSystem is the age of the Ship + */ + public void doEndUnloadingTwoCranes() { + SortedSet<Ship> oldBerth = getBerth(); + Ship ship = berth.first(); + berth.remove(ship); + firePropertyChange("berth", oldBerth, getBerth()); + + timeInSystem = ship.getAge(); + firePropertyChange("timeInSystem", getTimeInSystem()); + } + + /** + * This event is when a Ship arrives to find only one other Ship being + * unloaded.<br> + * Credit the ship in the berth with work at a rate of 2 (since 2 cranes + * have been unloading it<br> + * Interrupt EndUnloadingTwoCranes<br> + * Schedule EndUnloadingOneCrane with the Ship already in the berth<br> + * Schedule StartUnloadingOneCrane + */ + public void doSwitchToOneCrane() { + Ship ship = berth.first(); + ship.work(2.0); + ship.stampTime(); + + interrupt("EndUnloadingTwoCranes"); + + waitDelay("EndUnloadingOneCrane", ship.getRemainingUnloadingTime(), ship); + + waitDelay("StartUnloadingOneCrane", 0.0, Priority.HIGH); + } + + /** + * Pop the first Ship from the queue<br> + * delayInQueue is elapsedTime (from Arrival event)<br> + * Add that Ship to berth container<br> + * Schedule EndUnloadingOneCrane with that Ship + */ + public void doStartUnloadingOneCrane() { + SortedSet<Ship> oldQueue = getQueue(); + Ship ship = queue.first(); + queue.remove(ship); + firePropertyChange("queue", oldQueue, getQueue()); + + delayInQueue = ship.getElapsedTime(); + firePropertyChange("delayInQueue", getDelayInQueue()); + + ship.stampTime(); + + SortedSet<Ship> oldBerth = getBerth(); + berth.add(ship); + firePropertyChange("berth", oldBerth, getBerth()); + + waitDelay("EndUnloadingOneCrane", ship.getRemainingUnloadingTime(), ship); + } + + /** + * Remove given Ship from berth<br> + * If Ships in queue, schedule StartUnloadingOneCrane<br> + * If queue is empty, schedule SwitchToTwoCranes<br> + * timeInSystem is age of Ship + * + * @param ship Given Ship + */ + public void doEndUnloadingOneCrane(Ship ship) { + SortedSet<Ship> oldBerth = getBerth(); + berth.remove(ship); + firePropertyChange("berth", oldBerth, getBerth()); + + if (queue.size() > 0) { + waitDelay("StartUnloadingOneCrane", 0.0, Priority.HIGH); + } + + if (queue.isEmpty() && berth.size() == 1) { + waitDelay("SwitchToTwoCranes", 0.0); + } + + timeInSystem = ship.getAge(); + firePropertyChange("timeInSystem", getTimeInSystem()); + } + + /** + * Credit the work of the remaining Ship in berth at unit rate<br> + * Interrupt EndUnloadingOneCrane<br> + * Schedule EndUnloadingTwoCranes at double the rate (i.e., half the remaining time) + */ + public void doSwitchToTwoCranes() { + Ship ship = berth.first(); + ship.work(1.0); + ship.stampTime(); + + interrupt("EndUnloadingOneCrane", ship); + + waitDelay("EndUnloadingTwoCranes", + 0.5 * ship.getRemainingUnloadingTime()); + } + + /** + * + * @return Shallow copy of queue + */ + public SortedSet<Ship> getQueue() { + return new TreeSet<>(queue); + } + + /** + * + * @return Shallow copy of berth + */ + public SortedSet<Ship> getBerth() { + return new TreeSet<>(berth); + } + + /** + * + * @return The timeInSystem + */ + public double getTimeInSystem() { + return timeInSystem; + } + + /** + * + * @return The delayInQueue + */ + public double getDelayInQueue() { + return delayInQueue; + } +} diff --git a/examples/src/SimkitExamples/documentation/Discrete Event Simulation Modeling.pdf b/examples/src/SimkitExamples/documentation/Discrete Event Simulation Modeling.pdf new file mode 100644 index 0000000000000000000000000000000000000000..529b1ed191932d95269a4471d6fb0ed5c7ca3995 Binary files /dev/null and b/examples/src/SimkitExamples/documentation/Discrete Event Simulation Modeling.pdf differ diff --git a/examples/src/SimkitExamples/documentation/HarborWithTwoCranes.docx b/examples/src/SimkitExamples/documentation/HarborWithTwoCranes.docx new file mode 100644 index 0000000000000000000000000000000000000000..73271d2d04efcd4250e536d58b18e760f9c36b8d Binary files /dev/null and b/examples/src/SimkitExamples/documentation/HarborWithTwoCranes.docx differ diff --git a/examples/src/SimkitExamples/documentation/SimkitSimpleDiscreteEventSimulationModelForDIS.docx b/examples/src/SimkitExamples/documentation/SimkitSimpleDiscreteEventSimulationModelForDIS.docx new file mode 100644 index 0000000000000000000000000000000000000000..9b53790d0458594f1553db9b99c9cc03bf9b9096 Binary files /dev/null and b/examples/src/SimkitExamples/documentation/SimkitSimpleDiscreteEventSimulationModelForDIS.docx differ diff --git a/examples/src/SimkitExamples/documentation/WrittenAssignment5Solution.docx b/examples/src/SimkitExamples/documentation/WrittenAssignment5Solution.docx new file mode 100644 index 0000000000000000000000000000000000000000..496e068a041c1b3abcbf0f8c24568282c8f72606 Binary files /dev/null and b/examples/src/SimkitExamples/documentation/WrittenAssignment5Solution.docx differ diff --git a/examples/src/SimkitExamples/run/RunSimpleServer.java b/examples/src/SimkitExamples/run/RunSimpleServer.java new file mode 100644 index 0000000000000000000000000000000000000000..9682fd98454e92dd39495475bfbc3860bb86cf5b --- /dev/null +++ b/examples/src/SimkitExamples/run/RunSimpleServer.java @@ -0,0 +1,79 @@ +package SimkitExamples.run; + +import SimkitExamples.ArrivalProcess; +import SimkitExamples.SimpleServer; +import simkit.Schedule; +import simkit.random.RandomVariate; +import simkit.random.RandomVariateFactory; +import simkit.stat.SimpleStatsTimeVarying; +import simkit.util.SimplePropertyDumper; + +/** + * <h2>Output:</h2><pre> + * ArrivalProcess.1 + * interarrivalTimeGenerator = Uniform (0.900, 2.200) + * SimpleServer.2 + * serviceTimeGenerator = Gamma (1.700, 1.800) + * totalNumberServers = 2 + * 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</pre> + * + * @author ahbuss + */ +public class RunSimpleServer { + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + String rvName = "Uniform"; + double lower = 0.9; + double upper = 2.2; + RandomVariate interarrivalTimeGenerator = RandomVariateFactory.getInstance(rvName, lower, upper); + ArrivalProcess arrival = new ArrivalProcess(interarrivalTimeGenerator); + + rvName = "Gamma"; + double alpha = 1.7; + double beta = 1.8; + + RandomVariate serviceTimeGenerator = RandomVariateFactory.getInstance(rvName, alpha, beta); + int numServ = 2; + SimpleServer server = new SimpleServer(numServ, serviceTimeGenerator); + arrival.addSimEventListener(server); + + SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(); +// server.addPropertyChangeListener(simplePropertyDumper); +// arrival.addPropertyChangeListener(simplePropertyDumper); + + SimpleStatsTimeVarying numberInQueueStat = new SimpleStatsTimeVarying("numberInQueue"); + SimpleStatsTimeVarying numberAvailableServersStat = new SimpleStatsTimeVarying("numberAvailableServers"); + + server.addPropertyChangeListener(numberInQueueStat); + server.addPropertyChangeListener(numberAvailableServersStat); + + System.out.println(arrival); + System.out.println(server); + +// Schedule.setVerbose(true); +// Schedule.setSingleStep(false); +// double stopTime = 6.0; + double stopTime = 100000.0; + + Schedule.stopAtTime(stopTime); + + Schedule.reset(); + numberInQueueStat.reset(); + numberAvailableServersStat.reset(); + Schedule.startSimulation(); + + System.out.printf("Simulation ended at time %,.3f%n", Schedule.getSimTime()); + System.out.printf("%nThere have been %,d arrivals%n", arrival.getNumberArrivals()); + System.out.printf("There have been %,d customers served%n", server.getNumberServed()); + System.out.printf("Average number in queue\t%.4f%n", numberInQueueStat.getMean()); + System.out.printf("Average utilization\t%.4f%n", 1.0 - numberAvailableServersStat.getMean() / server.getTotalNumberServers()); + } +} diff --git a/examples/src/SimkitExamples/run/RunSimpleServerLog.txt b/examples/src/SimkitExamples/run/RunSimpleServerLog.txt new file mode 100644 index 0000000000000000000000000000000000000000..f6c7d92d8fb0701969f867ad04fde2de2e827a26 --- /dev/null +++ b/examples/src/SimkitExamples/run/RunSimpleServerLog.txt @@ -0,0 +1,20 @@ +ant -f C:\\x-nps-gitlab\\NetworkedGraphicsMV3500\\examples -Dnb.internal.action.name=run.single -Djavac.includes=SimkitExamples/run/RunSimpleServer.java -Drun.class=SimkitExamples.run.RunSimpleServer run-single +init: +Deleting: C:\x-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 +compile-single: +run-single: +ArrivalProcess.1 + interarrivalTimeGenerator = Uniform (0.900, 2.200) +SimpleServer.2 + totalNumberServers = 2 + 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 +BUILD SUCCESSFUL (total time: 3 seconds) diff --git a/examples/src/SimkitExamples/run/RunTwoCranesBerth.java b/examples/src/SimkitExamples/run/RunTwoCranesBerth.java new file mode 100644 index 0000000000000000000000000000000000000000..db89d731735df18a03edc50591acd9c295270150 --- /dev/null +++ b/examples/src/SimkitExamples/run/RunTwoCranesBerth.java @@ -0,0 +1,86 @@ +package SimkitExamples.run; + +import SimkitExamples.ShipArrivalProcess; +import SimkitExamples.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 ahbuss + */ +public class RunTwoCranesBerth { + + /** + * @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()); } + +} diff --git a/examples/src/SimkitExamples/run/RunTwoCranesBerthLog.txt b/examples/src/SimkitExamples/run/RunTwoCranesBerthLog.txt new file mode 100644 index 0000000000000000000000000000000000000000..4cd1afdaf837bfda5534c0266a3820025ad2a6e3 --- /dev/null +++ b/examples/src/SimkitExamples/run/RunTwoCranesBerthLog.txt @@ -0,0 +1,23 @@ +ant -f C:\\x-nps-gitlab\\NetworkedGraphicsMV3500\\examples -Dnb.internal.action.name=run.single -Djavac.includes=SimkitExamples/run/RunTwoCranesBerth.java -Drun.class=SimkitExamples.run.RunTwoCranesBerth run-single +init: +Deleting: C:\x-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 +compile-single: +run-single: +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 +BUILD SUCCESSFUL (total time: 3 seconds)