Skip to content

Commit

Permalink
refactor namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Apr 13, 2024
1 parent 8d2d66c commit 696697f
Show file tree
Hide file tree
Showing 97 changed files with 1,062 additions and 1,031 deletions.
14 changes: 7 additions & 7 deletions benchmarks/iterate_atoms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ namespace loki::benchmarks
struct AtomAccessResult
{
int atom_identifier;
loki::pddl::Predicate atom_predicate;
loki::pddl::TermList atom_terms;
loki::Predicate atom_predicate;
loki::TermList atom_terms;
};

static AtomAccessResult access_atom_data(const loki::pddl::Atom& atom)
static AtomAccessResult access_atom_data(const loki::Atom& atom)
{
const auto atom_identifier = atom->get_identifier();
const auto atom_predicate = atom->get_predicate();
auto atom_terms = loki::pddl::TermList();
auto atom_terms = loki::TermList();
for (const auto& term : atom->get_terms())
{
atom_terms.push_back(term);
Expand Down Expand Up @@ -70,7 +70,7 @@ static void BM_IterateAtoms(benchmark::State& state)
}
}

state.SetBytesProcessed(state.iterations() * atoms.size() * sizeof(loki::pddl::ActionImpl));
state.SetBytesProcessed(state.iterations() * atoms.size() * sizeof(loki::ActionImpl));
}

static void BM_RandomlyIterateAtoms(benchmark::State& state)
Expand Down Expand Up @@ -98,13 +98,13 @@ static void BM_RandomlyIterateAtoms(benchmark::State& state)
}
}

state.SetBytesProcessed(state.iterations() * atoms.size() * sizeof(loki::pddl::ActionImpl));
state.SetBytesProcessed(state.iterations() * atoms.size() * sizeof(loki::ActionImpl));
}

}

// Tetralith has Intel Xeon Gold 6130 with L1=512KB, L2=8192KB, L3=22528KB
// sizeof(loki::pddl::AtomImpl)=56 => 9142 fit into L1, 146285 fit into L2, 402285 fit into L3
// sizeof(loki::AtomImpl)=56 => 9142 fit into L1, 146285 fit into L2, 402285 fit into L3

// we just choose some reasonable numbers that can be observed in planning tasks
BENCHMARK(loki::benchmarks::BM_IterateAtoms)->Arg(100); // small tasks
Expand Down
55 changes: 23 additions & 32 deletions benchmarks/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,47 +1,38 @@
#include "utils.hpp"

namespace loki::benchmarks {
namespace loki::benchmarks
{

loki::pddl::AtomList create_atoms(
size_t num_objects,
size_t num_predicates,
loki::PDDLFactories& factories) {
loki::AtomList create_atoms(size_t num_objects, size_t num_predicates, loki::PDDLFactories& factories)
{
// Create num_objects-many objects with name object_1,...,object_<num_objects>
auto objects = loki::pddl::ObjectList();
for (size_t i = 1; i <= num_objects; ++i) {
objects.push_back(factories.objects.get_or_create<loki::pddl::ObjectImpl>(
("object_" + std::to_string(i)), pddl::TypeList())
);
auto objects = loki::ObjectList();
for (size_t i = 1; i <= num_objects; ++i)
{
objects.push_back(factories.get_or_create_object(("object_" + std::to_string(i)), TypeList()));
}

// Create num_predicates-many binary predicates with name predicate_1,...,predicate_<num_predicates>
auto parameters = loki::pddl::ParameterList{
factories.parameters.get_or_create<loki::pddl::ParameterImpl>(
factories.variables.get_or_create<loki::pddl::VariableImpl>("?variable_left"),
loki::pddl::TypeList{}),
factories.parameters.get_or_create<loki::pddl::ParameterImpl>(
factories.variables.get_or_create<loki::pddl::VariableImpl>("?variable_right"),
loki::pddl::TypeList{})
};
auto parameters = loki::ParameterList { factories.get_or_create_parameter(factories.get_or_create_variable("?variable_left"), loki::TypeList {}),
factories.get_or_create_parameter(factories.get_or_create_variable("?variable_right"), loki::TypeList {}) };

auto predicates = loki::pddl::PredicateList();
for (size_t i = 1; i <= num_predicates; ++i) {
predicates.push_back(factories.predicates.get_or_create<loki::pddl::PredicateImpl>(
("predicate_" + std::to_string(i)),
parameters));
auto predicates = loki::PredicateList();
for (size_t i = 1; i <= num_predicates; ++i)
{
predicates.push_back(factories.get_or_create_predicate(("predicate_" + std::to_string(i)), parameters));
}

auto atoms = loki::pddl::AtomList();
auto atoms = loki::AtomList();
// Construct num_objects^2 * num_predicates many atoms
for (const auto& predicate : predicates) {
for (const auto& object_left : objects) {
for (const auto& object_right : objects) {
atoms.push_back(factories.atoms.get_or_create<loki::pddl::AtomImpl>(
for (const auto& predicate : predicates)
{
for (const auto& object_left : objects)
{
for (const auto& object_right : objects)
{
atoms.push_back(factories.get_or_create_atom(
predicate,
loki::pddl::TermList{
factories.terms.get_or_create<loki::pddl::TermObjectImpl>(object_left),
factories.terms.get_or_create<loki::pddl::TermObjectImpl>(object_right)
}));
loki::TermList { factories.get_or_create_term_object(object_left), factories.get_or_create_term_object(object_right) }));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace loki::benchmarks
{

extern loki::pddl::AtomList create_atoms(size_t num_objects, size_t num_predicates, PDDLFactories& factories);
extern loki::AtomList create_atoms(size_t num_objects, size_t num_predicates, PDDLFactories& factories);
}

#endif
8 changes: 4 additions & 4 deletions examples/position_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ struct TestUnsupportedAndConditionVisitor
}

/// @brief For inner nodes we need to recursively call the visitor
void operator()(const loki::pddl::ConditionOrImpl& node)
void operator()(const loki::ConditionOrImpl& node)
{
for (const auto& child_node : node.get_conditions())
{
// We call front() to obtain the first occurence.
const auto child_position = position_cache.get<loki::pddl::ConditionImpl>(child_node).front();
const auto child_position = position_cache.get<loki::ConditionImpl>(child_node).front();
std::visit(TestUnsupportedAndConditionVisitor(child_position, position_cache, error_handler), *child_node);
}
}

/// @brief For the unsupported And-Condition,
/// we print an clang-style error message and throw an exception.
void operator()(const loki::pddl::ConditionAndImpl&)
void operator()(const loki::ConditionAndImpl&)
{
std::cout << error_handler(position, "Your awesome error message.") << std::endl;
throw std::runtime_error("Unexpected And-Condition.");
Expand All @@ -80,7 +80,7 @@ int main()
continue;
}
// We call front() to obtain the first occurence.
auto condition_position = position_cache.get<loki::pddl::ConditionImpl>(condition.value()).front();
auto condition_position = position_cache.get<loki::ConditionImpl>(condition.value()).front();
std::visit(TestUnsupportedAndConditionVisitor(condition_position, position_cache, error_handler), *condition.value());
}

Expand Down
2 changes: 1 addition & 1 deletion examples/undefined_behavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/// @brief This example illustrates incorrect ownership handling
int main()
{
auto domain = loki::pddl::Domain { nullptr };
auto domain = loki::Domain { nullptr };
{
// Parse the domain
auto domain_parser = loki::DomainParser("data/gripper/domain.pddl");
Expand Down
8 changes: 4 additions & 4 deletions include/loki/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DomainParser
std::unique_ptr<ScopeStack> m_scopes;

// Parsed result
pddl::Domain m_domain;
Domain m_domain;

friend class ProblemParser;

Expand All @@ -54,7 +54,7 @@ class DomainParser
const PDDLPositionCache& get_position_cache() const;

/// @brief Get the parsed domain.
const pddl::Domain& get_domain() const;
const Domain& get_domain() const;
};

class ProblemParser
Expand All @@ -70,7 +70,7 @@ class ProblemParser
std::unique_ptr<ScopeStack> m_scopes;

// Parsed result
pddl::Problem m_problem;
Problem m_problem;

public:
explicit ProblemParser(const fs::path& file_path, DomainParser& domain_parser);
Expand All @@ -79,7 +79,7 @@ class ProblemParser
const PDDLPositionCache& get_position_cache() const;

/// @brief Get the parsed problem.
const pddl::Problem& get_problem() const;
const Problem& get_problem() const;
};

}
Expand Down
4 changes: 2 additions & 2 deletions include/loki/pddl/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <optional>
#include <string>

namespace loki::pddl
namespace loki
{
class ActionImpl : public Base<ActionImpl>
{
Expand All @@ -38,7 +38,7 @@ class ActionImpl : public Base<ActionImpl>
ActionImpl(int identifier, std::string name, ParameterList parameters, std::optional<Condition> condition, std::optional<Effect> effect);

// Give access to the constructor.
friend class loki::PDDLFactory<ActionImpl, loki::Hash<ActionImpl*>, loki::EqualTo<ActionImpl*>>;
friend class PDDLFactory<ActionImpl, Hash<ActionImpl*>, EqualTo<ActionImpl*>>;

/// @brief Test for structural equivalence
bool is_structurally_equivalent_to_impl(const ActionImpl& other) const;
Expand Down
4 changes: 2 additions & 2 deletions include/loki/pddl/atom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include <string>

namespace loki::pddl
namespace loki
{
class AtomImpl : public Base<AtomImpl>
{
Expand All @@ -35,7 +35,7 @@ class AtomImpl : public Base<AtomImpl>
AtomImpl(int identifier, Predicate predicate, TermList terms);

// Give access to the constructor.
friend class loki::PDDLFactory<AtomImpl, loki::Hash<AtomImpl*>, loki::EqualTo<AtomImpl*>>;
friend class PDDLFactory<AtomImpl, Hash<AtomImpl*>, EqualTo<AtomImpl*>>;

/// @brief Test for semantic equivalence
bool is_structurally_equivalent_to_impl(const AtomImpl& other) const;
Expand Down
8 changes: 1 addition & 7 deletions include/loki/pddl/axiom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@

namespace loki
{
template<typename HolderType, typename Hash, typename EqualTo>
class PDDLFactory;
}

namespace loki::pddl
{
class AxiomImpl : public Base<AxiomImpl>
{
private:
Expand All @@ -41,7 +35,7 @@ class AxiomImpl : public Base<AxiomImpl>
AxiomImpl(int identifier, Literal literal, Condition condition);

// Give access to the constructor.
friend class loki::PDDLFactory<AxiomImpl, loki::Hash<AxiomImpl*>, loki::EqualTo<AxiomImpl*>>;
friend class PDDLFactory<AxiomImpl, Hash<AxiomImpl*>, EqualTo<AxiomImpl*>>;

/// @brief Test for structural equivalence
bool is_structurally_equivalent_to_impl(const AxiomImpl& other) const;
Expand Down
20 changes: 7 additions & 13 deletions include/loki/pddl/conditions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@

namespace loki
{
template<typename HolderType, typename Hash, typename EqualTo>
class PDDLFactory;
}

namespace loki::pddl
{

/* Literal */
class ConditionLiteralImpl : public Base<ConditionLiteralImpl>
Expand All @@ -42,7 +36,7 @@ class ConditionLiteralImpl : public Base<ConditionLiteralImpl>
ConditionLiteralImpl(int identifier, Literal literal);

// Give access to the constructor.
friend class loki::PDDLFactory<ConditionImpl, loki::Hash<ConditionImpl*>, loki::EqualTo<ConditionImpl*>>;
friend class PDDLFactory<ConditionImpl, Hash<ConditionImpl*>, EqualTo<ConditionImpl*>>;

bool is_structurally_equivalent_to_impl(const ConditionLiteralImpl& other) const;
size_t hash_impl() const;
Expand All @@ -64,7 +58,7 @@ class ConditionAndImpl : public Base<ConditionAndImpl>
ConditionAndImpl(int identifier, ConditionList conditions);

// Give access to the constructor.
friend class loki::PDDLFactory<ConditionImpl, loki::Hash<ConditionImpl*>, loki::EqualTo<ConditionImpl*>>;
friend class PDDLFactory<ConditionImpl, Hash<ConditionImpl*>, EqualTo<ConditionImpl*>>;

bool is_structurally_equivalent_to_impl(const ConditionAndImpl& other) const;
size_t hash_impl() const;
Expand All @@ -86,7 +80,7 @@ class ConditionOrImpl : public Base<ConditionOrImpl>
ConditionOrImpl(int identifier, ConditionList conditions);

// Give access to the constructor.
friend class loki::PDDLFactory<ConditionImpl, loki::Hash<ConditionImpl*>, loki::EqualTo<ConditionImpl*>>;
friend class PDDLFactory<ConditionImpl, Hash<ConditionImpl*>, EqualTo<ConditionImpl*>>;

bool is_structurally_equivalent_to_impl(const ConditionOrImpl& other) const;
size_t hash_impl() const;
Expand All @@ -108,7 +102,7 @@ class ConditionNotImpl : public Base<ConditionNotImpl>
ConditionNotImpl(int identifier, Condition condition);

// Give access to the constructor.
friend class loki::PDDLFactory<ConditionImpl, loki::Hash<ConditionImpl*>, loki::EqualTo<ConditionImpl*>>;
friend class PDDLFactory<ConditionImpl, Hash<ConditionImpl*>, EqualTo<ConditionImpl*>>;

bool is_structurally_equivalent_to_impl(const ConditionNotImpl& other) const;
size_t hash_impl() const;
Expand All @@ -131,7 +125,7 @@ class ConditionImplyImpl : public Base<ConditionNotImpl>
ConditionImplyImpl(int identifier, Condition condition_left, Condition condition_right);

// Give access to the constructor.
friend class loki::PDDLFactory<ConditionImpl, loki::Hash<ConditionImpl*>, loki::EqualTo<ConditionImpl*>>;
friend class PDDLFactory<ConditionImpl, Hash<ConditionImpl*>, EqualTo<ConditionImpl*>>;

bool is_structurally_equivalent_to_impl(const ConditionImplyImpl& other) const;
size_t hash_impl() const;
Expand All @@ -155,7 +149,7 @@ class ConditionExistsImpl : public Base<ConditionExistsImpl>
ConditionExistsImpl(int identifier, ParameterList parameters, Condition condition);

// Give access to the constructor.
friend class loki::PDDLFactory<ConditionImpl, loki::Hash<ConditionImpl*>, loki::EqualTo<ConditionImpl*>>;
friend class PDDLFactory<ConditionImpl, Hash<ConditionImpl*>, EqualTo<ConditionImpl*>>;

bool is_structurally_equivalent_to_impl(const ConditionExistsImpl& other) const;
size_t hash_impl() const;
Expand All @@ -179,7 +173,7 @@ class ConditionForallImpl : public Base<ConditionForallImpl>
ConditionForallImpl(int identifier, ParameterList parameters, Condition condition);

// Give access to the constructor.
friend class loki::PDDLFactory<ConditionImpl, loki::Hash<ConditionImpl*>, loki::EqualTo<ConditionImpl*>>;
friend class PDDLFactory<ConditionImpl, Hash<ConditionImpl*>, EqualTo<ConditionImpl*>>;

bool is_structurally_equivalent_to_impl(const ConditionForallImpl& other) const;
size_t hash_impl() const;
Expand Down
4 changes: 2 additions & 2 deletions include/loki/pddl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ struct Context
// For checking that certain PDDL objects were referenced at least once
ReferencedPDDLObjects references;
// For convenience, to avoid an additional parameter during semantic parsing
pddl::Requirements requirements;
std::unordered_set<pddl::Predicate> derived_predicates;
Requirements requirements;
std::unordered_set<Predicate> derived_predicates;

Context(PDDLFactories& factories_, PDDLPositionCache& positions_, ScopeStack& scopes_) :
factories(factories_),
Expand Down
4 changes: 0 additions & 4 deletions include/loki/pddl/declarations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ namespace loki
*/
template<typename T>
using PDDLElement = const T*;
}

namespace loki::pddl
{

/**
* Domain
Expand Down
8 changes: 1 addition & 7 deletions include/loki/pddl/domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@

namespace loki
{
template<typename HolderType, typename Hash, typename EqualTo>
class PDDLFactory;
}

namespace loki::pddl
{

class DomainImpl : public Base<DomainImpl>
{
Expand All @@ -59,7 +53,7 @@ class DomainImpl : public Base<DomainImpl>
AxiomList axioms);

// Give access to the constructor.
friend class loki::PDDLFactory<DomainImpl, loki::Hash<DomainImpl*>, loki::EqualTo<DomainImpl*>>;
friend class PDDLFactory<DomainImpl, Hash<DomainImpl*>, EqualTo<DomainImpl*>>;

/// @brief Test for structural equivalence
bool is_structurally_equivalent_to_impl(const DomainImpl& other) const;
Expand Down
Loading

0 comments on commit 696697f

Please sign in to comment.