stn

    Bounded task planning with temporal dependencies, exclusive-resource search and independent schedule verification.

    stn
    temporal
    difference-constraints
    scheduling
    Download zip
    Version
    0.2.30
    License
    Apache-2.0
    Last updated
    24 minutes ago
    Downloads
    259

    No dependencies

    #MoonSTN

    MoonSTN plans bounded tasks with duration ranges, deadlines, temporal dependencies and exclusive resources. Its MoonBit core searches resource orderings, prunes temporal conflicts and independently verifies schedules. It also 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

    Package version JingLan0v0/stn@0.2.30. Verification and installation receipts: acceptance. Repository: JingLan0v0/MoonSTN.

    #Release history

    VersionDateMain changes
    0.2.302026-11-23Reuse same-resource task links across planning search nodes.
    0.2.292026-11-22Narrow duplicate ID checks in resource branches to IDs that can match generated order rules.
    0.2.282026-11-21Reuse the arc and rule ID arrays along the active resource-order search path.
    0.2.272026-11-21Reuse task timepoint names and numeric suffixes in resource-order branches.
    0.2.262026-11-21Precompute built-in planning timepoint and rule names by task position.

    VersionDateMain changes
    0.2.252026-11-21Reuse timepoint names when constructing planning dependency rules.
    0.2.242026-11-20Reuse task indices to resolve planning dependency endpoints faster.
    0.2.232026-11-20Read planning dependency fields in one pass and preserve diagnostic order.
    0.2.222026-11-20Check exact integer spellings with less work per digit, including trailing-zero decimals.
    0.2.212026-11-20Reuse numeric constraint field lookups to skip a second scan of recognized keys.
    0.2.202026-11-20Reduce name, constraint ID, and bound validation work in large numeric models.
    0.2.192026-11-20Reuse reachable column indices in the wide closure to speed up sparse numeric networks.
    0.2.182026-11-20Reserve numeric closure work before allocating either distance matrix, so budget failures avoid setup costs.
    0.2.172026-11-20Scan JSON input directly before decoding. Verify existing resource limits at and beyond their boundaries.
    0.2.162026-11-19Resolve the two fields of well-formed numeric queries directly and preserve validation order.
    0.2.152026-11-19Write numeric CLI responses directly for faster large query batches, with field order and JSON escaping preserved.
    0.2.142026-11-19Speed up multi-pass numeric feasibility with packed arc endpoints and exact bounded arithmetic. Keep the original cycle evidence and budget thresholds.
    0.2.132026-11-19Reuse adjacent equal distance conversions when the closure has repeated values. Repeated-value dense library solves took 4.4–9.9% less time across four paired comparisons.
    0.2.122026-11-19Reuse reachable columns during dense closure. Median dense library solve time fell 30–32% in two benchmark rounds.
    0.2.112026-11-19Speed up arc indexing by reusing validated names for JSON requests and building a name map for dense library calls.
    0.2.102026-11-19Use exact Int32 arithmetic for eligible dense networks and return tight bounds as Int64.
    0.2.92026-11-19Skip closure updates that cannot improve the pivot row. Add an independent comparison for signed bounds on a 64-point network.
    0.2.82026-11-19Resolve query endpoints once and read tight bounds directly by index.
    0.2.72026-11-19Build planning results directly in their final JSON form.
    0.2.62026-11-19Fix integer validation for JSON fractions that round to integers or underflow to zero.
    0.2.52026-11-19Reuse timepoint indices when building planning constraints and resource-order edges.
    0.2.42026-11-19Charge the work budget once per complete relaxation pass to reduce overhead in deep searches.
    0.2.32026-11-18Stop scanning task pairs at the first exclusive-resource conflict.
    0.2.22026-11-18Build temporal arcs once per planning request and reuse them across search branches.
    0.2.12026-11-18Check feasibility directly during resource search, avoiding all-pairs closure on each branch.
    0.2.02026-11-17Add task planning with duration ranges, time windows, dependencies, exclusive resources and independent schedule verification.
    0.1.22026-11-16Check the full closure budget before traversing the matrix.
    0.1.12026-11-11Skip unreachable closure rows and reuse references to reachable rows.
    0.1.02026-11-11First release with numeric time constraints, tight bounds, verifiable conflict cycles and batch JSON processing.

    #New in 0.2.0: resource-aware task planning

    moon run cmd/main --target js -- --plan examples/release-plan.json moon run cmd/main --target js -- --plan examples/maintenance-plan.json moon run cmd/main --target js -- --plan examples/impossible-plan.json moon run examples/planning --target js

    The maintenance example requires backtracking; the delivery example has feasible time windows but impossible shared-resource usage. Library APIs planning_problem, plan, verify_plan, analyze_plan, analyze_plan_batch expose the same core. Schema, semantics and limits · Substantive revision.

    #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.2.30

    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. Planning adds <=24 tasks / 64 dependencies and bounded resource-order search. No alternative resource assignment, cron, calendar, uncertainty/STNU, network calls or task execution. Not a general constraint optimizer.

    Planning is checked against 1,440 exhaustive two-task cases and 256 seeded three-task cases by independent integer schedule enumeration in each build mode. The verifier also 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. 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
    automatically derived

    Constraint::not_equal

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

    Constraint::to_repr

    automatically derived

    Dependency

    pub(all) struct Dependency {
    before : String
    after : String
    kind : String
    min_lag : Int
    max_lag : Int?
    } derive(Eq,
    Debug
    )

    Dependency::equal

    fn Dependency::equal(Dependency, Dependency) -> Bool
    automatically derived

    Dependency::not_equal

    fn Dependency::not_equal(x : Dependency, y : Dependency) -> Bool
    automatically derived

    Dependency::to_repr

    automatically derived

    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
    automatically derived

    Edge::not_equal

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

    Edge::to_repr

    automatically derived

    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])
    }

    PlanResult

    pub(all) enum PlanResult {
    Planned(Array[ScheduledTask], PlanStats)
    Unschedulable(PlanStats)
    }

    PlanStats

    pub(all) struct PlanStats {
    nodes : Int
    pruned : Int
    decisions : Int
    charged_work : Int
    } derive(Eq,
    Debug
    )

    PlanStats::equal

    fn PlanStats::equal(PlanStats, PlanStats) -> Bool
    automatically derived

    PlanStats::not_equal

    fn PlanStats::not_equal(x : PlanStats, y : PlanStats) -> Bool
    automatically derived

    PlanStats::to_repr

    automatically derived

    PlanningProblem

    pub struct PlanningProblem {
    tasks : Array[Task]
    dependencies : Array[Dependency]
    names : Array[String]
    rules : Array[Constraint]
    }

    ScheduledTask

    pub(all) struct ScheduledTask {
    id : String
    start : Int64
    finish : Int64
    } derive(Eq,
    Debug
    )

    ScheduledTask::equal

    automatically derived

    ScheduledTask::not_equal

    fn ScheduledTask::not_equal(x : ScheduledTask, y : ScheduledTask) -> Bool
    automatically derived

    ScheduledTask::to_repr

    automatically derived

    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.

    Task

    pub(all) struct Task {
    id : String
    min_duration : Int
    max_duration : Int
    release : Int
    deadline : Int
    resource : String?
    } derive(Eq,
    Debug
    )

    Task::equal

    fn Task::equal(Task, Task) -> Bool
    automatically derived

    Task::not_equal

    fn Task::not_equal(x : Task, y : Task) -> Bool
    automatically derived

    Task::to_repr

    automatically derived

    analyze

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

    analyze_batch

    analyze_plan_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.

    plan

    fn plan(p : PlanningProblem, max_nodes? : Int, max_work? : Int) -> PlanResult raise StnError

    Bounded disjunctive search. Budget exhaustion raises, never returns Unschedulable.

    planning_problem

    fn planning_problem(tasks : Array[Task], dependencies : Array[Dependency]) -> PlanningProblem raise StnError

    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.

    verify_plan

    fn verify_plan(p : PlanningProblem, schedule : Array[ScheduledTask]) -> Bool

    Checks original task windows, durations, relations and exclusive resources; never calls solve.

    version

    fn version() -> String