Bugfix
- fixed negative sample from distribution for time
This commit is contained in:
@@ -6,7 +6,7 @@ public class Main {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// Parameters for the simulation
|
// Parameters for the simulation
|
||||||
var seed = System.nanoTime();
|
var seed = System.nanoTime();
|
||||||
var total = 1000;
|
var total = 100000;
|
||||||
var lambda = 1.0 / 4.5;
|
var lambda = 1.0 / 4.5;
|
||||||
var mu = 3.2;
|
var mu = 3.2;
|
||||||
var sigma = 0.6;
|
var sigma = 0.6;
|
||||||
@@ -22,8 +22,8 @@ public class Main {
|
|||||||
sim.addNode(node2);
|
sim.addNode(node2);
|
||||||
|
|
||||||
var maxDepartures = new EndSimulationCriteria.MaxDepartures("Queue", total);
|
var maxDepartures = new EndSimulationCriteria.MaxDepartures("Queue", total);
|
||||||
var maxTime = new EndSimulationCriteria.MaxTime(1000.0);
|
//var maxTime = new EndSimulationCriteria.MaxTime(1000.0);
|
||||||
var results = sim.run(maxDepartures, maxTime);
|
var results = sim.run(maxDepartures);
|
||||||
|
|
||||||
// Display the results
|
// Display the results
|
||||||
for (var entry : results.entrySet()) {
|
for (var entry : results.entrySet()) {
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ public class NetSimulation {
|
|||||||
|
|
||||||
if (event.node.maxServers > this.numServerBusy) {
|
if (event.node.maxServers > this.numServerBusy) {
|
||||||
this.numServerBusy++;
|
this.numServerBusy++;
|
||||||
var time = event.node.distribution.sample(this.rng);
|
var time = event.node.getPositiveSample(this.rng);
|
||||||
var departure = Event.newDeparture(event.node, timeNow + time);
|
var departure = Event.newDeparture(event.node, timeNow + time);
|
||||||
fel.add(departure);
|
fel.add(departure);
|
||||||
} else {
|
} else {
|
||||||
@@ -163,7 +163,7 @@ public class NetSimulation {
|
|||||||
if (this.queue.size() < this.numServerBusy) {
|
if (this.queue.size() < this.numServerBusy) {
|
||||||
this.numServerBusy--;
|
this.numServerBusy--;
|
||||||
} else {
|
} else {
|
||||||
var time = event.node.distribution.sample(this.rng);
|
var time = event.node.getPositiveSample(this.rng);
|
||||||
var departure = Event.newDeparture(event.node, timeNow + time);
|
var departure = Event.newDeparture(event.node, timeNow + time);
|
||||||
fel.add(departure);
|
fel.add(departure);
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,7 @@ public class NetSimulation {
|
|||||||
*/
|
*/
|
||||||
private void addArrivalIf(boolean condition, ServerNode node, double timeNow, PriorityQueue<Event> fel) {
|
private void addArrivalIf(boolean condition, ServerNode node, double timeNow, PriorityQueue<Event> fel) {
|
||||||
if (condition && node != null) {
|
if (condition && node != null) {
|
||||||
var delay = node.distribution.sample(this.rng);
|
var delay = node.getPositiveSample(this.rng);
|
||||||
fel.add(Event.newArrival(node, timeNow + delay));
|
fel.add(Event.newArrival(node, timeNow + delay));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,6 +102,22 @@ public class ServerNode {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a positive sample from the distribution.
|
||||||
|
* This is useful if you need to generate a positive value from a distribution
|
||||||
|
* that can generate negative values. For example, the normal distribution.
|
||||||
|
*
|
||||||
|
* @param rng The random number generator to use.
|
||||||
|
* @return A positive sample from the distribution.
|
||||||
|
*/
|
||||||
|
public double getPositiveSample(Rng rng) {
|
||||||
|
double sample;
|
||||||
|
do {
|
||||||
|
sample = this.distribution.sample(rng);
|
||||||
|
} while (sample < 0);
|
||||||
|
return sample;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if the node should spawn an arrival based on the number of
|
* Determines if the node should spawn an arrival based on the number of
|
||||||
* arrivals.
|
* arrivals.
|
||||||
|
|||||||
Reference in New Issue
Block a user