Commit a0bcd273 authored by Alejandro Suarez Hernandez's avatar Alejandro Suarez Hernandez
Browse files

Implemented total effects

parent 741010d5
......@@ -50,6 +50,27 @@ void DeleteEffect::operator()(PlanState& state, const Substitution& sigma) const
}
// TotalEffect's methods
std::string TotalEffect::to_str() const
{
return std::string("forall(") + condition_->to_str() + " -> " + eff_->to_str()
+ ')';
}
void TotalEffect::operator()(PlanState& state, const Substitution& sigma) const
{
// query expects a PlanState::Ptr, so create a non-owning pointer
PlanState::Ptr state_ptr(PlanState::Ptr(), &state);
Query::Ptr q = condition_->bind(state_ptr);
q->reset(sigma);
while (q->next_solution())
{
(*eff_)(state, q->get_solution());
}
}
// EffectV's methods
std::string EffectV::to_str() const
......
#ifndef _LIBIMAGINE_PLANNER_EFFECTS_H_
#define _LIBIMAGINE_PLANNER_EFFECTS_H_
#include "types.h"
#include "queries.h"
namespace imagine_planner
{
......@@ -51,7 +51,7 @@ class DeleteEffect : public Effect
{
public:
typedef std::shared_ptr<DeleteEffect> Ptr;
typedef std::shared_ptr<const DeleteEffect> Ptr;
DeleteEffect(const Predicate& effect) : effect_(effect) {}
......@@ -66,6 +66,27 @@ class DeleteEffect : public Effect
};
class TotalEffect : public Effect
{
public:
typedef std::shared_ptr<const TotalEffect> Ptr;
TotalEffect(const Query::Ptr& condition, const Effect::Ptr& eff) :
condition_(condition), eff_(eff) {}
virtual std::string to_str() const override;
virtual void operator()(PlanState& state,
const Substitution& sigma) const override;
private:
Query::Ptr condition_;
Effect::Ptr eff_;
};
class EffectV : public Effect
{
public:
......
......@@ -72,3 +72,31 @@ BOOST_AUTO_TEST_CASE(effectv_test1)
BOOST_CHECK_EQUAL(state2, goal);
}
BOOST_AUTO_TEST_CASE(total_effect_test1)
{
TermFactory T;
PlanState state({Predicate("p","a","b"), Predicate("p","a","c"),
Predicate("p","d","a"), Predicate("r", "c")});
PlanState goal({Predicate("p","a","b"), Predicate("p","a","c"),
Predicate("p","d","a"), Predicate("q", "b"),
Predicate("q", "c")});
PlanState goal_({Predicate("p","a","b"), Predicate("p","a","c"),
Predicate("p","d","a"), Predicate("q", "b"),
Predicate("q", "c"), Predicate("q", "a")});
INFO(state);
auto q1 = std::make_shared<SimpleQuery>(Predicate("p", "X", "Y"));
Effect::Ptr ef1 = std::make_shared<DeleteEffect>(Predicate("r", "Y"));
Effect::Ptr ef2 = std::make_shared<AddEffect>(Predicate("q", "Y"));
auto ef3 = std::make_shared<EffectV>(std::vector<Effect::Ptr>{ef1, ef2});
TotalEffect ef4(q1, ef3);
INFO("ef4: " << ef4);
PlanState state2(state);
PlanState state3(state);
ef4(state2, Substitution{{"X", T("a")}});
ef4(state3, Substitution());
//ef1(state2, Substitution({{"X", T("a")},
//{"Y", T(1.0+5e-10)}}));
BOOST_CHECK_EQUAL(state2, goal);
BOOST_CHECK_EQUAL(state3, goal_);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment