Repository navigation
Releases
Releases · anesask/discrete-sim
v0.1.20
Added
- Batch resource (#9):
new Batch<T>(sim, batchSize, { maxWait?, unbounded?, name? })accumulates items and releases them as full batches, or partial batchesmaxWaitafter the first item arrived.yield batch.put(item)blocks while a formed batch is still waiting to be taken (back-pressure) unlessunbounded;yield batch.take()resumes withitemsandisPartial. Statistics: batches formed, partial batches, average batch size, item wait, put wait, take wait. Works insideanyOf/allOfand is cleaned up on interrupt. - Example
examples/batch-oven/.
v0.1.19
Added
- Schedule (#10): piecewise-constant, optionally periodic values over simulation time for rush hours, shifts and seasons.
new Schedule(sim, { period, segments, defaultValue }),current,at(time),nextChange,hasMoreChanges,yield* waitForChange()andonChange(handler, { immediate }). Non-periodic schedules hold their last value; gaps usedefaultValueor throw. Resource.setCapacity(n)and acapacitygetter: change staffing while the simulation runs. Growing capacity grants waiting requests immediately; shrinking never interrupts anyone, surplus units are shed as they are released.availableis clamped at 0 andutilizationat 1 while usage exceeds a reduced capacity.- The bank-tellers example staffs the counter from a schedule (opening, rush, lunch, afternoon).
v0.1.18
Added
- Non-blocking and real-time execution (#11):
await sim.runAsync({ until?, batchSize?, signal? })processes events in batches and yields to the event loop between them, so browser pages and servers stay responsive. Same result asrun().sim.runRealtime({ factor?, until? })paces events to wall-clock time (factor= seconds per simulation unit) and returns a handle withpause(),resume(),stop(),setFactor(),isPaused,isActiveand adonepromise.- New
'progress'lifecycle event with{ now, eventsProcessed, eventsInQueue }, emitted after every batch (async) or every event (real time). - Calling
run(),runAsync()orrunRealtime()while another run is in flight throws. - New exported types
RunAsyncOptions,RealtimeOptions,RealtimeHandle,ProgressInfo.
- The React integration guide shows a play/pause/speed control built on
runRealtime.
v0.1.17
Added
- Process composition (#7):
process.done(): wait for another process to finish;result.stateis'completed'or'interrupted'(with the error).yield* anyOf([...]): wait for the first of several branches (resource/buffer/store requests,event.wait(),process.done(),timeout(n)). Pending branches are cancelled automatically;result.winner,result.indexandresult.completeddescribe the outcome. Enables reneging and balking patterns.yield* allOf([...]): wait until every branch has completed (barrier / join).- New exports
ProcessDoneRequest,AnyOfRequest,AllOfRequest,Waitableand the helpersanyOf,allOf;Process.interruptReasongetter.
- Example
examples/bank-renege/: customers leave when their patience runs out.
Fixed
- Interrupting a waiting process now cleans up its request. Previously a process interrupted while queued for a Resource, Buffer or Store stayed in the queue and was later granted the unit, which leaked capacity. All pending waits (queued requests, timeouts, event waiters, done() subscriptions) are cancelled on
interrupt(). A grant that arrives in the same instant a process stops waiting is given back. - A
waitFor()poll no longer keeps running after the process handled an interruption and moved on.
Internal
Resource._cancelAcquire,Buffer._cancelPut/_cancelGet,Store._cancelPut/_cancelGetremove a queued request by callback identity.- The two copies of the yield dispatch in
Processwere merged into one.
v0.1.16
Added
- Experiment runner (#6):
new Experiment(model)wraps a model factory(params, seed, replication) => metricsand runs it many times.replicate(params, { replications, seed?, onProgress? })returns aReplicationResultwithmean,stdDev,min,max,confidenceInterval,summary,tableandtoCSV.sweep(space, options)runs the full factorial of a parameter space and returns aSweepResultwithcompare(metric),best(metric, 'min' | 'max')andtoCSV().- Seeds are derived from the base seed with a hash (
deriveSeed), so experiments are reproducible and adjacent replications are not correlated. Replication i uses the same seed in every scenario (common random numbers).
- Example
examples/experiment-mm1/: 30 replications of M/M/1 with a confidence interval next to the theoretical wait, and a server-count sweep. - README section "Running Experiments"; GUIDE section "One run is not an answer".
v0.1.15
Added
- Confidence intervals and summaries in
Statistics(#5):getConfidenceInterval(name, confidence = 0.95): Student-t interval for the mean of a sample-tracked metric ({ mean, lower, upper, halfWidth, stdError, confidence, n }). Unbounded with fewer than two samples.getBatchMeansCI(name, { batches = 20, confidence = 0.95 }): interval via the method of batch means, for autocorrelated within-run series such as queue waits.getPercentiles(name, [50, 95, 99]): several percentiles from one sort.getSummary(name, confidence?): count, mean, standard deviation, variance, min, max, p50/p95/p99 and the interval in one object.- Dependency-free Student-t quantiles (regularized incomplete beta with bisection, accurate to about 1e-9) in
src/statistics/distributions.ts. - New exported types
ConfidenceInterval,BatchMeansResult,BatchMeansOptions,SummaryStatistics.
- The M/M/1 example prints a 95% confidence interval next to the theoretical mean wait.
v0.1.14
Added
- More distributions in
Random(#8):lognormal(mu, sigma)withRandom.lognormalParams(mean, stdDev),gamma(shape, scale)(Marsaglia-Tsang),erlang(k, mean),weibull(shape, scale),beta(alpha, beta),bernoulli(p),geometric(p),weightedChoice(items, weights),discrete([{ value, weight }])andempirical(samples, { interpolate }). All are seeded from the same generator, validate their parameters withValidationError, and document mean/variance in JSDoc. New exported typesWeightedValue<T>andEmpiricalOptions.
Fixed
exponential(),normal()and the new log-based transforms draw from the open interval (0, 1), so they can no longer returnInfinityorNaNon the one generator state per period that yields exactly 0.
v0.1.13
Added
- Queue disciplines for Store (#4):
putQueueDisciplineandgetQueueDisciplineoptions ('fifo' | 'lifo' | 'priority', or{ type, tieBreaker }) order the processes waiting to put into a full store or waiting for a matching item.store.put(item, priority?)andstore.get(filter?, priority?)accept an optional priority (lower = served first, default 0). Existing calls are unchanged; the default stays FIFO on both queues. Completes queue discipline support across Resource, Buffer and Store.
Internal
- Queue insertion logic is shared between Buffer and Store via
insertByDiscipline()insrc/types/queue-discipline.ts.
v0.1.12
Deprecated
- React Fast Refresh checker (#12):
analyzeExportsForReact,warnReactCompatibilityIssues,withReactCompatCheckand theExportAnalysistype are deprecated and will be removed from the package in v0.3.0. They have nothing to do with discrete-event simulation. Calling them outside test/production logs a one-time notice. A standalone copy now lives inexamples/react-integration/react-compat-checker.ts; copy it into your own project if you use it.
v0.1.11
Changed
- Node.js 20 or newer is required (
engines.nodewas>=16). Node 16 and 18 are end-of-life and the test tooling no longer runs on them. The library code itself is unchanged and still targets ES2020. package.jsondeclares"sideEffects": falseso bundlers can tree-shake unused exports.
Internal
- Toolchain upgrade (#3): ESLint 10 with flat config (
eslint.config.mjs) andtypescript-eslint8 replace ESLint 8 and the legacy.eslintrc.json;eslint-config-prettier10; vitest 4.1; TypeScript 5.9; typedoc 0.28;@types/node22. Lint now also coverstests/. TypeScript 7 was evaluated and deferred becausetypescript-eslintdoes not support it yet. - Performance and benchmark suites moved to
npm run test:perf(wall-clock assertions were flaky on shared CI runners);npm testruns the functional suites. - Dependabot removed; dependency upgrades are done deliberately.