Sign in

    moonqueuelab

    Analytical queueing networks, service-level capacity sizing and exact integer server planning

    queueing
    capacity-planning
    erlang
    jackson
    mva
    Download zip
    Author
    Version
    0.1.0
    License
    MIT
    Last updated
    10 hours ago
    Downloads
    13

    #MoonQueueLab

    纯 MoonBit 的解析排队模型与容量规划库,模块 usersD609/moonqueuelab@0.1.0。 给定到达率、服务能力、路由或有限人口,计算稳态指标、服务水平、所需服务器数和整数预算分配。 它不是消息队列、运行时限流器、压测工具或离散事件仿真器,也不将模型结果当作真实业务保证。

    #谁能使用

    使用者输入、处理与输出可运行集成
    服务架构与平台工程师外部流量、路由与节点服务率 → 解 Jackson 流量方程、找瓶颈、分配固定工作进程预算 → 新配置与平均响应时间examples/service_capacity
    客服/通信容量规划人员来电率、处理率、等待 SLA 或有限等候席位 → 分别计算无限队列人员数、阻塞/放弃约束、无等待中继容量 → 明确模型假设的配置examples/contact_center
    教学、运筹研究与交互系统设计者终端人口、访问次数、服务需求、思考时间 → 单类闭合网络 MVA 和人口目标搜索 → 吞吐量曲线、最小人口与守恒检查examples/closed_population

    这些任务复用同一数值引擎,但不把人员技能排班、实时伸缩执行或仿真事件内核放进库中。

    #实现能力

    • Erlang B/C、损失系统最少通道与反向流量上限;M/M/c 平均指标、状态概率/尾概率、等待与响应尾分布及分位数。
    • 有限生灭链的对数归一化、状态统计/分位数/平衡残差;M/M/c/K 及等待期间指数放弃;有限源 Engset。
    • M/G/1 Pollaczek–Khinchine 平均值;明确标记为近似的 GI/G/c 变异系数修正。
    • 最少服务器 SLA 搜索、固定服务器到达容量反解、负载情景扫描、有限缓冲区阻塞/放弃约束搜索。
    • 开放 Jackson 网络:带部分主元的流量求解、出口可达性/残差验证、平均外部响应、瓶颈负载系数。
    • 单类闭合 FCFS 单服务器/无限服务器 Delay 中心,精确 MVA 人口曲线、吞吐量目标搜索。
    • 固定整数服务器预算动态规划,优化 sum(Lq);Jackson 适配将其转为固定流量下的平均外部响应优化。
    • 有界、严格字段 JSON 协议和跨目标 CLI,便于非 MoonBit 工具调用。

    API 概览见生成的 pkg.generated.mbti,模型说明见 架构与数值边界。

    #环境、安装与快速开始

    开发验证锁定编译器 v0.10.14+7d59c7ec9,moon 0.1.20260920。使用 MoonBit 官方工具链。 库本身只依赖 moonbitlang/core,没有原生数学、网络或 Python 运行依赖。 CLI 使用 core/env;独立验证脚本额外需要 Python 3.8+ 和 Node.js。

    在一个新 MoonBit 项目中执行(精确版本):

    moon add usersD609/moonqueuelab@0.1.0

    在调用包的 moon.pkg 中添加:

    import {
    "usersD609/moonqueuelab" @queue,
    }
    pkgtype(kind: "executable")

    main.mbt:

    ///|
    fn main raise {
    let q : @queue.Mmc = { arrival: 2.0, service: 3.0, servers: 1 }
    let m = q.analyze()
    assert_true((m.mean_response - 1.0).abs() < 1.0e-10)
    println(m.to_json().stringify())
    println(q.response_quantile(0.95))
    }

    moon run . --target wasm-gc

    此例的平均响应时间为 1 个时间单位,95% 响应分位数约 2.995732。 所有到达率与服务率必须使用同一时间单位;service 是单服务器每单位时间服务率,不是服务时长。

    #三个完整工作流

    克隆本仓库后:

    moon run examples/service_capacity --target js moon run examples/contact_center --target js moon run examples/closed_population --target js

    1. 服务网络:两节点、重试边、外部流量 [5,1];预算 6 的最优配置为 [3,3],平均外部响应约 0.301666。示例逐个枚举小规模候选,验证动态规划结果,并检查原模型未被修改。
    2. 呼叫中心:12 次/分钟、每人 0.5 次/分钟,80% 在 0.5 分钟内开始服务、利用率上限 90%;无限队列模型需要 28 人。有限缓冲(8 个等候位、放弃率 0.1/分钟)与阻塞≤1%、已接入放弃≤5% 对应另一个模型,得到 29 人;损失系统 1% 阻塞对应 35 条通道。不能跨模型混用这些结论。
    3. 闭合系统:CPU/磁盘/Delay 与思考时间,求吞吐量≥6 的最小人口 10,并验证每个人口点的守恒。再将 CPU 时间减半,观察瓶颈改变,不把单服务器 MVA 冒充多服务器近似。

    #核心 API 组合

    ///|
    fn main raise {
    let network : @queue.JacksonNetwork = {
    nodes: [{ service: 6.0, servers: 2 }, { service: 5.0, servers: 2 }],
    external: [5.0, 1.0],
    routing: [[0.0, 0.6], [0.1, 0.0]],
    }
    let plan = network.allocate_servers([1, 1], [5, 5], 6)
    let configured = network.with_servers(plan.servers)
    println(configured.analyze().to_json().stringify())
    let finite : @queue.FiniteQueue = {
    arrival: 5.0, service: 2.0, servers: 3, capacity: 7, abandonment: 0.1,
    }
    println(finite.outcomes().to_json().stringify())
    }

    FiniteQueue.capacity 包含服务中的客户;放弃只作用于等候者。 blocked_fraction 的分母是尝试到达,abandoned_given_admission 的分母是成功接入。 mean_admitted_wait 包含最终放弃者的等待,不是“仅完成服务者”的条件均值。 Engset 的 time_full 与到达者见到的 arrival_blocking 不同,因为繁忙源不再发起请求。

    #JSON CLI

    CLI 接收恰好一个 JSON 字符串参数,输出一行 JSON,无文件读取或网络请求。 在源码仓库中构建后,可绕过 shell 的复杂转义直接从 Python 调用:

    moon build --target js python -c 'import subprocess,json; subprocess.run(["node","_build/js/debug/build/cmd/moonqueuelab/moonqueuelab.js",json.dumps(dict(op="loss",offered=12,channels=18))],check=True)'

    Windows PowerShell 建议使用 tools/verify_single.py 中相同的参数数组方式;不同 shell 的引号规则不同。 上面 python -c 行按 POSIX shell 编写。 也可直接调用纯函数 @queue.process_json(text)。

    协议成功含 ok:true 与 operation;失败只含 ok:false,code,不回显输入。 CLI 业务错误通常仍为退出码 0;调用者必须解析 ok,不能只检查进程退出码。

    op必填字段(除 op 外)输出主字段
    lossoffered, channelsblocking
    mmcarrival, service, servers, time, probability, statemetrics, wait_survival, response_survival, wait_quantile, response_quantile, state_probability, state_tail
    finitearrival, service, servers, capacity, abandonmentmetrics, outcomes
    engsetsources, channels, per_source, servicemetrics
    mg1arrival, mean_service, second_momentmetrics
    staffingarrival, service, target, time, maximum_utilization, maximum_serversstaffing
    birth_deathbirth 数组, death 数组states, summary, residual
    jacksonservices 数组, servers 整数数组, external 数组, routing 二维数组, maximum_utilizationmetrics, load_limit
    closedkinds 字符串数组(fcfs/delay), service_times, visits, think_time, populationcurve(包含人口0)
    allocatenodes 对象数组(arrival,service,minimum,maximum), budgetallocation

    所有字段必填,无协议默认值;未知字段、分数计数、错误类型/形状被拒绝。重复 JSON 键继承 core 解析器的后者覆盖行为,不宣称重复键检测。probability=1 的有限响应分位数不存在,应使用 <1。 错误码:invalid、numerical、limit、unstable、infeasible。类型化 API 抛出带说明的 QueueError。

    #模型假设与限制

    • 这是稳态、单类解析工具;M/M/c/Jackson 使用独立 Poisson 到达与指数服务、FCFS,无优先级、重试退避、相关突发或动态伸缩。路由重访只在 Jackson 假设内处理。
    • 统一使用 Double。输入必须有限;常见速率≤1e12、服务器≤10000。极小尾部下溢为0,接近饱和可能损失精度;不可表示的中间量/结果报数值错误,不保证所有有限输入可计算。
    • 有限链最多10000条转移;每条合成出生/死亡率也≤1e12。Engset 源≤10000。有限 staffing 最多200万估计状态评估;总容量≤10000。
    • Jackson 1..128节点,每行路由概率和≤1;每个节点须有路径离开系统;近奇异方程可能拒绝。M/M/c 节点必须严格稳定。零外部流量的平均外部响应取连续零负载约定值0,而非有效观测均值。
    • 闭合网络 1..128中心,人口0..1000;FCFS 仅单服务器,Delay 无限服务器,至少一个正访问比;不支持多类、多服务器 FCFS 或优先级。offered_load 是流量×服务时间(Erlangs),不是服务时间需求。
    • 分配1..64节点、预算1..10000、估计转移数≤2000万;恰好消耗预算,只优化独立节点 sum(Lq);没有价格权重、任意约束或一般整数规划。目标大到≥1e300时拒绝。
    • 情景扫描最多128点。JSON长度≤1000000个UTF-16代码单元,嵌套≤16;CLI还受操作系统参数长度限制。
    • 不提供真实流量采样、仿真器、限流执行、排班、置信区间、参数拟合或业务 SLA 保障。GI/G/c 是均值近似,不提供精确分布。

    #验证与开发

    moon info moon fmt moon fmt --check moon check --deny-warn --target wasm-gc moon test --deny-warn --target wasm-gc moon build --deny-warn --target wasm-gc moon build --target js python tools/verify_single.py python tools/verify_network.py python tools/audit_source.py

    把 target 替换为 wasm、js、native 可运行同一组检查。native 需要 C 编译器。 2026-10-22 Windows 本地:wasm-gc/wasm/js 各31测试通过、严格检查/构建及三个工作流通过;native 严格类型检查通过,但当地无 C 编译器,不声称本地 native 执行通过。 CI 配置在 Ubuntu 24.04 执行四目标检查/测试/构建及工作流,具体结果以对应提交的实际运行记录为准。

    独立 Python 标准库预言机固定种子6092026:单队列119请求、网络72请求,共191次。使用70位 Decimal有限乘积、阶乘公式、闭合网络乘积形式状态枚举、流量固定点迭代和整数配置穷举,避免仅验证同一实现的自洽性。容差为 3e-9*(1+abs(expected));小规模对照不等同于全域精度证明。

    保守生产规模为2101物理行,20个引擎文件;排除测试、CLI、示例、traits适配、生成接口、Python和文档。tools/audit_source.py 可复算,工程提交审计见 验收证据。未测覆盖率或生产性能,不宣称全覆盖或性能优势。

    #查重、来源与许可

    有界语义查重见 duplicate-check.md,不是官方唯一性判定。 重点近邻是 MoonDES/MoonSim 的离散事件仿真、FlowGate 运行时门控和 FairShift 人员技能排班;独立库提供不依赖这些事件/资源模型的解析规划接口,可作为仿真理论参考,而非取代它们。

    原创 MoonBit 实现,MIT,见 LICENSE。R queueing 0.2.12(GPL-2)仅作公开能力、数学行为与边界参考,没有移植其代码、文档或测试数据,不声称 R API 或功能全集兼容。依赖 core 的许可独立适用,见 NOTICE.md。AI 参与设计、实现、测试及文档,详细范围与责任见 AI-USE.md。

    QueueError

    pub suberror QueueError {
    Invalid(String)
    Numerical(String)
    Limit(String)
    Unstable(String)
    Infeasible(String)
    } derive(
    Debug
    )

    Domain, numerical range, resource, and unstable-model failures are distinct.

    ApproximateQueue

    pub(all) struct ApproximateQueue {
    mean_wait : Double
    mean_response : Double
    mean_queue : Double
    utilization : Double
    variability_factor : Double
    } derive(ToJson,
    Debug
    )

    An explicitly approximate GI/G/c mean model using the variability factor (Ca^2+Cs^2)/2 times the exact M/M/c wait. Not a distributional model.

    ApproximateQueue::to_json

    ArrivalCapacity

    pub(all) struct ArrivalCapacity {
    arrival : Double
    probability_within_threshold : Double
    utilization : Double
    upper_bounded : Bool
    } derive(ToJson,
    Debug
    )

    A feasible lower endpoint of the maximum admitted offered arrival rate, bounded by the caller's upper rate and a strict utilization ceiling.

    ArrivalCapacity::to_json

    ClosedCenter

    pub(all) enum ClosedCenter {
    Fcfs(Double)
    Delay(Double)
    } derive(ToJson,
    Debug
    )

    Product-form center for a single-class, single-server closed network. Fcfs centers model one exponential server; Delay centers have infinite servers and no queue.

    ClosedCenter::to_json

    ClosedCenterMetrics

    pub(all) struct ClosedCenterMetrics {
    mean_jobs : Double
    mean_queue : Double
    mean_wait : Double
    mean_response : Double
    offered_load : Double
    } derive(ToJson,
    Debug
    )

    Per-center mean-value analysis at one population. offered_load is throughput * visits * service time (Erlangs), not a service-time demand. It is busy probability at Fcfs and mean busy servers at Delay.

    ClosedCenterMetrics::to_json

    ClosedNetwork

    pub(all) struct ClosedNetwork {
    centers : Array[ClosedCenter]
    visits : Array[Double]
    think_time : Double
    } derive(ToJson,
    Debug
    )

    Single-class closed queueing network. Visits are relative visits per reference customer cycle; think_time is the per-customer delay-center time.

    ClosedNetwork::analyze_population

    fn ClosedNetwork::analyze_population(self : ClosedNetwork, population : Int) -> ClosedPopulationMetrics raise QueueError

    Analyze one requested population while retaining the exact MVA curve used for its recurrence.

    ClosedNetwork::population_curve

    fn ClosedNetwork::population_curve(self : ClosedNetwork, maximum_population : Int) -> Array[ClosedPopulationMetrics] raise QueueError

    Exact single-class MVA population curve for FCFS single-server and delay centers. Multiserver FCFS centers are deliberately not approximated here.

    ClosedNetwork::population_for_throughput

    fn ClosedNetwork::population_for_throughput(self : ClosedNetwork, target : Double, maximum_population : Int) -> ClosedPopulationMetrics raise QueueError

    Smallest closed population attaining a target cycle throughput. Exact MVA points are retained; infeasible targets never return an invented estimate.

    ClosedNetwork::to_json

    ClosedPopulationMetrics

    pub(all) struct ClosedPopulationMetrics {
    population : Int
    throughput : Double
    mean_network_response : Double
    mean_cycle_time : Double
    mean_think_population : Double
    centers : Array[ClosedCenterMetrics]
    conservation_residual : Double
    } derive(ToJson,
    Debug
    )

    Population operating point; conservation_residual compares center jobs, think population and the requested closed population.

    ClosedPopulationMetrics::to_json

    Engset

    pub(all) struct Engset {
    sources : Int
    channels : Int
    per_source : Double
    service : Double
    } derive(ToJson,
    Debug
    )

    Finite-source M/M/c/c loss model. Idle sources attempt at per_source rate; busy sources do not. Time-full probability differs from arrival blocking.

    Engset::analyze

    fn Engset::analyze(self : Engset) -> EngsetMetrics raise QueueError

    Engset::to_json

    fn Engset::to_json(Engset) -> Json

    Engset::to_repr

    EngsetMetrics

    pub(all) struct EngsetMetrics {
    states : Array[Double]
    mean_busy : Double
    time_full : Double
    arrival_blocking : Double
    attempted_rate : Double
    carried_rate : Double
    } derive(ToJson,
    Debug
    )

    EngsetMetrics::to_json

    FiniteMetrics

    pub(all) struct FiniteMetrics {
    states : Array[Double]
    mean_system : Double
    mean_queue : Double
    mean_busy : Double
    blocked_fraction : Double
    admitted_rate : Double
    service_rate : Double
    abandon_rate : Double
    mean_residence : Double
    } derive(ToJson,
    Debug
    )

    FiniteMetrics::to_json

    FiniteOutcomes

    pub(all) struct FiniteOutcomes {
    accepted_fraction : Double
    served_fraction : Double
    abandoned_fraction : Double
    served_given_admission : Double
    abandoned_given_admission : Double
    mean_admitted_wait : Double
    relative_rate_residual : Double
    } derive(ToJson,
    Debug
    )

    Long-run outcomes for attempted and admitted arrivals. Waiting time is averaged over all admitted customers, including those who abandon.

    FiniteOutcomes::to_json

    FiniteQueue

    pub(all) struct FiniteQueue {
    arrival : Double
    service : Double
    servers : Int
    capacity : Int
    abandonment : Double
    } derive(ToJson,
    Debug
    )

    Finite capacity includes customers in service. Exponential abandonment acts only on waiting customers, not on those already in service.

    FiniteQueue::analyze

    fn FiniteQueue::analyze(self : FiniteQueue) -> FiniteMetrics raise QueueError

    FiniteQueue::outcomes

    fn FiniteQueue::outcomes(self : FiniteQueue) -> FiniteOutcomes raise QueueError

    FiniteQueue::to_json

    fn FiniteQueue::to_json(FiniteQueue) -> Json

    FiniteStaffing

    pub(all) struct FiniteStaffing {
    servers : Int
    capacity : Int
    metrics : FiniteMetrics
    outcomes : FiniteOutcomes
    } derive(ToJson,
    Debug
    )

    Finite queue sizing result; capacity = servers + waiting_places. Targets constrain attempted-customer blocking and admitted-customer abandonment.

    FiniteStaffing::to_json

    JacksonMetrics

    pub(all) struct JacksonMetrics {
    nodes : Array[JacksonNodeMetrics]
    external_arrival : Double
    total_mean_customers : Double
    mean_external_response : Double
    relative_flow_residual : Double
    } derive(ToJson,
    Debug
    )

    Aggregate open-network result. Response time is per external customer, including all internal visits and feedback.

    JacksonMetrics::to_json

    JacksonNetwork

    pub(all) struct JacksonNetwork {
    nodes : Array[JacksonNode]
    external : Array[Double]
    routing : Array[Array[Double]]
    } derive(ToJson,
    Debug
    )

    Open single-class Jackson network. routing[i][j] is the probability that a completion at node i next visits node j; missing row mass exits the system.

    JacksonNetwork::allocate_servers

    fn JacksonNetwork::allocate_servers(self : JacksonNetwork, minimum : Array[Int], maximum : Array[Int], budget : Int) -> ServerAllocation raise QueueError

    Allocate identical-cost servers to fixed Jackson traffic. Routing does not depend on server counts; minimize sum Lq, equivalently external mean response because total service demand is fixed. No live scheduling.

    JacksonNetwork::analyze

    Analyze an open Jackson network. Every node must have a path to exit and each resulting M/M/c center must be strictly stable.

    JacksonNetwork::load_limit

    fn JacksonNetwork::load_limit(self : JacksonNetwork, maximum_utilization : Double) -> NetworkLoadLimit raise QueueError

    JacksonNetwork::scaled_load

    fn JacksonNetwork::scaled_load(self : JacksonNetwork, factor : Double) -> JacksonNetwork raise QueueError

    Copy a network and scale only its external arrivals, retaining routing and service parameters. This operation validates shapes but permits overload; analyze() remains the strict stability gate.

    JacksonNetwork::solve_traffic

    fn JacksonNetwork::solve_traffic(self : JacksonNetwork) -> Array[Double] raise QueueError

    Public traffic-only solve, useful for scenario reports without queue metrics.

    JacksonNetwork::to_json

    JacksonNetwork::with_servers

    fn JacksonNetwork::with_servers(self : JacksonNetwork, counts : Array[Int]) -> JacksonNetwork raise QueueError

    Copy with a selected server allocation and revalidate actual node models.

    JacksonNode

    pub(all) struct JacksonNode {
    service : Double
    servers : Int
    } derive(ToJson,
    Debug
    )

    One FCFS exponential service center in an open Jackson network.

    JacksonNode::to_json

    fn JacksonNode::to_json(JacksonNode) -> Json

    JacksonNodeMetrics

    pub(all) struct JacksonNodeMetrics {
    arrival : Double
    utilization : Double
    delay_probability : Double
    mean_queue : Double
    mean_system : Double
    mean_wait : Double
    mean_response : Double
    } derive(ToJson,
    Debug
    )

    Stable traffic and M/M/c results for one network node.

    JacksonNodeMetrics::to_json

    Mmc

    pub(all) struct Mmc {
    arrival : Double
    service : Double
    servers : Int
    } derive(ToJson,
    Debug
    )

    All rates use the same time unit. No runtime measurements are collected.

    Mmc::analyze

    fn Mmc::analyze(self : Mmc) -> QueueMetrics raise QueueError

    Mmc::conditional_wait

    fn Mmc::conditional_wait(self : Mmc) -> Double raise QueueError

    Conditional exponential waiting-time mean, undefined with zero arrivals.

    Mmc::response_quantile

    fn Mmc::response_quantile(self : Mmc, p : Double) -> Double raise QueueError

    Response quantile from the exact continuous tail. The unit quantile is infinite even with zero load because exponential service is unbounded.

    Mmc::response_survival

    fn Mmc::response_survival(self : Mmc, time : Double) -> Double raise QueueError

    Exact FCFS response tail for M/M/c: an exponential service time plus a mixture of zero wait and exponential delayed wait. Not GI/G/c.

    Mmc::state_probability

    fn Mmc::state_probability(self : Mmc, state : Int) -> Double raise QueueError

    Stationary P(N=n). Underflow of astronomically unlikely states is zero.

    Mmc::state_tail

    fn Mmc::state_tail(self : Mmc, state : Int) -> Double raise QueueError

    Tail P(N>=n); sums head probabilities without 1-CDF cancellation.

    Mmc::to_json

    fn Mmc::to_json(Mmc) -> Json

    Mmc::to_repr

    Mmc::wait_quantile

    fn Mmc::wait_quantile(self : Mmc, p : Double) -> Double raise QueueError

    Smallest t>=0 with P(Wq<=t)>=p. p=1 has no finite quantile when C>0.

    Mmc::wait_survival

    fn Mmc::wait_survival(self : Mmc, time : Double) -> Double raise QueueError

    P(Wq > t), with the point mass at zero kept separate: survival(0)=C.

    NetworkLoadLimit

    pub(all) struct NetworkLoadLimit {
    scale : Double?
    bottleneck : Int?
    node_utilizations : Array[Double]
    } derive(ToJson,
    Debug
    )

    Scale of the external-arrival vector at which the first utilized center reaches the requested utilization. None means there is no offered traffic.

    NetworkLoadLimit::to_json

    QueueMetrics

    pub(all) struct QueueMetrics {
    utilization : Double
    delay_probability : Double
    mean_queue : Double
    mean_system : Double
    mean_wait : Double
    mean_response : Double
    throughput : Double
    } derive(ToJson,
    Debug
    )

    Means are unconditional. Waiting excludes service; response includes it.

    QueueMetrics::to_json

    QueueScenario

    pub(all) struct QueueScenario {
    arrival : Double
    stable : Bool
    metrics : QueueMetrics?
    wait_tail : Double?
    } derive(ToJson,
    Debug
    )

    A scenario can be unstable without aborting an otherwise valid sweep. Malformed or numerically unrepresentable inputs still raise QueueError.

    QueueScenario::to_json

    ServerAllocation

    pub(all) struct ServerAllocation {
    servers : Array[Int]
    total_mean_queue : Double
    node_mean_queues : Array[Double]
    consumed_budget : Int
    } derive(ToJson,
    Debug
    )

    Exact allocation result. The selected counts consume the requested budget exactly; objective is the recomputed sum of node mean queue lengths.

    ServerAllocation::to_json

    ServerBudgetNode

    pub(all) struct ServerBudgetNode {
    arrival : Double
    service : Double
    minimum_servers : Int
    maximum_servers : Int
    } derive(ToJson,
    Debug
    )

    A fixed open-network node used by exact server-budget allocation.

    ServerBudgetNode::to_json

    SlaStaffing

    pub(all) struct SlaStaffing {
    servers : Int
    utilization : Double
    delay_probability : Double
    probability_within_threshold : Double
    mean_wait : Double
    } derive(ToJson,
    Debug
    )

    A service-level target for an open M/M/c center.

    SlaStaffing::to_json

    fn SlaStaffing::to_json(SlaStaffing) -> Json

    StateSummary

    pub(all) struct StateSummary {
    mean : Double
    variance : Double
    full_probability : Double
    empty_probability : Double
    } derive(ToJson,
    Debug
    )

    Distribution summaries, with variance from central deviations (not E[N2]-E[N]^2).

    StateSummary::to_json

    allocate_server_budget

    fn allocate_server_budget(nodes : Array[ServerBudgetNode], budget : Int) -> ServerAllocation raise QueueError

    Exact separable dynamic programming over integer server counts. Unstable node/count combinations are excluded instead of assigned an artificial finite penalty.

    arrival_capacity

    fn arrival_capacity(service : Double, server_count : Int, target_probability : Double, wait_threshold : Double, upper : Double, maximum_utilization? : Double) -> ArrivalCapacity raise QueueError

    balance_residual

    fn balance_residual(law : Array[Double], birth : Array[Double], death : Array[Double]) -> Double raise QueueError

    Largest absolute detailed-balance residual, scaled by each edge's rate.

    erlang_b

    fn erlang_b(offered : Double, channels : Int) -> Double raise QueueError

    Erlang loss probability by bounded recursion; no factorials or a^c. Offered traffic is dimensionless lambda/mu, not an arrival rate.

    erlang_c

    fn erlang_c(offered : Double, channels : Int) -> Double raise QueueError

    Delay probability in an infinite-buffer M/M/c model. Stability is strict.

    finite_staffing

    fn finite_staffing(arrival : Double, service : Double, waiting_places : Int, abandonment : Double, maximum_blocking : Double, maximum_abandonment : Double, maximum_servers : Int) -> FiniteStaffing raise QueueError

    gigc_approximation

    fn gigc_approximation(model : Mmc, arrival_scv : Double, service_scv : Double) -> ApproximateQueue raise QueueError

    loss_staffing

    fn loss_staffing(offered : Double, maximum_loss : Double, maximum_channels : Int) -> Int raise QueueError

    Minimum channels for a loss target. Zero channels may serve zero traffic but blocks every attempted arrival; use at least one for actual service.

    loss_traffic_limit

    fn loss_traffic_limit(channels : Int, maximum_loss : Double, upper : Double) -> Double raise QueueError

    Invert Erlang B in offered traffic on a caller-supplied bounded interval. Returns the greatest feasible traffic to relative interval tolerance.

    mg1

    fn mg1(arrival : Double, mean_service : Double, second_moment : Double) -> QueueMetrics raise QueueError

    M/G/1 FCFS means. The second moment is E[S^2], not variance or stddev.

    mmc_sweep

    fn mmc_sweep(service : Double, server_count : Int, arrivals : Array[Double], wait_threshold : Double) -> Array[QueueScenario] raise QueueError

    process_json

    fn process_json(text : String) -> String

    Bounded pure JSON transport. Errors do not echo supplied data. Duplicate keys use core JSON's last-value behavior. CLI wraps this function verbatim.

    sla_staffing

    fn sla_staffing(arrival : Double, service : Double, target_probability : Double, wait_threshold : Double, maximum_utilization? : Double, maximum_servers? : Int) -> SlaStaffing raise QueueError

    Find the smallest server count satisfying both an M/M/c waiting target and a utilization ceiling. The threshold is measured in the same time unit as service and arrival rates.

    state_quantile

    fn state_quantile(law : Array[Double], p : Double) -> Int raise QueueError

    Discrete quantile: smallest state with cumulative mass >= p; p=0 returns 0.

    stationary_birth_death

    fn stationary_birth_death(birth : Array[Double], death : Array[Double]) -> Array[Double] raise QueueError

    A finite birth-death stationary law. Birth[k] moves k to k+1; death[k] moves k+1 to k. All death rates must be strictly positive. Zero birth rates make upper states transient; their mass is exactly zero.

    summarize_states

    fn summarize_states(law : Array[Double]) -> StateSummary raise QueueError