asw_component/__init__.py +3−0 View file@@ -0,0 +1,3 @@
1 +
from .component import execute 2 +
3 +
__all__ = ["execute"][참조 MVP] 농작업 경로 최적화 A-SW — 작업 구간을 최근접 휴리스틱으로 재정렬해 공차 이동거리를 줄입니다.
https://git.agrithing.ai/ontariotech/path-optimization.git 31e9d33 9a8e645 78244d2 3e39860 511863b de87e68 fe5cc8b de87e6848c199c3e8ddce0896385a115ec38f7bc asw_component/__init__.py +3−0 View filefrom .component import execute__all__ = ["execute"]asw_component/component.py +15−0 View filefrom __future__ import annotationsimport mathdef execute(payload: dict) -> dict: current = list(payload.get("start", [0, 0])) remaining = list(payload.get("tasks", [])) order, distance = [], 0.0 while remaining: task = min(remaining, key=lambda item: math.dist(current, item["point"])) leg = math.dist(current, task["point"]) order.append({"id": task["id"], "point": task["point"], "transfer_distance_m": round(leg, 3)}) distance += leg current = task["point"] remaining.remove(task) return {"algorithm": "nearest_neighbor", "order": order, "total_transfer_distance_m": round(distance, 3)}examples/input.json +29−0 View file{ "start": [ 0, 0 ], "tasks": [ { "id": "A", "point": [ 8, 1 ] }, { "id": "B", "point": [ 2, 2 ] }, { "id": "C", "point": [ 5, 5 ] } ]}pyproject.toml +8−0 View file[project]name = "path_optimization"version = "0.1.0"description = "작업 구간을 최근접 휴리스틱으로 재정렬해 공차 이동거리를 줄입니다."requires-python = ">=3.11"[tool.unittest]test-path = "tests"run.py +10−0 View filefrom __future__ import annotationsimport jsonimport sysfrom asw_component import executeif __name__ == "__main__": path = sys.argv[1] if len(sys.argv) > 1 else None with open(path, encoding="utf-8") if path else sys.stdin as source: payload = json.load(source) print(json.dumps(execute(payload), ensure_ascii=False, indent=2))