stn

    Bounded simple temporal networks with exact integer bounds and checkable conflict witnesses.

    stn
    temporal
    difference-constraints
    Download zip
    Version
    0.1.1
    License
    Apache-2.0
    Last updated
    40 minutes ago
    Downloads
    7

    No dependencies

    #MoonSTN

    MoonSTN checks numeric time constraints without executing tasks. Give it rules such as “testing starts 10–20 minutes after build starts” and “release follows 5–15 minutes later”; it returns a feasible assignment and the tight release window, or a negative cycle identifying contradictory original rules.

    中文说明 · Apache-2.0 · Pure MoonBit core · JS CLI

    Published: JingLan0v0/stn@0.1.0. Verification and installation receipts: acceptance. Repository: JingLan0v0/MoonSTN.

    #Run

    Install the pinned MoonBit version in toolchain.json and Node 24.14.0.

    moon run cmd/main --target js -- examples/deployment.json moon run cmd/main --target js -- examples/delivery.json moon run cmd/main --target js -- examples/conflict.json node scripts/verify.mjs

    On this Windows machine ./scripts/moon.ps1 locates the separate local toolchain. The verifier accepts MOON_HOME and MOON_BIN. No runtime third-party libraries.

    #Input and meaning

    {"timepoints":["zero","a","b"],"constraints":[ {"id":"start","from":"zero","to":"a","lower":0,"upper":0}, {"id":"duration","from":"a","to":"b","lower":5,"upper":20} ],"queries":[{"from":"zero","to":"b"}]}

    Every rule means lower <= time[to] - time[from] <= upper. Either bound may be omitted/null, but at least one must exist. Units are chosen by the caller and must be consistent. Times are integer offsets, not dates or timezones. The first timepoint anchors the returned assignment at zero. No implicit nonnegativity constraint is added. A witness is one valid arrangement, not an optimized schedule.

    feasible includes assignment and requested bounds; a null bound means unbounded, never zero. inconsistent includes an ordered negative-weight cycle of original upper/lower edges. This is a checkable conflict, not a minimum-cardinality repair plan. Unknown fields and unknown endpoints are rejected.

    --batch file.json accepts an array and returns one result/error per request. Single input/schema/resource/I/O errors exit 2 with empty stdout. Valid feasible or inconsistent results exit 0. Batch exits 0 even with item errors: inspect status. Unparseable/oversized entire batch input exits 2. Output failure may leave partial bytes; consumers must check the process exit status.

    #Library

    Install the published package in your consumer module:

    moon add JingLan0v0/stn@0.1.0

    Import JingLan0v0/stn as stn in moon.pkg. A complete runnable example is in examples/library. For source development, see local workspace setup.

    • network(names, constraints) validates and snapshots inputs.
    • solve(network, max_steps=2000000) returns Feasible(Solution) or Inconsistent(Array[Edge]); failures raise StnError(code, message).
    • Solution::assignment() returns a copy; bounds(from,to) returns tight bounds.
    • verify_assignment and verify_conflict independently check evidence.
    • parse_json, analyze, analyze_batch provide bounded text/JSON integration.

    #Boundaries and evidence

    64 timepoints, 512 constraints, input bounds ±1,000,000, 64 batch items, 256 queries. Names/IDs: 1–64 ASCII letters/digits/underscore/dot/hyphen. Arithmetic uses Int64; logical work is bounded separately from input size. See resource contract. No resource assignment, disjunctive scheduling, cron, calendar, uncertainty/STNU, network calls or task execution. Not a general constraint optimizer.

    The verifier compares all 4,096 three-node directed networks (each of six arcs absent or weighted -1/0/1) with independent bounded assignment enumeration, including all nine ordered pair bounds and actual negative-cycle certificates. See acceptance for what was actually run, and ecosystem comparison for overlap and original contribution.

    #Development

    moon fmt moon check --target js --deny-warn moon test --target js --deny-warn moon info --target js node scripts/verify.mjs

    Windows and Ubuntu CI runs on repository pushes; actual receipts are recorded in acceptance.md. Mooncakes 0.1.0 was published on 2026-11-11. See progress, publishing, license and source attribution.

    StnError

    pub(all) suberror StnError {
    StnError(String, String)
    }

    Constraint

    pub(all) struct Constraint {
    id : String
    from : String
    to : String
    lower : Int?
    upper : Int?
    } derive(Eq,
    Debug
    )

    Constraint::equal

    fn Constraint::equal(Constraint, Constraint) -> Bool

    Constraint::not_equal

    fn Constraint::not_equal(x : Constraint, y : Constraint) -> Bool

    Edge

    pub(all) struct Edge {
    id : String
    from : String
    to : String
    bound : Int64
    side : String
    } derive(Eq,
    Debug
    )

    Edge::equal

    fn Edge::equal(Edge, Edge) -> Bool

    Edge::not_equal

    fn Edge::not_equal(x : Edge, y : Edge) -> Bool

    Edge::to_repr

    Network

    pub struct Network {
    names : Array[String]
    edges : Array[Edge]
    }

    Network::timepoints

    fn Network::timepoints(self : Network) -> Array[String]

    Outcome

    pub(all) enum Outcome {
    Feasible(Solution)
    Inconsistent(Array[Edge])
    }

    Solution

    pub struct Solution {
    names : Array[String]
    values : Array[Int64]
    distances : Array[Array[Int64?]]
    }

    Solution::assignment

    fn Solution::assignment(self : Solution) -> Array[(String, Int64)]

    Solution::bounds

    fn Solution::bounds(self : Solution, from : String, to : String) -> (Int64?, Int64?) raise StnError

    Returns the tight interval for to - from; None means unbounded in that direction.

    analyze

    One JSON request. Inconsistency is a valid result, while malformed input raises.

    analyze_batch

    network

    fn network(names : Array[String], constraints : Array[Constraint]) -> Network raise StnError

    parse_json

    fn parse_json(source : String) ->
    Json
    raise StnError

    Preflight bounds decoder work before delegating exact JSON grammar to core.

    solve

    fn solve(net : Network, max_steps? : Int) -> Outcome raise StnError

    All time coordinates are relative to the first timepoint, which is assigned zero.

    verify_assignment

    fn verify_assignment(net : Network, assignment : Array[(String, Int64)]) -> Bool

    Independently checks a complete integer assignment against every original edge.

    verify_conflict

    fn verify_conflict(net : Network, cycle : Array[Edge]) -> Bool

    A certificate is an ordered closed walk of authentic edges with negative total weight.

    version

    fn version() -> String