Convert list to SequentialPlan #487
-
Is there a way to convert a existing plan of the type list['str'], e.g.: plan = ['pick(ball1, rooma, left)', 'move(rooma, roomb)', 'drop(ball1, roomb, left)'] Into a plan of the type <class 'unified_planning.plans.sequential_plan.SequentialPlan'>? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @jdavidrcamacho , so, currently the feature you want is not implemented, but the
So, from your format (and the It would be something like: import unified_planning as up
plan = ['pick(ball1, rooma, left)', 'move(rooma, roomb)', 'drop(ball1, roomb, left)', 'move',' move()']
def convert_string_to_up_parsable(action_str: str) -> str:
"""Converts from 'action-name'('par1', 'par2', .. 'parN') to ('action-name' 'par1' 'par2' .. 'parN')"""
action_str = action_str.replace(" ", "")
if "(" not in action_str: # action without parameters
return f"({action_str})"
else:
action_name, params = action_str.split("(")
params = params.replace(",", " ")
return f"({action_name} {params}"
parsable_plan = "\n".join(map(convert_string_to_up_parsable, plan))
from unified_planning.io import PDDLReader
problem: up.model.Problem = ...
reader = PDDLReader()
sequential_plan = reader.parse_plan_string(problem, parsable_plan)
print(parsable_plan)
# (pick ball1 rooma left)
# (move rooma roomb)
# (drop ball1 roomb left)
# (move)
# (move ) I also opened a PR to document the |
Beta Was this translation helpful? Give feedback.
Hi @jdavidrcamacho , so, currently the feature you want is not implemented, but the
PDDLReader
offers aparse_plan_string
that createsSequentialPlans
from this format (citing doc.):So, from your format (and the
Problem
for which the plan is created) you can use python to create a string that fits the format above.It would be something like: