diff --git a/src/main/java/net/berack/upo/valpre/NetSimulation.java b/src/main/java/net/berack/upo/valpre/NetSimulation.java index 0fdf334..753ccad 100644 --- a/src/main/java/net/berack/upo/valpre/NetSimulation.java +++ b/src/main/java/net/berack/upo/valpre/NetSimulation.java @@ -139,7 +139,7 @@ public class NetSimulation { for (var node : nodes) { this.nodes.put(node.name, new NodeBehavior()); if (node.shouldSpawnArrival(0)) - this.addEvent(node, Event.Type.ARRIVAL); + this.addArrival(node); } } @@ -158,19 +158,18 @@ public class NetSimulation { switch (event.type) { case ARRIVAL -> { if (node.updateArrival(event.time, event.node.maxServers)) - this.addEvent(event.node, Event.Type.DEPARTURE); - - if (event.node.shouldSpawnArrival(node.stats.numArrivals)) { - this.addEvent(event.node, Event.Type.ARRIVAL); - } + this.addDeparture(event.node); } case DEPARTURE -> { if (node.updateDeparture(event.time)) - this.addEvent(event.node, Event.Type.DEPARTURE); + this.addDeparture(event.node); - if (!event.node.shouldSinkDeparture(node.stats.numDepartures)) { - var next = event.node.getChild(this.rng); - this.addEvent(next, Event.Type.ARRIVAL); + var next = event.node.getChild(this.rng); + if (next != null) { + this.addArrival(next); + } + if (event.node.shouldSpawnArrival(node.stats.numArrivals)) { + this.addArrival(event.node); } } } @@ -210,19 +209,26 @@ public class NetSimulation { } /** - * Adds an event to the future event list. - * The event is created based on the given node and type, and the delay is - * determined by the node's distribution. + * Adds an arrival event to the future event list. The event is created based + * on the given node, and no delay is added. * * @param node The node to create the event for. - * @param type The type of event to create. */ - public void addEvent(ServerNode node, Event.Type type) { - if (node != null) { - var delay = node.getPositiveSample(this.rng); - var event = Event.newType(node, this.time + delay, type); - fel.add(event); - } + public void addArrival(ServerNode node) { + var event = Event.newArrival(node, this.time); + fel.add(event); + } + + /** + * Adds a departure event to the future event list. The event is created based + * on the given node, and the delay is determined by the node's distribution. + * + * @param node The node to create the event for. + */ + public void addDeparture(ServerNode node) { + var delay = node.getPositiveSample(this.rng); + var event = Event.newDeparture(node, this.time + delay); + fel.add(event); } /** @@ -255,6 +261,7 @@ public class NetSimulation { /** * TODO + * * @param time * @param maxServers * @return @@ -280,6 +287,7 @@ public class NetSimulation { /** * TODO + * * @param time * @return */ diff --git a/src/main/java/net/berack/upo/valpre/ServerNode.java b/src/main/java/net/berack/upo/valpre/ServerNode.java index 62e5c08..4e6c5f0 100644 --- a/src/main/java/net/berack/upo/valpre/ServerNode.java +++ b/src/main/java/net/berack/upo/valpre/ServerNode.java @@ -12,7 +12,6 @@ import net.berack.upo.valpre.rand.Rng; public class ServerNode { public final String name; public final int maxServers; - public final int sinkDepartures; public final int spawnArrivals; public final Distribution distribution; private final List children = new ArrayList<>(); @@ -28,7 +27,7 @@ public class ServerNode { * @return The created source node. */ public static ServerNode createSource(String name, Distribution distribution) { - return new ServerNode(name, Integer.MAX_VALUE, distribution, Integer.MAX_VALUE, 0); + return new ServerNode(name, Integer.MAX_VALUE, distribution, Integer.MAX_VALUE); } /** @@ -41,7 +40,7 @@ public class ServerNode { * @return The created source node. */ public static ServerNode createLimitedSource(String name, Distribution distribution, int spawnArrivals) { - return new ServerNode(name, Integer.MAX_VALUE, distribution, spawnArrivals, 0); + return new ServerNode(name, Integer.MAX_VALUE, distribution, spawnArrivals); } /** @@ -54,7 +53,7 @@ public class ServerNode { * @return The created queue node. */ public static ServerNode createQueue(String name, int maxServers, Distribution distribution) { - return new ServerNode(name, maxServers, distribution, 0, 0); + return new ServerNode(name, maxServers, distribution, 0); } /** @@ -64,14 +63,12 @@ public class ServerNode { * @param maxServers The maximum number of servers in the queue. * @param distribution The distribution of the service times. * @param spawnArrivals The number of arrivals to spawn. - * @param sinkDepartures The number of departures to sink. */ - public ServerNode(String name, int maxServers, Distribution distribution, int spawnArrivals, int sinkDepartures) { + public ServerNode(String name, int maxServers, Distribution distribution, int spawnArrivals) { this.name = name; this.maxServers = maxServers; this.distribution = distribution; this.spawnArrivals = spawnArrivals; - this.sinkDepartures = sinkDepartures; } /** @@ -129,17 +126,6 @@ public class ServerNode { return this.spawnArrivals > numArrivals; } - /** - * Determines if the node should sink a departure based on the number of - * departures. - * - * @param numDepartures The number of departures to check against. - * @return True if the node should sink a departure, false otherwise. - */ - public boolean shouldSinkDeparture(double numDepartures) { - return this.sinkDepartures > numDepartures; - } - /** * Represents a child node with a probability to select it. */