Skip to content

Commit

Permalink
simplified axiom
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Feb 5, 2025
1 parent a571952 commit 8568df1
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 26 deletions.
18 changes: 5 additions & 13 deletions include/loki/details/pddl/axiom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ class AxiomImpl
{
private:
size_t m_index;
ParameterList m_parameters;
Predicate m_derived_predicate; ///< the predicate from the introduced :derived-predicates section
Literal m_subtyped_literal; ///< the axiom may use subtypes
ParameterList m_parameters; // the updated parameters which might contain subtypes.
Literal m_literal;
Condition m_condition;

AxiomImpl(size_t index, ParameterList parameters, Predicate derived_predicate, Literal subtyped_literal, Condition condition);
AxiomImpl(size_t index, ParameterList parameters, Literal subtyped_literal, Condition condition);

// Give access to the constructor.
template<typename T, typename Hash, typename EqualTo>
Expand All @@ -48,17 +47,10 @@ class AxiomImpl

size_t get_index() const;
const ParameterList& get_parameters() const;
const Predicate& get_derived_predicate() const;
const Literal& get_subtyped_literal() const;
const Literal& get_literal() const;
const Condition& get_condition() const;

auto identifying_members() const
{
return std::forward_as_tuple(std::as_const(m_parameters),
std::as_const(m_derived_predicate),
std::as_const(m_subtyped_literal),
std::as_const(m_condition));
}
auto identifying_members() const { return std::forward_as_tuple(std::as_const(m_parameters), std::as_const(m_literal), std::as_const(m_condition)); }
};

extern std::ostream& operator<<(std::ostream& out, const AxiomImpl& element);
Expand Down
2 changes: 1 addition & 1 deletion include/loki/details/pddl/repositories.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class PDDLRepositories
Action
get_or_create_action(std::string name, size_t original_arity, ParameterList parameters, std::optional<Condition> condition, std::optional<Effect> effect);

Axiom get_or_create_axiom(ParameterList parameters, Predicate derived_predicate, Literal subtyped_literal, Condition condition);
Axiom get_or_create_axiom(ParameterList parameters, Literal subtyped_literal, Condition condition);

OptimizationMetric get_or_create_optimization_metric(OptimizationMetricEnum metric, FunctionExpression function_expression);

Expand Down
9 changes: 3 additions & 6 deletions src/pddl/axiom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@

namespace loki
{
AxiomImpl::AxiomImpl(size_t index, ParameterList parameters, Predicate derived_predicate, Literal subtyped_literal, Condition condition) :
AxiomImpl::AxiomImpl(size_t index, ParameterList parameters, Literal literal, Condition condition) :
m_index(index),
m_parameters(std::move(parameters)),
m_derived_predicate(std::move(derived_predicate)),
m_subtyped_literal(std::move(subtyped_literal)),
m_literal(std::move(literal)),
m_condition(std::move(condition))
{
}
Expand All @@ -39,9 +38,7 @@ size_t AxiomImpl::get_index() const { return m_index; }

const ParameterList& AxiomImpl::get_parameters() const { return m_parameters; }

const Predicate& AxiomImpl::get_derived_predicate() const { return m_derived_predicate; }

const Literal& AxiomImpl::get_subtyped_literal() const { return m_subtyped_literal; }
const Literal& AxiomImpl::get_literal() const { return m_literal; }

const Condition& AxiomImpl::get_condition() const { return m_condition; }

Expand Down
4 changes: 2 additions & 2 deletions src/pddl/formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ void PDDLFormatter::write(const AtomImpl& element, std::ostream& out)

void PDDLFormatter::write(const AxiomImpl& element, std::ostream& out)
{
out << std::string(m_indent, ' ') << "(:derived " << element.get_derived_predicate()->get_name();
for (size_t i = 0; i < element.get_subtyped_literal()->get_atom()->get_terms().size(); ++i)
out << std::string(m_indent, ' ') << "(:derived " << element.get_literal()->get_atom()->get_predicate()->get_name();
for (size_t i = 0; i < element.get_literal()->get_atom()->get_terms().size(); ++i)
{
out << " ";
write(*element.get_parameters()[i], out);
Expand Down
2 changes: 1 addition & 1 deletion src/pddl/parser/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Axiom parse(const ast::Axiom& node, Context& context)
parameters.push_back(context.factories.get_or_create_parameter(variable, base_types));
}

const auto axiom = context.factories.get_or_create_axiom(parameters, predicate, literal, condition);
const auto axiom = context.factories.get_or_create_axiom(parameters, literal, condition);
context.positions.push_back(axiom, node);
return axiom;
}
Expand Down
5 changes: 2 additions & 3 deletions src/pddl/repositories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,9 @@ Action PDDLRepositories::get_or_create_action(std::string name,
.get_or_create(std::move(name), std::move(original_arity), std::move(parameters), std::move(condition), std::move(effect));
}

Axiom PDDLRepositories::get_or_create_axiom(ParameterList parameters, Predicate derived_predicate, Literal subtyped_literal, Condition condition)
Axiom PDDLRepositories::get_or_create_axiom(ParameterList parameters, Literal subtyped_literal, Condition condition)
{
return boost::hana::at_key(m_repositories, boost::hana::type<AxiomImpl> {})
.get_or_create(std::move(parameters), derived_predicate, subtyped_literal, condition);
return boost::hana::at_key(m_repositories, boost::hana::type<AxiomImpl> {}).get_or_create(std::move(parameters), subtyped_literal, condition);
}

OptimizationMetric PDDLRepositories::get_or_create_optimization_metric(OptimizationMetricEnum metric, FunctionExpression function_expression)
Expand Down

0 comments on commit 8568df1

Please sign in to comment.