This example demonstrates the use of Nextmv's discrete event simulator, Dash, for customers using Nextmv Enterprise.
In this example, we generalize the single-server queue by randomly generating customers with interarrival times and service times from discrete uniform distributions. Interarrival time is just the time between subsequent arrivals.
Randomization helps us to capture the uncertainty of real-world problems.
Input Data
Instead of using the input to specify deterministic customers, we define two arrays of integer values: interarrival times and service times. Our simulation will later generate users by sampling with replacement from each of these lists. We also specify the maximum number of customers to generate (if time permits).
Configuration
In the previous example, we used the CLI runner to load our customers from input data. In this version of the model, we generate customers instead of specifying them in the input data, so we define a struct to hold the number of customers and distribution of times.
The first three values will be automatically unmarshaled from the JSON. To initialize the samplers, we define a method on this struct:
Customers
The customer struct in this example is nearly identical to the single server queue:
The customer Run
method and measures also don't have to change from the earlier example. However, we add a new function newCustomer
which generates a random customer by sampling from the interarrival time and service time distributions.
Server
This example is able to reuse the same single server code from the previous example.
Runner
The runner in this example changes to handle the dynamic creation of customers. Instead of taking customers as input, the Run function takes a config
object. This config
object has to be initialized inside the run function to ensure the samplers are initialized with the input values.
The runner creates NumCustomers
customers and adds them to the simulator's queue.
We can run this example just like the single-server queue. Using jq
, we can look at the wait time measures:
Despite this being the randomized simulation example, if you rerun that command, you will get the same output as a result of Go using a default random seed. However, you can set the random seed with the -dash.simulator.random.seed
flag.
By setting a new random seed, we get a different simulation
To get different result each time, you could set the seed to $(date +%s)
or $RANDOM
.