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/task-allocation.git e513f8a 9619a21 9089584 3bf8432 8da6f7a 9d1acf5 9a07d04 9d1acf574331bd27de50dee268cc71f6b78b9186 asw_component/__init__.py +3−0 View filefrom .component import execute__all__ = ["execute"]asw_component/component.py +12−0 View filefrom __future__ import annotationsdef execute(payload: dict) -> dict: machines = [{**item, "assigned_workload": 0.0, "tasks": []} for item in payload.get("machines", [])] if not machines or any(float(m["capacity"]) <= 0 for m in machines): raise ValueError("positive-capacity machines are required") for task in sorted(payload.get("tasks", []), key=lambda item: float(item["workload"]), reverse=True): machine = min(machines, key=lambda item: item["assigned_workload"] / float(item["capacity"])) machine["tasks"].append(task["id"]) machine["assigned_workload"] += float(task["workload"]) allocations = [{"machine_id": m["id"], "tasks": m["tasks"], "estimated_time": round(m["assigned_workload"] / float(m["capacity"]), 3)} for m in machines] return {"allocations": allocations, "makespan": max(item["estimated_time"] for item in allocations)}examples/input.json +26−0 View file{ "machines": [ { "id": "tractor-1", "capacity": 1 }, { "id": "tractor-2", "capacity": 1.5 } ], "tasks": [ { "id": "F1", "workload": 4 }, { "id": "F2", "workload": 3 }, { "id": "F3", "workload": 2 } ]}pyproject.toml +8−0 View file[project]name = "task_allocation"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))