Skip to content

Commit

Permalink
Merge commit 'b7a4a68' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigimatsu committed Apr 26, 2022
2 parents e9fd2ef + b7a4a68 commit 210e5db
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
16 changes: 15 additions & 1 deletion include/symbolic/pddl.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,27 @@ class Pddl {
* derived predicates.
*
* @param state Current state.
* @param action Action call in the form of `"action(obj_a, obj_b)"`.
* @param action_call Action call in the form of `"action(obj_a, obj_b)"`.
* @returns Next state.
*
* @seepython{symbolic.Pddl,next_state}
*/
State NextState(const State& state, const std::string& action_call) const;

/**
* Execute a sequence of actions from the given state.
*
* The action preconditionss are not checked. The resulting state includes
* derived predicates.
*
* @param state Current state.
* @param action_call Action calls in the form of `"action(obj_a, obj_b)"`.
* @returns Final state.
*
* @seepython{symbolic.Pddl.execute}
*/
State ApplyActions(const State& state, const std::vector<std::string>& action_calls) const;

/**
* Apply the derived predicates to the given state.
*/
Expand Down
14 changes: 14 additions & 0 deletions src/pddl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,20 @@ TEST_CASE_FIXTURE(testing::Fixture, "Pddl.NextState") {
REQUIRE(pddl.NextState(state, "pick(hook)") == next_state);
}

State Pddl::ApplyActions(const State& state,
const std::vector<std::string>& action_calls) const {
State next_state(state);
for (const std::string& action_call : action_calls) {
const std::pair<Action, std::vector<Object>> action_args =
Action::Parse(*this, action_call);
const Action& action = action_args.first;
const std::vector<Object>& arguments = action_args.second;

Apply(action, arguments, derived_predicates(), &next_state);
}
return next_state;
}

State Pddl::DerivedState(const State& state) const {
return DerivedPredicate::Apply(state, derived_predicates());
}
Expand Down
20 changes: 20 additions & 0 deletions src/python/symbolic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,26 @@ PYBIND11_MODULE(pysymbolic, m) {
.. seealso:: C++: :symbolic:`symbolic::Pddl::NextState`.
)pbdoc")
.def(
"apply_actions",
[](const Pddl& pddl, const std::unordered_set<std::string>& state,
const std::vector<std::string>& actions) {
return pddl.ApplyActions(State(pddl, state), actions).Stringify();
},
"state"_a, "action"_a, R"pbdoc(
Execute a sequence of actions from the given state
The action preconditions are not checked. The resulting state includes
derived predicates.
Args:
state: Current state.
actions: Action calls in the form of :code:`"action(obj_a, obj_b)"`.
Returns:
Final state.
.. seealso:: C++: :symbolic:`symbolic::Pddl::Execute`.
)pbdoc")
.def(
"derived_state",
[](const Pddl& pddl, const std::unordered_set<std::string>& state) {
Expand Down

0 comments on commit 210e5db

Please sign in to comment.