Skip to content
Snippets Groups Projects
Commit d2bed601 authored by thomascecil's avatar thomascecil
Browse files

HW 3 submit.

parent 509f7863
No related branches found
No related tags found
No related merge requests found
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package MV3500Cohort2023MarchJune.homework3.Cecil;
import simkit.SimEntityBase;
import simkit.random.RandomVariate;
/**
* Specifies the cumulative number of arrivals with times between arrivals
* (deterministic or random).
* @author thomascecil
*/
public class ArrivalProcess extends SimEntityBase {
private RandomVariate interarrivalTimeGenerator;
protected int numberArrivals;
/**
* Constructor for the arrival process setting the interarrivalTimeGenerator.
* @param interarrivalTimeGenerator
*/
public ArrivalProcess(RandomVariate interarrivalTimeGenerator) {
this.setInterarrivalTimeGenerator(interarrivalTimeGenerator);
}
/**
* Constructs the arrival process.
*/
public ArrivalProcess() { }
/**
* Getter for the InterarrivalTimeGenerator.
* @return
*/
public RandomVariate getInterarrivalTimeGenerator() {
return interarrivalTimeGenerator;
}
/**
* Setter for the interarrivalTimeGenerator.
* @param interarrivalTimeGenerator
*/
public void setInterarrivalTimeGenerator(RandomVariate interarrivalTimeGenerator) {
this.interarrivalTimeGenerator = interarrivalTimeGenerator;
}
/**
* Getter for the number of arrivals.
* @return
*/
public int getNumberArrivals() {
return this.numberArrivals;
}
/**
* Sets all state variables to their initial values.
*/
@Override
public void reset() {
super.reset();
numberArrivals = 0;
}
/**
* Fires a property change then schedules the first event, a run event.
*/
public void doRun() {
firePropertyChange("numberArrivals", getNumberArrivals());
waitDelay("Arrival", interarrivalTimeGenerator);
}
/**
* Saves the old value for numberArrivals and passes it to firePropertyChange
* and updates time-varying state variables.
*/
public void doArrival() {
int oldNumberArrivals = getNumberArrivals();
numberArrivals = numberArrivals + 1;
firePropertyChange("numberArrivals", oldNumberArrivals,
getNumberArrivals());
waitDelay("Arrival", interarrivalTimeGenerator);
}
}
......@@ -16,6 +16,11 @@ 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 inheritable class is to provide an easily modifiable
* example simulation program that includes DIS-capable entities performing
* tasks of interest, and then reporting activity via PDUs to the network.
......@@ -37,13 +42,13 @@ public class ExampleSimulationProgram
protected PduFactory pduFactory;
/** seconds per loop for real-time or simulation execution */
private double simulationTimeStepDuration = 1.0; // seconds TODO encapsulate
private double simulationTimeStepDuration = 0.2; // seconds TODO encapsulate
/** initial simulation time in seconds */
double simulationTimeInitial = 0.0;
/** current simulation time in seconds */
double simulationTimeSeconds = simulationTimeInitial;
/** Maximum number of simulation loops */
int MAX_LOOP_COUNT = 4;
int MAX_LOOP_COUNT = 10;
String narrativeMessage1 = new String();
String narrativeMessage2 = new String();
......@@ -215,7 +220,26 @@ public class ExampleSimulationProgram
// =============================================================================================
// * your own simulation code starts here! *****************************************************
// =============================================================================================
RandomVariate interarrivalTimeGenerator = RandomVariateFactory.getInstance(
"Exponential", 3.2);
ArrivalProcess arrivalProcess = new ArrivalProcess(interarrivalTimeGenerator);
// Event listener for changes in numberArrivals
SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper();
arrivalProcess.addPropertyChangeListener(simplePropertyDumper);
System.out.println(arrivalProcess);
Schedule.stopAtTime(15.0);
Schedule.setVerbose(true);
// Initializes state variables and starts simulation
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
......
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