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

Commit final version of Computer Assignment 8

parent adf2c3b2
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 RandomVariate interarrivalTimeGenerator; private int stopTime;
public int stopTime;
//int stopTime = 480;
/** /**
* Zero-argument constructor * Zero-argument constructor
*/ */
...@@ -24,22 +21,27 @@ public int stopTime; ...@@ -24,22 +21,27 @@ public int stopTime;
} }
/** /**
* Instantiate with the given parameters * Constructs a StoppedPartArrivalProcess object with the given stop time.
* *
* @param interarrivalTimes Given inter arrival times * @param stopTime The duration for which the arrival of parts should be
* 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 next Arrival<br> * Schedule the next arrival after stopping. This method schedules the
* Schedule Arrival(index) * Arrival(index) process.
*/ */
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;
...@@ -13,58 +11,63 @@ import simkit.stat.StudentT; ...@@ -13,58 +11,63 @@ 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("Gamma", 3.2, 3.3), RandomVariateFactory.getInstance("Uniform", 4.5, 6.7), RandomVariateFactory.getInstance("Exponential", 3.0)}; = {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]; 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(),
...@@ -72,6 +75,5 @@ public class RunSteadyStateAnalysis { ...@@ -72,6 +75,5 @@ 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,7 +4,6 @@ import static java.lang.Math.sqrt; ...@@ -4,7 +4,6 @@ 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;
...@@ -21,50 +20,57 @@ public class RunTransientAnalysis { ...@@ -21,50 +20,57 @@ 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("Gamma", 3.2, 3.3), RandomVariateFactory.getInstance("Uniform", 4.5, 6.7), RandomVariateFactory.getInstance("Exponential", 3.0)}; = {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]; 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(),
...@@ -72,6 +78,5 @@ public class RunTransientAnalysis { ...@@ -72,6 +78,5 @@ 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