65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import copy
|
||
|
|
import json
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
from server.aps_domain.closed_loop_runtime import run_closed_loop_candidate
|
||
|
|
from server.state.packs import load_pack, list_packs
|
||
|
|
|
||
|
|
|
||
|
|
PACK_PATH = Path(__file__).resolve().parents[2] / "server" / "data" / "packs" / "optimize-simulation-v1.json"
|
||
|
|
RULES = ("EDD", "SPT", "PRIORITY", "FIFO", "LPT", "CR", "ATC")
|
||
|
|
|
||
|
|
|
||
|
|
def _next_id_factory():
|
||
|
|
counters: dict[str, int] = {}
|
||
|
|
|
||
|
|
def next_id(kind: str) -> int:
|
||
|
|
counters[kind] = counters.get(kind, 0) + 1
|
||
|
|
return counters[kind]
|
||
|
|
|
||
|
|
return next_id
|
||
|
|
|
||
|
|
|
||
|
|
def test_simulation_world_pack_is_a_generic_aps_fixture():
|
||
|
|
pack = json.loads(PACK_PATH.read_text(encoding="utf-8"))
|
||
|
|
world = load_pack(str(PACK_PATH))
|
||
|
|
|
||
|
|
assert pack["packVersion"] == 1
|
||
|
|
assert pack["name"] == "Optimize synthetic debug V1"
|
||
|
|
assert world["flexParams"]["dataGrade"] == "synthetic"
|
||
|
|
assert len(world["flexOrders"]) == 10
|
||
|
|
assert len(world["salesOrders"]) == 10
|
||
|
|
assert len(world["flexRoutings"]) == 72
|
||
|
|
assert len(world["flexEquipment"]) == 6
|
||
|
|
assert all(row["source"] == "SYNTHETIC" for row in world["flexOrders"])
|
||
|
|
assert {row["productCode"] for row in world["flexRoutings"]} == {
|
||
|
|
row["productCode"] for row in world["flexOrders"]
|
||
|
|
}
|
||
|
|
assert any(item["file"] == PACK_PATH.name for item in list_packs())
|
||
|
|
|
||
|
|
|
||
|
|
def test_simulation_world_pack_runs_all_optimize_dispatch_rules():
|
||
|
|
source_world = load_pack(str(PACK_PATH))
|
||
|
|
|
||
|
|
for rule in RULES:
|
||
|
|
world = copy.deepcopy(source_world)
|
||
|
|
result = run_closed_loop_candidate(
|
||
|
|
world,
|
||
|
|
_next_id_factory(),
|
||
|
|
business_date="2026-08-02",
|
||
|
|
engine_type="OPTIMIZE",
|
||
|
|
sort_mode=rule,
|
||
|
|
strict=True,
|
||
|
|
)
|
||
|
|
|
||
|
|
assert result["solveStatus"] == "FEASIBLE", rule
|
||
|
|
assert result["engineType"] == "OPTIMIZE", rule
|
||
|
|
assert result["algorithmId"] == f"optimize.{rule.lower()}", rule
|
||
|
|
assert result["orderCount"] == 10, rule
|
||
|
|
assert result["vlCount"] == 10, rule
|
||
|
|
assert result["woCount"] == 72, rule
|
||
|
|
assert result["validation"]["valid"] is True, rule
|
||
|
|
assert result["validation"]["hardViolations"] == [], rule
|