idea182-implementation/gravityweave/adapters/sat_planner.py

33 lines
1.1 KiB
Python

"""Toy satellite planner adapter.
Exposes a simple interface to produce local constraints and accept PlanDelta commits.
This is a stub implementation intended for integration tests and adapter conformance.
"""
from typing import Dict, Any
from ..plan_delta import PlanDelta
class SatPlannerAdapter:
def __init__(self, node_id: str):
self.node_id = node_id
self.local_state: Dict[str, Any] = {"fuel": 100.0, "power": 100.0}
def describe_local_problem(self) -> Dict[str, Any]:
# returns a serializable local problem description
return {"node_id": self.node_id, "state": self.local_state}
def apply_delta(self, delta: PlanDelta) -> bool:
# naive application: if commitment contains a "burn" element, deduct fuel
for c in delta.commitments.value():
if isinstance(c, dict) and c.get("type") == "burn":
amount = c.get("fuel", 0.0)
if self.local_state["fuel"] >= amount:
self.local_state["fuel"] -= amount
else:
return False
return True
def create(node_id: str):
return SatPlannerAdapter(node_id)