Skip to content
Snippets Groups Projects
Commit 3ce4bc9d authored by leahhedgcorth's avatar leahhedgcorth
Browse files

Added code to run the Arrival Process class

parent 3761d77d
No related branches found
No related tags found
No related merge requests found
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);
}
}
...@@ -13,15 +13,22 @@ import edu.nps.moves.dis7.utilities.PduFactory; ...@@ -13,15 +13,22 @@ import edu.nps.moves.dis7.utilities.PduFactory;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; 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 * @author leahhedgcorth
*/ */
public class ExampleSimulationProgram { public class ExampleSimulationProgram {
/* **************************** infrastructure code, modification is seldom needed ************************* */ /* **************************** infrastructure code, modification is seldom needed ************************* */
private String descriptor = this.getClass().getSimpleName(); private String descriptor = this.getClass().getSimpleName();
/** /**
* DIS channel defined by network address/port combination includes multiple * DIS channel defined by network address/port combination includes multiple
...@@ -48,7 +55,7 @@ public class ExampleSimulationProgram { ...@@ -48,7 +55,7 @@ public class ExampleSimulationProgram {
/** /**
* Maximum number of simulation loops * Maximum number of simulation loops
*/ */
int MAX_LOOP_COUNT = 4; int MAX_LOOP_COUNT = 10;
String narrativeMessage1 = new String(); String narrativeMessage1 = new String();
String narrativeMessage2 = new String(); String narrativeMessage2 = new String();
...@@ -216,7 +223,7 @@ public class ExampleSimulationProgram { ...@@ -216,7 +223,7 @@ public class ExampleSimulationProgram {
@SuppressWarnings("SleepWhileInLoop") // yes we might do that @SuppressWarnings("SleepWhileInLoop") // yes we might do that
public void runSimulationLoops() { public void runSimulationLoops() {
try { 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 int simulationLoopCount = 0; // variable, initialized at 0
boolean simulationComplete = false; // sentinel variable as termination condition, are we done yet? boolean simulationComplete = false; // sentinel variable as termination condition, are we done yet?
...@@ -235,6 +242,23 @@ public class ExampleSimulationProgram { ...@@ -235,6 +242,23 @@ public class ExampleSimulationProgram {
// ============================================================================================= // =============================================================================================
// * your own simulation code starts here! ***************************************************** // * 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 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 // 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... // compute a track, update an ESPDU, whatever it is that your model is doing...
......
This program does something different... 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.
/** /**
* Assignment 3 - Example Simulation Program for MV3500. * 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 <a href="https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/-/tree/master/assignments">networkedGraphicsMV3500 assignments</a>
* @see java.lang.Package * @see java.lang.Package
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment