33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from typing import Dict, Any
|
|
|
|
|
|
def to_canonical(local_problem: Dict[str, Any]) -> Dict[str, Any]:
|
|
"""
|
|
Minimal bridge: map a LocalProblem into a canonical representation.
|
|
In a full MVP this would be a richer translation; here we preserve shape.
|
|
"""
|
|
# Expect input like: {"id": "...", "objective": ..., "variables": {...}, "domain": "..."}
|
|
canonical = {
|
|
"LocalProblem": {
|
|
"id": local_problem.get("id"),
|
|
"domain": local_problem.get("domain", "unknown"),
|
|
"objective": local_problem.get("objective"),
|
|
"variables": local_problem.get("variables", {}),
|
|
}
|
|
}
|
|
return canonical
|
|
|
|
|
|
def from_canonical(canonical: Dict[str, Any]) -> Dict[str, Any]:
|
|
"""
|
|
Inverse mapping from canonical representation back to a LocalProblem-like dict.
|
|
"""
|
|
lp = canonical.get("LocalProblem", {})
|
|
# Flatten for compatibility with simple local problem consumer
|
|
return {
|
|
"id": lp.get("id"),
|
|
"domain": lp.get("domain", "unknown"),
|
|
"objective": lp.get("objective"),
|
|
"variables": lp.get("variables", {}),
|
|
}
|