Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • stefan.goericke.gy/NetworkedGraphicsMV3500
  • william.mahan/NetworkedGraphicsMV3500
  • alexander.white/NetworkedGraphicsMV3500
  • kyle.britt/NetworkedGraphicsMV3500
  • christopher.garibay/NetworkedGraphicsMV3500
  • christopher.cannon/NetworkedGraphicsMV3500
  • galoeffe/NetworkedGraphicsMV3500
  • dlcain1/NetworkedGraphicsMV3500
  • jmfurr/NetworkedGraphicsMV3500
  • jrjackso1/NetworkedGraphicsMV3500
  • kjmaroon1/NetworkedGraphicsMV3500
  • cdtacket/NetworkedGraphicsMV3500
12 results
Show changes
Showing
with 1630 additions and 0 deletions
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
*/
package mv3302.run;
import java.awt.geom.Point2D;
import mv3302.SimpleMover;
import mv3302.SimplePathMoverManager;
import mv3302.SimplePatrolMoverManager;
import mv3302.SimpleRandomMoverManager;
import simkit.Schedule;
import simkit.random.RandomVariate;
import simkit.random.RandomVariateFactory;
import simkit.util.SimplePropertyDumper;
/**
*
* @author dansl
*/
public class Assignment6 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Point2D initialLocation = new Point2D.Double(0.0, 250.0);
double maxSpeed = 30.0;
SimpleMover simpleMover = new SimpleMover(initialLocation, maxSpeed);
System.out.println(simpleMover);
Point2D[] path = new Point2D[]{
new Point2D.Double(-200.0, 0.0),
new Point2D.Double(-200.0, 250.0),
new Point2D.Double(200.0, 250.0),
new Point2D.Double(0.0, 250.0)};
SimplePathMoverManager simplePathMoverManager = new SimplePathMoverManager(path, true);
System.out.println(simplePathMoverManager);
Point2D initialLocation2 = new Point2D.Double(0.0, 150.0);
double maxSpeed2 = 40.0;
SimpleMover simpleMover2 = new SimpleMover(initialLocation2, maxSpeed2);
System.out.println(simpleMover2);
Point2D[] path2 = new Point2D[]{
new Point2D.Double(0.0, 300.0),
new Point2D.Double(0.0, -100.0)};
SimplePatrolMoverManager simplePatrolMoverManager = new SimplePatrolMoverManager(path2, true);
System.out.println(simplePatrolMoverManager);
// The coordinate generators
RandomVariate[] coordinateGenerator = new RandomVariate[]{
RandomVariateFactory.getInstance("Uniform", -250.0, 250.0),
RandomVariateFactory.getInstance("Uniform", -100, 300.0)
};
// Note startOnRun is now true
SimpleRandomMoverManager simpleRandomMoverManager = new SimpleRandomMoverManager(coordinateGenerator,
true);
System.out.println(simpleRandomMoverManager);
Point2D initialLocation3 = new Point2D.Double(0.0, 0.0);
double maxSpeed3 = 50.0;
SimpleMover simpleMover3 = new SimpleMover(initialLocation3, maxSpeed3);
System.out.println(simpleMover3);
simpleMover.addSimEventListener(simplePathMoverManager);
simplePathMoverManager.addSimEventListener(simpleMover);
simpleMover.addSimEventListener(simplePatrolMoverManager);
simplePatrolMoverManager.addSimEventListener(simpleMover);
simpleMover.addSimEventListener(simpleRandomMoverManager);
simpleRandomMoverManager.addSimEventListener(simpleMover);
SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper();
simpleMover.addPropertyChangeListener(simplePropertyDumper);
simplePathMoverManager.addPropertyChangeListener(simplePropertyDumper);
Schedule.setVerbose(true);
Schedule.stopAtTime(10.5);
Schedule.reset();
simpleMover.waitDelay("MoveTo", 0.0);
simpleMover.waitDelay("OrderStop", 0.1);
simpleMover.waitDelay("Stop", 0.2);
simplePatrolMoverManager.waitDelay("Stop", 10.0);
simpleRandomMoverManager.waitDelay("Stop", 20.0);
Schedule.startSimulation();
}
}
package mv3302.run;
import java.awt.geom.Point2D;
import java.util.Arrays;
import mv3302.SimpleConstantRateMediator;
import mv3302.SimpleMover;
import mv3302.SimplePathMoverManager;
import mv3302.SimpleReferee;
import mv3302.sensor.SimpleConstantRateSensor;
import simkit.Schedule;
import simkit.random.RandomVariate;
import simkit.random.RandomVariateFactory;
import simkit.smd.Mover;
import simkit.smd.Sensor;
import simkit.util.SimplePropertyDumper;
/**
*
* @author dansl
*/
public class Assignment7ConstantRate1Mover {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
RandomVariate exponentialGenerator = RandomVariateFactory.getInstance("Exponential", .7);
Mover[] targets = new Mover[]{
new SimpleMover(new Point2D.Double(30.0, 40.0), 20.0),
new SimpleMover(new Point2D.Double(0, 0), 20.0)
};
Point2D[] targetPath = new Point2D[]{new Point2D.Double(-30.0, -40.0), new Point2D.Double(60.0, 80.0)};
Point2D[] sensorPath = new Point2D[]{new Point2D.Double(30.0, 40.0)};
SimplePathMoverManager[] targetMoverManager = new SimplePathMoverManager[]{
new SimplePathMoverManager(targetPath, true),
new SimplePathMoverManager(sensorPath, true)
};
Sensor[] sensors = new Sensor[targets.length];
double meanTimeToDetect = 5.0;
sensors[0] = new SimpleConstantRateSensor(targets[0], 30, meanTimeToDetect);
sensors[1] = new SimpleConstantRateSensor(targets[1], 40, meanTimeToDetect);
SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(true);
for (Sensor sensor : sensors) {
sensor.addPropertyChangeListener(simplePropertyDumper);
}
for (int i = 0; i < targets.length; ++i) {
targets[i].addSimEventListener(targetMoverManager[i]);
targetMoverManager[i].addSimEventListener(targets[i]);
}
SimpleReferee simpleReferee = new SimpleReferee(Arrays.asList(sensors),
Arrays.asList(targets));
System.out.println(simpleReferee);
SimpleConstantRateMediator simpleConstantRateMediator = new SimpleConstantRateMediator(exponentialGenerator);
simpleReferee.addSimEventListener(simpleConstantRateMediator);
Schedule.setVerbose(true);
Schedule.reset();
Schedule.startSimulation();
}
}
package mv3302.run;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
import mv3302.SimpleConstantRateMediator;
import mv3302.SimpleMover;
import mv3302.SimplePathMoverManager;
import mv3302.SimpleReferee;
import mv3302.sensor.AbstractSimpleSensor;
import mv3302.sensor.SimpleConstantRateSensor;
import simkit.Schedule;
import simkit.random.RandomVariate;
import simkit.random.RandomVariateFactory;
import simkit.smd.Mover;
import simkit.smd.Sensor;
import simkit.util.SimplePropertyDumper;
/**
*
* @author dansl
*/
public class Assignment7ConstantRate2Movers {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
RandomVariate exponentialGenerator = RandomVariateFactory.getInstance("Exponential", .7);
SimpleMover mover1 = new SimpleMover(new Point2D.Double(-20.0, 0.0), 30.0);
AbstractSimpleSensor sensor1 = new SimpleConstantRateSensor(mover1, 20.0, 5.0);
Point2D[] moverPath1 = new Point2D[]{
new Point2D.Double(100.0, 0.0)
};
SimplePathMoverManager moverManager1 = new SimplePathMoverManager(moverPath1, true);
mover1.addSimEventListener(moverManager1);
moverManager1.addSimEventListener(mover1);
SimpleMover mover2 = new SimpleMover(new Point2D.Double(50.0, 0.0), 40.0);
AbstractSimpleSensor sensor2 = new SimpleConstantRateSensor(mover2, 30.0, 5.0);
Point2D[] moverPath2 = new Point2D[] {
new Point2D.Double(-100.0, 0.0)
};
SimplePathMoverManager moverManager2 = new SimplePathMoverManager(moverPath2, true);
mover2.addSimEventListener(moverManager2);
moverManager2.addSimEventListener(mover2);
SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(true);
mover1.addPropertyChangeListener(simplePropertyDumper);
moverManager1.addPropertyChangeListener(simplePropertyDumper);
sensor1.addPropertyChangeListener(simplePropertyDumper);
mover2.addPropertyChangeListener(simplePropertyDumper);
moverManager2.addPropertyChangeListener(simplePropertyDumper);
sensor2.addPropertyChangeListener(simplePropertyDumper);
List<Mover> targets = new ArrayList<>();
targets.add(mover1);
targets.add(mover2);
List<Sensor> sensors = new ArrayList<>();
sensors.add(sensor1);
sensors.add(sensor2);
SimpleReferee referee = new SimpleReferee(sensors, targets);
SimpleConstantRateMediator mediator1 = new SimpleConstantRateMediator(exponentialGenerator);
referee.addSimEventListener(mediator1);
System.out.println(mover1.paramString());
System.out.println(moverManager1);
System.out.println(sensor1.paramString());
System.out.println(mover2.paramString());
System.out.println(moverManager2);
System.out.println(sensor2.paramString());
System.out.println(referee);
Schedule.setVerbose(true);
Schedule.reset();
Schedule.startSimulation();
}
}
package mv3302.run;
import java.awt.geom.Point2D;
import java.util.Arrays;
import mv3302.SimpleConstantTimeMediator;
import mv3302.SimpleMover;
import mv3302.SimplePathMoverManager;
import mv3302.SimpleReferee;
import mv3302.sensor.SimpleConstantTimeSensor;
import simkit.Schedule;
import simkit.smd.Mover;
import simkit.smd.Sensor;
import simkit.util.SimplePropertyDumper;
/**
*
* @author dansl
*/
public class Assignment7ConstantTime1Mover {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Mover[] targets = new Mover[]{
new SimpleMover(new Point2D.Double(30.0, 40.0), 20.0),
new SimpleMover(new Point2D.Double(0, 0), 20.0)
};
Point2D[] targetPath = new Point2D[]{new Point2D.Double(-30.0, -40.0), new Point2D.Double(60.0, 80.0)};
Point2D[] sensorPath = new Point2D[]{new Point2D.Double(30.0, 40.0)};
SimplePathMoverManager[] targetMoverManager = new SimplePathMoverManager[]{
new SimplePathMoverManager(targetPath, true),
new SimplePathMoverManager(sensorPath, true)
};
Sensor[] sensors = new Sensor[targets.length];
double timeToDetect = 5.0;
sensors[0] = new SimpleConstantTimeSensor(targets[0], 30, timeToDetect);
sensors[1] = new SimpleConstantTimeSensor(targets[1], 40, timeToDetect);
SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(true);
for (Sensor sensor: sensors) {
sensor.addPropertyChangeListener(simplePropertyDumper);
}
for (int i = 0; i < targets.length; ++i) {
targets[i].addSimEventListener(targetMoverManager[i]);
targetMoverManager[i].addSimEventListener(targets[i]);
}
SimpleReferee simpleReferee = new SimpleReferee(Arrays.asList(sensors),
Arrays.asList(targets));
System.out.println(simpleReferee);
SimpleConstantTimeMediator simpleConstantTimeMediator = new SimpleConstantTimeMediator();
simpleReferee.addSimEventListener(simpleConstantTimeMediator);
Schedule.setVerbose(true);
Schedule.reset();
Schedule.startSimulation();
}
}
package mv3302.run;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
import mv3302.SimpleConstantTimeMediator;
import mv3302.SimpleMover;
import mv3302.SimplePathMoverManager;
import mv3302.SimpleReferee;
import mv3302.sensor.AbstractSimpleSensor;
import mv3302.sensor.SimpleConstantTimeSensor;
import simkit.Schedule;
import simkit.smd.Mover;
import simkit.smd.Sensor;
import simkit.util.SimplePropertyDumper;
/**
*
* @author dansl
*/
public class Assignment7ConstantTime2Movers {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
SimpleMover mover1 = new SimpleMover(new Point2D.Double(-20.0, 0.0), 30.0);
AbstractSimpleSensor sensor1 = new SimpleConstantTimeSensor(mover1, 20.0, 5.0);
Point2D[] moverPath1 = new Point2D[]{
new Point2D.Double(100.0, 0.0)
};
SimplePathMoverManager moverManager1 = new SimplePathMoverManager(moverPath1, true);
mover1.addSimEventListener(moverManager1);
moverManager1.addSimEventListener(mover1);
SimpleMover mover2 = new SimpleMover(new Point2D.Double(50.0, 0.0), 40.0);
AbstractSimpleSensor sensor2 = new SimpleConstantTimeSensor(mover2, 30.0, 5.0);
Point2D[] moverPath2 = new Point2D[] {
new Point2D.Double(-100.0, 0.0)
};
SimplePathMoverManager moverManager2 = new SimplePathMoverManager(moverPath2, true);
mover2.addSimEventListener(moverManager2);
moverManager2.addSimEventListener(mover2);
SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(true);
mover1.addPropertyChangeListener(simplePropertyDumper);
moverManager1.addPropertyChangeListener(simplePropertyDumper);
sensor1.addPropertyChangeListener(simplePropertyDumper);
mover2.addPropertyChangeListener(simplePropertyDumper);
moverManager2.addPropertyChangeListener(simplePropertyDumper);
sensor2.addPropertyChangeListener(simplePropertyDumper);
List<Mover> targets = new ArrayList<>();
targets.add(mover1);
targets.add(mover2);
List<Sensor> sensors = new ArrayList<>();
sensors.add(sensor1);
sensors.add(sensor2);
SimpleReferee referee = new SimpleReferee(sensors, targets);
SimpleConstantTimeMediator mediator1 = new SimpleConstantTimeMediator();
referee.addSimEventListener(mediator1);
System.out.println(mover1.paramString());
System.out.println(moverManager1);
System.out.println(sensor1.paramString());
System.out.println(mover2.paramString());
System.out.println(moverManager2);
System.out.println(sensor2.paramString());
System.out.println(referee);
Schedule.setVerbose(true);
Schedule.reset();
Schedule.startSimulation();
}
}
package mv3302.run;
import java.awt.geom.Point2D;
import java.util.Arrays;
import mv3302.SimpleCookieCutterMediator;
import mv3302.SimpleMover;
import mv3302.SimplePathMoverManager;
import mv3302.SimpleReferee;
import mv3302.sensor.SimpleCookieCutterSensor;
import simkit.Schedule;
import simkit.smd.Mover;
import simkit.smd.Sensor;
import simkit.util.SimplePropertyDumper;
/**
*
* @author dansl
*/
public class Assignment7CookieSensor1Mover {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Mover[] targets = new Mover[]{
new SimpleMover(new Point2D.Double(30.0, 40.0), 20.0),
new SimpleMover(new Point2D.Double(0, 0), 20.0)
};
Point2D[] targetPath = new Point2D[]{new Point2D.Double(-30.0, -40.0), new Point2D.Double(60.0, 80.0)};
Point2D[] sensorPath = new Point2D[]{new Point2D.Double(30.0, 40.0)};
SimplePathMoverManager[] targetMoverManager = new SimplePathMoverManager[]{
new SimplePathMoverManager(targetPath, true),
new SimplePathMoverManager(sensorPath, true)
};
Sensor[] sensors = new Sensor[targets.length];
sensors[0] = new SimpleCookieCutterSensor(targets[0], 30);
sensors[1] = new SimpleCookieCutterSensor(targets[1], 40);
SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(true);
for (Sensor sensor: sensors) {
sensor.addPropertyChangeListener(simplePropertyDumper);
}
for (int i = 0; i < targets.length; ++i) {
targets[i].addSimEventListener(targetMoverManager[i]);
targetMoverManager[i].addSimEventListener(targets[i]);
}
SimpleReferee simpleReferee = new SimpleReferee(Arrays.asList(sensors),
Arrays.asList(targets));
System.out.println(simpleReferee);
SimpleCookieCutterMediator simpleCookieCutterMediator = new SimpleCookieCutterMediator();
simpleReferee.addSimEventListener(simpleCookieCutterMediator);
Schedule.setVerbose(true);
Schedule.reset();
Schedule.startSimulation();
}
}
package mv3302.run;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
import mv3302.SimpleCookieCutterMediator;
import mv3302.SimpleMover;
import mv3302.SimplePathMoverManager;
import mv3302.SimpleReferee;
import mv3302.sensor.AbstractSimpleSensor;
import mv3302.sensor.SimpleCookieCutterSensor;
import simkit.Schedule;
import simkit.smd.Mover;
import simkit.smd.Sensor;
import simkit.util.SimplePropertyDumper;
/**
*
* @author dansl
*/
public class Assignment7CookieSensor2Movers {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
SimpleMover mover1 = new SimpleMover(new Point2D.Double(-20.0, 0.0), 30.0);
AbstractSimpleSensor sensor1 = new SimpleCookieCutterSensor(mover1, 20.0);
Point2D[] moverPath1 = new Point2D[]{
new Point2D.Double(100.0, 0.0)
};
SimplePathMoverManager moverManager1 = new SimplePathMoverManager(moverPath1, true);
mover1.addSimEventListener(moverManager1);
moverManager1.addSimEventListener(mover1);
SimpleMover mover2 = new SimpleMover(new Point2D.Double(50.0, 0.0), 40.0);
AbstractSimpleSensor sensor2 = new SimpleCookieCutterSensor(mover2, 30.0);
Point2D[] moverPath2 = new Point2D[] {
new Point2D.Double(-100.0, 0.0)
};
SimplePathMoverManager moverManager2 = new SimplePathMoverManager(moverPath2, true);
mover2.addSimEventListener(moverManager2);
moverManager2.addSimEventListener(mover2);
SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(true);
mover1.addPropertyChangeListener(simplePropertyDumper);
moverManager1.addPropertyChangeListener(simplePropertyDumper);
sensor1.addPropertyChangeListener(simplePropertyDumper);
mover2.addPropertyChangeListener(simplePropertyDumper);
moverManager2.addPropertyChangeListener(simplePropertyDumper);
sensor2.addPropertyChangeListener(simplePropertyDumper);
List<Mover> targets = new ArrayList<>();
targets.add(mover1);
targets.add(mover2);
List<Sensor> sensors = new ArrayList<>();
sensors.add(sensor1);
sensors.add(sensor2);
SimpleReferee referee = new SimpleReferee(sensors, targets);
SimpleCookieCutterMediator mediator1 = new SimpleCookieCutterMediator();
referee.addSimEventListener(mediator1);
System.out.println(mover1.paramString());
System.out.println(moverManager1);
System.out.println(sensor1.paramString());
System.out.println(mover2.paramString());
System.out.println(moverManager2);
System.out.println(sensor2.paramString());
System.out.println(referee);
Schedule.setVerbose(true);
Schedule.reset();
Schedule.startSimulation();
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
*/
package mv3302.run;
import mv3302.ArrivalProcess;
import simkit.Schedule;
import simkit.random.RandomVariateFactory;
import simkit.util.SimplePropertyDumper;
/**
* Class runs and tests methods associated with the functioning of the
* ArrivalProcess class
*
* @author dansl
*/
public class RunArrivalProcess {
/**
* main class starts the program to check functionality
*
* @param args the command line arguments
*/
public static void main(String[] args) {
//hard codes the Exponential value for the time to 3.2
var interarrivalTimeGenerator = RandomVariateFactory.getInstance("Exponential", 3.2);
//Initiates the Arrival Process based on the generated time value
ArrivalProcess arrivalProcess = new ArrivalProcess(interarrivalTimeGenerator);
System.out.println(arrivalProcess);
//Programs the schedule to stop at the 15 second mark
Schedule.stopAtTime(15.0);
Schedule.setVerbose(true);
Schedule.reset();
Schedule.startSimulation();
//Prints finalized counts based on the simulation run time
System.out.println("At time " + Schedule.getSimTime() + " there have been " + arrivalProcess.getNumberArrivals() + " arrivals");
SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper();
arrivalProcess.addPropertyChangeListener(simplePropertyDumper);
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
*/
package mv3302.run;
import mv3302.CustomerArrivalProcess;
import mv3302.ServerWithReneges;
import simkit.Schedule;
import simkit.random.RandomVariate;
import simkit.random.RandomVariateFactory;
import simkit.stat.CollectionSizeTimeVaryingStats;
import simkit.stat.SimpleStatsTally;
import simkit.stat.SimpleStatsTimeVarying;
import simkit.util.SimplePropertyDumper;
/**
* Simple test of ServerWithReneges calculating for Number of Arrivals, Number
* Served, Number Reneges, Percent Reneges Average number in queue, Average
* Utilization, Avg Delay in Queue Served, Avg Delay in Queue Reneged, and Avg
* Time in System
*/
public class RunServerWithReneges {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Instantiate CustomerArrivalProcess
RandomVariate interarrivalTimeGenerator = RandomVariateFactory.getInstance("Exponential", 1.5);
RandomVariate serviceTimeGenerator = RandomVariateFactory.getInstance("Gamma", 2.5, 1.2);
RandomVariate renegeTimeGenerator = RandomVariateFactory.getInstance("Uniform", 4.0, 6.0);
CustomerArrivalProcess renegingCustomerArrivalProcess = new CustomerArrivalProcess(renegeTimeGenerator, interarrivalTimeGenerator, serviceTimeGenerator);
System.out.println(renegingCustomerArrivalProcess);
// Instantiate ServerWithReneges
int totalNumberServers = 2;
ServerWithReneges serverWithReneges = new ServerWithReneges(totalNumberServers, serviceTimeGenerator);
System.out.println(serverWithReneges);
// The ServerWithReneges will "hear" Arrival(Customer) events
renegingCustomerArrivalProcess.addSimEventListener(serverWithReneges);
// This was used for debugging model
SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(true);
// This listener computes time-varying statictics for Collection states
CollectionSizeTimeVaryingStats numberInQueueStat = new CollectionSizeTimeVaryingStats("queue");
serverWithReneges.addPropertyChangeListener(numberInQueueStat);
// Same as SimpleServer model
SimpleStatsTimeVarying numberAvailableServersStat = new SimpleStatsTimeVarying("numberAvailableServers");
serverWithReneges.addPropertyChangeListener(numberAvailableServersStat);
// Tally statistics are computed in the same way by "listening"
SimpleStatsTally timeInSystemStat = new SimpleStatsTally("timeInSystem");
serverWithReneges.addPropertyChangeListener(timeInSystemStat);
SimpleStatsTally delayInQueueServedStat = new SimpleStatsTally("delayInQueueServed");
serverWithReneges.addPropertyChangeListener(delayInQueueServedStat);
SimpleStatsTally delayInQueueRenegedStat = new SimpleStatsTally("delayInQueueReneged");
serverWithReneges.addPropertyChangeListener(delayInQueueRenegedStat);
// Commented out after model debugged
// renegingCustomerArrivalProcess.addPropertyChangeListener(simplePropertyDumper);
// serverWithReneges.addPropertyChangeListener(simplePropertyDumper);
// Was "true" when debugging model
Schedule.setVerbose(false);
// Schedule.stopOnEvent(5, "EndService", Entity.class);
// Run for 100,000 time units
double stopTime = 100000.0;
Schedule.stopAtTime(stopTime);
// Initialized & run
Schedule.reset();
Schedule.startSimulation();
System.out.printf("%nSimulation ended at time %,.2f%n%n", Schedule.getSimTime());
System.out.printf("Number Arrivals: %,d%n", renegingCustomerArrivalProcess.getNumberArrivals());
System.out.printf("Number Served: %,d%n", serverWithReneges.getNumberServed());
System.out.printf("Number Reneges: %,d%n", renegingCustomerArrivalProcess.getNumberArrivals() - serverWithReneges.getNumberServed());
double percentReneges = (double) (renegingCustomerArrivalProcess.getNumberArrivals() - serverWithReneges.getNumberServed()) / renegingCustomerArrivalProcess.getNumberArrivals() * 100.00;
System.out.printf("Percent Reneges: %,.2f%%%n", percentReneges);
System.out.printf("Avg # in Queue: %,.3f%n", numberInQueueStat.getMean());
System.out.printf("Avg Utilization: %,.3f%n%n", numberAvailableServersStat.getMean());
// From directly computing delay in queue, delay in reneged and time in system
System.out.printf("Avg Delay in Queue Served: %,.3f%n", delayInQueueServedStat.getMean());
System.out.printf("Avg Delay in Queue Reneged: %,.3f%n", delayInQueueRenegedStat.getMean());
System.out.printf("Avg Time in System (Served): %,.3f%n", timeInSystemStat.getMean());
}
}
package mv3302.run;
import mv3302.ArrivalProcess;
import mv3302.SimpleServer;
import simkit.Schedule;
import simkit.random.RandomVariate;
import simkit.random.RandomVariateFactory;
import simkit.stat.SimpleStatsTimeVarying;
/**
*
* @author dansl
*/
public class RunSimpleServer {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//Creates a random variate and assigns that value to the interarrival time variable
RandomVariate interarrivalTime = RandomVariateFactory.getInstance("Uniform", 0.9, 2.2);
//Creates an instance variable of the arrival process
ArrivalProcess arrivalProcess = new ArrivalProcess(interarrivalTime);
//Prints out pertinent information about the arrival process in the sim
System.out.println(arrivalProcess);
//Creates a random variate with the following properties
String rvName = "Gamma";
double alpha = 1.7;
double beta = 1.8;
RandomVariate serviceTime = RandomVariateFactory.getInstance(rvName, alpha, beta);
//Creates a simple server with two servers and varying service times
SimpleServer simpleServer = new SimpleServer(2, serviceTime);
//Prints pertinent simple server details
System.out.println(simpleServer);
//Adds a sim event listener on the simple server for changes in the arrival process
arrivalProcess.addSimEventListener(simpleServer);
//Creates statistics tracking stats of pertinent variable changes in the simulation over time
SimpleStatsTimeVarying numberInQueueStat = new SimpleStatsTimeVarying("numberInQueue");
SimpleStatsTimeVarying numberAvailableServersStat = new SimpleStatsTimeVarying("numberAvailableServers");
//Sets statistics objects as listeners to state changes in the simple server
simpleServer.addPropertyChangeListener(numberInQueueStat);
simpleServer.addPropertyChangeListener(numberAvailableServersStat);
//Display each event & the Event List if value is set to true
Schedule.setVerbose(false);
//End at the given simulation time
Schedule.stopAtTime(100000.0);
//Invoke reset() on the Simkit component(s)
Schedule.reset();
//Execute the simulation
Schedule.startSimulation();
//Prints out final simulation statistics by pulling necessary values
System.out.printf("Simulation ended at time %,.3f%n", Schedule.getSimTime());
System.out.printf("%nThere have been %d arrivals%n", arrivalProcess.getNumberArrivals());
System.out.printf("There have been %d customers served%n", simpleServer.getNumberServed());
System.out.printf("Average number in queue\t%.3f%n", numberInQueueStat.getMean());
System.out.printf("Average utilization\t%.3f%n", 1.0 - numberAvailableServersStat.getMean() / simpleServer.getTotalNumberServers());
}
}
package mv3302.run;
import static java.lang.Math.sqrt;
import mv3302.PartArrivalProcess;
import mv3302.TransferLineComponent;
import simkit.Schedule;
import simkit.random.RandomVariate;
import simkit.random.RandomVariateFactory;
import simkit.stat.SimpleStatsTally;
import simkit.stat.StudentT;
import simkit.stat.TruncatingSimpleStatsTally;
/**
* The main class for running steady state analysis.
*
* @author dansl
*/
public class RunSteadyStateAnalysis {
/**
* The main method for executing the steady state analysis.
*
* @param args the command line arguments
*/
public static void main(String args[]) {
// Create a random variate generator for interarrival times with an exponential distribution and mean of 2.5
RandomVariate interarrivalTimeGenerator = RandomVariateFactory.getInstance(
"Exponential", 2.5);
// Create a part arrival process with the interarrival time generator
PartArrivalProcess arrivalProcess = new PartArrivalProcess(interarrivalTimeGenerator);
// Create an array of random variate generators for processing times
RandomVariate[] processingTimeGenerator
= {RandomVariateFactory.getInstance("Exponential", 2.4),
RandomVariateFactory.getInstance("Gamma", 3.2, 3.3),
RandomVariateFactory.getInstance("Uniform", 4.5, 6.7),
RandomVariateFactory.getInstance("Exponential", 3.0)};
// Create an array of total number of workstations
int[] totalNumberWorkstations = new int[4];
totalNumberWorkstations[0] = 1;
totalNumberWorkstations[1] = 5;
totalNumberWorkstations[2] = 4;
totalNumberWorkstations[3] = 2;
// Create a transfer line component with the processing time generators and total number of workstations
TransferLineComponent transferLineComponent = new TransferLineComponent(processingTimeGenerator, totalNumberWorkstations);
// Add the transfer line component as a listener to the arrival process
arrivalProcess.addSimEventListener(transferLineComponent);
int warmup = 1000;
int observations = 10000;
// Create a statistical tally for tracking delay in queue
SimpleStatsTally delayInQueueStat = new TruncatingSimpleStatsTally("delayInQueue", 2000);
// Add the delay in queue stat as a property change listener to the transfer line component
transferLineComponent.addPropertyChangeListener(delayInQueueStat);
System.out.println(arrivalProcess);
System.out.println(transferLineComponent);
// Create a statistical tally for tracking delay in queue in the outer loop
SimpleStatsTally outerDelayInQueueStat = new SimpleStatsTally("outerDelayInQueue");
// Stop the simulation after warmup + observations arrivals
Schedule.stopOnEvent(warmup + observations, "Arrival");
int numberReplications = 50;
double alpha = 0.05;
// Outer loop for multiple replications
System.out.println("Avg Delay In Queue");
for (int replication = 1; replication <= numberReplications; ++replication) {
// Reset the simulation schedule and delay in queue stat for each replication
Schedule.reset();
delayInQueueStat.reset();
Schedule.startSimulation();
// Record the mean delay in queue for the replication in the outer tally
outerDelayInQueueStat.newObservation(delayInQueueStat.getMean());
// Print the replication number, average delay, and confidence interval
System.out.printf("%d %.3f ± %.3f%n",
replication,
outerDelayInQueueStat.getMean(),
outerDelayInQueueStat.getStandardDeviation()
* StudentT.getQuantile(1.0 - 0.5 * alpha, outerDelayInQueueStat.getCount() - 1) / sqrt(outerDelayInQueueStat.getCount())
);
}
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
*/
package mv3302.run;
import mv3302.PartArrivalProcess;
import mv3302.TransferLineComponent;
import simkit.Schedule;
import simkit.random.RandomVariate;
import simkit.random.RandomVariateFactory;
import simkit.stat.MultipleCollectionSizeTimeVarying;
import simkit.stat.MultipleSimpleStatsTally;
import simkit.stat.SimpleStatsTally;
import simkit.util.SimplePropertyDumper;
/**
*
* @author dansl
*/
public class RunTransferLineComponent {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Instantiate PartArrivalProcess
RandomVariate interarrivalTimeGenerator = RandomVariateFactory.getInstance("Exponential", 1.7);
PartArrivalProcess arrivalProcess = new PartArrivalProcess(interarrivalTimeGenerator);
System.out.println(arrivalProcess);
// Instantiate TransferLineComponent
int[] totalNumberMachines = new int[3];
totalNumberMachines[0] = 5;
totalNumberMachines[1] = 4;
totalNumberMachines[2] = 2;
RandomVariate[] processingTimeGenerator = {RandomVariateFactory.getInstance("Gamma", 3.2, 2.3),
RandomVariateFactory.getInstance("Uniform", 4.5, 6.7),
RandomVariateFactory.getInstance("Exponential", 3.0)};
TransferLineComponent transferLineComponent = new TransferLineComponent(processingTimeGenerator, totalNumberMachines);
System.out.println(transferLineComponent);
// The transferLineComponent will "hear" Arrival(part) events
arrivalProcess.addSimEventListener(transferLineComponent);
// This was used for debugging model
// SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(true);
// This listener computes time-varying statistics for multiple Collection states
MultipleCollectionSizeTimeVarying numberInQueueStat
= new MultipleCollectionSizeTimeVarying("queue");
transferLineComponent.addPropertyChangeListener("queue", numberInQueueStat);
MultipleSimpleStatsTally numberAvailableMachinesStat
= new MultipleSimpleStatsTally("numberAvailableMachines");
transferLineComponent.addPropertyChangeListener("numberAvailableMachines", numberAvailableMachinesStat);
// Tally statistics are computed in the same way by "listening"
MultipleSimpleStatsTally timeAtStationStat
= new MultipleSimpleStatsTally("timeAtStation");
transferLineComponent.addPropertyChangeListener("timeAtStation",
timeAtStationStat);
MultipleSimpleStatsTally delayInQueueStat
= new MultipleSimpleStatsTally("delayInQueue");
transferLineComponent.addPropertyChangeListener("delayInQueue",
delayInQueueStat);
SimpleStatsTally totalTimeInSystemStat = new SimpleStatsTally("totalTimeInSystem");
transferLineComponent.addPropertyChangeListener(totalTimeInSystemStat);
SimpleStatsTally totalDelayInQueueStat = new SimpleStatsTally("totalDelayInQueue");
transferLineComponent.addPropertyChangeListener(totalDelayInQueueStat);
// arrivalProcess.addPropertyChangeListener(simplePropertyDumper);
// transferLineComponent.addPropertyChangeListener(simplePropertyDumper);
// Was "true" when debugging model
Schedule.setVerbose(false);
// Run for 500,000 time units
double stopTime = 500000.0;
Schedule.stopAtTime(stopTime);
// Initialized and Run
Schedule.reset();
//Start Running of Simulation
Schedule.startSimulation();
System.out.printf("%nSimulation ended at time %,.2f%n%n", Schedule.getSimTime());
System.out.printf("Number arrivals: %5s%n", arrivalProcess.getNumberArrivals());
System.out.printf("Number Completed: %4s%n%n", totalTimeInSystemStat.getCount());
System.out.printf("%15s%15s%15s%15s%15s%n", "", "Avg", "Avg #", "Avg Delay", "Avg Time");
System.out.printf("%15s%15s%15s%15s%15s%n", "station", "util", "in Queue", "in Queue", "at Station");
double avgNumberInSystem = numberInQueueStat.getMean() + 11
- numberAvailableMachinesStat.getMean();
double arrivalRate = arrivalProcess.getNumberArrivals() / Schedule.getSimTime();
for (int i = 0; i < totalNumberMachines.length; i++) {
double utilization = 1.0 - numberAvailableMachinesStat.getMean(i) / transferLineComponent.getTotalNumberMachines(i);
double avgNumberInQueue = numberInQueueStat.getMean(i);
double avgDelayInQueue = delayInQueueStat.getMean(i);
double avgTimeAtStation = timeAtStationStat.getMean(i);
System.out.printf("%15d%15.4f%15.4f%15.4f%15.4f%n", i, utilization, avgNumberInQueue, avgDelayInQueue, avgTimeAtStation);
}
System.out.println();
System.out.println("Using Little's Formula");
System.out.println();
System.out.printf("%15s%15s%15s%n", "", "Avg Delay", "Avg Time");
System.out.printf("%15s%15s%15s%n", "station", "in Queue", "at Station");
for (int i = 0; i < totalNumberMachines.length; i++) {
double avgNumberInQueue = numberInQueueStat.getMean(i);
double avgDelayInQueue = delayInQueueStat.getMean(i);
double avgTimeAtStation = avgNumberInQueue / arrivalRate;
System.out.printf("%15s%15.4f%15.4f%n", i, avgDelayInQueue, avgTimeAtStation);
}
System.out.println();
System.out.printf("Avg Time in System: %.4f (Using Little: %.4f)%n", totalTimeInSystemStat.getMean() + totalDelayInQueueStat.getMean(),
avgNumberInSystem / arrivalRate);
System.out.printf("Avg total delay in queue: %.4f (Using Little: %.4f)%n", totalDelayInQueueStat.getMean(),
totalDelayInQueueStat.getMean() - transferLineComponent.getTotalTimeInSystem() * ((1.0 - numberAvailableMachinesStat.getMean()) / totalNumberMachines.length));
}
}
package mv3302.run;
import static java.lang.Math.sqrt;
import mv3302.PartArrivalProcess;
import mv3302.StoppedPartArrivalProcess;
import mv3302.TransferLineComponent;
import simkit.Schedule;
import simkit.random.RandomVariate;
import simkit.random.RandomVariateFactory;
import simkit.stat.SimpleStatsTally;
import simkit.stat.StudentT;
/**
*
* @author dansl
*/
public class RunTransientAnalysis {
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
// Create an exponential random variate generator with a mean of 2.5
RandomVariate interarrivalTimeGenerator = RandomVariateFactory.getInstance(
"Exponential", 2.5);
// Define the stop time for the simulation (in minutes)
int stopTime = 480;
// Create a part arrival process using the interarrival time generator
PartArrivalProcess partArrivalProcess = new PartArrivalProcess(interarrivalTimeGenerator);
// Create a stopped part arrival process with the given stop time
StoppedPartArrivalProcess stoppedArrivalProcess = new StoppedPartArrivalProcess(stopTime);
// Create an array of random variate generators for processing times
RandomVariate[] processingTimeGenerator
= {RandomVariateFactory.getInstance("Exponential", 2.4),
RandomVariateFactory.getInstance("Gamma", 3.2, 3.3),
RandomVariateFactory.getInstance("Uniform", 4.5, 6.7),
RandomVariateFactory.getInstance("Exponential", 3.0)};
// Define the total number of workstations for each type of processing time
int[] totalNumberWorkstations = new int[4];
totalNumberWorkstations[0] = 1;
totalNumberWorkstations[1] = 5;
totalNumberWorkstations[2] = 4;
totalNumberWorkstations[3] = 2;
// Create a transfer line component with the processing time generators and workstation numbers
TransferLineComponent transferLineComponent = new TransferLineComponent(processingTimeGenerator, totalNumberWorkstations);
// Add the transfer line component as a listener to the part arrival processes
partArrivalProcess.addSimEventListener(transferLineComponent);
stoppedArrivalProcess.addSimEventListener(transferLineComponent);
// Create a statistics tally for total time in the system
SimpleStatsTally totalTimeInSystemStat = new SimpleStatsTally("totalTimeInSystem");
// Add the statistics tally as a property change listener to the transfer line component
transferLineComponent.addPropertyChangeListener(totalTimeInSystemStat);
System.out.println(partArrivalProcess);
System.out.println(stoppedArrivalProcess);
System.out.println(transferLineComponent);
// Create a statistics tally for outer time in the system
SimpleStatsTally outerTimeInSystemStat = new SimpleStatsTally("outerTimeInSystem");
// Define the confidence level (alpha)
double alpha = 0.05;
// Stop the simulation after 10,000 events with the name "Arrival"
Schedule.stopOnEvent(10000, "Arrival");
System.out.println("Avg Delay In Queue");
// Run the replications
for (int replication = 1; replication <= stopTime; ++replication) {
Schedule.reset();
// Reset the statistics tally for total time in the system
totalTimeInSystemStat.reset();
Schedule.startSimulation();
// Record the outer time in the system using the mean of the total time in the system
outerTimeInSystemStat.newObservation(totalTimeInSystemStat.getMean());
// Print the replication number, mean, and confidence interval
System.out.printf("%d %.3f ± %.3f%n",
replication,
outerTimeInSystemStat.getMean(),
outerTimeInSystemStat.getStandardDeviation()
* StudentT.getQuantile(1.0 - 0.5 * alpha, outerTimeInSystemStat.getCount() - 1) / sqrt(outerTimeInSystemStat.getCount())
);
}
}
}
package mv3302.run;
import java.awt.Color;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
import mv3302.SimpleCookieCutterMediator;
import mv3302.SimpleMover;
import mv3302.SimplePatrolMoverManager;
import mv3302.SimpleReferee;
import mv3302.sensor.AbstractSimpleSensor;
import mv3302.sensor.SimpleCookieCutterSensor;
import simkit.Schedule;
import simkit.animate.SandboxFrame;
import simkit.smd.Mover;
import simkit.smd.Sensor;
import simkit.util.PropertyChangeFrame;
/**
*
* @author ahbuss
*/
public class TestAnimations {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
SimpleMover mover1 = new SimpleMover(new Point2D.Double(-20.0, 0.0), 30.0);
AbstractSimpleSensor sensor1 = new SimpleCookieCutterSensor(mover1, 20.0);
Point2D[] moverPath1 = new Point2D[]{
new Point2D.Double(100.0, 0.0),
mover1.getInitialLocation()
};
SimplePatrolMoverManager moverManager1 = new SimplePatrolMoverManager(moverPath1, true);
mover1.addSimEventListener(moverManager1);
moverManager1.addSimEventListener(mover1);
SimpleMover mover2 = new SimpleMover(new Point2D.Double(50.0, 0.0), 40.0);
AbstractSimpleSensor sensor2 = new SimpleCookieCutterSensor(mover2, 30.0);
Point2D[] moverPath2 = new Point2D[] {
new Point2D.Double(-100.0, 0.0),
mover2.getInitialLocation()
};
SimplePatrolMoverManager moverManager2 = new SimplePatrolMoverManager(moverPath2, true);
mover2.addSimEventListener(moverManager2);
moverManager2.addSimEventListener(mover2);
// PropertyChangeListener propertyChangeFrame = new SimplePropertyDumper(true);
PropertyChangeFrame propertyChangeFrame = new PropertyChangeFrame();
// mover1.addPropertyChangeListener(propertyChangeFrame);
// moverManager1.addPropertyChangeListener(propertyChangeFrame);
sensor1.addPropertyChangeListener("detection", propertyChangeFrame);
sensor1.addPropertyChangeListener("undetection", propertyChangeFrame);
// mover2.addPropertyChangeListener(propertyChangeFrame);
// moverManager2.addPropertyChangeListener(propertyChangeFrame);
sensor2.addPropertyChangeListener("detection", propertyChangeFrame);
sensor2.addPropertyChangeListener("undetection", propertyChangeFrame);
//
List<Mover> targets = new ArrayList<>();
targets.add(mover1);
targets.add(mover2);
List<Sensor> sensors = new ArrayList<>();
sensors.add(sensor1);
sensors.add(sensor2);
SimpleReferee referee = new SimpleReferee(sensors, targets);
SimpleCookieCutterMediator mediator1 = new SimpleCookieCutterMediator();
referee.addSimEventListener(mediator1);
System.out.println(mover1.paramString());
System.out.println(moverManager1);
System.out.println(sensor1.paramString());
System.out.println(mover2.paramString());
System.out.println(moverManager2);
System.out.println(sensor2.paramString());
System.out.println(referee);
Schedule.setVerbose(false);
// Schedule.stopOnEvent(5, "Detection", SimpleMover.class);
SandboxFrame sandboxFrame = new SandboxFrame("Simple Referee");
sandboxFrame.getSandbox().setOrigin(new Point2D.Double(200, 200));
sandboxFrame.getSandbox().setDrawAxes(true);
sandboxFrame.addMover(mover1, Color.BLUE);
sandboxFrame.addSensor(sensor1, Color.RED);
sandboxFrame.addMover(mover2, Color.GREEN);
sandboxFrame.addSensor(sensor2, Color.ORANGE);
sandboxFrame.setVisible(true);
propertyChangeFrame.setLocation(sandboxFrame.getX() + sandboxFrame.getWidth(), sandboxFrame.getY());
propertyChangeFrame.setVisible(true);
Schedule.reset();
Schedule.addIgnoreOnDump("Ping");
// Schedule.startSimulation();
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
*/
package mv3302.run;
import mv3302.ShipArrivalProcess;
import mv3302.TwoCranesBerth;
import simkit.Adapter;
import simkit.Schedule;
import simkit.random.RandomVariate;
import simkit.random.RandomVariateFactory;
import simkit.stat.CollectionSizeTimeVaryingStats;
import simkit.stat.SimpleStatsTally;
/**
* A test class that simulates the arrival and unloading of ships at a two-crane
* berth. It initializes the required objects, listens to the events triggered
* by these objects, and collects statistical data during the simulation.
*
* @author dansl
*/
public class testShipArrivalProcess {
/**
* Runs the simulation of ship arrivals and unloading at a two-crane berth,
* and prints the collected statistical data at the end of the simulation.
*/
public static void main(String[] args) {
RandomVariate interarrivalTimeGenerator = RandomVariateFactory.getInstance("Exponential", .7);
RandomVariate unloadingTimeGenerator = RandomVariateFactory.getInstance("Uniform", 0.5, 1.5);
ShipArrivalProcess shipArrivalProcess = new ShipArrivalProcess(interarrivalTimeGenerator, unloadingTimeGenerator);
System.out.println(shipArrivalProcess);
TwoCranesBerth twoCranesBerth = new TwoCranesBerth();
System.out.println(twoCranesBerth);
// TwoCranesBerth will "hear" ShipArrivalProcess(Arrival) events
shipArrivalProcess.addSimEventListener(twoCranesBerth);
// The twoCranesBerth will "hear" the ShipArrival events of the
// first as Arrival events
Adapter adapter = new Adapter("ShipArrival", "Arrival");
adapter.connect(shipArrivalProcess, twoCranesBerth);
// This was used for debugging model
// SimplePropertyDumper simplePropertyDumper = new SimplePropertyDumper(true);
//
// twoCranesBerth.addPropertyChangeListener(simplePropertyDumper);
// shipArrivalProcess.addPropertyChangeListener(simplePropertyDumper);
// Tally statistics are computed in the same way by "listening"
SimpleStatsTally timeInSystemStat = new SimpleStatsTally("timeInSystem");
twoCranesBerth.addPropertyChangeListener(timeInSystemStat);
SimpleStatsTally delayInQueueStat = new SimpleStatsTally("delayInQueue");
twoCranesBerth.addPropertyChangeListener(delayInQueueStat);
CollectionSizeTimeVaryingStats numberInBerthsStat = new CollectionSizeTimeVaryingStats("berths");
twoCranesBerth.addPropertyChangeListener(numberInBerthsStat);
CollectionSizeTimeVaryingStats numberInQueueStat = new CollectionSizeTimeVaryingStats("queue");
twoCranesBerth.addPropertyChangeListener(numberInQueueStat);
// Was "true" when debugging model
Schedule.setVerbose(false);
double stopTime = 3650.0;
Schedule.stopAtTime(stopTime);
// Initialized & run
Schedule.reset();
Schedule.startSimulation();
System.out.printf("%nSimulation ended at time %,.2f%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", numberInBerthsStat.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());
}
}
package mv3302.sensor;
import java.awt.geom.Point2D;
import java.util.HashSet;
import java.util.Set;
import simkit.SimEntityBase;
import simkit.smd.Mover;
import simkit.smd.Sensor;
/**
* An abstract class representing a simple sensor. It extends the SimEntityBase
* class and implements the Sensor interface. Provides common functionality for
* sensors that detect and track movers. Subclasses need to implement specific
* detection algorithms.
*
* @author dansl
*/
public abstract class AbstractSimpleSensor extends SimEntityBase implements Sensor {
private Mover mover;
private double maxRange;
protected Set<Mover> contacts;
/**
* Constructs a new AbstractSimpleSensor with an empty contacts set.
*/
public AbstractSimpleSensor() {
contacts = new HashSet<>();
}
/**
* Constructs a new AbstractSimpleSensor with the specified mover and
* maximum range. The contacts set is initialized as an empty set.
*
* @param mover the mover associated with the sensor
* @param maxRange the maximum range of the sensor
*/
public AbstractSimpleSensor(Mover mover, double maxRange) {
this();
setMover(mover);
setMaxRange(maxRange);
}
/**
* Resets the sensor to its initial state. Clears the contacts set.
*/
@Override
public void reset() {
super.reset();
contacts.clear();
}
/**
* Runs the sensor and fires a property change event for the contacts set.
*/
public void doRun() {
firePropertyChange("contacts", getContacts());
}
/**
* Performs detection of a target mover. Adds the target mover to the
* contacts set and fires property change events for contacts and detection.
*
* @param target the mover to be detected
*/
public void doDetection(Mover target) {
Set<Mover> oldContacts = getContacts();
contacts.add(target);
firePropertyChange("contacts", oldContacts, getContacts());
firePropertyChange("detection", target);
}
/**
* Removes a target mover from the contacts set. Fires property change
* events for contacts and undetection.
*
* @param target the mover to be undetected
*/
public void doUndetection(Mover target) {
Set<Mover> oldContacts = getContacts();
contacts.remove(target);
firePropertyChange("contacts", oldContacts, getContacts());
firePropertyChange("undetection", target);
}
/**
* Initiates the start move action for the specified mover. Delays the
* action for the current simulation time.
*
* @param mover the mover to start moving
*/
public void doStartMove(Mover mover) {
waitDelay("StartMove", 0.0, this);
}
/**
* Initiates the stop action for the specified mover. Delays the action for
* the current simulation time.
*
* @param mover the mover to stop
*/
public void doStop(Mover mover) {
waitDelay("Stop", 0.0, this);
}
/**
* Initiates the stop action for the specified mover. Delays the action for
* the current simulation time.
*
* @param mover the mover to stop
*/
public void setMover(Mover mover) {
this.mover = mover;
this.mover.addSimEventListener(this);
}
/**
* Returns the maximum range of the sensor.
*
* @return the maxRange
*/
@Override
public double getMaxRange() {
return maxRange;
}
/**
* Sets the maximum range of the sensor.
*
* @param maxRange the maxRange to set
*/
public void setMaxRange(double maxRange) {
if (maxRange < 0.0) {
throw new IllegalArgumentException("maxRange must be ≥ 0.0: " + maxRange);
}
this.maxRange = maxRange;
}
/**
* Sets the contacts of the sensor.
*
* @return the contacts
*/
@Override
public Set<Mover> getContacts() {
return new HashSet<>(contacts);
}
/**
* Returns the mover associated with the sensor.
*
* @return the mover
*/
@Override
public Mover getMover() {
return mover;
}
/**
* Returns current location the mover associated with the sensor.
*
* @return the mover.currentLocation
*/
@Override
public Point2D getCurrentLocation() {
return mover.getCurrentLocation();
}
/**
* Returns velocity of the mover associated with the sensor.
*
* @return the movers velocity
*/
@Override
public Point2D getVelocity() {
return mover.getVelocity();
}
/**
* empty method for implementation
*/
@Override
public void doStartMove(Sensor sensor) {
}
/**
* empty method for implementation
*/
@Override
public void doStop(Sensor sensor) {
}
/**
* Returns a string representation of the AbstractSimpleSensor object. This
* method is overridden from the superclass to provide a customized string
* representation.
*
* @return a string representation of the AbstractSimpleSensor object
*/
public String paramString() {
return super.toString();
}
/**
* Returns a string representation of the AbstractSimpleSensor object. The
* string format includes the name, current location, velocity, and maximum
* range of the sensor.
*
* @return a string representation of the AbstractSimpleSensor object
*/
@Override
public String toString() {
return String.format("%s %s %s %,.4f", getName(), mover.getCurrentLocation(), mover.getVelocity(),
getMaxRange());
}
}
package mv3302.sensor;
import java.awt.geom.Point2D;
import java.util.Set;
import simkit.SimEntity;
import simkit.smd.Mover;
/**
*The Sensor interface represents a sensor entity in a simulation. It extends the SimEntity interface.
A sensor can provide information about its current location, velocity, and maximum range.
It can also start and stop moving, retrieve the mover associated with it, and get a set of contacts.
* @author dansl
*/
interface Sensor extends SimEntity {
public Point2D getCurrentLocation();
public Point2D getVelocity();
public double getMaxRange();
public void doStartMove(Mover mover);
public void doStop(Mover mover);
public Mover getMover();
public Set<Mover> getContacts();
}
package mv3302.sensor;
import simkit.smd.Mover;
/**
* A simple constant rate sensor that detects objects within a maximum range
* based on a mean time to detect. Inherits from AbstractSimpleSensor.
*/
public final class SimpleConstantRateSensor extends AbstractSimpleSensor {
private double meanTimeToDetect;
/**
* Constructs a SimpleConstantRateSensor object with default values.
*/
public SimpleConstantRateSensor() {
super();
}
/**
*
* Constructs a SimpleConstantRateSensor object with the specified mover,
* maximum range, and mean time to detect.
*
* @param mover the mover associated with the sensor
* @param maxRange the maximum range of the sensor
* @param meanTimeToDetect the mean time taken by the sensor to detect an
* object
*/
public SimpleConstantRateSensor(Mover mover, double maxRange, double meanTimeToDetect) {
super(mover, maxRange);
setMeanTimeToDetect(meanTimeToDetect);
}
/**
*
* Returns the mean time to detect an object.
*
* @return the mean time to detect an object
*/
public double getMeanTimeToDetect() {
return meanTimeToDetect;
}
/**
*
* Sets the mean time to detect an object.
*
* @param meanTimeToDetect the mean time to detect an object
* @throws IllegalArgumentException if the meanTimeToDetect value is less
* than 0.0
*/
public void setMeanTimeToDetect(double meanTimeToDetect) {
if (meanTimeToDetect < 0.0) {
throw new IllegalArgumentException("meanTimeToDetect must be >= 0.0: " + meanTimeToDetect);
}
this.meanTimeToDetect = meanTimeToDetect;
}
}