diff --git a/MV3302ClassCode/src/mv3302/Ship.java b/MV3302ClassCode/src/mv3302/Ship.java index 2098bd386f0995ec98b32c9f7c53651758c7a0de..23d4cf6b147201d58c0cf0e1ddb0a5d065cd78ab 100644 --- a/MV3302ClassCode/src/mv3302/Ship.java +++ b/MV3302ClassCode/src/mv3302/Ship.java @@ -10,7 +10,7 @@ import simkit.Entity; * * @author dansl */ -public class Ship extends Entity { +public final class Ship extends Entity { private double remainingUnloadingTime; diff --git a/MV3302ClassCode/src/mv3302/ShipArrivalProcess.java b/MV3302ClassCode/src/mv3302/ShipArrivalProcess.java index f714e555c70e00110e8abc48b920d968f5f94975..251236a69cc98495ec8d6b75afea059dec42f3d9 100644 --- a/MV3302ClassCode/src/mv3302/ShipArrivalProcess.java +++ b/MV3302ClassCode/src/mv3302/ShipArrivalProcess.java @@ -10,7 +10,7 @@ import simkit.random.RandomVariate; * * @author dansl */ -public class ShipArrivalProcess extends ArrivalProcess { +public final class ShipArrivalProcess extends ArrivalProcess { private RandomVariate interarrivalTimeGenerator; diff --git a/MV3302ClassCode/src/mv3302/TwoCranesBerth.java b/MV3302ClassCode/src/mv3302/TwoCranesBerth.java index 24286c70bdc741ac4549a11a00a28b616ae64f3c..9e60dbbbbe980a6adc0e4bda08b41867021221ee 100644 --- a/MV3302ClassCode/src/mv3302/TwoCranesBerth.java +++ b/MV3302ClassCode/src/mv3302/TwoCranesBerth.java @@ -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; } } diff --git a/MV3302ClassCode/src/mv3302/run/testShipArrivalProcess.java b/MV3302ClassCode/src/mv3302/run/testShipArrivalProcess.java index 5d099a2356ae15a21a1c51699ccfb52e2df0adc0..a037bd38f13ec63e50f8a5d58e67e49dbca10854 100644 --- a/MV3302ClassCode/src/mv3302/run/testShipArrivalProcess.java +++ b/MV3302ClassCode/src/mv3302/run/testShipArrivalProcess.java @@ -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()); } }