Skip to content
Snippets Groups Projects
Commit d9d7e7d6 authored by dansl's avatar dansl
Browse files

Revert "Commit final version of Computer Assignment 8"

This reverts commit de41879f.
parent de41879f
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/Beans/Bean.java to edit this template
*/
package mv3302; package mv3302;
import simkit.random.RandomVariate;
/** /**
* The StoppedPartArrivalProcess class extends the PartArrivalProcess class and
* represents a process that stops the arrival of parts for a specified
* duration. It overrides the doRun() method to wait for a specified stop time
* before resuming the arrival of parts. It also provides methods to schedule
* the next arrival and get/set the stop time.
* *
* @author dansl * @author dansl
*/ */
public final class StoppedPartArrivalProcess extends PartArrivalProcess { public final class StoppedPartArrivalProcess extends PartArrivalProcess {
private int stopTime; //private RandomVariate interarrivalTimeGenerator;
public int stopTime;
//int stopTime = 480;
/** /**
* Zero-argument constructor * Zero-argument constructor
*/ */
...@@ -21,27 +24,22 @@ public final class StoppedPartArrivalProcess extends PartArrivalProcess { ...@@ -21,27 +24,22 @@ public final class StoppedPartArrivalProcess extends PartArrivalProcess {
} }
/** /**
* Constructs a StoppedPartArrivalProcess object with the given stop time. * Instantiate with the given parameters
* *
* @param stopTime The duration for which the arrival of parts should be * @param interarrivalTimes Given inter arrival times
* stopped.
*/ */
public StoppedPartArrivalProcess(int stopTime) { public StoppedPartArrivalProcess(int stopTime) {
this.stopTime = stopTime; this.stopTime = stopTime;
} }
/**
* Overrides the doRun() method from the parent class. Pauses the arrival of
* parts for the specified stop time.
*/
@Override @Override
public void doRun() { public void doRun() {
waitDelay("StopArrivals", getStopTime()); waitDelay("StopArrivals", getStopTime());
} }
/** /**
* Schedule the next arrival after stopping. This method schedules the * Schedule next Arrival<br>
* Arrival(index) process. * Schedule Arrival(index)
*/ */
public void doStopArrivals() { public void doStopArrivals() {
interrupt("Arrival"); interrupt("Arrival");
......
package mv3302.run; package mv3302.run;
import static java.lang.Math.sqrt; import static java.lang.Math.sqrt;
import mv3302.PartArrivalProcess; import mv3302.PartArrivalProcess;
import mv3302.TransferLineComponent; import mv3302.TransferLineComponent;
...@@ -11,63 +13,58 @@ import simkit.stat.StudentT; ...@@ -11,63 +13,58 @@ import simkit.stat.StudentT;
import simkit.stat.TruncatingSimpleStatsTally; import simkit.stat.TruncatingSimpleStatsTally;
/** /**
* The main class for running steady state analysis.
* *
* @author dansl * @author dansl
*/ */
public class RunSteadyStateAnalysis { public class RunSteadyStateAnalysis {
/** /**
* The main method for executing the steady state analysis.
*
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String args[]) { 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( RandomVariate interarrivalTimeGenerator = RandomVariateFactory.getInstance(
"Exponential", 2.5); "Exponential", 2.5);
// Create a part arrival process with the interarrival time generator
PartArrivalProcess arrivalProcess = new PartArrivalProcess(interarrivalTimeGenerator); PartArrivalProcess arrivalProcess = new PartArrivalProcess(interarrivalTimeGenerator);
// Create an array of random variate generators for processing times
RandomVariate[] processingTimeGenerator RandomVariate[] processingTimeGenerator =
= {RandomVariateFactory.getInstance("Exponential", 2.4), {RandomVariateFactory.getInstance("Exponential", 2.4), RandomVariateFactory.getInstance("Gamma", 3.2, 3.3), RandomVariateFactory.getInstance("Uniform", 4.5, 6.7), RandomVariateFactory.getInstance("Exponential", 3.0)};
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]; int[] totalNumberWorkstations = new int[4];
totalNumberWorkstations[0] = 1; totalNumberWorkstations[0] = 1;
totalNumberWorkstations[1] = 5; totalNumberWorkstations[1] = 5;
totalNumberWorkstations[2] = 4; totalNumberWorkstations[2] = 4;
totalNumberWorkstations[3] = 2; totalNumberWorkstations[3] = 2;
// Create a transfer line component with the processing time generators and total number of workstations
TransferLineComponent transferLineComponent = new TransferLineComponent(processingTimeGenerator, totalNumberWorkstations); TransferLineComponent transferLineComponent = new TransferLineComponent(processingTimeGenerator, totalNumberWorkstations);
// Add the transfer line component as a listener to the arrival process
arrivalProcess.addSimEventListener(transferLineComponent); arrivalProcess.addSimEventListener(transferLineComponent);
int warmup = 1000; int warmup = 1000;
int observations = 10000; int observations = 10000;
// Create a statistical tally for tracking delay in queue
SimpleStatsTally delayInQueueStat = new TruncatingSimpleStatsTally("delayInQueue", 2000); 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); transferLineComponent.addPropertyChangeListener(delayInQueueStat);
System.out.println(arrivalProcess); System.out.println(arrivalProcess);
System.out.println(transferLineComponent); System.out.println(transferLineComponent);
// Create a statistical tally for tracking delay in queue in the outer loop
SimpleStatsTally outerDelayInQueueStat = new SimpleStatsTally("outerDelayInQueue"); SimpleStatsTally outerDelayInQueueStat = new SimpleStatsTally("outerDelayInQueue");
// Stop the simulation after warmup + observations arrivals
Schedule.stopOnEvent(warmup + observations, "Arrival"); Schedule.stopOnEvent(warmup + observations, "Arrival");
int numberReplications = 50;
int numberReplications = 15;
double alpha = 0.05; double alpha = 0.05;
// Outer loop for multiple replications
System.out.println("Avg Delay In Queue"); System.out.println("Avg Delay In Queue");
for (int replication = 1; replication <= numberReplications; ++replication) { for (int replication = 1; replication <= numberReplications; ++replication) {
// Reset the simulation schedule and delay in queue stat for each replication
Schedule.reset(); Schedule.reset();
delayInQueueStat.reset(); delayInQueueStat.reset();
Schedule.startSimulation(); Schedule.startSimulation();
// Record the mean delay in queue for the replication in the outer tally
outerDelayInQueueStat.newObservation(delayInQueueStat.getMean()); outerDelayInQueueStat.newObservation(delayInQueueStat.getMean());
// Print the replication number, average delay, and confidence interval
System.out.printf("%d %.3f ± %.3f%n", System.out.printf("%d %.3f ± %.3f%n",
replication, replication,
outerDelayInQueueStat.getMean(), outerDelayInQueueStat.getMean(),
...@@ -75,5 +72,6 @@ public class RunSteadyStateAnalysis { ...@@ -75,5 +72,6 @@ public class RunSteadyStateAnalysis {
* StudentT.getQuantile(1.0 - 0.5 * alpha, outerDelayInQueueStat.getCount() - 1) / sqrt(outerDelayInQueueStat.getCount()) * StudentT.getQuantile(1.0 - 0.5 * alpha, outerDelayInQueueStat.getCount() - 1) / sqrt(outerDelayInQueueStat.getCount())
); );
} }
} }
} }
\ No newline at end of file
...@@ -4,6 +4,7 @@ import static java.lang.Math.sqrt; ...@@ -4,6 +4,7 @@ import static java.lang.Math.sqrt;
import mv3302.PartArrivalProcess; import mv3302.PartArrivalProcess;
import mv3302.StoppedPartArrivalProcess; import mv3302.StoppedPartArrivalProcess;
import mv3302.TransferLineComponent; import mv3302.TransferLineComponent;
import mv3302.TransientStats;
import simkit.Schedule; import simkit.Schedule;
import simkit.random.RandomVariate; import simkit.random.RandomVariate;
import simkit.random.RandomVariateFactory; import simkit.random.RandomVariateFactory;
...@@ -20,57 +21,50 @@ public class RunTransientAnalysis { ...@@ -20,57 +21,50 @@ public class RunTransientAnalysis {
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String args[]) { public static void main(String args[]) {
// Create an exponential random variate generator with a mean of 2.5
RandomVariate interarrivalTimeGenerator = RandomVariateFactory.getInstance( RandomVariate interarrivalTimeGenerator = RandomVariateFactory.getInstance(
"Exponential", 2.5); "Exponential", 2.5);
// Define the stop time for the simulation (in minutes)
int stopTime = 480; int stopTime = 480;
// Create a part arrival process using the interarrival time generator
PartArrivalProcess partArrivalProcess = new PartArrivalProcess(interarrivalTimeGenerator); PartArrivalProcess partArrivalProcess = new PartArrivalProcess(interarrivalTimeGenerator);
// Create a stopped part arrival process with the given stop time
StoppedPartArrivalProcess stoppedArrivalProcess = new StoppedPartArrivalProcess(stopTime); StoppedPartArrivalProcess stoppedArrivalProcess = new StoppedPartArrivalProcess(stopTime);
// Create an array of random variate generators for processing times
RandomVariate[] processingTimeGenerator RandomVariate[] processingTimeGenerator
= {RandomVariateFactory.getInstance("Exponential", 2.4), = {RandomVariateFactory.getInstance("Exponential", 2.4), RandomVariateFactory.getInstance("Gamma", 3.2, 3.3), RandomVariateFactory.getInstance("Uniform", 4.5, 6.7), RandomVariateFactory.getInstance("Exponential", 3.0)};
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]; int[] totalNumberWorkstations = new int[4];
totalNumberWorkstations[0] = 1; totalNumberWorkstations[0] = 1;
totalNumberWorkstations[1] = 5; totalNumberWorkstations[1] = 5;
totalNumberWorkstations[2] = 4; totalNumberWorkstations[2] = 4;
totalNumberWorkstations[3] = 2; totalNumberWorkstations[3] = 2;
// Create a transfer line component with the processing time generators and workstation numbers
TransferLineComponent transferLineComponent = new TransferLineComponent(processingTimeGenerator, totalNumberWorkstations); TransferLineComponent transferLineComponent = new TransferLineComponent(processingTimeGenerator, totalNumberWorkstations);
// Add the transfer line component as a listener to the part arrival processes
partArrivalProcess.addSimEventListener(transferLineComponent); partArrivalProcess.addSimEventListener(transferLineComponent);
stoppedArrivalProcess.addSimEventListener(transferLineComponent); stoppedArrivalProcess.addSimEventListener(transferLineComponent);
// Create a statistics tally for total time in the system
// SimpleStatsTally delayInQueueTransient = new SimpleStatsTally("delayInQueue");
//
SimpleStatsTally totalTimeInSystemStat = new SimpleStatsTally("totalTimeInSystem"); SimpleStatsTally totalTimeInSystemStat = new SimpleStatsTally("totalTimeInSystem");
// Add the statistics tally as a property change listener to the transfer line component
transferLineComponent.addPropertyChangeListener(totalTimeInSystemStat); transferLineComponent.addPropertyChangeListener(totalTimeInSystemStat);
System.out.println(partArrivalProcess); System.out.println(partArrivalProcess);
System.out.println(stoppedArrivalProcess); System.out.println(stoppedArrivalProcess);
System.out.println(transferLineComponent); System.out.println(transferLineComponent);
// Create a statistics tally for outer time in the system
SimpleStatsTally outerTimeInSystemStat = new SimpleStatsTally("outerTimeInSystem"); SimpleStatsTally outerTimeInSystemStat = new SimpleStatsTally("outerTimeInSystem");
// Define the confidence level (alpha)
int numberReplications = 200;
double alpha = 0.05; double alpha = 0.05;
// Stop the simulation after 10,000 events with the name "Arrival"
Schedule.stopOnEvent(10000, "Arrival"); Schedule.stopOnEvent(10000, "Arrival");
System.out.println("Avg Delay In Queue"); System.out.println("Avg Delay In Queue");
// Run the replications
for (int replication = 1; replication <= stopTime; ++replication) { for (int replication = 1; replication <= stopTime; ++replication) {
Schedule.reset(); Schedule.reset();
// Reset the statistics tally for total time in the system
totalTimeInSystemStat.reset(); totalTimeInSystemStat.reset();
Schedule.startSimulation(); Schedule.startSimulation();
// Record the outer time in the system using the mean of the total time in the system
outerTimeInSystemStat.newObservation(totalTimeInSystemStat.getMean()); outerTimeInSystemStat.newObservation(totalTimeInSystemStat.getMean());
// Print the replication number, mean, and confidence interval
System.out.printf("%d %.3f ± %.3f%n", System.out.printf("%d %.3f ± %.3f%n",
replication, replication,
outerTimeInSystemStat.getMean(), outerTimeInSystemStat.getMean(),
...@@ -78,5 +72,6 @@ public class RunTransientAnalysis { ...@@ -78,5 +72,6 @@ public class RunTransientAnalysis {
* StudentT.getQuantile(1.0 - 0.5 * alpha, outerTimeInSystemStat.getCount() - 1) / sqrt(outerTimeInSystemStat.getCount()) * StudentT.getQuantile(1.0 - 0.5 * alpha, outerTimeInSystemStat.getCount() - 1) / sqrt(outerTimeInSystemStat.getCount())
); );
} }
} }
} }
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