moon-feeder-shift

    Offline SMT feeder changeover optimization and operation replay for short production runs

    smt
    manufacturing
    scheduling
    Download zip
    Author
    Version
    0.1.1
    License
    MIT
    Last updated
    47 minutes ago
    Downloads
    4

    #MoonFeederShift

    MoonFeederShift 是一个用于 SMT 小批量生产的离线换线工具。输入一条供料架的初始状态和已排好的工单,输出每单之前的拆装顺序、安装后的槽位和成本。工程师可以独立回放机器生成或人工编辑的动作单,定位第一次冲突。

    #运行示例

    已验证 MoonBit 0.10.16+b1a0e846e 和 1.0.0-rc1+3c0520448,均搭配各自版本的 core。CLI 运行在 Native 后端,核心库另在 JS、Wasm GC 和 Wasm 上执行测试。

    moon update moon run cmd/shift -- solve examples/lookahead.json moon run cmd/shift -- greedy examples/lookahead.json moon run cmd/shift -- solve examples/short-run.json > plan.json moon run cmd/shift -- verify examples/short-run.json plan.json moon run cmd/shift -- sheet examples/short-run.json plan.json moon run cmd/shift -- diagnose examples/conflict.json panel-io

    双工单样例的全序列最小成本为 6,逐单贪心为 11。四工单样例的回放成本为 27,最后一单复用在位的供料器。冲突样例会返回 USB-A 与 USB-C 的共同占位冲突。所有成本以输入权重为单位。保存动作单时请使用 UTF-8。

    命令输出
    solve SHIFT [BUDGET]在给定搜索上限内求固定顺序的最小总成本,成功时写出 JSON 动作单
    quick SHIFT [BUDGET]优先保留在位、优先使用空槽,搜索首个可行摆法并生成动作单
    greedy SHIFT逐单比较所有必需供料器的可行摆法,选择本次拆装成本最低的一种
    verify SHIFT PLAN从初始状态回放全部动作,输出复算总成本或首个错误
    sheet SHIFT PLAN回放校验通过后打印按工单分组的文本操作清单
    diagnose SHIFT JOB [BUDGET]给出该工单的可行性或冲突供料器,并标明冲突集是否已经逐项缩减

    退出码 0 表示成功,1 表示已证实无可行摆法或动作单未通过回放,2 表示输入、文件、用法或逐单基线错误,3 表示有界搜索达到上限。接口和数据字段见模型说明。

    #作为库使用

    moon add SongYZZZ/moon-feeder-shift@0.1.1

    在 moon.pkg 的 import 中加入 "SongYZZZ/moon-feeder-shift" @shift。用 @shift.decode_shift 读取 schema 1,调用 @shift.solve 或 @shift.quick,取得 Outcome.plan 后用 @shift.encode_plan 序列化。@shift.verify 也可直接接收 @shift.decode_plan 读取的第三方动作单。核心库依赖 MoonBit core。Native CLI 使用 moonbitlang/async 和 moonbitlang/x。

    #验证

    moon fmt --check moon check --deny-warn moon test --target all --deny-warn moon build --release --deny-warn python scripts/smoke.py --exe _build/native/release/build/cmd/shift/shift.exe python scripts/oracle.py --exe _build/native/release/build/cmd/shift/shift.exe

    样例为手工构造的单架离线工单。供料器编号、可用槽位和权重由使用方输入,生成的清单供人工确认。项目采用 MIT 许可证。

    InputError

    pub suberror InputError {
    Invalid(String)
    }

    Action

    pub(all) struct Action {
    kind : String
    feeder : String
    slot : Int
    }

    Diagnosis

    pub(all) struct Diagnosis {
    status : String
    job : String
    conflict : Array[String]
    minimal : Bool
    probes : Int
    }

    A conflict is a jointly infeasible subset of a job's requirements, with all rack restrictions and locked units retained. Minimal means removing any one named requirement makes that subset feasible.

    Diagnosis::to_json

    Feeder

    pub(all) struct Feeder {
    id : String
    width : Int
    starts : Array[Int]
    load : Int
    unload : Int
    locked : Bool
    }

    Finding

    pub(all) struct Finding {
    code : String
    step : Int
    action : Int
    detail : String
    }

    An actionable first failure. Step and action are one-based. Zero denotes a plan-wide finding or one found after all actions for the step.

    Finding::to_json

    Job

    pub(all) struct Job {
    id : String
    need : Array[String]
    }

    Outcome

    pub(all) struct Outcome {
    status : String
    job : String
    probes : Int
    edges : Int
    states : Int
    plan : Plan?
    }

    Only successful results include a plan. At limit or infeasible, job names the layer where search stopped.

    Outcome::to_json

    Shift

    pub(all) struct Shift {
    slots : Int
    blocked : Array[Int]
    feeders : Array[Feeder]
    initial : Array[Int]
    jobs : Array[Job]
    }

    Verification

    pub(all) struct Verification {
    cost : Int?
    finding : Finding?
    }

    Only a verified plan has a recomputed total.

    Verification::to_json

    arrangements

    fn arrangements(s : Shift, job : Int) -> Array[Array[Int]] raise InputError

    Return every mandatory placement within the enumeration cap.

    decode_plan

    fn decode_plan(text : String) -> Plan raise InputError

    Decode the output of encode_plan or an operator-edited sheet.

    decode_shift

    fn decode_shift(text : String) -> Shift raise InputError

    Decode a schema 1 input. Unknown fields and duplicate keys are errors.

    diagnose

    fn diagnose(s : Shift, index : Int, budget? : Int) -> Diagnosis raise InputError

    Diagnose one job without considering transition costs.

    encode_plan

    fn encode_plan(plan : Plan) ->
    Json

    Produce the schema 1 JSON representation for sharing and replay.

    greedy

    fn greedy(s : Shift) -> Plan raise InputError

    Minimize immediate cost only. First enumerated placement breaks ties.

    quick

    fn quick(s : Shift, budget? : Int) -> Outcome raise InputError

    Select a feasible placement for each job in turn, preferring to keep existing starts and to load into vacant slots. Never claims optimality.

    solve

    fn solve(s : Shift, budget? : Int) -> Outcome raise InputError

    Minimize total action weight for a fixed job sequence, with no terminal teardown.

    validate

    fn validate(s : Shift) -> Unit raise InputError

    Check static geometry, keys, weights and all references before planning.

    verify

    fn verify(s : Shift, plan : Plan) -> Verification raise InputError

    Independently replay the declared actions against a copy of the initial rack. Accepts manually prepared plans, including feasible plans with extra actions.