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

Commit Assignment 5 Sloan

parent 57db9529
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ import simkit.Entity;
*
* @author dansl
*/
public class Ship extends Entity {
public final class Ship extends Entity {
private double remainingUnloadingTime;
......
......@@ -10,7 +10,7 @@ import simkit.random.RandomVariate;
*
* @author dansl
*/
public class ShipArrivalProcess extends ArrivalProcess {
public final class ShipArrivalProcess extends ArrivalProcess {
private RandomVariate interarrivalTimeGenerator;
......
......@@ -41,8 +41,9 @@ public class TwoCranesBerth extends SimEntityBase {
public void doArrival(Ship ship) {
ship.stampTime();
SortedSet<Ship> oldQueue = getQueue();
queue.add(ship);
firePropertyChange("queue", getQueue());
firePropertyChange("queue", oldQueue, getQueue());
if (berths.size() == 1) {
waitDelay("SwitchTo1Crane", 0.0);
}
......@@ -57,7 +58,6 @@ public class TwoCranesBerth extends SimEntityBase {
ship.stampTime();
interrupt("EndUnload2Cranes");
waitDelay("StartUnload1Crane", 0.0);
System.out.println(ship.getRemainingUnloadingTime());
waitDelay("EndUnload1Crane", ship.getRemainingUnloadingTime(), ship);
}
......@@ -95,7 +95,7 @@ public class TwoCranesBerth extends SimEntityBase {
SortedSet<Ship> oldBerths = getBerths();
berths.remove(ship);
firePropertyChange("berths", oldBerths, getBerths());
double oldTimeInSystem = timeInSystem;
double oldTimeInSystem = getTimeInSystem();
timeInSystem = ship.getAge();
firePropertyChange("timeInSystem", oldTimeInSystem, getTimeInSystem());
if (!queue.isEmpty()){
......@@ -111,13 +111,13 @@ public class TwoCranesBerth extends SimEntityBase {
Ship ship = berths.first();
berths.remove(ship);
firePropertyChange("berths", oldBerths, getBerths());
double oldTimeInSystem = getTimeInSystem();
timeInSystem = ship.getAge();
firePropertyChange("timeInSystem", oldTimeInSystem, getTimeInSystem());
}
public void Switchto2Cranes(){
SortedSet<Ship> oldBerths = getBerths();
public void doSwitchTo2Cranes(){
Ship ship = berths.first();
berths.remove(ship);
firePropertyChange("berths", oldBerths, getBerths());
ship.work(1);
ship.stampTime();
waitDelay("EndUnload2Cranes", ship.getRemainingUnloadingTime()/2);
......@@ -142,13 +142,15 @@ public class TwoCranesBerth extends SimEntityBase {
* @return the delayInQueue
*/
public double getDelayInQueue() {
return delayInQueue;
double delayInQueueCopy = delayInQueue;
return delayInQueueCopy;
}
/**
* @return the timeInSystem
*/
public double getTimeInSystem() {
return timeInSystem;
double timeInSystemCopy = timeInSystem;
return timeInSystemCopy;
}
}
......@@ -4,14 +4,15 @@
*/
package mv3302.run;
import mv3302.Ship;
import mv3302.ShipArrivalProcess;
import mv3302.TwoCranesBerth;
import simkit.Adapter;
import simkit.Schedule;
import simkit.SimEventListener;
import simkit.random.RandomVariate;
import simkit.random.RandomVariateFactory;
import simkit.stat.CollectionSizeTimeVaryingStats;
import simkit.stat.MultipleSimpleStatsTally;
import simkit.stat.SimpleStatsTally;
import simkit.util.SimplePropertyDumper;
/**
......@@ -24,11 +25,11 @@ public class testShipArrivalProcess {
* @param args the command line arguments
*/
public static void main(String[] args) {
Ship ship = new Ship(5.0);
System.out.println(ship.getRemainingUnloadingTime());
ship.work(2);
System.out.println(ship.getRemainingUnloadingTime());
// Ship ship = new Ship(5.0);
//
// System.out.println(ship.getRemainingUnloadingTime());
// ship.work(2);
// System.out.println(ship.getRemainingUnloadingTime());
RandomVariate interarrivalTimeGenerator = RandomVariateFactory.getInstance("Exponential", .7);
RandomVariate unloadingTimeGenerator = RandomVariateFactory.getInstance("Uniform", 0.5, 1.5);
......@@ -38,7 +39,7 @@ public class testShipArrivalProcess {
TwoCranesBerth twoCranesBerth = new TwoCranesBerth();
System.out.println(twoCranesBerth);
// TwoCranesBerth will "hear" ShipArrivalProcess(ShipArrival) events
// TwoCranesBerth will "hear" ShipArrivalProcess(Arrival) events
shipArrivalProcess.addSimEventListener(twoCranesBerth);
// The twoCranesBerth will "hear" the ShipArrival events of the
......@@ -54,13 +55,30 @@ public class testShipArrivalProcess {
// Was "true" when debugging model
Schedule.setVerbose(true);
double stopTime = 10.0;
double stopTime = 3650.0;
Schedule.stopAtTime(stopTime);
// Initialized & run
Schedule.reset();
Schedule.startSimulation();
Schedule.startSimulation();
// Tally statistics are computed in the same way by "listening"
SimpleStatsTally timeInSystemStat = new SimpleStatsTally("timeInSystem");
twoCranesBerth.addPropertyChangeListener(timeInSystemStat);
CollectionSizeTimeVaryingStats numberInQueueStat = new CollectionSizeTimeVaryingStats("queue");
twoCranesBerth.addPropertyChangeListener(numberInQueueStat);
System.out.printf("%nSimulation ended at time %,.2f%n%n", Schedule.getSimTime());
System.out.printf("Number of Ships Arriving: %,d%n", shipArrivalProcess.getNumberArrivals());
System.out.printf("Number of Ships Unloaded: %,d%n", timeInSystemStat.getCount());
System.out.printf("Maximum # in Queue: %,d%n", numberInQueueStat.getCount());
// System.out.printf("Average # in Queue: %,.4f%n", numberInQueueStat.getMean());
// System.out.printf("Average # Busy Berths: %,.4f%n", numberInQueueStat.getMean());
System.out.printf("Average Time in System: %,.4f%n", timeInSystemStat.getMean());
// System.out.printf("Average Delay in Queue: %,.4f%n", delayInQueueStat.getMean());
}
}
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