Implement hierarchical task decomposition:
decompose(task, max_depth): Recursively break down tasks- If atomic or max_depth reached, return as leaf
- Otherwise split and recurse on subtasks
_is_atomic(task): Check if task is indivisible- Atomic if: no 'and'/'then', or length < 10 chars
_split_task(task): Split compound task- Split on ' and ', ' then ', ','
get_execution_order(): Topological sort of all subtasks
Tree Structure:
{'task': str, 'subtasks': [...], 'depth': int, 'id': str}
Execution Order: Return list of task IDs in dependency-respecting order.
Examples
Example 1:
Input:
td = TaskDecomposer(); tree = td.decompose('Research and write', 2); 'subtasks' in treeOutput:
TrueExplanation: Task decomposed into subtasks
Starter Code
class TaskDecomposer:
"""
Decompose complex tasks into subtasks with dependencies.
"""
def __init__(self):
self.subtasks = []
self.dependencies = {}
def decompose(self, task, max_depth=3):
"""
Recursively decompose task into subtasks.
Returns tree structure of subtasks.
"""
# Your implementation here
pass
def _is_atomic(self, task):
"""Check if task cannot be decomposed further"""
# Your implementation here
pass
def _split_task(self, task):
"""Split task into subtasks (simulated)"""
# Simulate: split by 'and', 'then'
pass
def get_execution_order(self):
"""Get topologically sorted execution order"""
# Your implementation here
passPython3
ReadyLines: 1Characters: 0
Ready