Rename sourceLimited method to terminal and update related logic for improved clarity; adjust spawn behavior to use -1 for infinite arrivals

This commit is contained in:
2025-02-19 11:49:31 +01:00
parent 8fe2f9d781
commit 744df75d41
6 changed files with 34 additions and 31 deletions

View File

@@ -78,22 +78,24 @@ public class NetBuilderInteractive {
* @return the node
*/
private ServerNode buildNode() {
var choice = choose("Choose the type of node to create:", "Source", "Queue", "Queue with unavailable time");
var choice = choose("Choose the type of node to create:", "Source", "Terminal", "Queue",
"Queue with unavailable time");
var name = ask("Node name: ");
var distribution = askDistribution("Service distribution");
return switch (choice) {
case 1 -> {
case 1 -> ServerNode.Builder.source(name, distribution);
case 2 -> {
var limit = ask("Arrivals limit (0 for Int.Max): ", Integer::parseInt);
if (limit <= 0)
limit = Integer.MAX_VALUE;
yield ServerNode.Builder.sourceLimited(name, limit, distribution);
yield ServerNode.Builder.terminal(name, limit, distribution);
}
case 2 -> {
case 3 -> {
var servers = ask("Number of servers: ", Integer::parseInt);
yield ServerNode.Builder.queue(name, servers, distribution, null);
}
case 3 -> {
case 4 -> {
var servers = ask("Number of servers: ", Integer::parseInt);
var unavailable = askDistribution("Unavailable distribution");
yield ServerNode.Builder.queue(name, servers, distribution, unavailable);
@@ -179,7 +181,7 @@ public class NetBuilderInteractive {
try {
var value = parser.apply(line);
return value;
} catch (Exception e) {
} catch (Exception e) {
}
}
}

View File

@@ -18,7 +18,7 @@ public class ServerNode {
/**
* Creates a generic node with the given name and distribution.
* The servers number must be 1 or higher; if lower will be put to 1.
* The spawn number must be 0 or higher; if lower will be put to 0.
* The spawn number must be 0 or higher; if lower will be put to -1 (infinite).
* The queue number must be equal or higher than the servers number; if lower
* will be put to the servers number.
* The service distribution can't be null, otherwise an exception is thrown.
@@ -37,7 +37,7 @@ public class ServerNode {
if (servers <= 0)
servers = 1;
if (spawn < 0)
spawn = 0;
spawn = -1;
if (queue < servers)
queue = servers;
@@ -205,26 +205,27 @@ public class ServerNode {
/**
* Creates a source node with the given name and distribution.
* It swpawns infinite arrivals (Integer.MAX_VALUE).
* It swpawns infinite arrivals (-1).
*
* @param name The name of the node.
* @param distribution The distribution of the inter-arrival times.
* @return The created source node.
*/
public static ServerNode source(String name, Distribution distribution) {
return new Builder(name, distribution).spawn(Integer.MAX_VALUE).build();
return new Builder(name, distribution).spawn(-1).build();
}
/**
* Creates a source node with the given name, distribution, and number of
* Creates a terminal node with the given name, distribution, and number of
* arrivals to spawn.
* Once it has finished spawning the arrivals, it will not spawn anymore.
*
* @param name The name of the node.
* @param service The distribution of the inter-arrival times.
* @param spawnArrivals The number of arrivals to spawn.
* @return The created source node.
*/
public static ServerNode sourceLimited(String name, int spawnArrivals, Distribution service) {
public static ServerNode terminal(String name, int spawnArrivals, Distribution service) {
return new Builder(name, service).spawn(spawnArrivals).build();
}

View File

@@ -69,7 +69,7 @@ public class ServerNodeState {
* @return True if the node should spawn an arrival, false otherwise.
*/
public boolean shouldSpawnArrival() {
return this.node.spawnArrivals > this.stats.numArrivals;
return this.node.spawnArrivals < 0 || this.node.spawnArrivals > this.stats.numArrivals;
}
/**