Skip to content

Commit

Permalink
added explicitly how many of the axiom parameters are used to synthes…
Browse files Browse the repository at this point in the history
…ize the atom in the heado
  • Loading branch information
drexlerd committed May 28, 2024
1 parent ef014c3 commit 596a4ea
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
9 changes: 8 additions & 1 deletion include/loki/details/pddl/axiom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ class AxiomImpl : public Base<AxiomImpl>
ParameterList m_parameters;
Condition m_condition;

AxiomImpl(size_t identifier, std::string derived_predicate_name, ParameterList parameters, Condition condition);
// Since translations might add additional parameters,
// we allow keeping track of parameters that are needed
// to ground the atom in the head of the axiom
size_t m_num_parameters_to_ground_head;

AxiomImpl(size_t identifier, std::string derived_predicate_name, ParameterList parameters, Condition condition, size_t num_parameters_to_ground_head);

// Give access to the constructor.
friend class PDDLFactory<AxiomImpl, Hash<AxiomImpl*>, EqualTo<AxiomImpl*>>;
Expand All @@ -50,6 +55,8 @@ class AxiomImpl : public Base<AxiomImpl>
const std::string& get_derived_predicate_name() const;
const ParameterList& get_parameters() const;
const Condition& get_condition() const;

size_t get_num_parameters_to_ground_head() const;
};

}
Expand Down
4 changes: 2 additions & 2 deletions include/loki/details/pddl/factories.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ class PDDLFactories
return actions.get_or_create<ActionImpl>(std::move(name), std::move(original_arity), std::move(parameters), std::move(condition), std::move(effect));
}

Axiom get_or_create_axiom(std::string derived_predicate_name, ParameterList parameters, Condition condition)
Axiom get_or_create_axiom(std::string derived_predicate_name, ParameterList parameters, Condition condition, size_t num_parameters_to_ground_head)
{
return axioms.get_or_create<AxiomImpl>(std::move(derived_predicate_name), std::move(parameters), std::move(condition));
return axioms.get_or_create<AxiomImpl>(std::move(derived_predicate_name), std::move(parameters), std::move(condition), num_parameters_to_ground_head);
}

OptimizationMetric get_or_create_optimization_metric(OptimizationMetricEnum metric, FunctionExpression function_expression)
Expand Down
11 changes: 9 additions & 2 deletions src/pddl/axiom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@

namespace loki
{
AxiomImpl::AxiomImpl(size_t identifier, std::string derived_predicate_name, ParameterList parameters, Condition condition) :
AxiomImpl::AxiomImpl(size_t identifier,
std::string derived_predicate_name,
ParameterList parameters,
Condition condition,
size_t num_parameters_to_ground_head) :
Base(identifier),
m_derived_predicate_name(std::move(derived_predicate_name)),
m_parameters(std::move(parameters)),
m_condition(std::move(condition))
m_condition(std::move(condition)),
m_num_parameters_to_ground_head(num_parameters_to_ground_head)
{
}

Expand Down Expand Up @@ -68,4 +73,6 @@ const Condition& AxiomImpl::get_condition() const { return m_condition; }

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

size_t AxiomImpl::get_num_parameters_to_ground_head() const { return m_num_parameters_to_ground_head; }

}
21 changes: 17 additions & 4 deletions src/pddl/parser/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,26 @@ Axiom parse(const ast::Axiom& node, Context& context)
}

auto result_parameters = ParameterList {};
// Create parameters for head.
for (const auto variable : variables)
{
const auto base_types = parameter_variable_to_types.count(variable) ? parameter_variable_to_types.at(variable) :
TypeList { context.factories.get_or_create_type("object", TypeList {}) };
result_parameters.push_back(context.factories.get_or_create_parameter(variable, base_types));
if (parameter_variable_to_types.count(variable))
{
const auto base_types = parameter_variable_to_types.at(variable);
result_parameters.push_back(context.factories.get_or_create_parameter(variable, base_types));
}
}
const auto num_parameters_to_ground_head = result_parameters.size();
// Create parameters for remaining free variables
for (const auto variable : variables)
{
if (!parameter_variable_to_types.count(variable))
{
const auto base_types = TypeList { context.factories.get_or_create_type("object", TypeList {}) };
result_parameters.push_back(context.factories.get_or_create_parameter(variable, base_types));
}
}
const auto axiom = context.factories.get_or_create_axiom(predicate_name, result_parameters, condition);
const auto axiom = context.factories.get_or_create_axiom(predicate_name, result_parameters, condition, num_parameters_to_ground_head);
context.positions.push_back(axiom, node);
return axiom;
}
Expand Down

0 comments on commit 596a4ea

Please sign in to comment.