Correct behavior for multi-task HTN methods.

Add tasks to the left of the deque, not the right.

Not symptomatic yet since we don't actually have any multi-task methods
currently.
This commit is contained in:
Dan Albert 2021-07-14 18:34:33 -07:00
parent 72c181a399
commit 56b17dfbcf

View File

@ -1,7 +1,7 @@
from __future__ import annotations from __future__ import annotations
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from collections import Iterator, deque from collections import Iterator, deque, Sequence
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any, Generic, Optional, TypeVar from typing import Any, Generic, Optional, TypeVar
@ -18,7 +18,7 @@ class Task(Generic[WorldStateT]):
pass pass
Method = list[Task[WorldStateT]] Method = Sequence[Task[WorldStateT]]
class PrimitiveTask(Task[WorldStateT], Generic[WorldStateT], ABC): class PrimitiveTask(Task[WorldStateT], Generic[WorldStateT], ABC):
@ -104,18 +104,20 @@ class Planner(Generic[WorldStateT, PrimitiveTaskT]):
methods = planning_state.methods methods = planning_state.methods
try: try:
method = next(methods) method = next(methods)
# Push the current node back onto the stack so that we resume
# handling this task when we pop back to this state.
resume_tasks: deque[Task[WorldStateT]] = deque([task])
resume_tasks.extend(planning_state.tasks_to_process)
history.push( history.push(
PlanningState( PlanningState(
planning_state.state.clone(), planning_state.state.clone(),
# Push the current node back onto the stack so that we resume_tasks,
# resume handling this task when we pop back to this state.
planning_state.tasks_to_process + deque([task]),
planning_state.plan, planning_state.plan,
methods, methods,
) )
) )
planning_state.methods = None planning_state.methods = None
planning_state.tasks_to_process.extend(method) planning_state.tasks_to_process.extendleft(reversed(method))
except StopIteration: except StopIteration:
try: try:
planning_state = history.pop() planning_state = history.pop()