跳转至

MG 迁移示例

MG 示例是 SQLite 驱动的 APS 兼容迁移示例。它保留原 program/ 风格的数据流:preprocess 生成输入表,OptAgent 替代模型阶段,postprocess 写回兼容输出表。

https://github.com/Dongbox/optagent-examples/tree/main/examples/mg

问题说明

MG 当前采用 sequence-blackbox 建模:

  • 从 SQLite 的 i_*t_* 表加载订单、工艺、规则成本和初始序列。
  • sequence_var(...) 表达订单顺序。
  • 用 Python 规则函数重算 MG 主要 rule cost,并通过 external_call(...) 作为目标。
  • 输出 o_mg_optagent_* 表,便于与原 APS 输出和后处理流程对齐。

目录结构

examples/mg/
  README.md
  program/
    main.py
    data/
      20260407000000.db
    model/
      model.py
      rules.py
      search.py
      reports.py
    scripts/
      preprocess/
        transformer.py
        data.py
        tables/
      postprocess/
        postprocess.py
tests/
  test_examples_mg.py

代码示例

from pathlib import Path
from mg.program.model.reports import run_production_case

payload = run_production_case(
    Path("examples/mg/program/data/20260407000000.db"),
    dry_run=True,
)
print(payload["manifest"]["status"])

运行

MG 示例需要 APS 兼容运行环境。正式运行请使用 Python 3.9,并安装管理员提供的 APS wheel。APS wheel 不随 optagent-examples 公开分发;需要向管理员申请匹配版本的 wheel 文件和安装权限。

python3.9 -m venv .venv-mg
source .venv-mg/bin/activate
python -m pip install <admin-provided-aps-wheel.whl>
python -m pip install -r requirements-dev.txt
PYTHONPATH=. python examples/mg/program/main.py examples/mg/program/data/20260407000000.db

注意事项

  • APS preprocess 失败时,MG 示例会停止后续模型和 postprocess 阶段。
  • 生产入口只接收一个 SQLite 路径,preprocess 输入、模型输出、兼容输出和 postprocess 输出都写在同一个 SQLite 文件中。
  • program/model/reports.py 提供 parity、structured edge、search replacement 和生产输出报告 API。
  • 当前模型以黑盒 Python scorer 为权威目标;规则尚未全部降低为结构化 DAG 约束。
  • 全量生产切换需要验证上游 t_connectables 生成、APS wheel 版本和全尺寸回归 case。