diff --git a/assignments/src/MV3500Cohort2023MarchJune/homework3/Hedgcorth/ArrivalProcess.java b/assignments/src/MV3500Cohort2023MarchJune/homework3/Hedgcorth/ArrivalProcess.java new file mode 100644 index 0000000000000000000000000000000000000000..e4b55ab972d226f7cea3bb909b5b1e2526757b6d --- /dev/null +++ b/assignments/src/MV3500Cohort2023MarchJune/homework3/Hedgcorth/ArrivalProcess.java @@ -0,0 +1,97 @@ +package MV3500Cohort2023MarchJune.homework3.Hedgcorth; + +import simkit.SimEntityBase; +import simkit.random.RandomVariate; + +/** + * The ArrivalProcess class represents an arrival process using the + * SimEntityBase from simkit. + * + * @author leahhedgcorth + */ +public class ArrivalProcess extends SimEntityBase { + + // parameter + private RandomVariate interarrivalTimeGenerator; + + // state variable + protected int numberArrivals; + + /** + * The constructor method ArrivalProcess(RandomVariate) sets the + * interarrivalTimeGenerator RandomVariate. + * + * @param interarrivalTimeGenerator + */ + public ArrivalProcess(RandomVariate interarrivalTimeGenerator) { + setInterarrivalTimeGenerator(interarrivalTimeGenerator); + } + + /** + * The constructor method ArrivalProcess() is currently left empty. + * + */ + public ArrivalProcess() { + } + + /** + * The method getInterarrivalTimeGenerator() returns the + * interarrivalTimeGenerator . + * + * @return + */ + public RandomVariate getInterarrivalTimeGenerator() { + return interarrivalTimeGenerator; + } + + /** + * The method setInterarrivalTimeGenerator sets the + * interarrivalTimeGenerator. + * + * @param interarrivalTimeGenerator + */ + public void setInterarrivalTimeGenerator(RandomVariate interarrivalTimeGenerator) { + this.interarrivalTimeGenerator = interarrivalTimeGenerator; + } + + /** + * The method getNumberArrivals returns the numberArrivals. + * + * @return + */ + public int getNumberArrivals() { + return numberArrivals; + } + + /** + * The method reset() sets all state variables to their initial values. + */ + @Override + public void reset() { + super.reset(); + numberArrivals = 0; + } + + /** + * The doRun() method first fires a PropertyChange and then schedules the + * first Arrival event. + */ + public void doRun() { + firePropertyChange("numberArrivals", getNumberArrivals()); + waitDelay("Arrival", interarrivalTimeGenerator); + } + + /** + * The doArrival() method saves the oldNumberArrivals and then passes the it to + * the firePropertyChange method to complete the state transition. It also + * increments numberArrivals by 1. + */ + public void doArrival() { + int oldNumberArrivals = getNumberArrivals(); + numberArrivals = numberArrivals + 1; + firePropertyChange("numberArrivals", oldNumberArrivals, + getNumberArrivals()); + waitDelay("Arrival", interarrivalTimeGenerator); + + } +} diff --git a/assignments/src/MV3500Cohort2023MarchJune/homework3/Hedgcorth/ExampleSimulationProgram.java b/assignments/src/MV3500Cohort2023MarchJune/homework3/Hedgcorth/ExampleSimulationProgram.java index 0fb320fec4ab75f4b0864ff06a6c30a7e5d52d47..4424f6e4a77772a106ddf7fb785abcc2839feda1 100644 --- a/assignments/src/MV3500Cohort2023MarchJune/homework3/Hedgcorth/ExampleSimulationProgram.java +++ b/assignments/src/MV3500Cohort2023MarchJune/homework3/Hedgcorth/ExampleSimulationProgram.java @@ -13,15 +13,22 @@ import edu.nps.moves.dis7.utilities.PduFactory; import java.time.LocalDateTime; import java.util.logging.Level; import java.util.logging.Logger; +import simkit.Schedule; +import simkit.random.RandomVariate; +import simkit.random.RandomVariateFactory; +import simkit.util.SimplePropertyDumper; /** + * The purpose of this program is to provide an easily modifiable example + * simulation program that includes DIS-capable entities doing tasks and + * reporting them to the network. Default settings include PDU recording turned + * on by default. * * @author leahhedgcorth */ public class ExampleSimulationProgram { /* **************************** infrastructure code, modification is seldom needed ************************* */ - private String descriptor = this.getClass().getSimpleName(); /** * DIS channel defined by network address/port combination includes multiple @@ -48,7 +55,7 @@ public class ExampleSimulationProgram { /** * Maximum number of simulation loops */ - int MAX_LOOP_COUNT = 4; + int MAX_LOOP_COUNT = 10; String narrativeMessage1 = new String(); String narrativeMessage2 = new String(); @@ -216,7 +223,7 @@ public class ExampleSimulationProgram { @SuppressWarnings("SleepWhileInLoop") // yes we might do that public void runSimulationLoops() { try { - final int SIMULATION_MAX_LOOP_COUNT = 10; // be deliberate out there! also avoid infinite loops. + final int SIMULATION_MAX_LOOP_COUNT = 20; // be deliberate out there! also avoid infinite loops. int simulationLoopCount = 0; // variable, initialized at 0 boolean simulationComplete = false; // sentinel variable as termination condition, are we done yet? @@ -235,6 +242,23 @@ public class ExampleSimulationProgram { // ============================================================================================= // * your own simulation code starts here! ***************************************************** // ============================================================================================= + + RandomVariate interarrivalTimeGenerator = RandomVariateFactory.getInstance("Exponential", 3.2); + ArrivalProcess arrivalProcess = new ArrivalProcess(interarrivalTimeGenerator); + + SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(); + arrivalProcess.addPropertyChangeListener(simplePropertyDumper); + + System.out.println(arrivalProcess); + + Schedule.stopAtTime(15.0); + Schedule.setVerbose(true); + + Schedule.reset(); + Schedule.startSimulation(); + System.out.println("At time " + Schedule.getSimTime() + " there have been " + arrivalProcess.getNumberArrivals() + " arrivals"); + + // are there any other variables to modify at the beginning of your loop? // are your reading any DIS PDUs from the network? check for them here // compute a track, update an ESPDU, whatever it is that your model is doing... diff --git a/assignments/src/MV3500Cohort2023MarchJune/homework3/Hedgcorth/README.md b/assignments/src/MV3500Cohort2023MarchJune/homework3/Hedgcorth/README.md index fbb12a9a1e345135b7b239319f6aa34e560cfc0f..93941d70567ac94cf37c6dd3bc28fa99a6d13bb8 100644 --- a/assignments/src/MV3500Cohort2023MarchJune/homework3/Hedgcorth/README.md +++ b/assignments/src/MV3500Cohort2023MarchJune/homework3/Hedgcorth/README.md @@ -1 +1,6 @@ This program does something different... + +I changed the MAX_LOOP_COUNT value to 10 and changed SIMULATION_LOOP_COUNT value +to 20. I also added code to run the Arrival Process Simulation program and +output the number of arrivals. + diff --git a/assignments/src/MV3500Cohort2023MarchJune/homework3/Hedgcorth/package-info.java b/assignments/src/MV3500Cohort2023MarchJune/homework3/Hedgcorth/package-info.java index 777b258fd7652d67e6cea6b5da1bfa0c51491417..291e392c4c21d577bb6e3e406bdd97c1932cb8da 100644 --- a/assignments/src/MV3500Cohort2023MarchJune/homework3/Hedgcorth/package-info.java +++ b/assignments/src/MV3500Cohort2023MarchJune/homework3/Hedgcorth/package-info.java @@ -1,5 +1,6 @@ /** * Assignment 3 - Example Simulation Program for MV3500. + * Final project assignments supporting the NPS MOVES MV3500 Networked Graphics course. * * @see <a href="https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/-/tree/master/assignments">networkedGraphicsMV3500 assignments</a> * @see java.lang.Package