stn

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

    stn
    temporal
    difference-constraints
    scheduling
    Download zip
    Version
    0.2.7
    License
    Apache-2.0
    Last updated
    20 minutes ago
    Downloads
    79

    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.7. Verification and installation receipts: acceptance. Repository: JingLan0v0/MoonSTN.

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

    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

    Constraint::not_equal

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

    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

    Dependency::not_equal

    fn Dependency::not_equal(x : Dependency, y : Dependency) -> 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])
    }

    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

    PlanStats::not_equal

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

    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

    ScheduledTask::not_equal

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

    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

    Task::not_equal

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

    Task::to_repr

    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