SSA (Stochastic Simulation Algorithm)
Methods · Configuration · Shared options · All solvers
The SSA solver is a stochastic simulator for continuous-time Markov chains. The state space is not generated upfront but is built during simulation starting from the initial state. The solver offers both serial and parallel execution modes, with the latter supporting independent replications across multiple cores.
Methods
The method names and defaults below describe the MATLAB interface. Aliases share a row; model-specific restrictions and backend differences are noted. Use solver.listValidMethods() to inspect the names available for your model.
| Method | Algorithm and applicability | Reference |
|---|---|---|
default | Prefer the next-reaction engine on closed queueing networks with INF/PS stations, and fall back to the serial engine wherever the reaction form does not cover the model. | — |
serial | One Gillespie trajectory over the model's event set, sampled event by event. | [1] |
ssa | Alias of serial. | — |
para, parallel | config.nreplicas independent replications of the serial engine, averaged; each replication gets ceil(samples/nreplicas) events and seed seed+r-1. | — |
nrm | Gibson-Bruck next reaction method: an indexed priority queue over reaction-form events with a dependency graph, asked for by name. | [2] |
Configuration options
The solver-specific fields below belong to options.config. Set them on an options struct, for example opt.config.name = value, and pass that struct to the solver constructor. See shared solver options for all top-level fields, shared configuration, defaults and usage. Options apply only to the methods and model features that consume them.
Relevant top-level options: samples, events, seed, confint, timespan, timeout.
SSA defaults to samples=1e4, timespan=[0,Inf] and config.state_space_gen='none'. For parallel runs, replication count is config.nreplicas; samples is the total event budget split across those replications.
| Option | Default | Description and values |
|---|---|---|
eventcache | true under lang='java', else false | Cache the enabled-event set between steps instead of recomputing it. |
nreplicas | 8 | Independent replications, fixed so the answer does not depend on the worker count. |
runLengthPlan | unset | A scalar or schedule prescribing how long each replication runs, overriding the sample budget. |
warmupfrac | 0.0 | Fraction of each replication discarded as warm-up. |
Example
This example demonstrates solving a simple M/M/1 queue using the SSA solver with stochastic simulation. The unique feature shown is the incremental sampling process (50,000 samples, fixed seed 23000) using Gillespie's algorithm to explore the state space. SSA is an independent per-language implementation, so the simulated estimates differ slightly across MATLAB/Java/Python for the same seed.
% Create a simple M/M/1 queue
model = Network('M/M/1 Example');
source = Source(model, 'Source');
queue = Queue(model, 'Queue1', SchedStrategy.FCFS);
sink = Sink(model, 'Sink');
jobclass = OpenClass(model, 'Class1');
source.setArrival(jobclass, Exp(0.9));
queue.setService(jobclass, Exp(1.0));
model.link(Network.serialRouting(source, queue, sink));
% Solve with SSA (Stochastic Simulation Algorithm)
solver = SSA(model, 'seed', 23000, 'samples', 50000);
% Display average performance metrics
solver.avgTable()
Output:
Default method: using serial SSA
SSA samples: 100
200
...
49900
50000
SSA analysis [method: default/serial; type: approximate, randomized; lang: matlab; env: 2025a] completed in 7.315s.
ans =
2×8 table
Station JobClass QLen Util RespT ResidT ArvR Tput
_______ ________ ______ ____ ______ ______ ____ _______
Source Class1 0 0 0 0 0 0.9
Queue1 Class1 8.4672 0.9 9.4127 9.4127 0.9 0.89954
import jline.lang.*;
import jline.lang.constant.SchedStrategy;
import jline.lang.nodes.*;
import jline.lang.processes.Exp;
import jline.solvers.NetworkAvgTable;
import jline.solvers.ssa.SSA;
public class SSAExample {
public static void main(String[] args) {
// Create a simple M/M/1 queue
Network model = new Network("M/M/1 Example");
Source source = new Source(model, "Source");
Queue queue = new Queue(model, "Queue1", SchedStrategy.FCFS);
Sink sink = new Sink(model, "Sink");
OpenClass jobclass = new OpenClass(model, "Class1");
source.setArrival(jobclass, Exp.fitRate(0.9));
queue.setService(jobclass, Exp.fitRate(1.0));
model.link(Network.serialRouting(source, queue, sink));
// Solve with SSA (Stochastic Simulation Algorithm)
SSA solver = new SSA(model);
solver.options.seed = 23000;
solver.options.samples = 50000;
// Display average performance metrics
NetworkAvgTable avgTable = solver.getAvgTable();
System.out.println(avgTable);
}
}
Output:
Default method: using serial SSA SSA samples: 50000 SSA analysis [method: default/serial; type: approximate, randomized; lang: java; env: 17.0.9] completed. Station JobClass QLen Util RespT ResidT ArvR Tput Source Class1 0.0 0.0 0.0 0.0 0.0 0.9 Queue1 Class1 8.4673 0.9 9.4129 9.4129 0.9 0.89954
from line_solver import *
# Create a simple M/M/1 queue
model = Network('M/M/1 Example')
source = Source(model, 'Source')
queue = Queue(model, 'Queue1', SchedStrategy.FCFS)
sink = Sink(model, 'Sink')
jobclass = OpenClass(model, 'Class1')
source.setArrival(jobclass, Exp(0.9))
queue.setService(jobclass, Exp(1.0))
model.link(Network.serialRouting(source, queue, sink))
# Solve with SSA (Stochastic Simulation Algorithm)
solver = SSA(model, seed=23000, samples=50000)
# Display average performance metrics
print(solver.avg_table())
Output:
Default method: using serial SSA SSA samples: 50000 SSA analysis [method: default/serial; type: approximate, randomized; lang: python; env: 3.13.7] completed. Station JobClass QLen Util RespT ResidT ArvR Tput 0 Source Class1 0.0 0.0 0.0 0.0 0.0 0.9 1 Queue1 Class1 9.3227 0.9 10.359 10.359 0.9 0.89998
References
- Gillespie, D. T. (1977). Exact stochastic simulation of coupled chemical reactions. The Journal of Physical Chemistry, 81(25), 2340-2361.
- Anderson, D. F. (2007). A modified next reaction method for simulating chemical systems with time dependent propensities and delays. The Journal of Chemical Physics, 127(21), 214107.