-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
194 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (C) 2023 Dominik Drexler and Simon Stahlberg and Simon Stahlberg | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*< | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef LOKI_INCLUDE_LOKI_PDDL_AXIOM_HPP_ | ||
#define LOKI_INCLUDE_LOKI_PDDL_AXIOM_HPP_ | ||
|
||
#include "loki/pddl/base.hpp" | ||
#include "loki/pddl/declarations.hpp" | ||
#include "loki/pddl/factory.hpp" | ||
|
||
#include <string> | ||
|
||
namespace loki::pddl | ||
{ | ||
class AxiomImpl : public Base<AxiomImpl> | ||
{ | ||
private: | ||
ParameterList m_parameters; | ||
Atom m_atom; | ||
Condition m_condition; | ||
|
||
AxiomImpl(int identifier, ParameterList parameters, Atom atom, Condition condition); | ||
|
||
// Give access to the constructor. | ||
friend class PDDLFactory<AxiomImpl, Hash<AxiomImpl*>, EqualTo<AxiomImpl*>>; | ||
|
||
/// @brief Test for structural equivalence | ||
bool is_structurally_equivalent_to_impl(const AxiomImpl& other) const; | ||
size_t hash_impl() const; | ||
void str_impl(std::ostream& out, const FormattingOptions& options) const; | ||
|
||
// Give access to the private interface implementations. | ||
friend class Base<AxiomImpl>; | ||
|
||
public: | ||
const ParameterList& get_parameters() const; | ||
const Atom& get_atom() const; | ||
const Condition& get_condition() const; | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (C) 2023 Dominik Drexler and Simon Stahlberg and Simon Stahlberg | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "loki/pddl/axiom.hpp" | ||
|
||
#include "loki/pddl/atom.hpp" | ||
#include "loki/pddl/conditions.hpp" | ||
#include "loki/pddl/parameter.hpp" | ||
#include "loki/pddl/predicate.hpp" | ||
#include "loki/pddl/visitors.hpp" | ||
#include "loki/utils/collections.hpp" | ||
#include "loki/utils/hash.hpp" | ||
|
||
namespace loki::pddl | ||
{ | ||
AxiomImpl::AxiomImpl(int identifier, ParameterList parameters, Atom atom, Condition condition) : | ||
Base(identifier), | ||
m_parameters(std::move(parameters)), | ||
m_atom(std::move(atom)), | ||
m_condition(std::move(condition)) | ||
{ | ||
// TODO (Dominik): must ensure that all parameters are used. Add assertion maybe? | ||
} | ||
|
||
bool AxiomImpl::is_structurally_equivalent_to_impl(const AxiomImpl& other) const | ||
{ | ||
return (m_parameters == other.m_parameters) && (m_atom == other.m_atom) && (m_condition == other.m_condition); | ||
} | ||
|
||
size_t AxiomImpl::hash_impl() const { return hash_combine(hash_container(m_parameters), m_atom, m_condition); } | ||
|
||
void AxiomImpl::str_impl(std::ostream& out, const FormattingOptions& options) const | ||
{ | ||
// Not PDDL language specific. Our own definition of how we want to print it. | ||
auto nested_options = FormattingOptions { options.indent + options.add_indent, options.add_indent }; | ||
out << std::string(options.indent, ' ') << "(:axiom" | ||
<< "\n"; | ||
|
||
out << std::string(nested_options.indent, ' ') << ":vars ("; | ||
for (size_t i = 0; i < m_parameters.size(); ++i) | ||
{ | ||
if (i != 0) | ||
out << " "; | ||
m_parameters[i]->str(out, options); | ||
} | ||
out << ")\n"; | ||
|
||
out << std::string(nested_options.indent, ' ') << ":context ("; | ||
std::visit(StringifyVisitor(out, nested_options), *m_condition); | ||
out << ")\n"; | ||
|
||
out << std::string(nested_options.indent, ' ') << ":implies (" << *m_atom << ")\n"; | ||
|
||
out << ")\n"; | ||
} | ||
|
||
const ParameterList& AxiomImpl::get_parameters() const { return m_parameters; } | ||
|
||
const Atom& AxiomImpl::get_atom() const { return m_atom; } | ||
|
||
const Condition& AxiomImpl::get_condition() const { return m_condition; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.