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

Revert "Revert "Commit final version of Computer Assignment 8""

This reverts commit d9d7e7d6.
parent d9d7e7d6
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;
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
*/
public final class StoppedPartArrivalProcess extends PartArrivalProcess {
//private RandomVariate interarrivalTimeGenerator;
public int stopTime;
//int stopTime = 480;
private int stopTime;
/**
* Zero-argument constructor
*/
......@@ -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) {
this.stopTime = stopTime;
}
/**
* Overrides the doRun() method from the parent class. Pauses the arrival of
* parts for the specified stop time.
*/
@Override
public void doRun() {
waitDelay("StopArrivals", getStopTime());
}
/**
* Schedule next Arrival<br>
* Schedule Arrival(index)
* Schedule the next arrival after stopping. This method schedules the
* Arrival(index) process.
*/
public void doStopArrivals() {
interrupt("Arrival");
......
package mv3302.run;
import static java.lang.Math.sqrt;
import mv3302.PartArrivalProcess;
import mv3302.TransferLineComponent;
......@@ -13,58 +11,63 @@ 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);
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 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 = 15;
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(),
......@@ -72,6 +75,5 @@ public class RunSteadyStateAnalysis {
* 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;
import mv3302.PartArrivalProcess;
import mv3302.StoppedPartArrivalProcess;
import mv3302.TransferLineComponent;
import mv3302.TransientStats;
import simkit.Schedule;
import simkit.random.RandomVariate;
import simkit.random.RandomVariateFactory;
......@@ -21,50 +20,57 @@ 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)};
= {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);
// SimpleStatsTally delayInQueueTransient = new SimpleStatsTally("delayInQueue");
//
// 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");
int numberReplications = 200;
// 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(),
......@@ -72,6 +78,5 @@ public class RunTransientAnalysis {
* 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