Skip to content

Improvements to the evaluate function focusing on optimizing derived predicates and existential preconditions resolution #330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 54 commits into
base: rolling
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
3178ee9
add == operator and hash to Instance and Predicate
Rezenders Oct 24, 2024
4718345
change checkNodeEquality to consider predicates w/ variables
Rezenders Oct 24, 2024
424ffb8
add checkParamTypeEquivalence
Rezenders Oct 24, 2024
485bb5b
⚡ new evaluate function (issue #328)
Rezenders Oct 24, 2024
b2c3a35
🔥 rm cart_product and replace_children_param
Rezenders Oct 24, 2024
ee7bb61
[plansys2_executor] use instances in evaluation
Rezenders Oct 25, 2024
67124e5
[evaluate] return true when apply and negate are true
Rezenders Oct 26, 2024
734e4ca
adjust plansys2_executor tests to new evaluate
Rezenders Oct 26, 2024
e7798ce
🎨 fix code style
Rezenders Oct 26, 2024
dd4fdf8
fixes to Expression and Ground getTree
Rezenders Oct 29, 2024
b6c996c
fixes to evaluate and helper functions
Rezenders Oct 29, 2024
bdf7324
[simple_bt_builder] add check_requirement
Rezenders Oct 29, 2024
9fcf27b
🔥 rm comments
Rezenders Oct 29, 2024
3d7cfdd
🔥 rm code commited by mistake
Rezenders Oct 29, 2024
b8c5540
getDerivedPredicates return vector<Derived>
Rezenders Oct 30, 2024
f5c7492
⚡ std::move(param_values) and evaluate return
Rezenders Oct 30, 2024
98f2e00
⚡ improve groundPredicate performance
Rezenders Oct 31, 2024
cb9656a
🚚 move solveAllDerived, solveDerived and groundPredicates to utils
Rezenders Oct 31, 2024
fa04d26
⚡ improve mergeParamsValuesVector performance
Rezenders Oct 31, 2024
1588dc3
✨ add State class to plansys2_core
Rezenders Oct 31, 2024
a3cea82
add state_ : State to ProblemExpert
Rezenders Oct 31, 2024
9e77a1e
[plansys2_msgs] add State.msg and GetState.srv
Rezenders Nov 5, 2024
8ae54f2
[plansys2_core] update State
Rezenders Nov 5, 2024
86cfa64
⚡ use state everywhere and move solveDerived to Utils
Rezenders Nov 5, 2024
8b81258
update tests
Rezenders Nov 5, 2024
3bbb433
commenting out stn_bt_builder in CMakeLists
Rezenders Nov 5, 2024
5ea6e09
[plansys2_executor] use state to evaluate/apply
Rezenders Nov 5, 2024
d950309
[plansys2_terminal] adjust to new getDerivedPredicates
Rezenders Nov 5, 2024
5841810
[#331]apply at_end_effects in get_node_contradict
Rezenders Nov 5, 2024
99065e8
⚡ only solveDerived once when applying effects
Rezenders Nov 6, 2024
2b495bb
add hash and == operator to State
Rezenders Nov 6, 2024
fc74974
[simple_bt_builder] add test for domain with derived
Rezenders Nov 6, 2024
c30e1b5
problem_expert: add derive argument to apply
Rezenders Nov 6, 2024
da7feb9
[simple_bt_builder] add action_state_cache
Rezenders Nov 6, 2024
130963c
add Graph class
Rezenders Nov 13, 2024
c5c3187
add getDerivedPredicateGraph
Rezenders Nov 13, 2024
a283308
solve derived predicates with graph
Rezenders Nov 13, 2024
0dae25a
add checkActionEquality
Rezenders Nov 14, 2024
3a0a90b
add Action class
Rezenders Nov 14, 2024
ab04571
updates to ActionVariant
Rezenders Nov 20, 2024
8a981d7
add ActionVariant and backtraverse to Graph
Rezenders Nov 20, 2024
8312c20
add tests to Graph and State
Rezenders Nov 20, 2024
cd88cda
solve derived predicates with graph algorithm
Rezenders Nov 20, 2024
3243773
create cpp for plansy2_core headers
Rezenders Nov 26, 2024
4256fb3
don´t solve derived predicates with getState
Rezenders Nov 26, 2024
bb6d90f
ActionVariant moved to plansys2_core
Rezenders Nov 26, 2024
19c4c60
move BTBuilder to bt_builder namespace
Rezenders Nov 26, 2024
2a53073
early return to get_node_satisfy
Rezenders Nov 26, 2024
e150cf9
simple_btbuilder: prune & solve derived predicates
Rezenders Nov 26, 2024
00824a5
🎨 fix code style
Rezenders Nov 26, 2024
633d921
add State.hasPredicate(str)
Rezenders Nov 27, 2024
44aad64
increase timeout when calling validate domain service
Rezenders Nov 27, 2024
b2dd5de
fix small bugs
Rezenders Nov 27, 2024
b29a4b1
solving derived predicates in BT action nodes
Rezenders Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plansys2_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ include_directories(include)

add_library(${PROJECT_NAME} SHARED
src/plansys2_core/Utils.cpp
src/plansys2_core/Action.cpp
src/plansys2_core/Graph.cpp
src/plansys2_core/State.cpp
)
ament_target_dependencies(${PROJECT_NAME} ${dependencies})
target_link_libraries(${PROJECT_NAME})

install(DIRECTORY include/
DESTINATION include/
Expand Down
195 changes: 195 additions & 0 deletions plansys2_core/include/plansys2_core/Action.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
// Copyright 2024 Intelligent Robotics Lab
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef PLANSYS2_CORE__ACTION_HPP_
#define PLANSYS2_CORE__ACTION_HPP_

#include <string>
#include <vector>
#include <memory>

#include "plansys2_core/Types.hpp"
#include "plansys2_msgs/msg/action.hpp"
#include "plansys2_msgs/msg/durative_action.hpp"

namespace plansys2
{

class Action : public plansys2_msgs::msg::Action
{
public:
Action()
: plansys2_msgs::msg::Action() {}
Action(const plansys2_msgs::msg::Action & action) // NOLINT(runtime/explicit)
: plansys2_msgs::msg::Action(action)
{
}

bool operator==(const Action & action) const
{
return parser::pddl::checkActionEquality(*this, action);
}
};

class DurativeAction : public plansys2_msgs::msg::DurativeAction
{
public:
DurativeAction()
: plansys2_msgs::msg::DurativeAction() {}
DurativeAction(const plansys2_msgs::msg::DurativeAction & action) // NOLINT(runtime/explicit)
: plansys2_msgs::msg::DurativeAction(action)
{
}

bool operator==(const DurativeAction & action) const
{
return parser::pddl::checkDurativeActionEquality(*this, action);
}
};
} // namespace plansys2

namespace std
{
template<>
struct hash<plansys2::Action>
{
std::size_t operator()(const plansys2::Action & action) const noexcept
{
std::size_t seed = 0;
hash_combine(seed, action.name);
hash_combine(seed, action.parameters.size());

for (const auto & param : action.parameters) {
hash_combine(seed, param.name);
}

for (auto node : action.preconditions.nodes) {
hash_combine(seed, node);
}
for (auto node : action.effects.nodes) {
hash_combine(seed, node);
}

return seed;
}
};

template<>
struct hash<plansys2::DurativeAction>
{
std::size_t operator()(const plansys2::DurativeAction & action) const noexcept
{
std::size_t seed = 0;
hash_combine(seed, action.name);
hash_combine(seed, action.parameters.size());

for (const auto & param : action.parameters) {
hash_combine(seed, param.name);
}

for (auto node : action.at_start_requirements.nodes) {
hash_combine(seed, node);
}
for (auto node : action.over_all_requirements.nodes) {
hash_combine(seed, node);
}
for (auto node : action.at_end_requirements.nodes) {
hash_combine(seed, node);
}
for (auto node : action.at_start_effects.nodes) {
hash_combine(seed, node);
}
for (auto node : action.at_end_effects.nodes) {
hash_combine(seed, node);
}

return seed;
}
};
} // namespace std

namespace plansys2
{

class ActionVariant
{
public:
using ActionVariantType = std::variant<plansys2::Action, plansys2::DurativeAction>;

ActionVariant() {}

template<typename ActionT>
ActionVariant(ActionT action) // NOLINT(runtime/explicit)
: action_(std::make_shared<ActionVariantType>(action))
{
}

template<typename ActionT>
ActionVariant & operator=(ActionT ptr)
{
action_ = std::make_shared<ActionVariantType>(ptr);
return *this;
}

template<typename ActionT>
ActionVariant & operator=(std::shared_ptr<ActionT> ptr)
{
action_ = std::make_shared<ActionVariantType>(*ptr);
return *this;
}

bool operator==(const ActionVariant & other) const {return *action_ == *other.action_;}

size_t hash() const
{
return std::visit(
[](auto && arg) {return std::hash<std::decay_t<decltype(arg)>>{}(arg);}, *action_);
}

std::string get_action_string() const;

std::string get_action_name() const;

std::vector<plansys2_msgs::msg::Param> get_action_params() const;

plansys2_msgs::msg::Tree get_overall_requirements() const;
plansys2_msgs::msg::Tree get_at_start_requirements() const;
plansys2_msgs::msg::Tree get_at_end_requirements() const;
plansys2_msgs::msg::Tree get_at_start_effects() const;
plansys2_msgs::msg::Tree get_at_end_effects() const;

bool is_action() const {return std::holds_alternative<plansys2::Action>(*action_);}

bool is_durative_action() const
{
return std::holds_alternative<plansys2::DurativeAction>(*action_);
}

bool is_empty() const {return action_->index() == std::variant_npos;}

private:
std::shared_ptr<ActionVariantType> action_;
};
} // namespace plansys2

namespace std
{
template<>
struct hash<plansys2::ActionVariant>
{
std::size_t operator()(const plansys2::ActionVariant & av) const noexcept {return av.hash();}
};
} // namespace std

#endif // PLANSYS2_CORE__ACTION_HPP_
Loading